KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > widget > ReadOnlyWidgetFilterNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget;
21
22 import java.beans.PropertyEditor JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24
25 import org.openide.actions.PropertiesAction;
26 import org.openide.nodes.FilterNode;
27 import org.openide.nodes.Node;
28 import org.openide.util.actions.SystemAction;
29
30 /**
31  * Default filter node implementation for all widgets.
32  *
33  * @author Nathan Fiedler
34  */

35 public class ReadOnlyWidgetFilterNode extends FilterNode {
36
37     /**
38      * Creates a new instance of WidgetFilterNode.
39      *
40      * @param original the original Node.
41      */

42     public ReadOnlyWidgetFilterNode(Node original) {
43         //super(original, new ReadOnlyChildren(original));
44
super(original);
45     }
46         
47     @Override JavaDoc
48     public javax.swing.Action JavaDoc[] getActions(boolean context) {
49         return new javax.swing.Action JavaDoc[] {
50                 SystemAction.get(PropertiesAction.class)};
51     }
52
53
54     @Override JavaDoc
55     public PropertySet[] getPropertySets () {
56         PropertySet[] propertySet = super.getPropertySets();
57         for(int i = 0; i < propertySet.length; i++) {
58             PropertySet pSet = propertySet[i];
59             ReadOnlyPropertySet rpSet = new ReadOnlyPropertySet(pSet);
60             propertySet[i] = rpSet;
61         }
62         return propertySet;
63     }
64
65     @Override JavaDoc
66     public boolean canRename()
67     {
68         return false;
69     }
70
71     @Override JavaDoc
72     public boolean canDestroy()
73     {
74         return false;
75     }
76
77     @Override JavaDoc
78     public boolean canCut()
79     {
80         return false;
81     }
82
83     @Override JavaDoc
84     public boolean canCopy()
85     {
86         return false;
87     }
88
89     @Override JavaDoc
90     public boolean hasCustomizer()
91     {
92         return false;
93     }
94     
95     
96     public static class ReadOnlyChildren extends FilterNode.Children {
97        
98        public ReadOnlyChildren(Node node) {
99            super(node);
100        }
101        
102        @Override JavaDoc
103        protected Node[] createNodes(Node n) {
104             return new Node[] {new ReadOnlyWidgetFilterNode(n)};
105        }
106    }
107    
108    public static class ReadOnlyProperty extends Node.Property {
109            
110        private Node.Property mDelegate;
111            
112        public ReadOnlyProperty(Node.Property delegate) {
113            super(delegate.getClass());
114            this.mDelegate = delegate;
115            this.setDisplayName(this.mDelegate.getDisplayName());
116            this.setName(this.mDelegate.getName());
117            this.setShortDescription(this.mDelegate.getShortDescription());
118            this.setExpert(this.mDelegate.isExpert());
119            this.setHidden(this.mDelegate.isHidden());
120            this.setPreferred(this.mDelegate.isPreferred());
121            
122        }
123        
124        @Override JavaDoc
125        public boolean equals(Object JavaDoc property) {
126            return this.mDelegate.equals(property);
127        }
128        
129        @Override JavaDoc
130        public String JavaDoc getHtmlDisplayName() {
131            return this.mDelegate.getHtmlDisplayName();
132        }
133        
134        @Override JavaDoc
135        public PropertyEditor JavaDoc getPropertyEditor() {
136            return this.mDelegate.getPropertyEditor();
137        }
138        
139        @Override JavaDoc
140        public Class JavaDoc getValueType() {
141            return this.mDelegate.getValueType();
142        }
143        
144        @Override JavaDoc
145        public int hashCode() {
146            return this.mDelegate.hashCode();
147        }
148        
149        @Override JavaDoc
150        public boolean isDefaultValue() {
151            return this.mDelegate.isDefaultValue();
152        }
153        
154        @Override JavaDoc
155        public void restoreDefaultValue() throws IllegalAccessException JavaDoc,
156                InvocationTargetException JavaDoc {
157            this.mDelegate.restoreDefaultValue();
158        }
159        
160        @Override JavaDoc
161        public boolean supportsDefaultValue() {
162            return this.mDelegate.supportsDefaultValue();
163        }
164        
165        @Override JavaDoc
166        public boolean canRead() {
167            return true;
168        }
169        
170        @Override JavaDoc
171        public boolean canWrite() {
172            return false;
173        }
174        
175        @Override JavaDoc
176        public Object JavaDoc getValue() throws IllegalAccessException JavaDoc,
177                InvocationTargetException JavaDoc {
178            return mDelegate.getValue();
179        }
180        
181        @Override JavaDoc
182        public void setValue(Object JavaDoc val) throws IllegalAccessException JavaDoc,
183                IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
184            //do nothing
185
}
186    }
187    
188    public static class ReadOnlyPropertySet extends Node.PropertySet {
189            
190        private Node.PropertySet mDelegate;
191        
192        public ReadOnlyPropertySet(Node.PropertySet delegate) {
193            super(delegate.getName(), delegate.getDisplayName(), delegate.getShortDescription());
194            this.mDelegate = delegate;
195        }
196        
197        @Override JavaDoc
198        public Property[] getProperties() {
199            Property[] properties = this.mDelegate.getProperties();
200            for(int i = 0; i < properties.length; i++) {
201                Property p = properties[i];
202                ReadOnlyProperty rp = new ReadOnlyProperty(p);
203                properties[i] = rp;
204            }
205            
206            return properties;
207        }
208    }
209 }
210
Popular Tags