KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > WebServicesNodeFactory


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 package org.netbeans.modules.websvc.core.jaxws.nodes;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
32 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientView;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
34 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
35 import org.netbeans.modules.websvc.jaxws.api.JAXWSView;
36 import org.netbeans.spi.project.ui.support.NodeFactory;
37 import org.netbeans.spi.project.ui.support.NodeList;
38 import org.openide.filesystems.FileObject;
39 import org.openide.nodes.Node;
40
41 /**
42  *
43  * @author Milan Kuchtiak
44  */

45 public class WebServicesNodeFactory implements NodeFactory {
46     
47     /** Creates a new instance of WebServicesNodeFactory */
48     public WebServicesNodeFactory() {
49     }
50     
51     public NodeList createNodes(Project p) {
52         assert p != null;
53         return new WsNodeList(p);
54     }
55     
56     private static class WsNodeList implements NodeList<String JavaDoc> {
57         // Web Services
58
private static final String JavaDoc KEY_SERVICES = "web_services"; // NOI18N
59
// Web Service Client
60
private static final String JavaDoc KEY_SERVICE_REFS = "serviceRefs"; // NOI18N
61

62         private Project project;
63         
64         private List JavaDoc<ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
65         private final JaxWsChangeListener jaxWsListener;
66         
67         public WsNodeList(Project proj) {
68             project = proj;
69             this.jaxWsListener = new JaxWsChangeListener();
70         }
71         
72         public List JavaDoc<String JavaDoc> keys() {
73             List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
74             JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class);
75             FileObject projectDir = project.getProjectDirectory();
76             JAXWSSupport jaxwsSupport = JAXWSSupport.getJAXWSSupport(projectDir);
77             JAXWSClientSupport jaxwsClientSupport = JAXWSClientSupport.getJaxWsClientSupport(projectDir);
78             if (jaxWsModel != null) {
79                 if ( jaxwsSupport != null && jaxWsModel.getServices().length>0) {
80                         result.add(KEY_SERVICES);
81                 }
82                 if ( jaxwsClientSupport != null && jaxWsModel.getClients().length>0) {
83                         result.add(KEY_SERVICE_REFS);
84                 }
85             }
86             return result;
87         }
88         
89         public synchronized void addChangeListener(ChangeListener JavaDoc l) {
90             listeners.add(l);
91         }
92         
93         public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
94             listeners.remove(l);
95         }
96         
97         private void fireChange() {
98             ArrayList JavaDoc<ChangeListener JavaDoc> list = new ArrayList JavaDoc<ChangeListener JavaDoc>();
99             synchronized (this) {
100                 list.addAll(listeners);
101             }
102             Iterator JavaDoc<ChangeListener JavaDoc> it = list.iterator();
103             while (it.hasNext()) {
104                 ChangeListener JavaDoc elem = it.next();
105                 elem.stateChanged(new ChangeEvent JavaDoc( this ));
106             }
107         }
108         
109         public Node node(String JavaDoc key) {
110             if (KEY_SERVICES.equals(key)) {
111                 JAXWSView view = JAXWSView.getJAXWSView();
112                 return view.createJAXWSView(project);
113             } else if (KEY_SERVICE_REFS.equals(key)) {
114                 JAXWSClientView view = JAXWSClientView.getJAXWSClientView();
115                 return view.createJAXWSClientView(project);
116             }
117             return null;
118         }
119         
120         public void addNotify() {
121             JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class);
122             if (jaxWsModel!=null) jaxWsModel.addPropertyChangeListener(jaxWsListener);
123         }
124         
125         public void removeNotify() {
126             JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class);
127             if (jaxWsModel!=null) jaxWsModel.removePropertyChangeListener(jaxWsListener);
128         }
129         
130         
131         private final class JaxWsChangeListener implements PropertyChangeListener JavaDoc {
132             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
133                 SwingUtilities.invokeLater(new Runnable JavaDoc() {
134                     public void run() {
135                         fireChange();
136                     }
137                 });
138             }
139         }
140     }
141     
142 }
143
Popular Tags