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.websvc.core.client.wizard;
043:
044: import java.util.HashSet;
045: import java.util.Iterator;
046: import java.util.Set;
047:
048: import java.awt.Component;
049: import javax.swing.event.ChangeEvent;
050: import javax.swing.event.ChangeListener;
051:
052: import org.openide.WizardDescriptor;
053: import org.openide.util.HelpCtx;
054: import org.openide.util.NbBundle;
055:
056: import org.netbeans.api.project.Project;
057: import org.netbeans.spi.project.ui.templates.support.Templates;
058:
059: /**
060: *
061: * @author Peter Williams
062: */
063: public class WebServiceClientWizardDescriptor implements
064: WizardDescriptor.FinishablePanel,
065: WizardDescriptor.ValidatingPanel {
066:
067: private WizardDescriptor wizardDescriptor;
068: private ClientInfo component = null;
069: private String projectPath;
070: private Project project;
071:
072: public WebServiceClientWizardDescriptor() {
073: }
074:
075: public boolean isFinishPanel() {
076: return true;
077: }
078:
079: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
080: 1);
081:
082: public final void addChangeListener(ChangeListener l) {
083: synchronized (listeners) {
084: listeners.add(l);
085: }
086: }
087:
088: public final void removeChangeListener(ChangeListener l) {
089: synchronized (listeners) {
090: listeners.remove(l);
091: }
092: }
093:
094: protected final void fireChangeEvent() {
095: Iterator<ChangeListener> it;
096: synchronized (listeners) {
097: it = new HashSet<ChangeListener>(listeners).iterator();
098: }
099: ChangeEvent ev = new ChangeEvent(this );
100: while (it.hasNext()) {
101: it.next().stateChanged(ev);
102: }
103: }
104:
105: public Component getComponent() {
106: if (component == null) {
107: component = new ClientInfo(this );
108: }
109:
110: return component;
111: }
112:
113: public HelpCtx getHelp() {
114: return new HelpCtx(WebServiceClientWizardDescriptor.class);
115: }
116:
117: public boolean isValid() {
118: boolean projectDirValid = true;
119: String illegalChar = null;
120:
121: if (projectPath.indexOf("%") >= 0) {
122: projectDirValid = false;
123: illegalChar = "%";
124: } else if (projectPath.indexOf("&") >= 0) {
125: projectDirValid = false;
126: illegalChar = "&";
127: } else if (projectPath.indexOf("?") >= 0) {
128: projectDirValid = false;
129: illegalChar = "?";
130: }
131: if (!projectDirValid) {
132: wizardDescriptor.putProperty("WizardPanel_errorMessage",
133: NbBundle.getMessage(
134: WebServiceClientWizardDescriptor.class,
135: "MSG_InvalidProjectPath", projectPath,
136: illegalChar));
137: return false;
138: }
139:
140: return component.valid(wizardDescriptor);
141: }
142:
143: public void readSettings(Object settings) {
144: wizardDescriptor = (WizardDescriptor) settings;
145: project = Templates.getProject(wizardDescriptor);
146: projectPath = project.getProjectDirectory().getPath();
147: component.read(wizardDescriptor);
148:
149: // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
150: // this name is used in NewFileWizard to modify the title
151: wizardDescriptor.putProperty("NewFileWizard_Title", NbBundle
152: .getMessage(WebServiceClientWizardDescriptor.class,
153: "LBL_WebServiceClient"));// NOI18N
154: }
155:
156: public void storeSettings(Object settings) {
157: WizardDescriptor d = (WizardDescriptor) settings;
158: component.store(d);
159: ((WizardDescriptor) d).putProperty("NewFileWizard_Title", null); // NOI18N
160: }
161:
162: public void validate() throws org.openide.WizardValidationException {
163: component.validatePanel();
164: }
165:
166: }
|