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-2006 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.mobility.jsr172.wizard;
043:
044: import java.util.HashSet;
045: import java.util.Set;
046:
047: import java.awt.Component;
048: import javax.swing.event.ChangeEvent;
049: import javax.swing.event.ChangeListener;
050:
051: import org.openide.WizardDescriptor;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054:
055: import org.netbeans.api.project.Project;
056: import org.netbeans.spi.project.ui.templates.support.Templates;
057:
058: /**
059: *
060: * @author Peter Williams
061: */
062: public class WebServiceClientWizardDescriptor implements
063: WizardDescriptor.FinishablePanel,
064: WizardDescriptor.ValidatingPanel {
065:
066: private WizardDescriptor wizardDescriptor;
067: private ClientInfo component = null;
068: private String projectPath;
069: private Project project;
070:
071: public static final HelpCtx HELP_CTX = new HelpCtx(
072: "me.wcb_clientinformation"); // NOI18N
073:
074: public boolean isFinishPanel() {
075: return true;
076: }
077:
078: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
079: 1);
080:
081: public final void addChangeListener(final ChangeListener l) {
082: synchronized (listeners) {
083: listeners.add(l);
084: }
085: }
086:
087: public final void removeChangeListener(final ChangeListener l) {
088: synchronized (listeners) {
089: listeners.remove(l);
090: }
091: }
092:
093: protected final void fireChangeEvent() {
094: ChangeListener[] lst;
095: synchronized (listeners) {
096: lst = listeners
097: .toArray(new ChangeListener[listeners.size()]);
098: }
099: final ChangeEvent ev = new ChangeEvent(this );
100: for (ChangeListener cl : lst)
101: cl.stateChanged(ev);
102: }
103:
104: public Component getComponent() {
105: if (component == null) {
106: component = new ClientInfo(this );
107: }
108:
109: return component;
110: }
111:
112: public HelpCtx getHelp() {
113: return WebServiceClientWizardDescriptor.HELP_CTX;
114: }
115:
116: public boolean isValid() {
117: boolean projectDirValid = true;
118: String illegalChar = null;
119: if (projectPath.indexOf('%') >= 0) {
120: projectDirValid = false;
121: illegalChar = "%";
122: } else if (projectPath.indexOf('&') >= 0) {
123: projectDirValid = false;
124: illegalChar = "&";
125: } else if (projectPath.indexOf('?') >= 0) {
126: projectDirValid = false;
127: illegalChar = "?";
128: }
129: if (!projectDirValid) {
130: wizardDescriptor.putProperty("WizardPanel_errorMessage",
131: NbBundle.getMessage(
132: WebServiceClientWizardDescriptor.class,
133: "MSG_InvalidProjectPath", projectPath,
134: illegalChar));
135: return false;
136: } else if (!testClassPath()) {
137: wizardDescriptor.putProperty("WizardPanel_errorMessage",
138: NbBundle.getMessage(
139: WebServiceClientWizardDescriptor.class,
140: "MSG_MissingXMLJars"));
141: return false;
142: } else {
143: return component.valid(wizardDescriptor);
144: }
145: }
146:
147: public void readSettings(final Object settings) {
148: wizardDescriptor = (WizardDescriptor) settings;
149: component.read(wizardDescriptor);
150: project = Templates.getProject(wizardDescriptor);
151: projectPath = project.getProjectDirectory().getPath();
152:
153: // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
154: // this name is used in NewFileWizard to modify the title
155: wizardDescriptor.putProperty("NewFileWizard_Title", //NOI18N
156: NbBundle.getMessage(
157: WebServiceClientWizardDescriptor.class,
158: "LBL_WebServiceClient"));// NOI18N
159: }
160:
161: public void storeSettings(final Object settings) {
162: final WizardDescriptor d = (WizardDescriptor) settings;
163: component.store(d);
164: d.putProperty("NewFileWizard_Title", null); // NOI18N
165: }
166:
167: @SuppressWarnings("unused")
168: public void validate() throws org.openide.WizardValidationException {
169: }
170:
171: private boolean testClassPath() {
172: // SourceGroup[] sgs = WebServiceClientWizardIterator.getJavaSourceGroups(project);
173: // ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE);
174: // WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(project.getProjectDirectory());
175: // if (clientSupport==null) {
176: // String mes = NbBundle.getMessage(WebServiceClientWizardDescriptor.class, "ERR_NoWebServiceClientSupport"); // NOI18N
177: // NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
178: // DialogDisplayer.getDefault().notify(desc);
179: // return true;
180: // }
181: // if (clientSupport.getDeploymentDescriptor()==null) { // testing java project type
182: // // test for the platform
183: // String javaVersion = System.getProperty("java.version"); //NOI18N
184: // if (javaVersion!=null && javaVersion.startsWith("1.4")) { //NOI18N
185: // FileObject documentRangeFO = classPath.findResource("org/w3c/dom/ranges/DocumentRange.class"); //NOI18N
186: // FileObject saxParserFO = classPath.findResource("com/sun/org/apache/xerces/internal/jaxp/SAXParserFactoryImpl.class"); //NOI18N
187: // if (documentRangeFO == null || saxParserFO == null) {
188: // ProjectClassPathExtender pce = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class);
189: // Library jaxrpclib_ext = LibraryManager.getDefault().getLibrary("jaxrpc16_xml"); //NOI18N
190: // if (pce==null || jaxrpclib_ext == null) {
191: // return false;
192: // }
193: // }
194: // }
195: // }
196: return true;
197: }
198: }
|