001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.site;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
016: import org.eclipse.pde.internal.core.isite.ISiteDescription;
017: import org.w3c.dom.Node;
018: import org.w3c.dom.NodeList;
019:
020: public class SiteCategoryDefinition extends SiteObject implements
021: ISiteCategoryDefinition {
022:
023: private static final long serialVersionUID = 1L;
024: private String name;
025: private ISiteDescription description;
026:
027: /**
028: * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#getName()
029: */
030: public String getName() {
031: return name;
032: }
033:
034: public boolean isValid() {
035: return name != null && getLabel() != null;
036: }
037:
038: /**
039: * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#setName(java.lang.String)
040: */
041: public void setName(String name) throws CoreException {
042: ensureModelEditable();
043: Object oldValue = this .name;
044: this .name = name;
045: firePropertyChanged(P_NAME, oldValue, name);
046: }
047:
048: /**
049: * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#getDescription()
050: */
051: public ISiteDescription getDescription() {
052: return description;
053: }
054:
055: /**
056: * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#setDescription(org.eclipse.pde.internal.core.isite.ISiteDescription)
057: */
058: public void setDescription(ISiteDescription description)
059: throws CoreException {
060: ensureModelEditable();
061: Object oldValue = this .description;
062: this .description = description;
063: firePropertyChanged(P_DESCRIPTION, oldValue, description);
064: }
065:
066: protected void reset() {
067: super .reset();
068: name = null;
069: description = null;
070: }
071:
072: protected void parse(Node node) {
073: super .parse(node);
074: name = getNodeAttribute(node, "name"); //$NON-NLS-1$
075: NodeList children = node.getChildNodes();
076: for (int i = 0; i < children.getLength(); i++) {
077: Node child = children.item(i);
078: if (child.getNodeType() == Node.ELEMENT_NODE
079: && child.getNodeName().equalsIgnoreCase(
080: "description")) { //$NON-NLS-1$
081: description = getModel().getFactory()
082: .createDescription(this );
083: ((SiteDescription) description).parse(child);
084: ((SiteDescription) description).setInTheModel(true);
085: break;
086: }
087: }
088: }
089:
090: public void restoreProperty(String name, Object oldValue,
091: Object newValue) throws CoreException {
092: if (name.equals(P_NAME)) {
093: setName(newValue != null ? newValue.toString() : null);
094: } else if (name.equals(P_DESCRIPTION)
095: && newValue instanceof ISiteDescription) {
096: setDescription((ISiteDescription) newValue);
097: } else
098: super .restoreProperty(name, oldValue, newValue);
099: }
100:
101: public void write(String indent, PrintWriter writer) {
102: writer.print(indent);
103: writer.print("<category-def"); //$NON-NLS-1$
104: if (name != null)
105: writer
106: .print(" name=\"" + SiteObject.getWritableString(name) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
107: if (label != null)
108: writer
109: .print(" label=\"" + SiteObject.getWritableString(label) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
110: if (description != null) {
111: writer.println(">"); //$NON-NLS-1$
112: description.write(indent + Site.INDENT, writer);
113: writer.println(indent + "</category-def>"); //$NON-NLS-1$
114: } else
115: writer.println("/>"); //$NON-NLS-1$
116: }
117: }
|