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.ISimpleCSAction; 21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel; 22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject; 23 import org.eclipse.pde.internal.core.util.PDETextHelper; 24 import org.w3c.dom.Attr ; 25 import org.w3c.dom.Element ; 26 27 31 public class SimpleCSAction extends SimpleCSObject implements ISimpleCSAction { 32 33 36 private String fClazz; 37 38 41 private String fPluginId; 42 43 46 private boolean fConfirm; 47 48 51 private String fWhen; 52 53 56 private String fTranslate; 57 58 61 private ArrayList fParams; 62 63 private static final int F_MAX_PARAMS = 9; 64 65 68 private static final long serialVersionUID = 1L; 69 70 74 public SimpleCSAction(ISimpleCSModel model, ISimpleCSObject parent) { 75 super(model, parent); 76 reset(); 77 } 78 79 82 public String getClazz() { 83 return fClazz; 84 } 85 86 89 public boolean getConfirm() { 90 return fConfirm; 91 } 92 93 96 public String [] getParams() { 97 return (String [])fParams.toArray(new String [fParams.size()]); 98 } 99 100 103 public String getPluginId() { 104 return fPluginId; 105 } 106 107 110 public void setClazz(String clazz) { 111 String old = fClazz; 112 fClazz = clazz; 113 if (isEditable()) { 114 firePropertyChanged(ATTRIBUTE_CLASS, old, fClazz); 115 } 116 } 117 118 121 public void setConfirm(boolean confirm) { 122 Boolean old = Boolean.valueOf(fConfirm); 123 fConfirm = confirm; 124 if (isEditable()) { 125 firePropertyChanged(ATTRIBUTE_CONFIRM, old, Boolean.valueOf(fConfirm)); 126 } 127 } 128 129 132 public void setPluginId(String pluginId) { 133 String old = fPluginId; 134 fPluginId = pluginId; 135 if (isEditable()) { 136 firePropertyChanged(ATTRIBUTE_PLUGINID, old, fPluginId); 137 } 138 } 139 140 143 public void parse(Element element) { 144 fClazz = element.getAttribute(ATTRIBUTE_CLASS); 147 fPluginId = element.getAttribute(ATTRIBUTE_PLUGINID); 150 if (element.getAttribute(ATTRIBUTE_CONFIRM).compareTo( 152 ATTRIBUTE_VALUE_TRUE) == 0) { 153 fConfirm = true; 154 } 155 fWhen = element.getAttribute(ATTRIBUTE_WHEN); 158 Attr translateAttribute = element.getAttributeNode(ATTRIBUTE_TRANSLATE); 162 if (translateAttribute == null) { 163 fTranslate = null; 164 } else { 165 fTranslate = translateAttribute.getValue(); 166 } 167 for (int i = 0; i < F_MAX_PARAMS; i++) { 169 int adjustedIndex = i + 1; 170 String parameter = ATTRIBUTE_PARAM + adjustedIndex; 171 String value = element.getAttribute(parameter); 173 fParams.add(i, value); 174 } 175 } 176 177 180 public void write(String indent, PrintWriter writer) { 181 182 StringBuffer buffer = new StringBuffer (); 183 184 try { 185 buffer.append(ELEMENT_ACTION); 187 if ((fClazz != null) && 189 (fClazz.length() > 0)) { 190 buffer.append(XMLPrintHandler.wrapAttribute( 192 ATTRIBUTE_CLASS, fClazz)); 193 } 194 if ((fPluginId != null) && 196 (fPluginId.length() > 0)) { 197 buffer.append(XMLPrintHandler.wrapAttribute( 199 ATTRIBUTE_PLUGINID, fPluginId)); 200 } 201 buffer.append(XMLPrintHandler.wrapAttribute( 203 ATTRIBUTE_CONFIRM, new Boolean (fConfirm).toString())); 204 if ((fWhen != null) && 206 (fWhen.length() > 0)) { 207 buffer.append(XMLPrintHandler.wrapAttribute( 209 ATTRIBUTE_WHEN, fWhen)); 210 } 211 if (fTranslate != null) { 213 buffer.append(XMLPrintHandler.wrapAttribute( 215 ATTRIBUTE_TRANSLATE, fTranslate)); 216 } 217 for (int i = 0; i < F_MAX_PARAMS; i++) { 219 int adjustedIndex = i + 1; 220 String parameter = ATTRIBUTE_PARAM + adjustedIndex; 221 String value = (String )fParams.get(i); 222 if (PDETextHelper.isDefined(value)) { 226 buffer.append(XMLPrintHandler.wrapAttribute( 228 parameter, value)); 229 } 230 } 231 232 XMLPrintHandler.printBeginElement(writer, buffer.toString(), 234 indent, false); 235 XMLPrintHandler.printEndElement(writer, ELEMENT_ACTION, indent); 237 238 } catch (IOException e) { 239 } 242 } 243 244 247 public void reset() { 248 fClazz = null; 249 fPluginId = null; 250 fConfirm = false; 251 fWhen = null; 252 fParams = new ArrayList (F_MAX_PARAMS); 253 fTranslate = null; 254 } 255 256 259 public int getType() { 260 return TYPE_ACTION; 261 } 262 263 266 public String getWhen() { 267 return fWhen; 268 } 269 270 273 public String getTranslate() { 274 return fTranslate; 275 } 276 277 280 public void setWhen(String when) { 281 String old = fWhen; 282 fWhen = when; 283 if (isEditable()) { 284 firePropertyChanged(ATTRIBUTE_WHEN, old, fWhen); 285 } 286 } 287 288 291 public void setTranslate(String translate) { 292 String old = fTranslate; 293 fTranslate = translate; 294 if (isEditable()) { 295 firePropertyChanged(ATTRIBUTE_TRANSLATE, old, fTranslate); 296 } 297 } 298 299 302 public String getName() { 303 return ELEMENT_ACTION; 305 } 306 307 310 public List getChildren() { 311 return new ArrayList (); 312 } 313 314 317 public String getParam(int index) { 318 if ((index < 1) || 321 (index > F_MAX_PARAMS)) { 322 return null; 323 } 324 int actualIndex = index - 1; 325 return (String )fParams.get(actualIndex); 326 } 327 328 331 public void setParam(String param, int index) { 332 if ((index < 1) || 335 (index > F_MAX_PARAMS)) { 336 return; 337 } 338 int actualIndex = index - 1; 339 String old = (String )fParams.get(actualIndex); 340 fParams.set(actualIndex, param); 341 342 if (isEditable()) { 343 firePropertyChanged(ATTRIBUTE_PARAM, old, param); 344 } 345 } 346 347 } 348 | Popular Tags |