KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > nodes > elements > EnumNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.ui.nodes.elements;
21
22 import org.openide.nodes.Children;
23 import org.openide.nodes.Sheet;
24 import org.openide.nodes.Node;
25 import org.openide.util.datatransfer.NewType;
26 import org.openide.src.ElementProperties;
27 import org.netbeans.jmi.javamodel.JavaEnum;
28
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31
32 /**
33  * Node representing an enumeration
34  * @see org.netbeans.jmi.javamodel.JavaEnum
35  */

36 public final class EnumNode extends ElementNode {
37
38     private static final Map JavaDoc mapAttributeName;
39
40     static {
41         mapAttributeName = new HashMap JavaDoc();
42         mapAttributeName.put(PROP_MODIFIERS, PROP_MODIFIERS);
43         mapAttributeName.put(ElementProperties.PROP_NAME, ElementProperties.PROP_NAME);
44         mapAttributeName.put("interfaceNames", PROP_INTERFACES); // NOI18N
45
}
46     
47     public EnumNode(JavaEnum element, Children children, boolean writeable) {
48         super(element, children, writeable);
49         setElementFormat0(getElementFormatProperty());
50     }
51
52     protected String JavaDoc resolveIconBase() {
53         return IconStrings.ENUM;
54     }
55
56     protected ElementFormat getElementFormatProperty() {
57         return getSourceOptions().getEnumElementFormat();
58     }
59
60     protected ElementFormat getHintElementFormat() {
61         return getSourceOptions().getEnumElementLongFormat();
62     }
63
64     protected Map JavaDoc getAttributeNameMap() {
65         return mapAttributeName;
66     }
67
68     public NewType[] getNewTypes() {
69         if (writeable) {
70             return SourceEditSupport.createEnumNewTypes(getEnum());
71         } else {
72             return super.getNewTypes();
73         }
74     }
75
76     protected Sheet createSheet() {
77         Sheet s = Sheet.createDefault();
78         Sheet.Set ps = s.get(Sheet.PROPERTIES);
79         ps.put(createModifiersProperty(writeable));
80         ps.put(createNameProperty(getEnum()));
81         ps.put(createInterfacesProperty(writeable));
82         return s;
83     }
84
85     /** Create a node property for the implemented interfaces of this class.
86     * (Or, extended interfaces if this is itself an interface.)
87     * @param canW if <code>false</code>, property will be read-only
88     * @return the property
89     */

90     private Node.Property createInterfacesProperty(boolean canW) {
91         Node.Property prop = ClassNode.createInterfacesProperty(getEnum(), canW);
92
93         prop.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */, Boolean.FALSE); // NOI18N
94
setModel(getEnum(), prop);
95         
96         return prop;
97     }
98     
99     private JavaEnum getEnum() {
100         return (JavaEnum) this.element;
101     }
102 }
103
Popular Tags