KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > cheatsheet > simple > SimpleCSCommand


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.simple;
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.simple.ISimpleCSCommand;
21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
23 import org.w3c.dom.Attr JavaDoc;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * SimpleCSCommand
28  *
29  */

30 public class SimpleCSCommand extends SimpleCSObject implements ISimpleCSCommand {
31
32     /**
33      * Attribute: serialization
34      */

35     private String JavaDoc fSerialization;
36     
37     /**
38      * Attribute: returns
39      */

40     private String JavaDoc fReturns;
41     
42     /**
43      * Attribute: confirm
44      */

45     private boolean fConfirm;
46     
47     /**
48      * Attribute: when
49      */

50     private String JavaDoc fWhen;
51     
52     /**
53      * Attribute: translate
54      */

55     private String JavaDoc fTranslate;
56     
57     /**
58      *
59      */

60     private static final long serialVersionUID = 1L;
61
62     /**
63      * @param model
64      * @param parent
65      */

66     public SimpleCSCommand(ISimpleCSModel model, ISimpleCSObject parent) {
67         super(model, parent);
68         reset();
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#getConfirm()
73      */

74     public boolean getConfirm() {
75         return fConfirm;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#getReturns()
80      */

81     public String JavaDoc getReturns() {
82         return fReturns;
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#getSerialization()
87      */

88     public String JavaDoc getSerialization() {
89         return fSerialization;
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#getWhen()
94      */

95     public String JavaDoc getWhen() {
96         return fWhen;
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSRunObject#getTranslate()
101      */

102     public String JavaDoc getTranslate() {
103         return fTranslate;
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#setConfirm(boolean)
108      */

109     public void setConfirm(boolean confirm) {
110         Boolean JavaDoc old = Boolean.valueOf(fConfirm);
111         fConfirm = confirm;
112         if (isEditable()) {
113             firePropertyChanged(ATTRIBUTE_CONFIRM, old, Boolean.valueOf(fConfirm));
114         }
115     }
116
117     /* (non-Javadoc)
118      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#setReturns(boolean)
119      */

120     public void setReturns(String JavaDoc returns) {
121         String JavaDoc old = fReturns;
122         fReturns = returns;
123         if (isEditable()) {
124             firePropertyChanged(ATTRIBUTE_RETURNS, old, fReturns);
125         }
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#setSerialization(java.lang.String)
130      */

131     public void setSerialization(String JavaDoc serialization) {
132         String JavaDoc old = fSerialization;
133         fSerialization = serialization;
134         if (isEditable()) {
135             firePropertyChanged(ATTRIBUTE_SERIALIZATION, old, fSerialization);
136         }
137     }
138
139     /* (non-Javadoc)
140      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSCommand#setWhen(java.lang.String)
141      */

142     public void setWhen(String JavaDoc when) {
143         String JavaDoc old = fWhen;
144         fWhen = when;
145         if (isEditable()) {
146             firePropertyChanged(ATTRIBUTE_WHEN, old, fWhen);
147         }
148     }
149
150     /* (non-Javadoc)
151      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSRunObject#setTranslate(java.lang.String)
152      */

153     public void setTranslate(String JavaDoc translate) {
154         String JavaDoc old = fTranslate;
155         fTranslate = translate;
156         if (isEditable()) {
157             firePropertyChanged(ATTRIBUTE_TRANSLATE, old, fTranslate);
158         }
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#parse(org.w3c.dom.Node)
163      */

164     public void parse(Element JavaDoc element) {
165         // Process serialization attribute
166
// Read as is. Do not translate
167
fSerialization = element.getAttribute(ATTRIBUTE_SERIALIZATION);
168         // Process returns attribute
169
// Read as is. Do not translate
170
fReturns = element.getAttribute(ATTRIBUTE_RETURNS);
171         // Process confirm attribute
172
if (element.getAttribute(ATTRIBUTE_CONFIRM).compareTo(
173                 ATTRIBUTE_VALUE_TRUE) == 0) {
174             fConfirm = true;
175         }
176         // Process when attribute
177
// Read as is. Do not translate
178
fWhen = element.getAttribute(ATTRIBUTE_WHEN);
179         // Process translate attribute
180
// Read as is. Do not translate
181
// Need to be able to write out the empty string
182
Attr JavaDoc translateAttribute = element.getAttributeNode(ATTRIBUTE_TRANSLATE);
183         if (translateAttribute == null) {
184             fTranslate = null;
185         } else {
186             fTranslate = translateAttribute.getValue();
187         }
188     }
189
190     /* (non-Javadoc)
191      * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
192      */

193     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
194         
195         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
196         
197         try {
198             // Print command element
199
buffer.append(ELEMENT_COMMAND);
200             // Print serialization attribute
201
if ((fSerialization != null) &&
202                     (fSerialization.length() > 0)) {
203                 // Write as is. Do not translate
204
buffer.append(XMLPrintHandler.wrapAttribute(
205                         ATTRIBUTE_SERIALIZATION, fSerialization));
206             }
207             if ((fReturns != null) &&
208                     (fReturns.length() > 0)) {
209                 // Write as is. Do not translate
210
buffer.append(XMLPrintHandler.wrapAttribute(
211                         ATTRIBUTE_RETURNS, fReturns));
212             }
213             // Print confirm attribute
214
buffer.append(XMLPrintHandler.wrapAttribute(
215                     ATTRIBUTE_CONFIRM, new Boolean JavaDoc(fConfirm).toString()));
216             // Print when attribute
217
if ((fWhen != null) &&
218                     (fWhen.length() > 0)) {
219                 // Write as is. Do not translate
220
buffer.append(XMLPrintHandler.wrapAttribute(
221                         ATTRIBUTE_WHEN, fWhen));
222             }
223             // Print translate attribute
224
if (fTranslate != null) {
225                 // Write as is. Do not translate
226
buffer.append(XMLPrintHandler.wrapAttribute(
227                         ATTRIBUTE_TRANSLATE, fTranslate));
228             }
229             // Start element
230
XMLPrintHandler.printBeginElement(writer, buffer.toString(),
231                     indent, false);
232             // End element
233
XMLPrintHandler.printEndElement(writer, ELEMENT_COMMAND, indent);
234             
235         } catch (IOException JavaDoc e) {
236             // Suppress
237
//e.printStackTrace();
238
}
239         
240     }
241
242     /* (non-Javadoc)
243      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#reset()
244      */

245     public void reset() {
246         fSerialization = null;
247         fReturns = null;
248         fConfirm = false;
249         fWhen = null;
250         fTranslate = null;
251     }
252
253     /* (non-Javadoc)
254      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getType()
255      */

256     public int getType() {
257         return TYPE_COMMAND;
258     }
259
260     /* (non-Javadoc)
261      * @see org.eclipse.pde.internal.core.cheatsheet.simple.SimpleCSObject#getName()
262      */

263     public String JavaDoc getName() {
264         // Leave as is. Not a separate node in tree view
265
return ELEMENT_COMMAND;
266     }
267
268     /* (non-Javadoc)
269      * @see org.eclipse.pde.internal.core.cheatsheet.simple.SimpleCSObject#getChildren()
270      */

271     public List JavaDoc getChildren() {
272         return new ArrayList JavaDoc();
273     }
274
275 }
276
Popular Tags