001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.ejbjarproject.ui.customizer;
043:
044: import java.util.List;
045: import java.util.ResourceBundle;
046: import javax.swing.JComponent;
047: import javax.swing.JPanel;
048: import org.netbeans.modules.j2ee.common.project.ui.ProjectProperties;
049: import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject;
050: import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProvider;
051: import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
052: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
053: import org.openide.filesystems.FileObject;
054: import org.openide.util.Lookup;
055: import org.openide.util.NbBundle;
056:
057: /**
058: *
059: * @author mkleint, rnajman
060: */
061: public class EjbJarCompositePanelProvider implements
062: ProjectCustomizer.CompositeCategoryProvider {
063:
064: private static final String SOURCES = "Sources";
065: static final String LIBRARIES = "Libraries";
066:
067: private static final String BUILD = "Build";
068: private static final String JAR = "Jar";
069: private static final String JAVADOC = "Javadoc";
070: public static final String RUN = "Run";
071:
072: private static final String WEBSERVICES = "WebServices";
073: private static final String WEBSERVICESCATEGORY = "WebServicesCategory";
074:
075: private String name;
076:
077: /** Creates a new instance of EjbJarCompositePanelProvider */
078: public EjbJarCompositePanelProvider(String name) {
079: this .name = name;
080: }
081:
082: public ProjectCustomizer.Category createCategory(Lookup context) {
083: ResourceBundle bundle = NbBundle
084: .getBundle(EjbJarCompositePanelProvider.class);
085: ProjectCustomizer.Category toReturn = null;
086:
087: if (SOURCES.equals(name)) {
088: toReturn = ProjectCustomizer.Category.create(SOURCES,
089: bundle.getString("LBL_Config_Sources"), //NOI18N
090: null);
091: } else if (LIBRARIES.equals(name)) {
092: toReturn = ProjectCustomizer.Category.create(LIBRARIES,
093: bundle.getString("LBL_Config_Libraries"), // NOI18N
094: null);
095: } else if (BUILD.equals(name)) {
096: toReturn = ProjectCustomizer.Category.create(BUILD, bundle
097: .getString("LBL_Config_Build"), // NOI18N
098: null);
099: } else if (JAR.equals(name)) {
100: toReturn = ProjectCustomizer.Category.create(JAR, bundle
101: .getString("LBL_Config_Jar"), // NOI18N
102: null);
103: } else if (JAVADOC.equals(name)) {
104: toReturn = ProjectCustomizer.Category.create(JAVADOC,
105: bundle.getString("LBL_Config_Javadoc"), // NOI18N
106: null);
107: } else if (RUN.equals(name)) {
108: toReturn = ProjectCustomizer.Category.create(RUN, bundle
109: .getString("LBL_Config_Run"), // NOI18N
110: null);
111: } else if (WEBSERVICESCATEGORY.equals(name)
112: && showWebServicesCategory(context
113: .lookup(EjbJarProjectProperties.class))) {
114: ProjectCustomizer.Category services = ProjectCustomizer.Category
115: .create(WEBSERVICES, bundle
116: .getString("LBL_Config_WebServices"), // NOI18N
117: null);
118: toReturn = ProjectCustomizer.Category.create(
119: WEBSERVICESCATEGORY,
120: bundle.getString("LBL_Config_WebServiceCategory"), // NOI18N
121: null, services);
122: }
123:
124: // assert toReturn != null : "No category for name:" + name;
125: return toReturn;
126: }
127:
128: public JComponent createComponent(
129: ProjectCustomizer.Category category, Lookup context) {
130: String nm = category.getName();
131: EjbJarProjectProperties uiProps = context
132: .lookup(EjbJarProjectProperties.class);
133: if (SOURCES.equals(nm)) {
134: return new CustomizerSources(uiProps);
135: } else if (LIBRARIES.equals(nm)) {
136: CustomizerProviderImpl.SubCategoryProvider prov = context
137: .lookup(CustomizerProviderImpl.SubCategoryProvider.class);
138: assert prov != null : "Assuming CustomizerProviderImpl.SubCategoryProvider in customizer context";
139: return new CustomizerLibraries(uiProps, prov);
140: } else if (BUILD.equals(nm)) {
141: return new CustomizerCompile(uiProps);
142: } else if (JAR.equals(nm)) {
143: return new CustomizerJar(uiProps);
144: } else if (JAVADOC.equals(nm)) {
145: return new CustomizerJavadoc(uiProps);
146: } else if (RUN.equals(nm)) {
147: return new CustomizerRun(uiProps);
148: } else if (WEBSERVICES.equals(nm)) {
149: EjbJarProvider ejbJarProvider = uiProps.getProject()
150: .getLookup().lookup(EjbJarProvider.class);
151: FileObject metaInf = ejbJarProvider.getMetaInf();
152: List servicesSettings = null;
153: if (metaInf != null) {
154: WebServicesSupport servicesSupport = WebServicesSupport
155: .getWebServicesSupport(metaInf);
156: if (servicesSupport != null) {
157: servicesSettings = servicesSupport.getServices();
158: }
159: }
160: if (servicesSettings != null && servicesSettings.size() > 0) {
161: return new CustomizerWSServiceHost(uiProps,
162: servicesSettings);
163: } else {
164: return new NoWebServicesPanel();
165: }
166: }
167:
168: return new JPanel();
169: }
170:
171: public static EjbJarCompositePanelProvider createSources() {
172: return new EjbJarCompositePanelProvider(SOURCES);
173: }
174:
175: public static EjbJarCompositePanelProvider createLibraries() {
176: return new EjbJarCompositePanelProvider(LIBRARIES);
177: }
178:
179: public static EjbJarCompositePanelProvider createBuild() {
180: return new EjbJarCompositePanelProvider(BUILD);
181: }
182:
183: public static EjbJarCompositePanelProvider createJar() {
184: return new EjbJarCompositePanelProvider(JAR);
185: }
186:
187: public static EjbJarCompositePanelProvider createJavadoc() {
188: return new EjbJarCompositePanelProvider(JAVADOC);
189: }
190:
191: public static EjbJarCompositePanelProvider createRun() {
192: return new EjbJarCompositePanelProvider(RUN);
193: }
194:
195: public static EjbJarCompositePanelProvider createWebServicesCategory() {
196: return new EjbJarCompositePanelProvider(WEBSERVICESCATEGORY);
197: }
198:
199: private static boolean showWebServicesCategory(
200: EjbJarProjectProperties uiProperties) {
201: EjbJarProject project = (EjbJarProject) uiProperties
202: .getProject();
203: if (ProjectProperties.J2EE_1_4.equals(project.getEjbModule()
204: .getJ2eePlatformVersion())) {
205: return WebServicesSupport.getWebServicesSupport(project
206: .getProjectDirectory()) != null;
207: }
208: return false;
209: }
210: }
|