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 import java.util.ListIterator ; 19 20 import org.eclipse.pde.core.IModelChangedEvent; 21 import org.eclipse.pde.internal.core.XMLPrintHandler; 22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel; 23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory; 24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject; 25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam; 26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask; 27 import org.w3c.dom.Element ; 28 29 33 public class CompCSTask extends CompCSTaskObject implements ICompCSTask { 34 35 private ArrayList fFieldParams; 36 37 40 private static final long serialVersionUID = 1L; 41 42 46 public CompCSTask(ICompCSModel model, ICompCSObject parent) { 47 super(model, parent); 48 reset(); 49 } 50 51 54 public List getChildren() { 55 return new ArrayList (); 56 } 57 58 61 public String getName() { 62 return fFieldName; 63 } 64 65 68 public int getType() { 69 return TYPE_TASK; 70 } 71 72 75 public String getElement() { 76 return ELEMENT_TASK; 77 } 78 79 82 protected void parseElement(Element element) { 83 super.parseElement(element); 84 String name = element.getNodeName(); 85 ICompCSModelFactory factory = getModel().getFactory(); 86 87 if (name.equals(ELEMENT_PARAM)) { 88 ICompCSParam param = factory.createCompCSParam(this); 90 fFieldParams.add(param); 91 param.parse(element); 92 } 93 } 94 95 98 public void addFieldParam(ICompCSParam param) { 99 fFieldParams.add(param); 100 if (isEditable()) { 101 fireStructureChanged(param, IModelChangedEvent.INSERT); 102 } 103 } 104 105 108 public ICompCSParam[] getFieldParams() { 109 return (ICompCSParam[]) fFieldParams 110 .toArray(new ICompCSParam[fFieldParams.size()]); 111 } 112 113 116 public void removeFieldParam(ICompCSParam param) { 117 fFieldParams.remove(param); 118 if (isEditable()) { 119 fireStructureChanged(param, IModelChangedEvent.REMOVE); 120 } 121 } 122 123 126 public void reset() { 127 super.reset(); 128 129 fFieldParams = new ArrayList (); 130 } 131 132 135 protected void writeElements(String indent, PrintWriter writer) { 136 super.writeElements(indent, writer); 137 String newIndent = indent + XMLPrintHandler.XML_INDENT; 138 Iterator iterator = fFieldParams.iterator(); 140 while (iterator.hasNext()) { 141 ICompCSParam param = (ICompCSParam)iterator.next(); 142 param.write(newIndent, writer); 143 } 144 } 145 146 149 public boolean hasFieldParams() { 150 if (fFieldParams.isEmpty()) { 151 return false; 152 } 153 return true; 154 } 155 156 159 public ICompCSParam getFieldParam(String name) { 160 if (fFieldParams.isEmpty()) { 161 return null; 162 } 163 ListIterator iterator = fFieldParams.listIterator(); 164 while (iterator.hasNext()) { 165 ICompCSParam parameter = (ICompCSParam)iterator.next(); 166 if (parameter.getFieldName().equals(name)) { 167 return parameter; 168 } 169 } 170 return null; 171 } 172 } 173 | Popular Tags |