~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/wsdlui/src/org/netbeans/modules/xml/wsdl/ui/view/treeeditor/ImportNode.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
 
 
43
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
 
44
 
 
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;
 
50
 
 
51
import javax.swing.Action;
 
52
 
 
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;
 
80
 
 
81
 
 
82
/**
 
83
 *
 
84
 * @author Ritesh Adval
 
85
 *
 
86
 * @version 
 
87
 */
 
88
public class ImportNode extends WSDLElementNode<Import> {
 
89
 
 
90
    private static final String NAMESPACE_PROP = "namespace";//NOI18N
 
91
 
 
92
    Image ICON  = Utilities.loadImage
 
93
    ("org/netbeans/modules/xml/wsdl/ui/view/resources/import-include-redefine.png");
 
94
 
 
95
    private ImportPropertyAdapter mPropertyAdapter;
 
96
 
 
97
    private static final SystemAction[] ACTIONS = new SystemAction[]{
 
98
        SystemAction.get(CutAction.class),
 
99
        SystemAction.get(CopyAction.class),
 
100
        SystemAction.get(PasteAction.class),
 
101
        null,
 
102
        SystemAction.get(NewAction.class),
 
103
        SystemAction.get(DeleteAction.class),
 
104
        null,
 
105
        SystemAction.get(CommonAddExtensibilityAttributeAction.class),
 
106
        SystemAction.get(RemoveAttributesAction.class),
 
107
        null,
 
108
        SystemAction.get(GoToAction.class),
 
109
        null,
 
110
        SystemAction.get(PropertiesAction.class)
 
111
    };
 
112
 
 
113
    public ImportNode(Children children,
 
114
            Import wsdlConstruct) {
 
115
        super(children, wsdlConstruct);
 
116
        this.mPropertyAdapter = new ImportPropertyAdapter();
 
117
    }
 
118
 
 
119
 
 
120
    @Override
 
121
    public Image getIcon(int type) {
 
122
        return ICON;
 
123
    }
 
124
 
 
125
    @Override
 
126
    public Image getOpenedIcon(int type) {
 
127
        return ICON;
 
128
    }
 
129
 
 
130
    @Override
 
131
    public Action[] getActions(boolean context) {
 
132
        return ACTIONS;
 
133
    }
 
134
 
 
135
    @Override
 
136
    protected void refreshAttributesSheetSet(Sheet sheet)  {
 
137
        Sheet.Set ss = sheet.get(Sheet.PROPERTIES);
 
138
 
 
139
        try {
 
140
            //namespace
 
141
            Node.Property namespaceProperty = new BaseAttributeProperty(mPropertyAdapter, 
 
142
                    String.class, 
 
143
                    NAMESPACE_PROP);
 
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);
 
148
 
 
149
            //location
 
150
            Node.Property locationProperty = new ImportLocationProperty(mPropertyAdapter, 
 
151
                    String.class, 
 
152
                    "getLocation", 
 
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);
 
158
 
 
159
 
 
160
 
 
161
        } catch(Exception ex) {
 
162
            mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
 
163
        }
 
164
    }
 
165
 
 
166
    @Override
 
167
    protected void updateDisplayName() {
 
168
        if (getWSDLComponent() != null) {
 
169
            setDisplayName(getWSDLComponent().getNamespace());
 
170
        }
 
171
    }
 
172
 
 
173
    public class ImportPropertyAdapter extends PropertyAdapter {
 
174
 
 
175
        public ImportPropertyAdapter() {
 
176
            super(getWSDLComponent());
 
177
        }
 
178
 
 
179
        public void setLocation(String location) {
 
180
            Import imp = (Import) getDelegate();
 
181
            imp.getModel().startTransaction();
 
182
            imp.setLocation(location);
 
183
            imp.getModel().endTransaction();
 
184
        }
 
185
 
 
186
        public String getLocation() {
 
187
            if(getWSDLComponent().getLocation() == null) {
 
188
                return "";
 
189
            }
 
190
 
 
191
            return getWSDLComponent().getLocation();
 
192
        }
 
193
 
 
194
        public void setNamespace(String namespace) {
 
195
            getWSDLComponent().getModel().startTransaction();
 
196
            (getWSDLComponent()).setNamespace(namespace);
 
197
            getWSDLComponent().getModel().endTransaction();
 
198
        }
 
199
 
 
200
        public String getNamespace() {
 
201
            if(getWSDLComponent().getNamespace() == null) {
 
202
                return "";
 
203
            }
 
204
 
 
205
            return getWSDLComponent().getNamespace();
 
206
        } 
 
207
 
 
208
    }
 
209
 
 
210
    private final class ImportLocationProperty
 
211
    extends BaseAttributeProperty {
 
212
 
 
213
        public ImportLocationProperty(PropertyAdapter instance, Class valueType,
 
214
                String getter, String setter) throws NoSuchMethodException {
 
215
            super(instance, valueType, getter, setter);
 
216
        }
 
217
 
 
218
        @Override
 
219
        public PropertyEditor getPropertyEditor() {
 
220
            return new ImportLocationPropertyEditor(getWSDLComponent());
 
221
        }
 
222
    }
 
223
 
 
224
    @Override
 
225
    public String getTypeDisplayName() {
 
226
        return NbBundle.getMessage(ImportNode.class, "LBL_UnrecognizedImport_TypeDisplayName");
 
227
    }
 
