KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > customization > multiview > WSCustomizationView


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * WSCustomizationView.java
22  *
23  * Created on February 27, 2006, 12:04 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.websvc.customization.multiview;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Set JavaDoc;
35 import org.netbeans.modules.xml.multiview.ui.InnerPanelFactory;
36 import org.netbeans.modules.xml.multiview.ui.SectionContainer;
37 import org.netbeans.modules.xml.multiview.ui.SectionContainerNode;
38 import org.netbeans.modules.xml.multiview.ui.SectionPanel;
39 import org.netbeans.modules.xml.multiview.ui.SectionView;
40 import org.netbeans.modules.xml.wsdl.model.Binding;
41 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
42 import org.netbeans.modules.xml.wsdl.model.Definitions;
43 import org.netbeans.modules.xml.wsdl.model.Fault;
44 import org.netbeans.modules.xml.wsdl.model.Operation;
45 import org.netbeans.modules.xml.wsdl.model.Port;
46 import org.netbeans.modules.xml.wsdl.model.PortType;
47 import org.netbeans.modules.xml.wsdl.model.Service;
48 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
49 import org.openide.nodes.AbstractNode;
50 import org.openide.nodes.Children;
51 import org.openide.nodes.Node;
52 import org.openide.util.HelpCtx;
53 import org.openide.util.NbBundle;
54
55 /**
56  *
57  * @author Roderico Cruz
58  */

