~ubuntu-branches/ubuntu/trusty/netbeans/trusty

« back to all changes in this revision

Viewing changes to xml/wsdlui/src/org/netbeans/modules/xml/wsdl/ui/view/treeeditor/PortNode.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
 * Created on May 17, 2005
 
44
 *
 
45
 * To change the template for this generated file go to
 
46
 * Window - Preferences - Java - Code Generation - Code and Comments
 
47
 */
 
48
package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
 
49
 
 
50
import java.awt.Image;
 
51
import java.util.ArrayList;
 
52
import java.util.Arrays;
 
53
import java.util.List;
 
54
import java.util.logging.Level;
 
55
 
 
56
import javax.xml.namespace.QName;
 
57
 
 
58
import org.netbeans.modules.xml.wsdl.model.Binding;
 
59
import org.netbeans.modules.xml.wsdl.model.Port;
 
60
import org.netbeans.modules.xml.wsdl.model.Service;
 
61
import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
 
62
import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
 
63
import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
 
64
import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
 
65
import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
 
66
import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
 
67
import org.netbeans.modules.xml.wsdl.ui.view.property.BindingAttributeProperty;
 
68
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
 
69
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
 
70
import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
 
71
import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
 
72
import org.openide.ErrorManager;
 
73
import org.openide.nodes.Node;
 
74
import org.openide.util.NbBundle;
 
75
import org.openide.util.Utilities;
 
76
import org.openide.util.datatransfer.NewType;
 
77
 
 
78
 
 
79
 
 
80
/**
 
81
 * @author radval
 
82
 *
 
83
 * To change the template for this generated type comment go to
 
84
 * Window - Preferences - Java - Code Generation - Code and Comments
 
85
 */
 
