1 11 package org.eclipse.pde.internal.core.site; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition; 17 import org.eclipse.pde.internal.core.isite.ISiteDescription; 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 21 public class SiteCategoryDefinition 22 extends SiteObject 23 implements ISiteCategoryDefinition { 24 25 private static final long serialVersionUID = 1L; 26 private String name; 27 private ISiteDescription description; 28 29 32 public String getName() { 33 return name; 34 } 35 36 public boolean isValid() { 37 return name!=null && getLabel()!=null; 38 } 39 40 43 public void setName(String name) throws CoreException { 44 ensureModelEditable(); 45 Object oldValue = this.name; 46 this.name = name; 47 firePropertyChanged(P_NAME, oldValue, name); 48 } 49 50 53 public ISiteDescription getDescription() { 54 return description; 55 } 56 57 60 public void setDescription(ISiteDescription description) 61 throws CoreException { 62 ensureModelEditable(); 63 Object oldValue = this.description; 64 this.description = description; 65 firePropertyChanged(P_DESCRIPTION, oldValue, description); 66 } 67 68 protected void reset() { 69 super.reset(); 70 name = null; 71 description = null; 72 } 73 74 protected void parse(Node node) { 75 super.parse(node); 76 name = getNodeAttribute(node, "name"); NodeList children = node.getChildNodes(); 78 for (int i = 0; i < children.getLength(); i++) { 79 Node child = children.item(i); 80 if (child.getNodeType() == Node.ELEMENT_NODE 81 && child.getNodeName().equalsIgnoreCase("description")) { description = getModel().getFactory().createDescription(this); 83 ((SiteDescription) description).parse(child); 84 ((SiteDescription)description).setInTheModel(true); 85 break; 86 } 87 } 88 } 89 public void restoreProperty(String name, Object oldValue, Object newValue) 90 throws CoreException { 91 if (name.equals(P_NAME)) { 92 setName(newValue != null ? newValue.toString() : null); 93 } else if ( 94 name.equals(P_DESCRIPTION) 95 && newValue instanceof ISiteDescription) { 96 setDescription((ISiteDescription) newValue); 97 } else 98 super.restoreProperty(name, oldValue, newValue); 99 } 100 public void write(String indent, PrintWriter writer) { 101 writer.print(indent); 102 writer.print("<category-def"); if (name != null) 104 writer.print(" name=\"" + SiteObject.getWritableString(name) + "\""); if (label != null) 106 writer.print(" label=\"" + SiteObject.getWritableString(label) + "\""); if (description != null) { 108 writer.println(">"); description.write(indent + Site.INDENT, writer); 110 writer.println(indent + "</category-def>"); } else 112 writer.println("/>"); } 114 } 115 | Popular Tags |