1 11 12 package org.eclipse.pde.internal.core.cheatsheet.comp; 13 14 import java.io.PrintWriter ; 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.internal.core.XMLPrintHandler; 21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSDependency; 22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro; 23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel; 24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory; 25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject; 26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion; 27 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject; 28 import org.eclipse.pde.internal.core.util.PDETextHelper; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Text ; 31 32 36 public abstract class CompCSTaskObject extends CompCSObject implements 37 ICompCSTaskObject { 38 39 protected String fFieldId; 40 41 protected String fFieldKind; 42 43 protected ICompCSIntro fFieldIntro; 44 45 protected ICompCSOnCompletion fFieldOnCompletion; 46 47 protected String fFieldName; 48 49 protected boolean fFieldSkip; 50 51 protected ArrayList fFieldDependencies; 52 53 57 public CompCSTaskObject(ICompCSModel model, ICompCSObject parent) { 58 super(model, parent); 59 } 61 62 65 public abstract List getChildren(); 66 67 70 public abstract String getName(); 71 72 75 public abstract int getType(); 76 77 80 public void reset() { 81 fFieldId = null; 82 fFieldKind = null; 83 fFieldIntro = null; 84 fFieldOnCompletion = null; 85 fFieldName = null; 86 fFieldSkip = false; 87 fFieldDependencies = new ArrayList (); 88 } 89 90 93 public void addFieldDependency(ICompCSDependency dependency) { 94 fFieldDependencies.add(dependency); 95 if (isEditable()) { 96 fireStructureChanged(dependency, IModelChangedEvent.INSERT); 97 } 98 } 99 100 103 public String getFieldId() { 104 return fFieldId; 105 } 106 107 110 public ICompCSIntro getFieldIntro() { 111 return fFieldIntro; 112 } 113 114 117 public String getFieldKind() { 118 return fFieldKind; 119 } 120 121 124 public String getFieldName() { 125 return fFieldName; 126 } 127 128 131 public ICompCSOnCompletion getFieldOnCompletion() { 132 return fFieldOnCompletion; 133 } 134 135 138 public boolean getFieldSkip() { 139 return fFieldSkip; 140 } 141 142 145 public void removeFieldDepedency(ICompCSDependency dependency) { 146 fFieldDependencies.remove(dependency); 147 if (isEditable()) { 148 fireStructureChanged(dependency, IModelChangedEvent.REMOVE); 149 } 150 } 151 152 155 public void setFieldId(String id) { 156 String old = fFieldId; 157 fFieldId = id; 158 if (isEditable()) { 159 firePropertyChanged(ATTRIBUTE_ID, old, fFieldId); 160 } 161 } 162 163 166 public void setFieldIntro(ICompCSIntro intro) { 167 ICompCSObject old = fFieldIntro; 168 fFieldIntro = intro; 169 if (isEditable()) { 170 fireStructureChanged(intro, old); 171 } 172 } 173 174 177 public void setFieldKind(String kind) { 178 String old = fFieldKind; 179 fFieldKind = kind; 180 if (isEditable()) { 181 firePropertyChanged(ATTRIBUTE_KIND, old, fFieldKind); 182 } 183 } 184 185 188 public void setFieldName(String name) { 189 String old = fFieldName; 190 fFieldName = name; 191 if (isEditable()) { 192 firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName); 193 } 194 } 195 196 199 public void setFieldOnCompletion(ICompCSOnCompletion onCompletion) { 200 ICompCSObject old = fFieldOnCompletion; 201 fFieldOnCompletion = onCompletion; 202 if (isEditable()) { 203 fireStructureChanged(onCompletion, old); 204 } 205 } 206 207 210 public void setFieldSkip(boolean skip) { 211 Boolean old = Boolean.valueOf(fFieldSkip); 212 fFieldSkip = skip; 213 if (isEditable()) { 214 firePropertyChanged(ATTRIBUTE_SKIP, old, Boolean.valueOf(fFieldSkip)); 215 } 216 } 217 218 221 public ICompCSDependency[] getFieldDependencies() { 222 return (ICompCSDependency[]) fFieldDependencies 223 .toArray(new ICompCSDependency[fFieldDependencies.size()]); 224 } 225 226 229 protected void parseText(Text text) { 230 } 232 233 236 protected void parseAttributes(Element element) { 237 fFieldId = element.getAttribute(ATTRIBUTE_ID).trim(); 240 fFieldKind = element.getAttribute(ATTRIBUTE_KIND).trim(); 243 fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim(); 246 if (element.getAttribute(ATTRIBUTE_SKIP).compareTo( 248 ATTRIBUTE_VALUE_TRUE) == 0) { 249 fFieldSkip = true; 250 } 251 } 252 253 256 protected void writeAttributes(StringBuffer buffer) { 257 if ((fFieldId != null) && 259 (fFieldId.length() > 0)) { 260 buffer.append(XMLPrintHandler.wrapAttribute( 263 ATTRIBUTE_ID, 264 PDETextHelper.translateWriteText( 265 fFieldId.trim(), DEFAULT_SUBSTITUTE_CHARS))); 266 } 267 if ((fFieldKind != null) && 269 (fFieldKind.length() > 0)) { 270 buffer.append(XMLPrintHandler.wrapAttribute( 273 ATTRIBUTE_KIND, fFieldKind)); 274 } 275 if ((fFieldName != null) && 277 (fFieldName.length() > 0)) { 278 buffer.append(XMLPrintHandler.wrapAttribute( 281 ATTRIBUTE_NAME, 282 PDETextHelper.translateWriteText( 283 fFieldName.trim(), DEFAULT_SUBSTITUTE_CHARS))); 284 } 285 buffer.append(XMLPrintHandler.wrapAttribute( 287 ATTRIBUTE_SKIP, new Boolean (fFieldSkip).toString())); 288 } 289 290 293 protected void parseElement(Element element) { 294 String name = element.getNodeName(); 295 ICompCSModelFactory factory = getModel().getFactory(); 296 297 if (name.equals(ELEMENT_INTRO)) { 298 fFieldIntro = factory.createCompCSIntro(this); 300 fFieldIntro.parse(element); 301 } else if (name.equals(ELEMENT_ONCOMPLETION)) { 302 fFieldOnCompletion = factory.createCompCSOnCompletion(this); 304 fFieldOnCompletion.parse(element); 305 } else if (name.equals(ELEMENT_DEPENDENCY)) { 306 ICompCSDependency dependency = factory.createCompCSDependency(this); 308 fFieldDependencies.add(dependency); 309 dependency.parse(element); 310 } 311 } 312 313 316 protected void writeElements(String indent, PrintWriter writer) { 317 String newIndent = indent + XMLPrintHandler.XML_INDENT; 318 if (fFieldIntro != null) { 320 fFieldIntro.write(newIndent, writer); 321 } 322 if (fFieldOnCompletion != null) { 324 fFieldOnCompletion.write(newIndent, writer); 325 } 326 Iterator iterator = fFieldDependencies.iterator(); 328 while (iterator.hasNext()) { 329 ICompCSDependency dependency = (ICompCSDependency)iterator.next(); 330 dependency.write(newIndent, writer); 331 } 332 } 333 334 337 public abstract String getElement(); 338 339 } 340 | Popular Tags |