86
public class PortNode extends WSDLExtensibilityElementNode<Port> {
 
87
    
 
88
    
 
89
    private Port mWSDLConstruct;
 
90
    
 
91
    
 
92
    private ServicePortPropertyAdapter mPropertyAdapter = null;
 
93
    
 
94
    private static Image ICON  = Utilities.loadImage
 
95
            ("org/netbeans/modules/xml/wsdl/ui/view/resources/serviceport.png");
 
96
    
 
97
    public PortNode(Port wsdlConstruct) {
 
98
        super(new GenericWSDLComponentChildren<Port>(wsdlConstruct), wsdlConstruct, new ServicePortNewTypesFactory());
 
99
        mWSDLConstruct = wsdlConstruct;
 
100
        
 
101
        
 
102
        this.mPropertyAdapter = new ServicePortPropertyAdapter();
 
103
        super.setNamedPropertyAdapter(this.mPropertyAdapter);
 
104
    }
 
105
    
 
106
    @Override
 
107
    public String getNameInLayer() {
 
108
        return WSDLExtensibilityElements.ELEMENT_SERVICE_PORT;
 
109
    }
 
110
    
 
111
    @Override
 
112
    public Image getIcon(int type) {
 
113
        return ICON;
 
114
    }
 
115
    
 
116
    @Override
 
117
    public Image getOpenedIcon(int type) {
 
118
        return ICON;
 
119
    }
 
120
    
 
121
    @Override
 
122
    protected Node.Property createAttributeProperty(QName attrQName) {
 
123
        Node.Property attrValueProperty = null;
 
124
        try {
 
125
            String attrName = attrQName.getLocalPart();
 
126
            //name
 
127
            if(attrName.equals(Port.NAME_PROPERTY)) { //NOT I18N
 
128
                //name
 
129
                attrValueProperty = createNameProperty();
 
130
                
 
131
                
 
132
            } else if(attrName.equals(Port.BINDING_PROPERTY)) {
 
133
                attrValueProperty = createBindingProperty();
 
134
                
 
135
            } else {
 
136
                attrValueProperty = super.createAttributeProperty(attrQName);
 
137
            }
 
138
            
 
139
        } catch(Exception ex) {
 
140
            mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
 
141
            ErrorManager.getDefault().notify(ex);
 
142
        }
 
143
        return attrValueProperty;
 
144
    }
 
145
    
 
146
    @Override
 
147
     protected List<Node.Property> createAlwaysPresentAttributeProperty() throws Exception {
 
148
        ArrayList<Node.Property> alwaysPresentAttrProperties = new ArrayList<Node.Property>();
 
149
        alwaysPresentAttrProperties.add(createNameProperty());
 
150
        alwaysPresentAttrProperties.add(createBindingProperty());
 
151
        return alwaysPresentAttrProperties;
 
152
    }
 
153
    
 
154
    
 
155
    private Node.Property createNameProperty() throws NoSuchMethodException {
 
156
        Node.Property attrValueProperty;
 
157
        attrValueProperty = new BaseAttributeProperty(mPropertyAdapter,
 
158
                String.class,
 
159
                Port.NAME_PROPERTY);
 
160
        attrValueProperty.setName(Port.NAME_PROPERTY);
 
161
        attrValueProperty.setDisplayName(NbBundle.getMessage(PortNode.class, "PROP_NAME_DISPLAYNAME"));
 
162
        attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_NAME_DESC"));
 
163
        
 
164
        return attrValueProperty;
 
165
    }
 
166
    
 
167
    private Node.Property createBindingProperty() throws NoSuchMethodException {
 
168
        Node.Property attrValueProperty;
 
169
        attrValueProperty = new BindingAttributeProperty(mPropertyAdapter,
 
170
                String.class,
 
171
                Port.BINDING_PROPERTY);
 
172
        
 
173
        attrValueProperty.setName(Port.BINDING_PROPERTY);
 
174
        attrValueProperty.setDisplayName(NbBundle.getMessage(PortNode.class, "PROP_BINDING_DISPLAYNAME"));
 
175
        attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_BINDING_DESC"));
 
176
        
 
177
        return attrValueProperty;
 
178
    }
 
179
    
 
180
    
 
181
    public class ServicePortPropertyAdapter extends ConstraintNamedPropertyAdapter {
 
182
        
 
183
        public ServicePortPropertyAdapter() {
 
184
            super(mWSDLConstruct);
 
185
        }
 
186
        
 
187
        @Override
 
188
        public boolean isNameExists(String name) {
 
189
            return NameGenerator.getInstance().isServicePortExists(name,
 
190
                    (Service) mWSDLConstruct.getParent());
 
191
        }
 
192
        
 
193
        public void setBinding(String bindingName) {
 
194
            if(bindingName != null) {
 
195
                try {
 
196
                    org.netbeans.modules.xml.wsdl.ui.common.QName bindingQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(bindingName);
 
197
                    if(bindingQName == null) {
 
198
                        mWSDLConstruct.getModel().startTransaction();
 
199
                        mWSDLConstruct.setBinding(null);
 
200
                        mWSDLConstruct.getModel().endTransaction();
 
201
                    } else {
 
202
                        
 
203
                        String ns = bindingQName.getNamespaceURI();
 
204
                        String prefix = bindingQName.getPrefix();
 
205
                        if(ns == null || ns.trim().equals("")) {
 
206
                            ns = Utility.getNamespaceURI(prefix, mWSDLConstruct.getModel());
 
207
                        }
 
208
                        
 
209
                        
 
210
                        QName qname = null;
 
211
                        if (ns != null) {
 
212
                            qname = new QName(ns, bindingQName.getLocalName());
 
213
                        }
 
214
                        
 
215
                        if(qname != null) {
 
216
                            Binding binding = mWSDLConstruct.getModel().findComponentByName(qname, Binding.class);
 
217
                            if (binding == null) {
 
218
                                ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception("Not a valid type"));
 
219
                            } else {
 
220
                                mWSDLConstruct.getModel().startTransaction();
 
221
                                mWSDLConstruct.setBinding(mWSDLConstruct.createReferenceTo(binding, Binding.class));
 
222
                                
 
223
                                mWSDLConstruct.getModel().endTransaction();
 
224
                            }
 
225
                        }
 
226
                    }
 
227
                    fireDisplayNameChange(null, getDisplayName());
 
228
                } catch (Exception e) {
 
229
                    ErrorManager.getDefault().notify(e);
 
230
                }
 
231
            }
 
232
        }
 
233
        
 
234
        
 
235
        public String getBinding() {
 
236
            NamedComponentReference binding = mWSDLConstruct.getBinding();
 
237
            if (binding != null) {
 
238
                QName bindingQName = binding.getQName();
 
239
                if(bindingQName != null) {
 
240
                    return Utility.fromQNameToString(bindingQName);
 
241
                }
 
242
            }
 
243
            return "";
 
244
            
 
245
        }
 
246
        
 
247
        public Port getServicePort() {
 
248
            return mWSDLConstruct;
 
249
        }
 
250
    }
 
251
    
 
252
    public static final class ServicePortNewTypesFactory implements NewTypesFactory{
 
253
        
 
254
        public NewType[] getNewTypes(WSDLComponent def) {
 
255
            ArrayList<NewType> list = new ArrayList<NewType>();
 
256
            if (def.getDocumentation() == null) {
 
257
                list.add(new DocumentationNewType(def));
 
258
            }
 
259
            
 
260
            list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_SERVICE_PORT).getNewTypes(def)));
 
261
            return list.toArray(new NewType[]{});
 
262
        }
 
263
    }
 
264
 
 
265
    @Override
 
266
    public String getTypeDisplayName() {
 
267
        return NbBundle.getMessage(PortNode.class, "LBL_PortNode_TypeDisplayName");
 
268
    }
 
269
    
 
270
    @Override
 
271
    public String getHtmlDisplayName() {
 
272
        String htmlDisplayName = super.getHtmlDisplayName();
 
273
        NamedComponentReference<Binding> binding = mWSDLConstruct.getBinding();
 
274
        
 
275
        String decoration = null;
 
276
        if (binding != null && binding.get() != null) {
 
277
            String tns = binding.get().getModel().getDefinitions().getTargetNamespace();
 
278
            decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_Binding", 
 
279
                    Utility.getNameAndDropPrefixIfInCurrentModel(tns, binding.get().getName(), mWSDLConstruct.getModel()));
 
280
        }
 
281
        
 
282
        if (decoration == null) {
 
283
            //decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_BindingNotSet");
 
284
            return htmlDisplayName;
 
285
        }
 
286
        return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>";
 
287
    }
 
288
}
 
289
 
 
290
 
 
291