KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > service > ServiceView


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

19 package org.netbeans.modules.websvc.wsitconf.ui.service;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
24 import org.netbeans.modules.websvc.wsitconf.ui.nodes.BindingFaultNode;
25 import org.netbeans.modules.websvc.wsitconf.ui.nodes.OperationNode;
26 import org.netbeans.modules.websvc.wsitconf.ui.nodes.ServiceNode;
27 import org.netbeans.modules.websvc.wsitconf.ui.nodes.OperationContainerServiceNode;
28 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.WSITModelSupport;
29 import org.netbeans.modules.xml.multiview.SectionNode;
30 import org.netbeans.modules.xml.multiview.ui.*;
31 import org.netbeans.modules.xml.wsdl.model.Binding;
32 import org.netbeans.modules.xml.wsdl.model.BindingFault;
33 import org.netbeans.modules.xml.wsdl.model.BindingInput;
34 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
35 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37 import org.openide.nodes.AbstractNode;
38 import org.openide.nodes.Children;
39 import org.openide.nodes.Node;
40 import org.openide.util.RequestProcessor;
41
42 import java.util.Collection JavaDoc;
43 import org.netbeans.modules.websvc.wsitconf.ui.nodes.BindingContainerServiceNode;
44 import org.netbeans.modules.websvc.wsitconf.ui.nodes.BindingInputNode;
45 import org.netbeans.modules.websvc.wsitconf.ui.nodes.BindingOutputNode;
46 import org.netbeans.modules.websvc.wsitconf.util.Util;
47 import org.openide.filesystems.FileObject;
48
49 /**
50  * @author Martin Grebac
51  */

