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.ICompCSModel; 22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory; 23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject; 24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask; 25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup; 26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject; 27 import org.w3c.dom.Element ; 28 29 33 public class CompCSTaskGroup extends CompCSTaskObject implements 34 ICompCSTaskGroup { 35 36 37 private ArrayList fFieldTaskObjects; 38 39 42 private static final long serialVersionUID = 1L; 43 44 48 public CompCSTaskGroup(ICompCSModel model, ICompCSObject parent) { 49 super(model, parent); 50 reset(); 51 } 52 53 56 public List getChildren() { 57 ArrayList list = new ArrayList (); 58 if (fFieldTaskObjects.size() > 0) { 60 list.addAll(fFieldTaskObjects); 61 } 62 return list; 63 } 64 65 68 public String getName() { 69 return fFieldName; 70 } 71 72 75 public int getType() { 76 return TYPE_TASKGROUP; 77 } 78 79 82 public void reset() { 83 super.reset(); 84 85 fFieldTaskObjects = new ArrayList (); 86 } 87 88 91 public void addFieldTaskObject(ICompCSTaskObject taskObject) { 92 fFieldTaskObjects.add(taskObject); 93 if (isEditable()) { 94 fireStructureChanged(taskObject, IModelChangedEvent.INSERT); 95 } 96 } 97 98 101 public void addFieldTaskObject(int index, ICompCSTaskObject taskObject) { 102 if (index < 0){ 103 return; 104 } 105 if (index >= fFieldTaskObjects.size()) { 106 fFieldTaskObjects.add(taskObject); 107 } else { 108 fFieldTaskObjects.add(index, taskObject); 109 } 110 111 if (isEditable()) { 112 fireStructureChanged(taskObject, IModelChangedEvent.INSERT); 113 } 114 } 115 116 119 public int getFieldTaskObjectCount() { 120 return fFieldTaskObjects.size(); 121 } 122 123 126 public ICompCSTaskObject[] getFieldTaskObjects() { 127 return (ICompCSTaskObject[]) fFieldTaskObjects 128 .toArray(new ICompCSTaskObject[fFieldTaskObjects.size()]); 129 } 130 131 134 public boolean hasFieldTaskObjects() { 135 if (fFieldTaskObjects.isEmpty()) { 136 return false; 137 } 138 return true; 139 } 140 141 144 public int indexOfFieldTaskObject(ICompCSTaskObject taskObject) { 145 return fFieldTaskObjects.indexOf(taskObject); 146 } 147 148 151 public boolean isFirstFieldTaskObject(ICompCSTaskObject taskObject) { 152 int position = fFieldTaskObjects.indexOf(taskObject); 153 if (position == 0) { 154 return true; 155 } 156 return false; 157 } 158 159 162 public boolean isLastFieldTaskObject(ICompCSTaskObject taskObject) { 163 int position = fFieldTaskObjects.indexOf(taskObject); 164 int lastPosition = fFieldTaskObjects.size() - 1; 165 if (position == lastPosition) { 166 return true; 167 } 168 return false; 169 } 170 171 174 public void removeFieldTaskObject(ICompCSTaskObject taskObject) { 175 fFieldTaskObjects.remove(taskObject); 176 if (isEditable()) { 177 fireStructureChanged(taskObject, IModelChangedEvent.REMOVE); 178 } 179 } 180 181 184 public void removeFieldTaskObject(int index) { 185 if ((index < 0) || 186 (index > (fFieldTaskObjects.size() - 1))) { 187 return; 188 } 189 ICompCSTaskObject taskObject = 190 (ICompCSTaskObject)fFieldTaskObjects.remove(index); 191 if (isEditable()) { 192 fireStructureChanged(taskObject, IModelChangedEvent.REMOVE); 193 } 194 } 195 196 199 protected void parseElement(Element element) { 200 super.parseElement(element); 201 String name = element.getNodeName(); 202 ICompCSModelFactory factory = getModel().getFactory(); 203 204 if (name.equals(ELEMENT_TASK)) { 205 ICompCSTask task = factory.createCompCSTask(this); 207 fFieldTaskObjects.add(task); 208 task.parse(element); 209 } else if (name.equals(ELEMENT_TASKGROUP)) { 210 ICompCSTaskGroup taskGroup = factory.createCompCSTaskGroup(this); 212 fFieldTaskObjects.add(taskGroup); 213 taskGroup.parse(element); 214 } 215 } 216 217 220 protected void writeElements(String indent, PrintWriter writer) { 221 super.writeElements(indent, writer); 222 String newIndent = indent + XMLPrintHandler.XML_INDENT; 223 Iterator iterator = fFieldTaskObjects.iterator(); 225 while (iterator.hasNext()) { 226 ICompCSTaskObject taskObject = (ICompCSTaskObject)iterator.next(); 227 taskObject.write(newIndent, writer); 228 } 229 } 230 231 234 public String getElement() { 235 return ELEMENT_TASKGROUP; 236 } 237 238 241 public ICompCSTaskObject getNextSibling(ICompCSTaskObject taskObject) { 242 int position = fFieldTaskObjects.indexOf(taskObject); 243 int lastIndex = fFieldTaskObjects.size() - 1; 244 if ((position == -1) || 245 (position == lastIndex)) { 246 return null; 249 } 250 return (ICompCSTaskObject)fFieldTaskObjects.get(position + 1); 251 } 252 253 256 public ICompCSTaskObject getPreviousSibling(ICompCSTaskObject taskObject) { 257 int position = fFieldTaskObjects.indexOf(taskObject); 258 if ((position == -1) || 259 (position == 0)) { 260 return null; 263 } 264 return (ICompCSTaskObject)fFieldTaskObjects.get(position - 1); 265 } 266 267 270 public void moveFieldTaskObject(ICompCSTaskObject taskObject, 271 int newRelativeIndex) { 272 int currentIndex = indexOfFieldTaskObject(taskObject); 274 if (currentIndex == -1) { 276 return; 277 } 278 int newIndex = newRelativeIndex + currentIndex; 280 if ((newIndex < 0) || 282 (newIndex >= fFieldTaskObjects.size())) { 283 return; 284 } 285 fFieldTaskObjects.remove(taskObject); 287 fFieldTaskObjects.add(newIndex, taskObject); 289 if (isEditable()) { 291 fireStructureChanged(taskObject, IModelChangedEvent.INSERT); 292 } 293 } 294 295 } 296 | Popular Tags |