1 11 12 package org.eclipse.pde.internal.core.cheatsheet.comp; 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.comp.ICompCS; 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.ICompCSTaskObject; 25 import org.eclipse.pde.internal.core.util.PDETextHelper; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.Text ; 28 29 33 public class CompCS extends CompCSObject implements ICompCS { 34 35 private String fFieldName; 36 37 private ICompCSTaskObject fFieldTaskObject; 38 39 40 43 private static final long serialVersionUID = 1L; 44 45 48 public CompCS(ICompCSModel model) { 49 super(model, null); 50 reset(); 51 } 52 53 56 public List getChildren() { 57 ArrayList list = new ArrayList (); 58 if (fFieldTaskObject != null) { 60 list.add(fFieldTaskObject); 61 } 62 return list; 63 } 64 65 68 public String getName() { 69 return fFieldName; 70 } 71 72 75 public int getType() { 76 return TYPE_COMPOSITE_CHEATSHEET; 77 } 78 79 82 protected void parseAttributes(Element element) { 83 fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim(); 86 } 87 88 91 protected void parseElement(Element element) { 92 String name = element.getNodeName(); 93 ICompCSModelFactory factory = getModel().getFactory(); 94 95 if (name.equals(ELEMENT_TASK)) { 96 fFieldTaskObject = factory.createCompCSTask(this); 98 fFieldTaskObject.parse(element); 99 } else if (name.equals(ELEMENT_TASKGROUP)) { 100 fFieldTaskObject = factory.createCompCSTaskGroup(this); 102 fFieldTaskObject.parse(element); 103 } 104 } 105 106 109 public void reset() { 110 fFieldName = null; 111 fFieldTaskObject = null; 112 } 113 114 117 public void write(String indent, PrintWriter writer) { 118 119 try { 120 XMLPrintHandler.printHead(writer, ATTRIBUTE_VALUE_ENCODING); 122 super.write(indent, writer); 123 } catch (IOException e) { 124 } 127 } 128 129 132 protected void writeAttributes(StringBuffer buffer) { 133 if ((fFieldName != null) && 135 (fFieldName.length() > 0)) { 136 buffer.append(XMLPrintHandler.wrapAttribute( 139 ATTRIBUTE_NAME, 140 PDETextHelper.translateWriteText( 141 fFieldName.trim(), DEFAULT_SUBSTITUTE_CHARS))); 142 } 143 } 144 145 148 protected void writeElements(String indent, PrintWriter writer) { 149 String newIndent = indent + XMLPrintHandler.XML_INDENT; 150 if (fFieldTaskObject != null) { 152 fFieldTaskObject.write(newIndent, writer); 153 } 154 } 155 156 159 public String getFieldName() { 160 return fFieldName; 161 } 162 163 166 public ICompCSTaskObject getFieldTaskObject() { 167 return fFieldTaskObject; 168 } 169 170 173 public void setFieldName(String name) { 174 String old = fFieldName; 175 fFieldName = name; 176 if (isEditable()) { 177 firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName); 178 } 179 } 180 181 184 public void setFieldTaskObject(ICompCSTaskObject taskObject) { 185 ICompCSObject old = fFieldTaskObject; 186 fFieldTaskObject = taskObject; 187 if (isEditable()) { 188 fireStructureChanged(fFieldTaskObject, old); 189 } 190 } 191 192 195 public String getElement() { 196 return ELEMENT_COMPOSITE_CHEATSHEET; 197 } 198 199 202 protected void parseText(Text text) { 203 } 205 206 } 207 | Popular Tags |