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.ISimpleCSModel; 21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModelFactory; 22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject; 23 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSRepeatedSubItem; 24 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 29 33 public class SimpleCSRepeatedSubItem extends SimpleCSObject implements 34 ISimpleCSRepeatedSubItem { 35 36 39 private String fValues; 40 41 44 private ISimpleCSSubItem fSubItem; 45 46 49 private static final long serialVersionUID = 1L; 50 51 55 public SimpleCSRepeatedSubItem(ISimpleCSModel model, ISimpleCSObject parent) { 56 super(model, parent); 57 reset(); 58 } 59 60 63 public ISimpleCSSubItem getSubItem() { 64 return fSubItem; 65 } 66 67 70 public String getValues() { 71 return fValues; 72 } 73 74 77 public void setSubItem(ISimpleCSSubItem subitem) { 78 ISimpleCSObject old = fSubItem; 79 fSubItem = subitem; 80 81 if (isEditable()) { 82 fireStructureChanged(subitem, old); 83 } 84 } 85 86 89 public void setValues(String values) { 90 String old = fValues; 91 fValues = values; 92 if (isEditable()) { 93 firePropertyChanged(ATTRIBUTE_VALUES, old, fValues); 94 } 95 } 96 97 100 public void parse(Element element) { 101 fValues = element.getAttribute(ATTRIBUTE_VALUES); 104 105 NodeList children = element.getChildNodes(); 107 ISimpleCSModelFactory factory = getModel().getFactory(); 108 for (int i = 0; i < children.getLength(); i++) { 109 Node child = children.item(i); 110 if (child.getNodeType() == Node.ELEMENT_NODE) { 111 String name = child.getNodeName(); 112 Element childElement = (Element )child; 113 114 if (name.equals(ELEMENT_SUBITEM)) { 115 fSubItem = factory.createSimpleCSSubItem(this); 116 fSubItem.parse(childElement); 117 break; 119 } 120 } 121 } 122 123 } 124 125 128 public void write(String indent, PrintWriter writer) { 129 130 StringBuffer buffer = new StringBuffer (); 131 String newIndent = indent + XMLPrintHandler.XML_INDENT; 132 133 try { 134 buffer.append(ELEMENT_REPEATED_SUBITEM); 136 if ((fValues != null) && 138 (fValues.length() > 0)) { 139 buffer.append(XMLPrintHandler.wrapAttribute( 141 ATTRIBUTE_VALUES, fValues)); 142 } 143 XMLPrintHandler.printBeginElement(writer, buffer.toString(), 145 indent, false); 146 if (fSubItem != null) { 148 fSubItem.write(newIndent, writer); 149 } 150 XMLPrintHandler.printEndElement(writer, ELEMENT_REPEATED_SUBITEM, indent); 152 153 } catch (IOException e) { 154 } 157 158 } 159 160 163 public void reset() { 164 fValues = null; 165 fSubItem = null; 166 } 167 168 171 public int getType() { 172 return TYPE_REPEATED_SUBITEM; 173 } 174 175 178 public String getName() { 179 return ELEMENT_REPEATED_SUBITEM; 181 } 182 183 186 public List getChildren() { 187 ArrayList list = new ArrayList (); 188 if (fSubItem != null) { 190 list.add(fSubItem); 191 } 192 return list; 193 } 194 195 } 196 | Popular Tags |