KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
19 import org.eclipse.pde.core.IModelChangedEvent;
20 import org.eclipse.pde.internal.core.XMLPrintHandler;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDependency;
22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro;
23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory;
25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion;
27 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject;
28 import org.eclipse.pde.internal.core.util.PDETextHelper;
29 import org.w3c.dom.Element JavaDoc;
30 import org.w3c.dom.Text JavaDoc;
31
32 /**
33  * CompCSTaskObject
34  *
35  */

36 public abstract class CompCSTaskObject extends CompCSObject implements
37         ICompCSTaskObject {
38
39     protected String JavaDoc fFieldId;
40     
41     protected String JavaDoc fFieldKind;
42     
43     protected ICompCSIntro fFieldIntro;
44     
45     protected ICompCSOnCompletion fFieldOnCompletion;
46     
47     protected String JavaDoc fFieldName;
48     
49     protected boolean fFieldSkip;
50     
51     protected ArrayList JavaDoc fFieldDependencies;
52     
53     /**
54      * @param model
55      * @param parent
56      */

57     public CompCSTaskObject(ICompCSModel model, ICompCSObject parent) {
58         super(model, parent);
59         // Reset called by child class
60
}
61
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getChildren()
64      */

65     public abstract List JavaDoc getChildren();
66
67     /* (non-Javadoc)
68      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getName()
69      */

70     public abstract String JavaDoc getName();
71
72     /* (non-Javadoc)
73      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getType()
74      */

75     public abstract int getType();
76
77     /* (non-Javadoc)
78      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#reset()
79      */

80     public void reset() {
81         fFieldId = null;
82         fFieldKind = null;
83         fFieldIntro = null;
84         fFieldOnCompletion = null;
85         fFieldName = null;
86         fFieldSkip = false;
87         fFieldDependencies = new ArrayList JavaDoc();
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#addFieldDependency(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDependency)
92      */

93     public void addFieldDependency(ICompCSDependency dependency) {
94         fFieldDependencies.add(dependency);
95         if (isEditable()) {
96             fireStructureChanged(dependency, IModelChangedEvent.INSERT);
97         }
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldId()
102      */

103     public String JavaDoc getFieldId() {
104         return fFieldId;
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldIntro()
109      */

110     public ICompCSIntro getFieldIntro() {
111         return fFieldIntro;
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldKind()
116      */

117     public String JavaDoc getFieldKind() {
118         return fFieldKind;
119     }
120
121     /* (non-Javadoc)
122      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldName()
123      */

124     public String JavaDoc getFieldName() {
125         return fFieldName;
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldOnCompletion()
130      */

131     public ICompCSOnCompletion getFieldOnCompletion() {
132         return fFieldOnCompletion;
133     }
134
135     /* (non-Javadoc)
136      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldSkip()
137      */

138     public boolean getFieldSkip() {
139         return fFieldSkip;
140     }
141
142     /* (non-Javadoc)
143      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#removeFieldDepedency(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDependency)
144      */

145     public void removeFieldDepedency(ICompCSDependency dependency) {
146         fFieldDependencies.remove(dependency);
147         if (isEditable()) {
148             fireStructureChanged(dependency, IModelChangedEvent.REMOVE);
149         }
150     }
151
152     /* (non-Javadoc)
153      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldId(java.lang.String)
154      */

155     public void setFieldId(String JavaDoc id) {
156         String JavaDoc old = fFieldId;
157         fFieldId = id;
158         if (isEditable()) {
159             firePropertyChanged(ATTRIBUTE_ID, old, fFieldId);
160         }
161     }
162
163     /* (non-Javadoc)
164      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldIntro(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro)
165      */

166     public void setFieldIntro(ICompCSIntro intro) {
167         ICompCSObject old = fFieldIntro;
168         fFieldIntro = intro;
169         if (isEditable()) {
170             fireStructureChanged(intro, old);
171         }
172     }
173
174     /* (non-Javadoc)
175      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldKind(java.lang.String)
176      */

177     public void setFieldKind(String JavaDoc kind) {
178         String JavaDoc old = fFieldKind;
179         fFieldKind = kind;
180         if (isEditable()) {
181             firePropertyChanged(ATTRIBUTE_KIND, old, fFieldKind);
182         }
183     }
184
185     /* (non-Javadoc)
186      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldName(java.lang.String)
187      */

188     public void setFieldName(String JavaDoc name) {
189         String JavaDoc old = fFieldName;
190         fFieldName = name;
191         if (isEditable()) {
192             firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName);
193         }
194     }
195
196     /* (non-Javadoc)
197      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldOnCompletion(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion)
198      */

199     public void setFieldOnCompletion(ICompCSOnCompletion onCompletion) {
200         ICompCSObject old = fFieldOnCompletion;
201         fFieldOnCompletion = onCompletion;
202         if (isEditable()) {
203             fireStructureChanged(onCompletion, old);
204         }
205     }
206
207     /* (non-Javadoc)
208      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#setFieldSkip(boolean)
209      */

210     public void setFieldSkip(boolean skip) {
211         Boolean JavaDoc old = Boolean.valueOf(fFieldSkip);
212         fFieldSkip = skip;
213         if (isEditable()) {
214             firePropertyChanged(ATTRIBUTE_SKIP, old, Boolean.valueOf(fFieldSkip));
215         }
216     }
217
218     /* (non-Javadoc)
219      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject#getFieldDependencies()
220      */

221     public ICompCSDependency[] getFieldDependencies() {
222         return (ICompCSDependency[]) fFieldDependencies
223         .toArray(new ICompCSDependency[fFieldDependencies.size()]);
224     }
225
226     /* (non-Javadoc)
227      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseText(org.w3c.dom.Text)
228      */

229     protected void parseText(Text JavaDoc text) {
230         // NO-OP
231
}
232     
233     /* (non-Javadoc)
234      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseAttributes(org.w3c.dom.Element)
235      */

236     protected void parseAttributes(Element JavaDoc element) {
237         // Process id attribute
238
// Trim leading and trailing whitespace
239
fFieldId = element.getAttribute(ATTRIBUTE_ID).trim();
240         // Process kind attribute
241
// Trim leading and trailing whitespace
242
fFieldKind = element.getAttribute(ATTRIBUTE_KIND).trim();
243         // Process name attribute
244
// Trim leading and trailing whitespace
245
fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim();
246         // Process skip attribute
247
if (element.getAttribute(ATTRIBUTE_SKIP).compareTo(
248                 ATTRIBUTE_VALUE_TRUE) == 0) {
249             fFieldSkip = true;
250         }
251     }
252     
253     /* (non-Javadoc)
254      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeAttributes(java.lang.StringBuffer)
255      */

256     protected void writeAttributes(StringBuffer JavaDoc buffer) {
257         // Print id attribute
258
if ((fFieldId != null) &&
259                 (fFieldId.length() > 0)) {
260             // Trim leading and trailing whitespace
261
// Encode characters
262
buffer.append(XMLPrintHandler.wrapAttribute(
263                     ATTRIBUTE_ID,
264                     PDETextHelper.translateWriteText(
265                             fFieldId.trim(), DEFAULT_SUBSTITUTE_CHARS)));
266         }
267         // Print kind attribute
268
if ((fFieldKind != null) &&
269                 (fFieldKind.length() > 0)) {
270             // No trim required
271
// No encode required
272
buffer.append(XMLPrintHandler.wrapAttribute(
273                     ATTRIBUTE_KIND, fFieldKind));
274         }
275         // Print name attribute
276
if ((fFieldName != null) &&
277                 (fFieldName.length() > 0)) {
278             // Trim leading and trailing whitespace
279
// Encode characters
280
buffer.append(XMLPrintHandler.wrapAttribute(
281                     ATTRIBUTE_NAME,
282                     PDETextHelper.translateWriteText(
283                             fFieldName.trim(), DEFAULT_SUBSTITUTE_CHARS)));
284         }
285         // Print skip attribute
286
buffer.append(XMLPrintHandler.wrapAttribute(
287                 ATTRIBUTE_SKIP, new Boolean JavaDoc(fFieldSkip).toString()));
288     }
289     
290     /* (non-Javadoc)
291      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
292      */

293     protected void parseElement(Element JavaDoc element) {
294         String JavaDoc name = element.getNodeName();
295         ICompCSModelFactory factory = getModel().getFactory();
296         
297         if (name.equals(ELEMENT_INTRO)) {
298             // Process intro element
299
fFieldIntro = factory.createCompCSIntro(this);
300             fFieldIntro.parse(element);
301         } else if (name.equals(ELEMENT_ONCOMPLETION)) {
302             // Process onCompletion element
303
fFieldOnCompletion = factory.createCompCSOnCompletion(this);
304             fFieldOnCompletion.parse(element);
305         } else if (name.equals(ELEMENT_DEPENDENCY)) {
306             // Process dependency element
307
ICompCSDependency dependency = factory.createCompCSDependency(this);
308             fFieldDependencies.add(dependency);
309             dependency.parse(element);
310         }
311     }
312     
313     /* (non-Javadoc)
314      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeElements(java.lang.String, java.io.PrintWriter)
315      */

316     protected void writeElements(String JavaDoc indent, PrintWriter JavaDoc writer) {
317         String JavaDoc newIndent = indent + XMLPrintHandler.XML_INDENT;
318         // Print intro element
319
if (fFieldIntro != null) {
320             fFieldIntro.write(newIndent, writer);
321         }
322         // Print onCompletion element
323
if (fFieldOnCompletion != null) {
324             fFieldOnCompletion.write(newIndent, writer);
325         }
326         // Print dependency elements
327
Iterator JavaDoc iterator = fFieldDependencies.iterator();
328         while (iterator.hasNext()) {
329             ICompCSDependency dependency = (ICompCSDependency)iterator.next();
330             dependency.write(newIndent, writer);
331         }
332     }
333     
334     /* (non-Javadoc)
335      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getElement()
336      */

337     public abstract String JavaDoc getElement();
338     
339 }
340
Popular Tags