KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > src > nodes > InitializerElementNode


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.openide.src.nodes;
21
22 import java.io.IOException JavaDoc;
23 import java.beans.*;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25
26 import org.openide.src.*;
27 import org.openide.nodes.*;
28
29 /** Node representing an initializer (static or nonstatic).
30 * @see InitializerElement
31 *
32 * @author Petr Hamernik
33 */

34 public class InitializerElementNode extends ElementNode {
35     /** Return value of getIconAffectingProperties method. */
36     private static final String JavaDoc[] ICON_AFFECTING_PROPERTIES = new String JavaDoc[] {
37                 PROP_STATIC
38             };
39
40     /** Create a new initializer node.
41     * @param element initializer element to represent
42     * @param writeable <code>true</code> to be writable
43     */

44     public InitializerElementNode(InitializerElement element, boolean writeable) {
45         super(element, Children.LEAF, writeable);
46         setElementFormat0(sourceOptions.getInitializerElementFormat());
47         superSetName("<initializer>"); // NOI18N
48
}
49
50
51     public org.openide.util.HelpCtx getHelpCtx () {
52         return new org.openide.util.HelpCtx ("org.openide.src.nodes.InitializerNode"); // NOI18N
53
}
54
55     /* Resolve the current icon base.
56     * @return icon base string.
57     */

58     protected String JavaDoc resolveIconBase() {
59         return ((InitializerElement)element).isStatic() ? INITIALIZER_ST : INITIALIZER;
60     }
61
62     /* This method is used for resolving the names of the properties,
63     * which could affect the icon (such as "modifiers").
64     * @return the appropriate array.
65     */

66     protected String JavaDoc[] getIconAffectingProperties() {
67         return ICON_AFFECTING_PROPERTIES;
68     }
69
70     /* This method resolve the appropriate hint format for the type
71     * of the element. It defines the short description.
72     */

73     protected ElementFormat getHintElementFormat() {
74         return sourceOptions.getInitializerElementLongFormat();
75     }
76
77     /* Creates property set for this node */
78     protected Sheet createSheet () {
79         Sheet sheet = Sheet.createDefault();
80         Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
81         ps.put(createStaticProperty(writeable));
82         return sheet;
83     }
84
85     /** Indicate that this node cannot be renamed.
86     * An initializer has no name.
87     * @return <code>false</code>
88     */

89     public boolean canRename() {
90         return false;
91     }
92
93     /* Removes the element from the class and calls superclass.
94     *
95     * @exception IOException if SourceException is thrown
96     * from the underlayed Element.
97     */

98     public void destroy() throws IOException JavaDoc {
99         SourceEditSupport.invokeAtomicAsUser(element, new SourceEditSupport.ExceptionalRunnable() {
100                                                  public void run() throws SourceException {
101                                                      InitializerElement el = (InitializerElement) element;
102                                                      el.getDeclaringClass().removeInitializer(el);
103                                                  }
104                                              });
105         super.destroy();
106     }
107
108     /** Create a property for whether or not the initializer is static.
109     * @param canW <code>false</code> to force property to be read-only
110     * @return the property
111     */

112     protected Node.Property createStaticProperty(boolean canW) {
113         return new ElementProp(ElementProperties.PROP_STATIC, Boolean.TYPE, canW) {
114                    /** Gets the value */
115                    public Object JavaDoc getValue () {
116                        return ((InitializerElement)element).isStatic() ? Boolean.TRUE : Boolean.FALSE;
117                    }
118
119                    /** Sets the value */
120                    public void setValue(final Object JavaDoc val) throws IllegalArgumentException JavaDoc,
121                        IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
122                        super.setValue(val);
123
124                        if (!(val instanceof Boolean JavaDoc))
125                            throw new IllegalArgumentException JavaDoc();
126
127                        runAtomic(element, new SourceEditSupport.ExceptionalRunnable() {
128                                      public void run() throws SourceException {
129                                          ((InitializerElement)element).setStatic(((Boolean JavaDoc)val).booleanValue());
130                                      }
131                                  });
132                    }
133                };
134     }
135 }
136
Popular Tags