59 public class WSCustomizationView extends SectionView{
60     private Set JavaDoc<WSDLModel> models;
61     private Definitions primaryDefinitions;
62     
63     static final String JavaDoc ID_PORT_TYPE = "ID_PORT_TYPE";
64     static final String JavaDoc ID_PORT_TYPE_OPERATION = "ID_PORT_TYPE_OPERATION";
65     static final String JavaDoc ID_PORT_TYPE_OPERATION_FAULT = "ID_PORT_TYPE_OPERATION_FAULT";
66     static final String JavaDoc ID_BINDING = "ID_BINDING";
67     static final String JavaDoc ID_BINDING_OPERATION = "ID_BINDING_OPERATION";
68     static final String JavaDoc ID_SERVICE = "ID_SERVICE";
69     static final String JavaDoc ID_PORT= "ID_PORT";
70     static final String JavaDoc ID_EXTERNAL_BINDING = "ID_EXTERNAL_BINDING";
71     
72     /** Creates a new instance of WSCustomizationView */
73     public WSCustomizationView(InnerPanelFactory factory, Set JavaDoc<WSDLModel> models ,
74             Definitions primaryDefinitions) {
75         super(factory);
76         this.models = models;
77         this.primaryDefinitions = primaryDefinitions;
78         populateData();
79         //create root node
80
Children rootChildren = new Children.Array();
81         Node root = new AbstractNode(rootChildren);
82         
83         //create Definitions node
84
Node definitionsNode = new DefinitionsNode(this, primaryDefinitions);
85         
86         addSection(new SectionPanel(this, definitionsNode, primaryDefinitions), false); //NOI18N
87

88         //add the port types section
89
Children portTypeChildren = new Children.Array();
90         Node[] portTypeNodes = new Node[portTypesList.size()];
91         int i = 0;
92         for(PortType portType : portTypesList){
93             portTypeNodes[i++] = new PortTypeNode(this, portType);
94         }
95         portTypeChildren.add(portTypeNodes);
96         Node portTypeNodeContainer = new SectionContainerNode(portTypeChildren);
97         portTypeNodeContainer.setName(ID_PORT_TYPE);
98         portTypeNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
99                 "TITLE_PORTTYPES"));
100         
101         SectionContainer portTypesCont =
102                 new SectionContainer(this,portTypeNodeContainer,
103                 NbBundle.getMessage(WSCustomizationView.class,
104                 "TITLE_PORTTYPES"));
105         // creating section panels for PortTypes
106
SectionPanel[] portTypePanels = new SectionPanel[portTypesList.size()];
107         i = 0;
108         for(PortType portType : portTypesList){
109             portTypePanels[i] = new SectionPanel(this, portTypeNodes[i], portType);
110             portTypesCont.addSection(portTypePanels[i], false);
111             i++;
112         }
113         addSection(portTypesCont, false);
114         
115         //add the port types operation section
116
Children opChildren = new Children.Array();
117         Node[] operationNodes = new Node[portTypeOperationsList.size()];
118         i = 0;
119         for(Operation operation : portTypeOperationsList){
120             operationNodes[i++] = new PortTypeOperationNode(this, operation);
121         }
122         opChildren.add(operationNodes);
123         Node operationNodeContainer = new SectionContainerNode(opChildren);
124         operationNodeContainer.setName(ID_PORT_TYPE_OPERATION);
125         operationNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
126                 "TITLE_PORTTYPE_OPERATIONS"));
127         
128         SectionContainer operationCont =
129                 new SectionContainer(this,operationNodeContainer,
130                 NbBundle.getMessage(WSCustomizationView.class,
131                 "TITLE_PORTTYPE_OPERATIONS"));
132         // creatings section panels for PortType Operations
133
SectionPanel[] operationPanels = new SectionPanel[portTypeOperationsList.size()];
134         i = 0;
135         for(Operation op : portTypeOperationsList){
136             operationPanels[i] = new SectionPanel(this, operationNodes[i], op);
137             operationCont.addSection(operationPanels[i], false);
138             i++;
139         }
140         addSection(operationCont, false);
141         
142         //add the port type fault section
143
Children faultChildren = new Children.Array();
144         Node[] faultNodes = new Node[portTypeOperationFaultsList.size()];
145         i = 0;
146         for(Fault fault : portTypeOperationFaultsList){
147             faultNodes[i++] = new PortTypeOperationFaultNode(this, fault);
148         }
149         faultChildren.add(faultNodes);
150         Node faultNodeContainer = new SectionContainerNode(faultChildren);
151         faultNodeContainer.setName(ID_PORT_TYPE_OPERATION_FAULT);
152         faultNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
153                 "TITLE_PORTTYPE_FAULTS"));
154         
155         SectionContainer faultCont =
156                 new SectionContainer(this,faultNodeContainer,
157                 NbBundle.getMessage(WSCustomizationView.class,
158                 "TITLE_PORTTYPE_FAULTS"));
159         // creatings section panels for PortType Operation faults
160
SectionPanel[] faultPanels = new SectionPanel[portTypeOperationFaultsList.size()];
161         i = 0;
162         for(Fault fault : portTypeOperationFaultsList){
163             faultPanels[i] = new SectionPanel(this, faultNodes[i], fault);
164             faultCont.addSection(faultPanels[i], false);
165             i++;
166         }
167         addSection(faultCont, false);
168         
169         //add binding section
170
Children bindingChildren = new Children.Array();
171         Node[] bindingNodes = new Node[bindingsList.size()];
172         i = 0;
173         for(Binding binding : bindingsList){
174             bindingNodes[i++] = new BindingNode(this, binding);
175         }
176         bindingChildren.add(bindingNodes);
177         Node bindingNodeContainer = new SectionContainerNode(bindingChildren);
178         bindingNodeContainer.setName(ID_BINDING);
179         bindingNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
180                 "TITLE_BINDINGS"));
181         
182         SectionContainer bindingCont =
183                 new SectionContainer(this,bindingNodeContainer,
184                 NbBundle.getMessage(WSCustomizationView.class,
185                 "TITLE_BINDINGS"));
186         // creatings section panels for Bindings
187
SectionPanel[] bindingPanels = new SectionPanel[bindingsList.size()];
188         i = 0;
189         for(Binding binding : bindingsList){
190             bindingPanels[i] = new SectionPanel(this, bindingNodes[i], binding);
191             bindingCont.addSection(bindingPanels[i], false);
192             i++;
193         }
194         addSection(bindingCont, false);
195         
196         //add binding operation section
197
Children bindingOpChildren = new Children.Array();
198         Node[] bindingOpNodes = new Node[bindingOperationsList.size()];
199         i = 0;
200         for(BindingOperation bindingOp : bindingOperationsList){
201             bindingOpNodes[i++] = new BindingOperationNode(this, bindingOp);
202         }
203         bindingOpChildren.add(bindingOpNodes);
204         Node bindingOpNodeContainer = new SectionContainerNode(bindingOpChildren);
205         bindingOpNodeContainer.setName(ID_BINDING_OPERATION);
206         bindingOpNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
207                 "TITLE_BINDING_OPERATIONS"));
208         
209         SectionContainer bindingOpCont =
210                 new SectionContainer(this,bindingOpNodeContainer,
211                 NbBundle.getMessage(WSCustomizationView.class,
212                 "TITLE_BINDING_OPERATIONS"));
213         // creating section panels for Binding Operations
214
SectionPanel[] bindingOpPanels = new SectionPanel[bindingOperationsList.size()];
215         i = 0;
216         for(BindingOperation bindingOp : bindingOperationsList){
217             bindingOpPanels[i] = new SectionPanel(this, bindingOpNodes[i], bindingOp);
218             bindingOpCont.addSection(bindingOpPanels[i], false);
219             i++;
220         }
221         addSection(bindingOpCont, false);
222         
223         Children serviceChildren = new Children.Array();
224         Node[] serviceNodes = new Node[servicesList.size()];
225         i = 0;
226         for(Service service : servicesList){
227             serviceNodes[i++] = new ServiceNode(this, service);
228         }
229         serviceChildren.add(serviceNodes);
230         Node serviceNodeContainer = new SectionContainerNode(serviceChildren);
231         serviceNodeContainer.setName(ID_SERVICE);
232         serviceNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
233                 "TITLE_SERVICES"));
234         
235         SectionContainer servicesCont =
236                 new SectionContainer(this,serviceNodeContainer,
237                 NbBundle.getMessage(WSCustomizationView.class,
238                 "TITLE_SERVICES"));
239         // creating section panels for Services
240
SectionPanel[] servicePanels = new SectionPanel[servicesList.size()];
241         i = 0;
242         for(Service service : servicesList){
243             servicePanels[i] = new SectionPanel(this, serviceNodes[i], service);
244             servicesCont.addSection(servicePanels[i], false);
245             i++;
246         }
247         addSection(servicesCont, false);
248
249         Children portChildren = new Children.Array();
250         Node[] portNodes = new Node[portsList.size()];
251         i = 0;
252         for(Port port : portsList){
253             portNodes[i++] = new PortNode(this, port);
254         }
255         portChildren.add(portNodes);
256         Node portNodeContainer = new SectionContainerNode(portChildren);
257         portNodeContainer.setName(ID_PORT);
258         portNodeContainer.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
259                 "TITLE_PORTS"));
260         
261         SectionContainer portCont =
262                 new SectionContainer(this,portNodeContainer,
263                 NbBundle.getMessage(WSCustomizationView.class,
264                 "TITLE_PORTS"));
265         // creating section panels for Ports
266
SectionPanel[] portPanels = new SectionPanel[portsList.size()];
267         i = 0;
268         for(Port port : portsList){
269             portPanels[i] = new SectionPanel(this, portNodes[i], port);
270             portCont.addSection(portPanels[i], false);
271             i++;
272         }
273         addSection(portCont, false);
274         
275         ExternalBindingNode externalBindingNode = new ExternalBindingNode(Children.LEAF);
276         externalBindingNode.setDisplayName(NbBundle.getMessage(WSCustomizationView.class,
277                 "TITLE_EXTERNAL_BINDING_FILES"));
278         addSection(new SectionPanel(this, externalBindingNode, new BindingKey()), false);
279         rootChildren.add(new Node[] {definitionsNode, portTypeNodeContainer,
280         operationNodeContainer, faultNodeContainer,
281         bindingNodeContainer, bindingOpNodeContainer,
282         serviceNodeContainer, portNodeContainer,
283         externalBindingNode});
284         setRoot(root);
285     }
286     
287     private void populateData(){
288         portTypesList = new ArrayList JavaDoc<PortType>();
289         portTypeOperationsList = new ArrayList JavaDoc<Operation>();
290         portTypeOperationFaultsList = new ArrayList JavaDoc<Fault>();
291         bindingsList = new ArrayList JavaDoc<Binding>();
292         bindingOperationsList = new ArrayList JavaDoc<BindingOperation>();
293         servicesList = new ArrayList JavaDoc<Service>();
294         portsList = new ArrayList JavaDoc<Port>();
295         
296         for(WSDLModel wsdlModel : models){
297             Definitions def = wsdlModel.getDefinitions();
298             Collection JavaDoc<PortType> portTypes = def.getPortTypes();
299             portTypesList.addAll(portTypes);
300             for(PortType portType : portTypes){
301                 Collection JavaDoc<Operation> operations = portType.getOperations();
302                 portTypeOperationsList.addAll(operations);
303                 for(Operation operation : operations){
304                     Collection JavaDoc<Fault> faults = operation.getFaults();
305                     portTypeOperationFaultsList.addAll(faults);
306                 }
307             }
308             
309             Collection JavaDoc<Binding> bindings = def.getBindings();
310             bindingsList.addAll(bindings);
311             for(Binding binding : bindings){
312                 Collection JavaDoc<BindingOperation> bindingOperations = binding.getBindingOperations();
313                 bindingOperationsList.addAll(bindingOperations);
314             }
315             
316             Collection JavaDoc<Service> services = def.getServices();
317             servicesList.addAll(services);
318             for(Service service : services){
319                 Collection JavaDoc<Port> ports = service.getPorts();
320                 portsList.addAll(ports);
321             }
322         }
323     }
324     
325     private List JavaDoc<PortType> portTypesList;
326     private List JavaDoc<Operation> portTypeOperationsList;
327     private List JavaDoc<Fault> portTypeOperationFaultsList;
328     private List JavaDoc<Binding> bindingsList;
329     private List JavaDoc<BindingOperation> bindingOperationsList;
330     private List JavaDoc<Service> servicesList;
331     private List JavaDoc<Port> portsList;
332     
333     
334     static class ExternalBindingNode extends AbstractNode{
335         public ExternalBindingNode(Children children){
336             super(children);
337         }
338
339         public HelpCtx getHelpCtx() {
340             return new HelpCtx(ID_EXTERNAL_BINDING);
341         }
342     }
343     
344     public static class BindingKey extends Object JavaDoc{
345         //dummy object that serves as the key for the ExternalBindingPanel
346
}
347 }
348
Popular Tags