KickJava   Java API By Example, From Geeks To Geeks.

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


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.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.logging.Level JavaDoc;
28
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.netbeans.modules.xml.wsdl.model.Message;
32 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
33 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
34 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
35 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
36 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
37 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
38 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
39 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
40 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.MessagePartNewType;
41 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
42 import org.openide.ErrorManager;
43 import org.openide.nodes.Node;
44 import org.openide.util.HelpCtx;
45 import org.openide.util.NbBundle;
46 import org.openide.util.Utilities;
47 import org.openide.util.datatransfer.NewType;
48
49
50
51 /**
52  *
53  * @author Ritesh Adval
54  *
55  */

56 public class MessageNode extends WSDLExtensibilityElementNode {
57     
58     Image JavaDoc ICON = Utilities.loadImage
59     ("org/netbeans/modules/xml/wsdl/ui/view/resources/message.png");
60     
61     
62     private MessagePropertyAdapter mPropertyAdapter;
63     
64     public MessageNode(Message wsdlConstruct) {
65         super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new MessageNewTypesFactory());
66         
67         this.mPropertyAdapter = new MessagePropertyAdapter();
68         super.setNamedPropertyAdapter(this.mPropertyAdapter);
69     }
70     
71     @Override JavaDoc
72     public String JavaDoc getNameInLayer() {
73         return WSDLExtensibilityElements.ELEMENT_MESSAGE;
74     }
75     
76     @Override JavaDoc
77     public Image JavaDoc getIcon(int type) {
78         return ICON;
79     }
80     
81     @Override JavaDoc
82     public Image JavaDoc getOpenedIcon(int type) {
83         return ICON;
84     }
85     
86     @Override JavaDoc
87     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
88         Node.Property attrValueProperty = null;
89         try {
90             String JavaDoc attrName = attrQName.getLocalPart();
91             //name
92
if(attrName.equals(NAME_PROP)) { //NOT I18N
93
//name
94
attrValueProperty = createNameProperty();
95                 
96             } else {
97                 attrValueProperty = super.createAttributeProperty(attrQName);
98             }
99             
100         } catch(Exception JavaDoc ex) {
101             mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
102             ErrorManager.getDefault().notify(ex);
103         }
104         return attrValueProperty;
105     }
106     
107     
108     @Override JavaDoc
109     protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
110         ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
111         alwaysPresentAttrProperties.add(createNameProperty());
112         
113         return alwaysPresentAttrProperties;
114     }
115     
116     
117     private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
118         Node.Property attrValueProperty;
119         attrValueProperty = new BaseAttributeProperty(mPropertyAdapter,
120                 String JavaDoc.class, NAME_PROP);
121         attrValueProperty.setName(NbBundle.getMessage(MessageNode.class, "PROP_NAME_DISPLAYNAME"));
122         attrValueProperty.setShortDescription(NbBundle.getMessage(MessageNode.class, "MESSAGE_NAME_DESC"));
123         
124         return attrValueProperty;
125     }
126     
127     @Override JavaDoc
128     public HelpCtx getHelpCtx() {
129         return new HelpCtx(MessageNode.class);
130     }
131     
132     public class MessagePropertyAdapter extends ConstraintNamedPropertyAdapter {
133         
134         public MessagePropertyAdapter() {
135             super(getWSDLComponent());
136         }
137         
138         @Override JavaDoc
139         public boolean isNameExists(String JavaDoc name) {
140             WSDLModel document = getWSDLComponent().getModel();
141             return NameGenerator.getInstance().isMessageExists(name, document);
142         }
143         
144     }
145     
146     public static final class MessageNewTypesFactory implements NewTypesFactory{
147         
148         public NewType[] getNewTypes(WSDLComponent def) {
149             ArrayList JavaDoc<NewType> list = new ArrayList JavaDoc<NewType>();
150             list.add(new MessagePartNewType(def));
151             if (def.getDocumentation() == null) {
152                 list.add(new DocumentationNewType(def));
153             }
154             list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_MESSAGE).getNewTypes(def)));
155             return list.toArray(new NewType[]{});
156         }
157         
158     }
159
160     @Override JavaDoc
161     public String JavaDoc getTypeDisplayName() {
162         return NbBundle.getMessage(MessageNode.class, "LBL_MessageNode_TypeDisplayName");
163     }
164 }
165
Popular Tags