KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ui > customizer > WebCompositePanelProvider


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 package org.netbeans.modules.web.project.ui.customizer;
21
22 import java.util.List JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.modules.web.project.ProjectWebModule;
28 import org.netbeans.modules.web.project.WebProject;
29 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
30 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
31 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author mkleint, rnajman
39  */

40 public class WebCompositePanelProvider implements ProjectCustomizer.CompositeCategoryProvider {
41     
42     private static final String JavaDoc SOURCES = "Sources";
43     static final String JavaDoc LIBRARIES = "Libraries";
44     private static final String JavaDoc FRAMEWORKS = "Frameworks";
45
46     private static final String JavaDoc BUILD = "Build";
47     private static final String JavaDoc WAR = "War";
48     private static final String JavaDoc JAVADOC = "Javadoc";
49     public static final String JavaDoc RUN = "Run";
50     
51     private static final String JavaDoc WEBSERVICES = "WebServices";
52     private static final String JavaDoc WEBSERVICECLIENTS = "WebServiceClients";
53
54     private String JavaDoc name;
55     
56     /** Creates a new instance of WebCompositePanelProvider */
57     public WebCompositePanelProvider(String JavaDoc name) {
58         this.name = name;
59     }
60
61     public ProjectCustomizer.Category createCategory(Lookup context) {
62         ResourceBundle JavaDoc bundle = NbBundle.getBundle( CustomizerProviderImpl.class );
63         ProjectCustomizer.Category toReturn = null;
64         
65         if (SOURCES.equals(name)) {
66             toReturn = ProjectCustomizer.Category.create(
67                     SOURCES,
68                     bundle.getString("LBL_Config_Sources"), //NOI18N
69
null,
70                     null);
71         } else if (FRAMEWORKS.equals(name)) {
72             toReturn = ProjectCustomizer.Category.create(
73                     FRAMEWORKS,
74                     bundle.getString( "LBL_Config_Frameworks" ), // NOI18N
75
null,
76                     null );
77         } else if (LIBRARIES.equals(name)) {
78             toReturn = ProjectCustomizer.Category.create(
79                     LIBRARIES,
80                     bundle.getString( "LBL_Config_Libraries" ), // NOI18N
81
null,
82                     null );
83         } else if (BUILD.equals(name)) {
84             toReturn = ProjectCustomizer.Category.create(
85                     BUILD,
86                     bundle.getString( "LBL_Config_Build" ), // NOI18N
87
null,
88                     null);
89         } else if (WAR.equals(name)) {
90             toReturn = ProjectCustomizer.Category.create(
91                     WAR,
92                     bundle.getString( "LBL_Config_War" ), // NOI18N
93
null,
94                     null );
95         } else if (JAVADOC.equals(name)) {
96             toReturn = ProjectCustomizer.Category.create(
97                     JAVADOC,
98                     bundle.getString( "LBL_Config_Javadoc" ), // NOI18N
99
null,
100                     null );
101         } else if (RUN.equals(name)) {
102             toReturn = ProjectCustomizer.Category.create(
103                     RUN,
104                     bundle.getString( "LBL_Config_Run" ), // NOI18N
105
null,
106                     null );
107         } else if (WEBSERVICES.equals(name) || WEBSERVICECLIENTS.equals(name)) {
108             WebProject project = (WebProject) context.lookup(WebProject.class);
109             ProjectWebModule wm = (ProjectWebModule) project.getLookup().lookup(ProjectWebModule.class);
110             FileObject docBase = wm.getDocumentBase();
111             if (WEBSERVICES.equals(name)) {
112                 List JavaDoc servicesSettings = null;
113                 if (docBase != null) {
114                     WebServicesSupport servicesSupport = WebServicesSupport.getWebServicesSupport(docBase);
115                     if (servicesSupport != null) {
116                         servicesSettings = servicesSupport.getServices();
117                     }
118                 }
119                 if ((servicesSettings!=null && servicesSettings.size()>0)) {
120                     toReturn = ProjectCustomizer.Category.create(
121                             WEBSERVICES,
122                             bundle.getString( "LBL_Config_WebServices" ), // NOI18N
123
null,
124                             null );
125                 }
126             } else if (WEBSERVICECLIENTS.equals(name)) {
127                 List JavaDoc serviceClientsSettings = null;
128                 if (docBase != null) {
129                     WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(docBase);
130                     if (clientSupport != null) {
131                         serviceClientsSettings = clientSupport.getServiceClients();
132                     }
133                 }
134                 if(serviceClientsSettings != null && serviceClientsSettings.size() > 0) {
135                     toReturn = ProjectCustomizer.Category.create(
136                             WEBSERVICECLIENTS,
137                             bundle.getString( "LBL_Config_WebServiceClients" ), // NOI18N
138
null,
139                             null );
140                 }
141             }
142         }
143         
144 // assert toReturn != null : "No category for name:" + name;
145
return toReturn;
146     }
147
148     public JComponent JavaDoc createComponent(ProjectCustomizer.Category category, Lookup context) {
149         String JavaDoc nm = category.getName();
150         WebProjectProperties uiProps = (WebProjectProperties)context.lookup(WebProjectProperties.class);
151         if (SOURCES.equals(nm)) {
152             return new CustomizerSources(uiProps);
153         } else if (FRAMEWORKS.equals(nm)) {
154             return new CustomizerFrameworks(uiProps);
155         } else if (LIBRARIES.equals(nm)) {
156             CustomizerProviderImpl.SubCategoryProvider prov = (CustomizerProviderImpl.SubCategoryProvider)context.lookup(CustomizerProviderImpl.SubCategoryProvider.class);
157             assert prov != null : "Assuming CustomizerProviderImpl.SubCategoryProvider in customizer context";
158             return new CustomizerLibraries(uiProps, prov);
159         } else if (BUILD.equals(nm)) {
160             return new CustomizerCompile(uiProps);
161         } else if (WAR.equals(nm)) {
162             return new CustomizerWar(uiProps);
163         } else if (JAVADOC.equals(nm)) {
164             return new CustomizerJavadoc(uiProps);
165         } else if (RUN.equals(nm)) {
166             return new CustomizerRun(uiProps);
167         } else if (WEBSERVICES.equals(nm) || WEBSERVICECLIENTS.equals(nm)) {
168             ProjectWebModule wm = (ProjectWebModule) uiProps.getProject().getLookup().lookup(ProjectWebModule.class);
169             FileObject docBase = wm.getDocumentBase();
170             if (WEBSERVICES.equals(nm)) {
171                 List JavaDoc servicesSettings = null;
172                 if (docBase != null) {
173                     WebServicesSupport servicesSupport = WebServicesSupport.getWebServicesSupport(docBase);
174                     if (servicesSupport != null) {
175                         servicesSettings = servicesSupport.getServices();
176                     }
177                 }
178                 if(servicesSettings != null && servicesSettings.size() > 0) {
179                     return new CustomizerWSServiceHost( uiProps, servicesSettings );
180                 } else {
181                     return new NoWebServicesPanel();
182                 }
183             } else if (WEBSERVICECLIENTS.equals(nm)) {
184                 List JavaDoc serviceClientsSettings = null;
185                 if (docBase != null) {
186                     WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(docBase);
187                     if (clientSupport != null) {
188                         serviceClientsSettings = clientSupport.getServiceClients();
189                     }
190                 }
191                 if(serviceClientsSettings != null && serviceClientsSettings.size() > 0) {
192                     return new CustomizerWSClientHost( uiProps, serviceClientsSettings );
193                 } else {
194                     return new NoWebServiceClientsPanel();
195                 }
196             }
197         }
198         
199         return new JPanel JavaDoc();
200     }
201
202     public static WebCompositePanelProvider createSources() {
203         return new WebCompositePanelProvider(SOURCES);
204     }
205     
206     public static WebCompositePanelProvider createFrameworks() {
207         return new WebCompositePanelProvider(FRAMEWORKS);
208     }
209
210     public static WebCompositePanelProvider createLibraries() {
211         return new WebCompositePanelProvider(LIBRARIES);
212     }
213
214     public static WebCompositePanelProvider createBuild() {
215         return new WebCompositePanelProvider(BUILD);
216     }
217
218     public static WebCompositePanelProvider createWar() {
219         return new WebCompositePanelProvider(WAR);
220     }
221
222     public static WebCompositePanelProvider createJavadoc() {
223         return new WebCompositePanelProvider(JAVADOC);
224     }
225
226     public static WebCompositePanelProvider createRun() {
227         return new WebCompositePanelProvider(RUN);
228     }
229
230     public static WebCompositePanelProvider createWebServices() {
231         return new WebCompositePanelProvider(WEBSERVICES);
232     }
233     
234     public static WebCompositePanelProvider createWebServiceClients() {
235         return new WebCompositePanelProvider(WEBSERVICECLIENTS);
236     }
237     
238 }
239
Popular Tags