2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
45
import java.awt.Image;
46
import java.awt.datatransfer.Transferable;
47
import java.beans.PropertyEditor;
48
import java.lang.reflect.InvocationTargetException;
49
import java.util.logging.Level;
51
import javax.swing.Action;
53
import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
54
import org.netbeans.modules.xml.wsdl.model.Import;
55
import org.netbeans.modules.xml.wsdl.ui.actions.CommonAddExtensibilityAttributeAction;
56
import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction;
57
import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter;
58
import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
59
import org.netbeans.modules.xml.wsdl.ui.view.property.ImportLocationPropertyEditor;
60
import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
61
import org.openide.actions.CopyAction;
62
import org.openide.actions.CutAction;
63
import org.openide.actions.DeleteAction;
64
import org.openide.actions.NewAction;
65
import org.openide.actions.PasteAction;
66
import org.openide.actions.PropertiesAction;
67
import org.openide.cookies.SaveCookie;
68
import org.openide.nodes.Children;
69
import org.openide.nodes.FilterNode;
70
import org.openide.nodes.Node;
71
import org.openide.nodes.Sheet;
72
import org.openide.util.Lookup;
73
import org.openide.util.NbBundle;
74
import org.openide.util.Utilities;
75
import org.openide.util.actions.SystemAction;
76
import org.openide.util.datatransfer.NewType;
77
import org.openide.util.datatransfer.PasteType;
78
import org.openide.util.lookup.Lookups;
79
import org.openide.util.lookup.ProxyLookup;
84
* @author Ritesh Adval
88
public class ImportNode extends WSDLElementNode<Import> {
90
private static final String NAMESPACE_PROP = "namespace";//NOI18N
92
Image ICON = Utilities.loadImage
93
("org/netbeans/modules/xml/wsdl/ui/view/resources/import-include-redefine.png");
95
private ImportPropertyAdapter mPropertyAdapter;
97
private static final SystemAction[] ACTIONS = new SystemAction[]{
98
SystemAction.get(CutAction.class),
99
SystemAction.get(CopyAction.class),
100
SystemAction.get(PasteAction.class),
102
SystemAction.get(NewAction.class),
103
SystemAction.get(DeleteAction.class),
105
SystemAction.get(CommonAddExtensibilityAttributeAction.class),
106
SystemAction.get(RemoveAttributesAction.class),
108
SystemAction.get(GoToAction.class),
110
SystemAction.get(PropertiesAction.class)
113
public ImportNode(Children children,
114
Import wsdlConstruct) {
115
super(children, wsdlConstruct);
116
this.mPropertyAdapter = new ImportPropertyAdapter();
121
public Image getIcon(int type) {
126
public Image getOpenedIcon(int type) {
131
public Action[] getActions(boolean context) {
136
protected void refreshAttributesSheetSet(Sheet sheet) {
137
Sheet.Set ss = sheet.get(Sheet.PROPERTIES);
141
Node.Property namespaceProperty = new BaseAttributeProperty(mPropertyAdapter,
144
namespaceProperty.setName(Import.NAMESPACE_URI_PROPERTY);
145
namespaceProperty.setDisplayName(NbBundle.getMessage(ImportNode.class, "PROP_NAMESPACE_DISPLAYNAME"));
146
namespaceProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "NAMESPACE_DESC"));
147
ss.put(namespaceProperty);
150
Node.Property locationProperty = new ImportLocationProperty(mPropertyAdapter,
153
"setLocation");//NOI18N
154
locationProperty.setName(Import.LOCATION_PROPERTY);
155
locationProperty.setDisplayName(NbBundle.getMessage(ImportNode.class, "PROP_LOCATION_DISPLAYNAME"));
156
locationProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "LOCATION_DESC"));
157
ss.put(locationProperty);
161
} catch(Exception ex) {
162
mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
167
protected void updateDisplayName() {
168
if (getWSDLComponent() != null) {
169
setDisplayName(getWSDLComponent().getNamespace());
173
public class ImportPropertyAdapter extends PropertyAdapter {
175
public ImportPropertyAdapter() {
176
super(getWSDLComponent());
179
public void setLocation(String location) {
180
Import imp = (Import) getDelegate();
181
imp.getModel().startTransaction();
182
imp.setLocation(location);
183
imp.getModel().endTransaction();
186
public String getLocation() {
187
if(getWSDLComponent().getLocation() == null) {
191
return getWSDLComponent().getLocation();
194
public void setNamespace(String namespace) {
195
getWSDLComponent().getModel().startTransaction();
196
(getWSDLComponent()).setNamespace(namespace);
197
getWSDLComponent().getModel().endTransaction();
200
public String getNamespace() {
201
if(getWSDLComponent().getNamespace() == null) {
205
return getWSDLComponent().getNamespace();
210
private final class ImportLocationProperty
211
extends BaseAttributeProperty {
213
public ImportLocationProperty(PropertyAdapter instance, Class valueType,
214
String getter, String setter) throws NoSuchMethodException {
215
super(instance, valueType, getter, setter);
219
public PropertyEditor getPropertyEditor() {
220
return new ImportLocationPropertyEditor(getWSDLComponent());
225
public String getTypeDisplayName() {
226
return NbBundle.getMessage(ImportNode.class, "LBL_UnrecognizedImport_TypeDisplayName");
230
public static class ReadOnlyNode extends FilterNode {
231
private static final SystemAction[] ACTIONS = new SystemAction[] {
232
SystemAction.get(GoToAction.class),
233
(SystemAction)RefactoringActionsFactory.whereUsedAction(),
235
SystemAction.get(PropertiesAction.class),
238
public ReadOnlyNode(Node original) {
239
this(original, null);
242
public ReadOnlyNode(Node original, Lookup lookup) {
243
super(original, new ReadOnlyChildren(original, lookup),
244
new ProxyLookup(new Lookup[] {lookup,
245
Lookups.exclude(original.getLookup(), new Class[] {
249
disableDelegation(FilterNode.DELEGATE_DESTROY);
250
disableDelegation(FilterNode.DELEGATE_GET_ACTIONS);
251
disableDelegation(FilterNode.DELEGATE_GET_CONTEXT_ACTIONS);
252
disableDelegation(FilterNode.DELEGATE_SET_DISPLAY_NAME);
253
disableDelegation(FilterNode.DELEGATE_SET_NAME);
254
disableDelegation(FilterNode.DELEGATE_SET_SHORT_DESCRIPTION);
255
disableDelegation(FilterNode.DELEGATE_SET_VALUE);
259
public Action[] getActions(boolean context) {
265
public PropertySet[] getPropertySets () {
266
PropertySet[] propertySet = super.getPropertySets();
267
for(int i = 0; i < propertySet.length; i++) {
268
PropertySet pSet = propertySet[i];
269
ReadOnlyPropertySet rpSet = new ReadOnlyPropertySet(pSet);
270
propertySet[i] = rpSet;
275
public NewType[] getNewTypes() {
276
return new NewType[]{};
279
public PasteType[] getPasteTypes(Transferable transferable) {
280
// Disallow pasting anything to read-only nodes.
281
return new PasteType[0];
284
public PasteType getDropType(Transferable transferable, int action, int index) {
285
// Disallow dropping anything to read-only nodes.
290
public boolean canRename()
296
public boolean canDestroy()
302
public boolean canCut()
308
public boolean canCopy()
314
public boolean hasCustomizer()
321
public static class ReadOnlyChildren extends FilterNode.Children {
325
public ReadOnlyChildren(Node node) {
329
public ReadOnlyChildren (Node node, Lookup lookup) {
331
this.lookup = lookup;
335
protected Node copyNode(Node node) {
336
if (lookup != null) {
337
return new ReadOnlyNode(node, lookup);
339
return new ReadOnlyNode(node);
343
public static class ReadOnlyProperty extends Node.Property {
345
private Node.Property mDelegate;
347
public ReadOnlyProperty(Node.Property delegate) {
348
super(delegate.getClass());
349
this.mDelegate = delegate;
350
this.setDisplayName(this.mDelegate.getDisplayName());
351
this.setName(this.mDelegate.getName());
352
this.setShortDescription(this.mDelegate.getShortDescription());
353
this.setExpert(this.mDelegate.isExpert());
354
this.setHidden(this.mDelegate.isHidden());
355
this.setPreferred(this.mDelegate.isPreferred());
360
public boolean equals(Object property) {
361
return this.mDelegate.equals(property);
365
public String getHtmlDisplayName() {
366
return this.mDelegate.getHtmlDisplayName();
370
public PropertyEditor getPropertyEditor() {
371
return this.mDelegate.getPropertyEditor();
375
public Class getValueType() {
376
return this.mDelegate.getValueType();
380
public int hashCode() {
381
return this.mDelegate.hashCode();
385
public boolean isDefaultValue() {
386
return this.mDelegate.isDefaultValue();
390
public void restoreDefaultValue() {
395
public boolean supportsDefaultValue() {
400
public boolean canRead() {
405
public boolean canWrite() {
410
public Object getValue() throws IllegalAccessException,
411
InvocationTargetException {
412
return mDelegate.getValue();
416
public void setValue(Object val) {
421
public static class ReadOnlyPropertySet extends Node.PropertySet {
423
private Node.PropertySet mDelegate;
425
public ReadOnlyPropertySet(Node.PropertySet delegate) {
426
super(delegate.getName(), delegate.getDisplayName(), delegate.getShortDescription());
427
this.mDelegate = delegate;
431
public Property[] getProperties() {
432
Property[] properties = this.mDelegate.getProperties();
433
for(int i = 0; i < properties.length; i++) {
434
Property p = properties[i];
435
ReadOnlyProperty rp = new ReadOnlyProperty(p);