KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > cheatsheet > comp > CompCSTask


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.core.cheatsheet.comp;
13
14 import java.io.PrintWriter JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.ListIterator JavaDoc;
19
20 import org.eclipse.pde.core.IModelChangedEvent;
21 import org.eclipse.pde.internal.core.XMLPrintHandler;
22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory;
24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam;
26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask;
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * CompCSTask
31  *
32  */

33 public class CompCSTask extends CompCSTaskObject implements ICompCSTask {
34
35     private ArrayList JavaDoc fFieldParams;
36     
37     /**
38      *
39      */

40     private static final long serialVersionUID = 1L;
41
42     /**
43      * @param model
44      * @param parent
45      */

46     public CompCSTask(ICompCSModel model, ICompCSObject parent) {
47         super(model, parent);
48         reset();
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSTaskObject#getChildren()
53      */

54     public List JavaDoc getChildren() {
55         return new ArrayList JavaDoc();
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSTaskObject#getName()
60      */

61     public String JavaDoc getName() {
62         return fFieldName;
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSTaskObject#getType()
67      */

68     public int getType() {
69         return TYPE_TASK;
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getElement()
74      */

75     public String JavaDoc getElement() {
76         return ELEMENT_TASK;
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
81      */

82     protected void parseElement(Element JavaDoc element) {
83         super.parseElement(element);
84         String JavaDoc name = element.getNodeName();
85         ICompCSModelFactory factory = getModel().getFactory();
86         
87         if (name.equals(ELEMENT_PARAM)) {
88             // Process param element
89
ICompCSParam param = factory.createCompCSParam(this);
90             fFieldParams.add(param);
91             param.parse(element);
92         }
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask#addFieldParam(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam)
97      */

98     public void addFieldParam(ICompCSParam param) {
99         fFieldParams.add(param);
100         if (isEditable()) {
101             fireStructureChanged(param, IModelChangedEvent.INSERT);
102         }
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask#getFieldParams()
107      */

108     public ICompCSParam[] getFieldParams() {
109         return (ICompCSParam[]) fFieldParams
110         .toArray(new ICompCSParam[fFieldParams.size()]);
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask#removeFieldParam(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam)
115      */

116     public void removeFieldParam(ICompCSParam param) {
117         fFieldParams.remove(param);
118         if (isEditable()) {
119             fireStructureChanged(param, IModelChangedEvent.REMOVE);
120         }
121     }
122
123     /* (non-Javadoc)
124      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSTaskObject#reset()
125      */

126     public void reset() {
127         super.reset();
128         
129         fFieldParams = new ArrayList JavaDoc();
130     }
131     
132     /* (non-Javadoc)
133      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSTaskObject#writeElements(java.lang.String, java.io.PrintWriter)
134      */

135     protected void writeElements(String JavaDoc indent, PrintWriter JavaDoc writer) {
136         super.writeElements(indent, writer);
137         String JavaDoc newIndent = indent + XMLPrintHandler.XML_INDENT;
138         // Print param elements
139
Iterator JavaDoc iterator = fFieldParams.iterator();
140         while (iterator.hasNext()) {
141             ICompCSParam param = (ICompCSParam)iterator.next();
142             param.write(newIndent, writer);
143         }
144     }
145
146     /* (non-Javadoc)
147      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask#hasFieldParams()
148      */

149     public boolean hasFieldParams() {
150         if (fFieldParams.isEmpty()) {
151             return false;
152         }
153         return true;
154     }
155
156     /* (non-Javadoc)
157      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask#getFieldParam(java.lang.String)
158      */

159     public ICompCSParam getFieldParam(String JavaDoc name) {
160         if (fFieldParams.isEmpty()) {
161             return null;
162         }
163         ListIterator JavaDoc iterator = fFieldParams.listIterator();
164         while (iterator.hasNext()) {
165             ICompCSParam parameter = (ICompCSParam)iterator.next();
166             if (parameter.getFieldName().equals(name)) {
167                 return parameter;
168             }
169         }
170         return null;
171     }
172 }
173
Popular Tags