KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
15 import java.io.PrintWriter JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.pde.internal.core.XMLPrintHandler;
20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory;
23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject;
25 import org.eclipse.pde.internal.core.util.PDETextHelper;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Text JavaDoc;
28
29 /**
30  * CompCS
31  *
32  */

33 public class CompCS extends CompCSObject implements ICompCS {
34
35     private String JavaDoc fFieldName;
36     
37     private ICompCSTaskObject fFieldTaskObject;
38     
39     
40     /**
41      *
42      */

43     private static final long serialVersionUID = 1L;
44
45     /**
46      * @param model
47      */

48     public CompCS(ICompCSModel model) {
49         super(model, null);
50         reset();
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getChildren()
55      */

56     public List JavaDoc getChildren() {
57         ArrayList JavaDoc list = new ArrayList JavaDoc();
58         // Add task / taskGroup
59
if (fFieldTaskObject != null) {
60             list.add(fFieldTaskObject);
61         }
62         return list;
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getName()
67      */

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

75     public int getType() {
76         return TYPE_COMPOSITE_CHEATSHEET;
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseAttributes(org.w3c.dom.Element)
81      */

82     protected void parseAttributes(Element JavaDoc element) {
83         // Process name attribute
84
// Trim leading and trailing whitespace
85
fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim();
86     }
87     
88     /* (non-Javadoc)
89      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
90      */

91     protected void parseElement(Element JavaDoc element) {
92         String JavaDoc name = element.getNodeName();
93         ICompCSModelFactory factory = getModel().getFactory();
94         
95         if (name.equals(ELEMENT_TASK)) {
96             // Process task element
97
fFieldTaskObject = factory.createCompCSTask(this);
98             fFieldTaskObject.parse(element);
99         } else if (name.equals(ELEMENT_TASKGROUP)) {
100             // Process taskGroup element
101
fFieldTaskObject = factory.createCompCSTaskGroup(this);
102             fFieldTaskObject.parse(element);
103         }
104     }
105     
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#reset()
108      */

109     public void reset() {
110         fFieldName = null;
111         fFieldTaskObject = null;
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#write(java.lang.String, java.io.PrintWriter)
116      */

117     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
118         
119         try {
120             // Print XML decl
121
XMLPrintHandler.printHead(writer, ATTRIBUTE_VALUE_ENCODING);
122             super.write(indent, writer);
123         } catch (IOException JavaDoc e) {
124             // Suppress
125
//e.printStackTrace();
126
}
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeAttributes(java.lang.StringBuffer)
131      */

132     protected void writeAttributes(StringBuffer JavaDoc buffer) {
133         // Print name attribute
134
if ((fFieldName != null) &&
135                 (fFieldName.length() > 0)) {
136             // Trim leading and trailing whitespace
137
// Encode characters
138
buffer.append(XMLPrintHandler.wrapAttribute(
139                     ATTRIBUTE_NAME,
140                     PDETextHelper.translateWriteText(
141                             fFieldName.trim(), DEFAULT_SUBSTITUTE_CHARS)));
142         }
143     }
144
145     /* (non-Javadoc)
146      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeElements(java.lang.String, java.io.PrintWriter)
147      */

148     protected void writeElements(String JavaDoc indent, PrintWriter JavaDoc writer) {
149         String JavaDoc newIndent = indent + XMLPrintHandler.XML_INDENT;
150         // Print task / taskGroup element
151
if (fFieldTaskObject != null) {
152             fFieldTaskObject.write(newIndent, writer);
153         }
154     }
155     
156     /* (non-Javadoc)
157      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS#getFieldName()
158      */

159     public String JavaDoc getFieldName() {
160         return fFieldName;
161     }
162
163     /* (non-Javadoc)
164      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS#getFieldTaskObject()
165      */

166     public ICompCSTaskObject getFieldTaskObject() {
167         return fFieldTaskObject;
168     }
169
170     /* (non-Javadoc)
171      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS#setFieldName(java.lang.String)
172      */

173     public void setFieldName(String JavaDoc name) {
174         String JavaDoc old = fFieldName;
175         fFieldName = name;
176         if (isEditable()) {
177             firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName);
178         }
179     }
180
181     /* (non-Javadoc)
182      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS#setFieldTaskObject(org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject)
183      */

184     public void setFieldTaskObject(ICompCSTaskObject taskObject) {
185         ICompCSObject old = fFieldTaskObject;
186         fFieldTaskObject = taskObject;
187         if (isEditable()) {
188             fireStructureChanged(fFieldTaskObject, old);
189         }
190     }
191
192     /* (non-Javadoc)
193      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject#getElement()
194      */

195     public String JavaDoc getElement() {
196         return ELEMENT_COMPOSITE_CHEATSHEET;
197     }
198
199     /* (non-Javadoc)
200      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseText(org.w3c.dom.Text)
201      */

202     protected void parseText(Text JavaDoc text) {
203         // NO-OP
204
}
205
206 }
207
Popular Tags