52 public class ServiceView extends SectionView {
53
54     private SectionNode rootNode;
55     
56     private static final int REFRESH_DELAY = 40;
57     
58     private WSDLModel model;
59        
60     ServiceView(InnerPanelFactory factory, WSDLModel model, Node node, Service s) {
61         this(factory, model, node, s, null);
62     }
63     
64     ServiceView(InnerPanelFactory factory, WSDLModel model, Node node, Service s, Collection JavaDoc<Binding> bs) {
65         super(factory);
66         this.model = model;
67
68         if (model == null) return;
69         
70         Collection JavaDoc<Binding> bindings = bs;
71         if (bindings == null) {
72             bindings = new HashSet JavaDoc();
73             WSITModelSupport.fillImportedBindings(model, bindings, new HashSet JavaDoc());
74         }
75         
76         //add binding section
77
Node[] bindingNodes = new Node[bindings.size()];
78         Children rootChildren = new Children.Array();
79        
80         FileObject jc = null;
81         if (s != null) {
82             String JavaDoc wsdlUrl = s.getWsdlUrl();
83             if (wsdlUrl == null) { // WS from Java
84
jc = (FileObject)node.getLookup().lookup(FileObject.class);
85             }
86         }
87                 
88         // if there's only one binding, make the dialog simpler
89
if (bindingNodes.length > 1) {
90             Node root = new AbstractNode(rootChildren);
91             int i = 0;
92             setRoot(root);
93
94             for (Binding binding : bindings) {
95
96                 if (jc != null) {
97                     Util.refreshOperations(binding, jc);
98                 }
99                 
100                 // main node container for a specific binding
101
Children bindingChildren = new Children.Array();
102                 Node bindingNodeContainer = new BindingContainerServiceNode(bindingChildren);
103                 SectionContainer bindingCont = new SectionContainer(this,
104                         bindingNodeContainer, binding.getName() + " Binding"); //NOI18N
105
addSection(bindingCont, false);
106
107                 ArrayList JavaDoc nodes = new ArrayList JavaDoc();
108
109                 Node serviceNode = new ServiceNode(this, binding);
110                 nodes.add(serviceNode);
111                 SectionPanel servicePanel = new SectionPanel(this, serviceNode, binding, true);
112                 bindingCont.addSection(servicePanel, false);
113
114                 Collection JavaDoc<BindingOperation> operations = binding.getBindingOperations();
115                 for (BindingOperation op : operations) {
116                     Children opChildren = new Children.Array();
117                     Node opNodeContainer = new OperationContainerServiceNode(opChildren);
118                     SectionContainer opCont = new SectionContainer(this, opNodeContainer, op.getName() + " Operation"); //NOI18N
119
bindingCont.addSection(opCont, false);
120                     
121                     ArrayList JavaDoc subNodes = new ArrayList JavaDoc();
122
123                     Node opNode = new OperationNode(this, op);
124                     subNodes.add(opNode);
125                     SectionPanel opPanel = new SectionPanel(this, opNode, op, false);
126                     opCont.addSection(opPanel, false);
127
128                     BindingInput bi = op.getBindingInput();
129                     if (bi != null) {
130                         Node biNode = new BindingInputNode(this, bi);
131                         subNodes.add(biNode);
132                         SectionPanel biPanel = new SectionPanel(this, biNode, bi, false);
133                         opCont.addSection(biPanel, false);
134                     }
135                     BindingOutput bo = op.getBindingOutput();
136                     if (bo != null) {
137                         Node boNode = new BindingOutputNode(this, bo);
138                         subNodes.add(boNode);
139                         SectionPanel boPanel = new SectionPanel(this, boNode, bo, false);
140                         opCont.addSection(boPanel, false);
141                     }
142                     Collection JavaDoc<BindingFault> bfs = op.getBindingFaults();
143                     for (BindingFault bf : bfs) {
144                         Node bfNode = new BindingFaultNode(this, bf);
145                         subNodes.add(bfNode);
146                         SectionPanel bfPanel = new SectionPanel(this, bfNode, bf, false);
147                         opCont.addSection(bfPanel, false);
148                     }
149                     opChildren.add((Node[]) subNodes.toArray(new Node[subNodes.size()]));
150                     nodes.add(opNodeContainer);
151                 }
152
153                 bindingChildren.add((Node[]) nodes.toArray(new Node[nodes.size()]));
154
155                 bindingNodes[i++] = bindingNodeContainer;
156             }
157             rootChildren.add(bindingNodes);
158         } else {
159             Binding b = (Binding) bindings.toArray()[0];
160             if (jc != null) {
161                 Util.refreshOperations(b, jc);
162             }
163             Node root = new AbstractNode(rootChildren);
164             setRoot(root);
165
166             Node serviceNode = new ServiceNode(this, b);
167             ArrayList JavaDoc nodes = new ArrayList JavaDoc();
168             nodes.add(serviceNode);
169             
170             SectionPanel servicePanel = new SectionPanel(this, serviceNode, b, true);
171             addSection(servicePanel, false);
172
173             Collection JavaDoc<BindingOperation> operations = b.getBindingOperations();
174             for (BindingOperation op : operations) {
175
176                 Children opChildren = new Children.Array();
177                 Node opNodeContainer = new OperationContainerServiceNode(opChildren);
178                 SectionContainer opCont = new SectionContainer(this, opNodeContainer, op.getName() + " Operation"); //NOI18N
179
addSection(opCont, false);
180
181                 ArrayList JavaDoc subNodes = new ArrayList JavaDoc();
182
183                 Node opNode = new OperationNode(this, op);
184                 subNodes.add(opNode);
185                 SectionPanel opPanel = new SectionPanel(this, opNode, op, false);
186                 opCont.addSection(opPanel, false);
187
188                 BindingInput bi = op.getBindingInput();
189                 if (bi != null) {
190                     Node biNode = new BindingInputNode(this, bi);
191                     subNodes.add(biNode);
192                     SectionPanel biPanel = new SectionPanel(this, biNode, bi, false);
193                     opCont.addSection(biPanel, false);
194                 }
195                 BindingOutput bo = op.getBindingOutput();
196                 if (bo != null) {
197                     Node boNode = new BindingOutputNode(this, bo);
198                     subNodes.add(boNode);
199                     SectionPanel boPanel = new SectionPanel(this, boNode, bo, false);
200                     opCont.addSection(boPanel, false);
201                 }
202                 Collection JavaDoc<BindingFault> bfs = op.getBindingFaults();
203                 for (BindingFault bf : bfs) {
204                     Node bfNode = new BindingFaultNode(this, bf);
205                     subNodes.add(bfNode);
206                     SectionPanel bfPanel = new SectionPanel(this, bfNode, bf, false);
207                     opCont.addSection(bfPanel, false);
208                 }
209                 opChildren.add((Node[]) subNodes.toArray(new Node[subNodes.size()]));
210                 nodes.add(opNodeContainer);
211             }
212             rootChildren.add((Node[]) nodes.toArray(new Node[nodes.size()]));
213             servicePanel.open();
214         }
215     }
216
217     private final RequestProcessor.Task refreshTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
218         public void run() {
219             getRootNode().refreshSubtree();
220         }
221     });
222
223     public void refreshView() {
224         rootNode.refreshSubtree();
225     }
226     
227     public void scheduleRefreshView() {
228         refreshTask.schedule(REFRESH_DELAY);
229     }
230
231     public void dataModelPropertyChange(Object JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
232         rootNode.dataModelPropertyChange(source, propertyName, oldValue, newValue);
233     }
234     
235     public SectionNode getRootNode() {
236         return rootNode;
237     }
238
239 }
240
Popular Tags