KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.logging.Level JavaDoc;
27
28 import javax.swing.Action JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
31
32 //import org.netbeans.modules.xml.refactoring.actions.FindUsagesAction;
33
//import org.netbeans.modules.xml.refactoring.actions.RefactorAction;
34
import org.netbeans.modules.xml.wsdl.model.PortType;
35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37 import org.netbeans.modules.xml.wsdl.ui.actions.CommonAddExtensibilityAttributeAction;
38 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
39 import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction;
40 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
41 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
42 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingAndServiceNewType;
43 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
44 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
45 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.PortTypeOperationNewType;
46 import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
47 import org.openide.ErrorManager;
48 import org.openide.actions.CopyAction;
49 import org.openide.actions.CutAction;
50 import org.openide.actions.DeleteAction;
51 import org.openide.actions.NewAction;
52 import org.openide.actions.PasteAction;
53 import org.openide.actions.PropertiesAction;
54 import org.openide.nodes.Node;
55 import org.openide.util.HelpCtx;
56 import org.openide.util.NbBundle;
57 import org.openide.util.Utilities;
58 import org.openide.util.actions.SystemAction;
59 import org.openide.util.datatransfer.NewType;
60
61
62
63 /**
64  * @author Ritesh Adval
65  *
66  */

67 public class PortTypeNode extends WSDLNamedElementNode {
68
69     private PortType mWSDLConstruct;
70    
71     private static Image JavaDoc ICON = Utilities.loadImage
72             ("org/netbeans/modules/xml/wsdl/ui/view/resources/portType.png");
73
74     private PortTypePropertyAdapter mPropertyAdapter;
75
76     private static final SystemAction[] ACTIONS = new SystemAction[] {
77         SystemAction.get(CutAction.class),
78         SystemAction.get(CopyAction.class),
79         SystemAction.get(PasteAction.class),
80         null,
81         SystemAction.get(NewAction.class),
82         SystemAction.get(DeleteAction.class),
83         null,
84         SystemAction.get(CommonAddExtensibilityAttributeAction.class),
85         SystemAction.get(RemoveAttributesAction.class),
86         null,
87         SystemAction.get(GoToAction.class),
88         //SystemAction.get(FindUsagesAction.class),
89
(SystemAction)RefactoringActionsFactory.whereUsedAction(),
90         null,
91         (SystemAction)RefactoringActionsFactory.editorSubmenuAction(),
92         //SystemAction.get(RefactorAction.class),
93
null,
94         SystemAction.get(PropertiesAction.class)
95     };
96     
97     public PortTypeNode(PortType wsdlConstruct) {
98         super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new PortTypeNewTypesFactory());
99         mWSDLConstruct = wsdlConstruct;
100         
101         this.mPropertyAdapter = new PortTypePropertyAdapter();
102         super.setNamedPropertyAdapter(this.mPropertyAdapter);
103     }
104     
105     
106     @Override JavaDoc
107     public Image JavaDoc getIcon(int type) {
108         return ICON;
109     }
110
111     @Override JavaDoc
112     public Image JavaDoc getOpenedIcon(int type) {
113         return ICON;
114     }
115     
116     @Override JavaDoc
117     public Action JavaDoc[] getActions(boolean context) {
118         return ACTIONS;
119     }
120
121      @Override JavaDoc
122     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
123             Node.Property attrValueProperty = null;
124             try {
125             String JavaDoc attrName = attrQName.getLocalPart();
126              //name
127
if(attrName.equals(NAME_PROP)) {
128                 //name
129
attrValueProperty = createNameProperty();
130             } else {
131                 attrValueProperty = super.createAttributeProperty(attrQName);
132              }
133             
134             } catch(Exception JavaDoc ex) {
135                 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
136                 ErrorManager.getDefault().notify(ex);
137             }
138              return attrValueProperty;
139         }
140     
141      
142       @Override JavaDoc
143     protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
144             ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
145             alwaysPresentAttrProperties.add(createNameProperty());
146             
147             return alwaysPresentAttrProperties;
148     }
149     
150     
151       private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
152           Node.Property attrValueProperty;
153           attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String JavaDoc.class, NAME_PROP);
154           attrValueProperty.setName(NbBundle.getMessage(PortTypeNode.class, "PROP_NAME_DISPLAYNAME"));
155           attrValueProperty.setShortDescription(NbBundle.getMessage(PortTypeNode.class, "PORTTYPE_NAME_DESC"));
156             
157           return attrValueProperty;
158       }
159     
160     @Override JavaDoc
161     public HelpCtx getHelpCtx() {
162         return new HelpCtx(PortTypeNode.class);
163     }
164     
165     
166     public class PortTypePropertyAdapter extends ConstraintNamedPropertyAdapter {
167         
168         public PortTypePropertyAdapter() {
169             super(mWSDLConstruct);
170         }
171          
172         @Override JavaDoc
173         public boolean isNameExists(String JavaDoc name) {
174             WSDLModel document = mWSDLConstruct.getModel();
175             return NameGenerator.getInstance().isPortTypeExists(name, document);
176         }
177     }
178     
179     public static final class PortTypeNewTypesFactory implements NewTypesFactory{
180
181         public NewType[] getNewTypes(WSDLComponent def) {
182             ArrayList JavaDoc<NewType> list = new ArrayList JavaDoc<NewType>();
183             list.add(new PortTypeOperationNewType(def));
184             list.add(new BindingAndServiceNewType(def));
185             if (def.getDocumentation() == null) {
186                 list.add(new DocumentationNewType(def));
187             }
188             return list.toArray(new NewType[]{});
189         }
190
191     }
192
193     @Override JavaDoc
194     public String JavaDoc getTypeDisplayName() {
195         return NbBundle.getMessage(PortTypeNode.class, "LBL_PortTypeNode_TypeDisplayName");
196     }
197 }
198
Popular Tags