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.awt.Component;
045: import java.io.IOException;
046: import java.util.Collections;
047: import java.util.NoSuchElementException;
048: import java.util.Set;
049: import javax.swing.JComponent;
050: import javax.swing.event.ChangeListener;
051: import org.netbeans.modules.websvc.core.ClientCreator;
052: import org.netbeans.modules.websvc.core.CreatorProvider;
053: import org.netbeans.modules.websvc.core.JaxWsUtils;
054: import org.openide.WizardDescriptor;
055: import org.openide.util.NbBundle;
056:
057: import org.netbeans.api.project.Project;
058: import org.netbeans.spi.project.ui.templates.support.Templates;
059: import org.openide.filesystems.FileObject;
060: import org.openide.loaders.DataObject;
061: import org.openide.loaders.TemplateWizard;
062:
063: /** Wizard for adding web service clients to an application
064: */
065: public class WebServiceClientWizardIterator implements
066: TemplateWizard.Iterator {
067:
068: private int index = 0;
069: private WizardDescriptor.Panel[] panels;
070:
071: private TemplateWizard wiz;
072: // !PW FIXME How to handle freeform???
073: private Project project;
074:
075: /** Entry point specified in layer
076: */
077: public static WebServiceClientWizardIterator create() {
078: return new WebServiceClientWizardIterator();
079: }
080:
081: private WizardDescriptor.Panel[] createPanels() {
082: return new WizardDescriptor.Panel[] { new WebServiceClientWizardDescriptor() };
083: }
084:
085: public void initialize(TemplateWizard wizard) {
086: wiz = wizard;
087: project = Templates.getProject(wiz);
088:
089: index = 0;
090: panels = createPanels();
091:
092: Object prop = wiz.getProperty("WizardPanel_contentData"); // NOI18N
093: String[] beforeSteps = null;
094: if (prop != null && prop instanceof String[]) {
095: beforeSteps = (String[]) prop;
096: }
097: String[] steps = JaxWsUtils.createSteps(beforeSteps, panels);
098:
099: for (int i = 0; i < panels.length; i++) {
100: Component c = panels[i].getComponent();
101: if (steps[i] == null) {
102: // Default step name to component name of panel.
103: // Mainly useful for getting the name of the target
104: // chooser to appear in the list of steps.
105: steps[i] = c.getName();
106: }
107:
108: assert c instanceof JComponent;
109: JComponent jc = (JComponent) c;
110: // Step #.
111: jc.putClientProperty("WizardPanel_contentSelectedIndex",
112: Integer.valueOf(i)); // NOI18N
113: // Step name (actually the whole list for reference).
114: jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
115: }
116: }
117:
118: public void uninitialize(TemplateWizard wizard) {
119: wiz = null;
120: panels = null;
121: }
122:
123: public Set<DataObject> instantiate(TemplateWizard wiz)
124: throws IOException {
125: FileObject template = Templates.getTemplate(wiz);
126: DataObject dTemplate = DataObject.find(template);
127: ClientCreator creator = CreatorProvider.getClientCreator(
128: project, wiz);
129: if (creator != null)
130: creator.createClient();
131:
132: return Collections.singleton(dTemplate);
133: }
134:
135: public String name() {
136: return NbBundle.getMessage(
137: WebServiceClientWizardIterator.class,
138: "LBL_WebServiceClient"); // NOI18N
139: }
140:
141: public WizardDescriptor.Panel<WizardDescriptor> current() {
142: return panels[index];
143: }
144:
145: public boolean hasNext() {
146: return index < panels.length - 1;
147: }
148:
149: public void nextPanel() {
150: if (!hasNext()) {
151: throw new NoSuchElementException();
152: }
153:
154: index++;
155: }
156:
157: public boolean hasPrevious() {
158: return index > 0;
159: }
160:
161: public void previousPanel() {
162: if (!hasNext()) {
163: throw new NoSuchElementException();
164: }
165:
166: index--;
167: }
168:
169: public void addChangeListener(ChangeListener l) {
170: // nothing to do yet
171: }
172:
173: public void removeChangeListener(ChangeListener l) {
174: // nothing to do yet
175: }
176: }
|