KickJava   Java API By Example, From Geeks To Geeks.

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


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.netbeans.jmi.javamodel.Method;
23 import org.openide.nodes.Children;
24 import org.openide.nodes.Sheet;
25 import org.openide.nodes.Node;
26 import org.openide.src.ElementProperties;
27
28 import javax.jmi.reflect.InvalidObjectException;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31
32 /** Node for a method element.
33  * @see org.netbeans.jmi.javamodel.Method
34  * @author Petr Hamernik, Jan Pokorsky
35  * XXX help ids
36  */

37 public class MethodNode extends ElementNode {
38
39     private static final Map JavaDoc mapAttributeName;
40     
41     static {
42         mapAttributeName = new HashMap JavaDoc();
43         mapAttributeName.put(PROP_MODIFIERS, PROP_MODIFIERS);
44         mapAttributeName.put(ElementProperties.PROP_NAME, ElementProperties.PROP_NAME);
45         mapAttributeName.put(PROP_PARAMETERS, PROP_PARAMETERS);
46         mapAttributeName.put("typeName", PROP_RETURN); // NOI18N
47
mapAttributeName.put("exceptionNames", PROP_EXCEPTIONS); // NOI18N
48
}
49     
50     /** Create a new method node.
51     * @param element method element to represent
52     * @param writeable <code>true</code> to be writable
53     */

54     public MethodNode(Method element, boolean writeable) {
55         super(element, Children.LEAF, writeable);
56         setElementFormat0(getElementFormatProperty());
57         superSetName(element.getName());
58     }
59
60     protected String JavaDoc resolveIconBase() {
61         return IconResolver.getIconBaseForMethod(getMethod());
62     }
63
64     protected ElementFormat getElementFormatProperty() {
65         return getSourceOptions().getMethodElementFormat();
66     }
67
68     /* This method resolve the appropriate hint format for the type
69     * of the element. It defines the short description.
70     */

71     protected ElementFormat getHintElementFormat() {
72         return getSourceOptions().getMethodElementLongFormat();
73     }
74
75     protected Map JavaDoc getAttributeNameMap() {
76         return mapAttributeName;
77     }
78
79     /* Creates property set for this node */
80     protected Sheet createSheet () {
81         Sheet sheet = Sheet.createDefault();
82         Node.Property[] props = new Node.Property[6];
83         try {
84             props[0] = createModifiersProperty(writeable);
85             props[1] = createNameProperty(getMethod());
86             props[2] = createTypeParametersProperty();
87             props[3] = createParametersProperty(false);
88             props[4] = createReturnProperty(writeable);
89             props[5] = createExceptionsProperty(writeable);
90             Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
91             ps.put(props);
92         } catch (InvalidObjectException e) {
93             // does not matter since class children will refresh its contents
94
}
95         return sheet;
96     }
97     
98     private Node.Property createParametersProperty(boolean canW) {
99         // this should be read-olny -> refactoring job
100
Node.Property p = createParametersProperty(getMethod(), canW);
101         p.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */,Boolean.FALSE); // NOI18N
102
return p;
103     }
104
105     /** Create a node property for constructor exceptions.
106     * @param canW <code>false</code> to force property to be read-only
107     * @return the property
108     */

109     private Node.Property createExceptionsProperty(boolean canW) {
110         Node.Property p = createExceptionsProperty(getMethod(), canW);
111         p.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */,Boolean.FALSE); // NOI18N
112
return p;
113     }
114     
115     Node.Property createTypeParametersProperty() {
116         Node.Property np = createTypeParametersProperty(PROP_TYPE_PARAMETERS, getMethod(), false);
117         np.setValue("changeImmediate" /* PropertyEnv.PROP_CHANGE_IMMEDIATE */, Boolean.FALSE); // NOI18N
118
return np;
119     }
120
121     /** Create a property for the method return value.
122     * @param canW <code>false</code> to force property to be read-only
123     * @return the property
124     */

125     private Node.Property createReturnProperty(boolean canW) {
126         return createTypeProperty(PROP_RETURN, getMethod(), canW);
127     }
128     
129     private Method getMethod() {
130         return (Method) this.element;
131     }
132 }
133
Popular Tags