KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > site > SiteCategory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.site;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.core.isite.ISite;
17 import org.eclipse.pde.internal.core.isite.ISiteCategory;
18 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
19 import org.w3c.dom.Node JavaDoc;
20
21 public class SiteCategory extends SiteObject implements ISiteCategory {
22     private static final long serialVersionUID = 1L;
23     private String JavaDoc name;
24     /**
25      * @see org.eclipse.pde.internal.core.isite.ISiteCategory#getName()
26      */

27     public String JavaDoc getName() {
28         return name;
29     }
30     
31     public boolean isValid() {
32         return name!=null;
33     }
34     
35     protected void parse(Node JavaDoc 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 JavaDoc name) throws CoreException {
47         ensureModelEditable();
48         Object JavaDoc oldValue = this.name;
49         this.name = name;
50         firePropertyChanged(P_NAME, oldValue, name);
51     }
52     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
53         writer.print(indent);
54         writer.print("<category"); //$NON-NLS-1$
55
if (name!=null)
56             writer.print(" name=\"" + SiteObject.getWritableString(name) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
57
writer.println("/>"); //$NON-NLS-1$
58
}
59     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
60         throws CoreException {
61         if (name.equals(P_NAME)) {
62             setName(newValue != null ? newValue.toString() : null);
63         }
64         else super.restoreProperty(name, oldValue, newValue);
65     }
66
67     public ISiteCategoryDefinition getDefinition() {
68         ISite site = getSite();
69         ISiteCategoryDefinition [] definitions = site.getCategoryDefinitions();
70         for (int i=0; i<definitions.length; i++) {
71             ISiteCategoryDefinition def = definitions[i];
72             if (def.getName().equals(getName()))
73                 return def;
74         }
75         return null;
76     }
77 }
78
Popular Tags