01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.site;
11:
12: import java.io.PrintWriter;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.pde.internal.core.isite.ISite;
16: import org.eclipse.pde.internal.core.isite.ISiteCategory;
17: import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
18: import org.w3c.dom.Node;
19:
20: public class SiteCategory extends SiteObject implements ISiteCategory {
21: private static final long serialVersionUID = 1L;
22: private String name;
23:
24: /**
25: * @see org.eclipse.pde.internal.core.isite.ISiteCategory#getName()
26: */
27: public String getName() {
28: return name;
29: }
30:
31: public boolean isValid() {
32: return name != null;
33: }
34:
35: protected void parse(Node node) {
36: name = getNodeAttribute(node, "name"); //$NON-NLS-1$
37: }
38:
39: protected void reset() {
40: name = null;
41: }
42:
43: /**
44: * @see org.eclipse.pde.internal.core.isite.ISiteCategory#setName(java.lang.String)
45: */
46: public void setName(String name) throws CoreException {
47: ensureModelEditable();
48: Object oldValue = this .name;
49: this .name = name;
50: firePropertyChanged(P_NAME, oldValue, name);
51: }
52:
53: public void write(String indent, PrintWriter writer) {
54: writer.print(indent);
55: writer.print("<category"); //$NON-NLS-1$
56: if (name != null)
57: writer
58: .print(" name=\"" + SiteObject.getWritableString(name) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
59: writer.println("/>"); //$NON-NLS-1$
60: }
61:
62: public void restoreProperty(String name, Object oldValue,
63: Object newValue) throws CoreException {
64: if (name.equals(P_NAME)) {
65: setName(newValue != null ? newValue.toString() : null);
66: } else
67: super .restoreProperty(name, oldValue, newValue);
68: }
69:
70: public ISiteCategoryDefinition getDefinition() {
71: ISite site = getSite();
72: ISiteCategoryDefinition[] definitions = site
73: .getCategoryDefinitions();
74: for (int i = 0; i < definitions.length; i++) {
75: ISiteCategoryDefinition def = definitions[i];
76: if (def.getName().equals(getName()))
77: return def;
78: }
79: return null;
80: }
81: }
|