KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wizard > CreateBindingFromPortTypeWizardIterator


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.xml.wsdl.ui.wizard;
21
22 import java.awt.Component JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.event.ChangeEvent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31
32 import org.netbeans.modules.xml.wsdl.model.PortType;
33 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
34 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementsFactory;
35 import org.openide.WizardDescriptor;
36
37 public final class CreateBindingFromPortTypeWizardIterator implements WizardDescriptor.Iterator {
38     
39     // To invoke this wizard, copy-paste and run the following code, e.g. from
40
// SomeAction.performAction():
41
/*
42     WizardDescriptor.Iterator iterator = new CreateBindingFromPortTypeWizardIterator();
43     WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
44     // {0} will be replaced by WizardDescriptor.Panel.getComponent().getName()
45     // {1} will be replaced by WizardDescriptor.Iterator.name()
46     wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})"));
47     wizardDescriptor.setTitle("Your wizard dialog title here");
48     Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
49     dialog.setVisible(true);
50     dialog.toFront();
51     boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
52     if (!cancelled) {
53         // do something
54     }
55      */

56     
57     private int index;
58     
59     private WizardDescriptor.Panel[] panels;
60
61     private PortType mPortType;
62     private WSDLExtensibilityElements extensibilityElements;
63     
64     public CreateBindingFromPortTypeWizardIterator(PortType portType) {
65         mPortType = portType;
66         try {
67         extensibilityElements
68         = WSDLExtensibilityElementsFactory.getInstance().getWSDLExtensibilityElements();
69         
70         } catch (Exception JavaDoc e) {
71             
72         }
73     }
74     /**
75      * Initialize panels representing individual wizard's steps and sets
76      * various properties for them influencing wizard appearance.
77      */

78     private WizardDescriptor.Panel[] getPanels() {
79         if (panels == null) {
80             panels = new WizardDescriptor.Panel[] {
81                 new CreateBindingFromPortTypeWizardPanel1(mPortType, extensibilityElements)/*,
82                 new CreateBindingFromPortTypeWizardPanel2(extensibilityElements),
83                 new CreateBindingFromPortTypeWizardPanel3(),
84                 new CreateBindingFromPortTypeWizardPanel4()*/

85             };
86             String JavaDoc[] steps = new String JavaDoc[panels.length];
87             for (int i = 0; i < panels.length; i++) {
88                 Component JavaDoc c = panels[i].getComponent();
89                 // Default step name to component name of panel.
90
steps[i] = c.getName();
91                 if (c instanceof JComponent JavaDoc) { // assume Swing components
92
JComponent JavaDoc jc = (JComponent JavaDoc) c;
93                     // Sets step number of a component
94
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i));
95                     // Sets steps names for a panel
96
jc.putClientProperty("WizardPanel_contentData", steps);
97                     // Turn on subtitle creation on each step
98
jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
99                     // Show steps on the left side with the image on the background
100
jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
101                     // Turn on numbering of all steps
102
jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
103                 }
104             }
105         }
106         return panels;
107     }
108     
109     public WizardDescriptor.Panel current() {
110         return getPanels()[index];
111     }
112     
113     public String JavaDoc name() {
114         return index + 1 + ". from " + getPanels().length;
115     }
116     
117     public boolean hasNext() {
118         if (current().isValid()) {
119             return index < getPanels().length - 1;
120         }
121         return false;
122     }
123     
124     public boolean hasPrevious() {
125         return index > 0;
126     }
127     
128     public void nextPanel() {
129         if (!hasNext()) {
130             throw new NoSuchElementException JavaDoc();
131         }
132         index++;
133     }
134     
135     public void previousPanel() {
136         if (!hasPrevious()) {
137             throw new NoSuchElementException JavaDoc();
138         }
139         index--;
140     }
141     
142     // If nothing unusual changes in the middle of the wizard, simply:
143
/* public void addChangeListener(ChangeListener l) {}
144     public void removeChangeListener(ChangeListener l) {}*/

145     
146     // If something changes dynamically (besides moving between panels), e.g.
147
// the number of panels changes in response to user input, then uncomment
148
// the following and call when needed: fireChangeEvent();
149

150     private Set JavaDoc<ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
151     public final void addChangeListener(ChangeListener JavaDoc l) {
152         synchronized (listeners) {
153             listeners.add(l);
154         }
155     }
156     public final void removeChangeListener(ChangeListener JavaDoc l) {
157         synchronized (listeners) {
158             listeners.remove(l);
159         }
160     }
161     protected final void fireChangeEvent() {
162         Iterator JavaDoc<ChangeListener JavaDoc> it;
163         synchronized (listeners) {
164             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
165         }
166         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
167         while (it.hasNext()) {
168             it.next().stateChanged(ev);
169         }
170     }
171      
172     
173 }
174
Popular Tags