KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
17
18 import org.eclipse.pde.internal.core.XMLPrintHandler;
19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDataObject;
20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
22 import org.eclipse.pde.internal.core.util.CheatSheetUtil;
23 import org.eclipse.pde.internal.core.util.PDETextHelper;
24 import org.w3c.dom.Element JavaDoc;
25 import org.w3c.dom.Text JavaDoc;
26
27 /**
28  * CompCSDataObject
29  *
30  */

31 public abstract class CompCSDataObject extends CompCSObject implements
32         ICompCSDataObject {
33
34     private String JavaDoc fFieldContent;
35     
36     /**
37      * @param model
38      * @param parent
39      */

40     public CompCSDataObject(ICompCSModel model, ICompCSObject parent) {
41         super(model, parent);
42         // Reset called by child class
43
}
44
45     /* (non-Javadoc)
46      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getChildren()
47      */

48     public List JavaDoc getChildren() {
49         return new ArrayList JavaDoc();
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getElement()
54      */

55     public abstract String JavaDoc getElement();
56
57     /* (non-Javadoc)
58      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getName()
59      */

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

67     public abstract int getType();
68
69     /* (non-Javadoc)
70      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseContent(org.w3c.dom.Element)
71      */

72     protected void parseContent(Element JavaDoc element) {
73         // Override to handle unusual mixed content as in this case
74
// Trim leading and trailing whitespace
75
fFieldContent = CheatSheetUtil.parseElementText(element).trim();
76     }
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseAttributes(org.w3c.dom.Element)
80      */

81     protected void parseAttributes(Element JavaDoc element) {
82         // NO-OP
83
}
84
85     /* (non-Javadoc)
86      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
87      */

88     protected void parseElement(Element JavaDoc element) {
89         // NO-OP
90
}
91
92     /* (non-Javadoc)
93      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseText(org.w3c.dom.Text)
94      */

95     protected void parseText(Text JavaDoc text) {
96         // NO-OP
97
}
98     
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#reset()
101      */

102     public void reset() {
103         fFieldContent = null;
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeAttributes(java.lang.StringBuffer)
108      */

109     protected void writeAttributes(StringBuffer JavaDoc buffer) {
110         // NO-OP
111
}
112
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeElements(java.lang.String, java.io.PrintWriter)
115      */

116     protected void writeElements(String JavaDoc indent, PrintWriter JavaDoc writer) {
117         String JavaDoc newIndent = indent + XMLPrintHandler.XML_INDENT;
118         // Print contents
119
if ((fFieldContent != null) &&
120                 (fFieldContent.length() > 0)) {
121             // Trim leading and trailing whitespace
122
// Encode characters
123
// Preserve tag exceptions
124
writer.write(newIndent
125                     + PDETextHelper.translateWriteText(fFieldContent.trim(),
126                             DEFAULT_TAG_EXCEPTIONS, DEFAULT_SUBSTITUTE_CHARS) + "\n"); //$NON-NLS-1$
127
}
128     }
129
130     /* (non-Javadoc)
131      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDataObject#getFieldContent()
132      */

133     public String JavaDoc getFieldContent() {
134         return fFieldContent;
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDataObject#setFieldContent(java.lang.String)
139      */

140     public void setFieldContent(String JavaDoc content) {
141         String JavaDoc old = fFieldContent;
142         fFieldContent = content;
143         if (isEditable()) {
144             firePropertyChanged(getElement(), old, fFieldContent);
145         }
146     }
147
148 }
149
Popular Tags