1 11 12 package org.eclipse.pde.internal.core.cheatsheet.simple; 13 14 import java.io.IOException ; 15 import java.io.PrintWriter ; 16 import java.util.ArrayList ; 17 import java.util.List ; 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 ; 24 import org.w3c.dom.Element ; 25 26 30 public class SimpleCSCommand extends SimpleCSObject implements ISimpleCSCommand { 31 32 35 private String fSerialization; 36 37 40 private String fReturns; 41 42 45 private boolean fConfirm; 46 47 50 private String fWhen; 51 52 55 private String fTranslate; 56 57 60 private static final long serialVersionUID = 1L; 61 62 66 public SimpleCSCommand(ISimpleCSModel model, ISimpleCSObject parent) { 67 super(model, parent); 68 reset(); 69 } 70 71 74 public boolean getConfirm() { 75 return fConfirm; 76 } 77 78 81 public String getReturns() { 82 return fReturns; 83 } 84 85 88 public String getSerialization() { 89 return fSerialization; 90 } 91 92 95 public String getWhen() { 96 return fWhen; 97 } 98 99 102 public String getTranslate() { 103 return fTranslate; 104 } 105 106 109 public void setConfirm(boolean confirm) { 110 Boolean old = Boolean.valueOf(fConfirm); 111 fConfirm = confirm; 112 if (isEditable()) { 113 firePropertyChanged(ATTRIBUTE_CONFIRM, old, Boolean.valueOf(fConfirm)); 114 } 115 } 116 117 120 public void setReturns(String returns) { 121 String old = fReturns; 122 fReturns = returns; 123 if (isEditable()) { 124 firePropertyChanged(ATTRIBUTE_RETURNS, old, fReturns); 125 } 126 } 127 128 131 public void setSerialization(String serialization) { 132 String old = fSerialization; 133 fSerialization = serialization; 134 if (isEditable()) { 135 firePropertyChanged(ATTRIBUTE_SERIALIZATION, old, fSerialization); 136 } 137 } 138 139 142 public void setWhen(String when) { 143 String old = fWhen; 144 fWhen = when; 145 if (isEditable()) { 146 firePropertyChanged(ATTRIBUTE_WHEN, old, fWhen); 147 } 148 } 149 150 153 public void setTranslate(String translate) { 154 String old = fTranslate; 155 fTranslate = translate; 156 if (isEditable()) { 157 firePropertyChanged(ATTRIBUTE_TRANSLATE, old, fTranslate); 158 } 159 } 160 161 164 public void parse(Element element) { 165 fSerialization = element.getAttribute(ATTRIBUTE_SERIALIZATION); 168 fReturns = element.getAttribute(ATTRIBUTE_RETURNS); 171 if (element.getAttribute(ATTRIBUTE_CONFIRM).compareTo( 173 ATTRIBUTE_VALUE_TRUE) == 0) { 174 fConfirm = true; 175 } 176 fWhen = element.getAttribute(ATTRIBUTE_WHEN); 179 Attr translateAttribute = element.getAttributeNode(ATTRIBUTE_TRANSLATE); 183 if (translateAttribute == null) { 184 fTranslate = null; 185 } else { 186 fTranslate = translateAttribute.getValue(); 187 } 188 } 189 190 193 public void write(String indent, PrintWriter writer) { 194 195 StringBuffer buffer = new StringBuffer (); 196 197 try { 198 buffer.append(ELEMENT_COMMAND); 200 if ((fSerialization != null) && 202 (fSerialization.length() > 0)) { 203 buffer.append(XMLPrintHandler.wrapAttribute( 205 ATTRIBUTE_SERIALIZATION, fSerialization)); 206 } 207 if ((fReturns != null) && 208 (fReturns.length() > 0)) { 209 buffer.append(XMLPrintHandler.wrapAttribute( 211 ATTRIBUTE_RETURNS, fReturns)); 212 } 213 buffer.append(XMLPrintHandler.wrapAttribute( 215 ATTRIBUTE_CONFIRM, new Boolean (fConfirm).toString())); 216 if ((fWhen != null) && 218 (fWhen.length() > 0)) { 219 buffer.append(XMLPrintHandler.wrapAttribute( 221 ATTRIBUTE_WHEN, fWhen)); 222 } 223 if (fTranslate != null) { 225 buffer.append(XMLPrintHandler.wrapAttribute( 227 ATTRIBUTE_TRANSLATE, fTranslate)); 228 } 229 XMLPrintHandler.printBeginElement(writer, buffer.toString(), 231 indent, false); 232 XMLPrintHandler.printEndElement(writer, ELEMENT_COMMAND, indent); 234 235 } catch (IOException e) { 236 } 239 240 } 241 242 245 public void reset() { 246 fSerialization = null; 247 fReturns = null; 248 fConfirm = false; 249 fWhen = null; 250 fTranslate = null; 251 } 252 253 256 public int getType() { 257 return TYPE_COMMAND; 258 } 259 260 263 public String getName() { 264 return ELEMENT_COMMAND; 266 } 267 268 271 public List getChildren() { 272 return new ArrayList (); 273 } 274 275 } 276 | Popular Tags |