KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > ImportNode


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
21 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
22
23 import java.awt.Image JavaDoc;
24 import java.beans.PropertyEditor JavaDoc;
25 import java.util.logging.Level JavaDoc;
26
27 import javax.swing.Action JavaDoc;
28
29 import org.netbeans.modules.xml.wsdl.model.Import;
30 import org.netbeans.modules.xml.wsdl.ui.actions.CommonAddExtensibilityAttributeAction;
31 import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction;
32 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter;
33 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
34 import org.netbeans.modules.xml.wsdl.ui.view.property.ImportLocationPropertyEditor;
35 import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
36 import org.openide.actions.CopyAction;
37 import org.openide.actions.CutAction;
38 import org.openide.actions.DeleteAction;
39 import org.openide.actions.NewAction;
40 import org.openide.actions.PasteAction;
41 import org.openide.actions.PropertiesAction;
42 import org.openide.nodes.Children;
43 import org.openide.nodes.Node;
44 import org.openide.nodes.Sheet;
45 import org.openide.util.NbBundle;
46 import org.openide.util.Utilities;
47 import org.openide.util.actions.SystemAction;
48
49
50 /**
51  *
52  * @author Ritesh Adval
53  *
54  * @version $Revision: 1.4 $
55  */

56 public class ImportNode extends WSDLElementContainerNode {
57     
58     private static final String JavaDoc NAMESPACE_PROP = "namespace";//NOI18N
59
private Import mWSDLConstruct;
60             
61     Image JavaDoc ICON = Utilities.loadImage
62      ("org/netbeans/modules/xml/wsdl/ui/view/resources/import-include-redefine.png");
63     
64     private ImportPropertyAdapter mPropertyAdapter;
65
66     private static final SystemAction[] ACTIONS = new SystemAction[]{
67         SystemAction.get(CutAction.class),
68         SystemAction.get(CopyAction.class),
69         SystemAction.get(PasteAction.class),
70         null,
71         SystemAction.get(NewAction.class),
72         SystemAction.get(DeleteAction.class),
73         null,
74         SystemAction.get(CommonAddExtensibilityAttributeAction.class),
75         SystemAction.get(RemoveAttributesAction.class),
76         null,
77         SystemAction.get(GoToAction.class),
78         null,
79         SystemAction.get(PropertiesAction.class)
80     };
81
82     public ImportNode(Children children,
83                       Import wsdlConstruct) {
84         super(children, wsdlConstruct);
85         mWSDLConstruct = wsdlConstruct;
86         this.mPropertyAdapter = new ImportPropertyAdapter();
87     }
88     
89     
90     @Override JavaDoc
91     public Image JavaDoc getIcon(int type) {
92         return ICON;
93     }
94
95     @Override JavaDoc
96     public Image JavaDoc getOpenedIcon(int type) {
97         return ICON;
98     }
99     
100     @Override JavaDoc
101     public Action JavaDoc[] getActions(boolean context) {
102         return ACTIONS;
103     }
104
105     public Object JavaDoc getWSDLConstruct() {
106         return mWSDLConstruct;
107     }
108     
109     @Override JavaDoc
110     protected void refreshAttributesSheetSet() {
111         Sheet.Set ss = createPropertiesSheetSet();
112         
113         try {
114             //namespace
115
Node.Property namespaceProperty = new BaseAttributeProperty(mPropertyAdapter,
116                                                                         String JavaDoc.class,
117                                                                         NAMESPACE_PROP);
118             namespaceProperty.setName(NbBundle.getMessage(ImportNode.class, "PROP_NAMESPACE_DISPLAYNAME"));
119             namespaceProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "NAMESPACE_DESC"));
120             ss.put(namespaceProperty);
121             
122             //location
123
Node.Property locationProperty = new ImportLocationProperty(mPropertyAdapter,
124                     String JavaDoc.class,
125                     "getLocation",
126                     "setLocation");//NOI18N
127
locationProperty.setName(NbBundle.getMessage(ImportNode.class, "PROP_LOCATION_DISPLAYNAME"));
128             locationProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "LOCATION_DESC"));
129             ss.put(locationProperty);
130             
131
132             
133         } catch(Exception JavaDoc ex) {
134             mLogger.log(Level.SEVERE, "failed to create property sheet for "+ mWSDLConstruct, ex);
135         }
136     }
137
138     @Override JavaDoc
139     protected void updateDisplayName() {
140         setDisplayName(mWSDLConstruct.getNamespace());
141     }
142     
143     public class ImportPropertyAdapter extends PropertyAdapter {
144         
145         public ImportPropertyAdapter() {
146             super(getWSDLComponent());
147         }
148         
149         public void setLocation(String JavaDoc location) {
150             getWSDLComponent().getModel().startTransaction();
151             ((Import) getWSDLComponent()).setLocation(location);
152                 getWSDLComponent().getModel().endTransaction();
153          }
154          
155          public String JavaDoc getLocation() {
156              if(mWSDLConstruct.getLocation() == null) {
157                  return "";
158              }
159              
160              return mWSDLConstruct.getLocation();
161          }
162          
163          public void setNamespace(String JavaDoc namespace) {
164              getWSDLComponent().getModel().startTransaction();
165              ((Import) getWSDLComponent()).setNamespace(namespace);
166                  getWSDLComponent().getModel().endTransaction();
167          }
168          
169          public String JavaDoc getNamespace() {
170              if(mWSDLConstruct.getNamespace() == null) {
171                  return "";
172              }
173              
174              return mWSDLConstruct.getNamespace();
175          }
176          
177     }
178
179     private final class ImportLocationProperty
180             extends BaseAttributeProperty {
181
182         public ImportLocationProperty(PropertyAdapter instance, Class JavaDoc valueType,
183                 String JavaDoc getter, String JavaDoc setter) throws NoSuchMethodException JavaDoc {
184             super(instance, valueType, getter, setter);
185         }
186
187         @Override JavaDoc
188         public PropertyEditor JavaDoc getPropertyEditor() {
189             return new ImportLocationPropertyEditor(mWSDLConstruct);
190         }
191     }
192
193     @Override JavaDoc
194     public String JavaDoc getTypeDisplayName() {
195         return NbBundle.getMessage(ImportNode.class, "LBL_UnrecognizedImport_TypeDisplayName");
196     }
197
198 }
199
Popular Tags