228
 
 
229
 
 
230
    public static class ReadOnlyNode extends FilterNode {
 
231
        private static final SystemAction[] ACTIONS = new SystemAction[] {
 
232
            SystemAction.get(GoToAction.class),
 
233
            (SystemAction)RefactoringActionsFactory.whereUsedAction(),
 
234
            null,
 
235
            SystemAction.get(PropertiesAction.class),
 
236
        };
 
237
        
 
238
        public ReadOnlyNode(Node original) {
 
239
            this(original, null);
 
240
        }
 
241
 
 
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[] {
 
246
                                SaveCookie.class
 
247
                            })
 
248
            }));
 
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);
 
256
        }
 
257
 
 
258
        @Override
 
259
        public Action[] getActions(boolean context) {
 
260
            return ACTIONS;
 
261
        }
 
262
        
 
263
 
 
264
        @Override
 
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;
 
271
            }
 
272
            return propertySet;
 
273
        }
 
274
 
 
275
        public NewType[] getNewTypes() {
 
276
            return new NewType[]{};
 
277
        }
 
278
        
 
279
        public PasteType[] getPasteTypes(Transferable transferable) {
 
280
            // Disallow pasting anything to read-only nodes.
 
281
            return new PasteType[0];
 
282
        }
 
283
        
 
284
        public PasteType getDropType(Transferable transferable, int action, int index) {
 
285
            // Disallow dropping anything to read-only nodes.
 
286
            return null;
 
287
        }
 
288
        
 
289
        @Override
 
290
        public boolean canRename()
 
291
        {
 
292
            return false;
 
293
        }
 
294
 
 
295
        @Override
 
296
        public boolean canDestroy()
 
297
        {
 
298
            return false;
 
299
        }
 
300
 
 
301
        @Override
 
302
        public boolean canCut()
 
303
        {
 
304
            return false;
 
305
        }
 
306
 
 
307
        @Override
 
308
        public boolean canCopy()
 
309
        {
 
310
            return false;
 
311
        }
 
312
 
 
313
        @Override
 
314
        public boolean hasCustomizer()
 
315
        {
 
316
            return false;
 
317
        }
 
318
    }
 
319
 
 
320
 
 
321
    public static class ReadOnlyChildren extends FilterNode.Children {
 
322
 
 
323
        Lookup lookup;
 
324
 
 
325
        public ReadOnlyChildren(Node node) {
 
326
            this(node, null);
 
327
        }
 
328
 
 
329
        public ReadOnlyChildren (Node node, Lookup lookup) {
 
330
            super(node);
 
331
            this.lookup = lookup;
 
332
        }
 
333
 
 
334
        @Override
 
335
        protected Node copyNode(Node node) {
 
336
            if (lookup != null) {
 
337
                return new ReadOnlyNode(node, lookup);
 
338
            }
 
339
            return new ReadOnlyNode(node);
 
340
        }
 
341
    } 
 
342
 
 
343
    public static class ReadOnlyProperty extends Node.Property {
 
344
 
 
345
        private Node.Property mDelegate;
 
346
 
 
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());
 
356
 
 
357
        }
 
358
 
 
359
        @Override
 
360
        public boolean equals(Object property) {
 
361
            return this.mDelegate.equals(property);
 
362
        }
 
363
 
 
364
        @Override
 
365
        public String getHtmlDisplayName() {
 
366
            return this.mDelegate.getHtmlDisplayName();
 
367
        }
 
368
 
 
369
        @Override
 
370
        public PropertyEditor getPropertyEditor() {
 
371
            return this.mDelegate.getPropertyEditor();
 
372
        }
 
373
 
 
374
        @Override
 
375
        public Class getValueType() {
 
376
            return this.mDelegate.getValueType();
 
377
        }
 
378
 
 
379
        @Override
 
380
        public int hashCode() {
 
381
            return this.mDelegate.hashCode();
 
382
        }
 
383
 
 
384
        @Override
 
385
        public boolean isDefaultValue() {
 
386
            return this.mDelegate.isDefaultValue();
 
387
        }
 
388
 
 
389
        @Override
 
390
        public void restoreDefaultValue() {
 
391
            //do nothing
 
392
        }
 
393
 
 
394
        @Override
 
395
        public boolean supportsDefaultValue() {
 
396
            return false;
 
397
        }
 
398
 
 
399
        @Override
 
400
        public boolean canRead() {
 
401
            return true;
 
402
        }
 
403
 
 
404
        @Override
 
405
        public boolean canWrite() {
 
406
            return false;
 
407
        }
 
408
 
 
409
        @Override
 
410
        public Object getValue() throws IllegalAccessException,
 
411
        InvocationTargetException {
 
412
            return mDelegate.getValue();
 
413
        }
 
414
 
 
415
        @Override
 
416
        public void setValue(Object val) {
 
417
            //do nothing
 
418
        }
 
419
    }
 
420
 
 
421
    public static class ReadOnlyPropertySet extends Node.PropertySet {
 
422
 
 
423
        private Node.PropertySet mDelegate;
 
424
 
 
425
        public ReadOnlyPropertySet(Node.PropertySet delegate) {
 
426
            super(delegate.getName(), delegate.getDisplayName(), delegate.getShortDescription());
 
427
            this.mDelegate = delegate;
 
428
        }
 
429
 
 
430
        @Override
 
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);
 
436
                properties[i] = rp;
 
437
            }
 
438
 
 
439
            return properties;
 
440
        }    
 
441
    }
 
442
 
 
443
}