KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ejb > wizard > dd > EjbJarXmlWizardIterator


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.dd;
21
22 import java.awt.Component JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26 import java.util.Set JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
31 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
32 import org.openide.WizardDescriptor;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.FileUtil;
35 import org.openide.filesystems.Repository;
36
37 /**
38  *
39  * @author Martin Adamek
40  */

41 public final class EjbJarXmlWizardIterator implements WizardDescriptor.InstantiatingIterator {
42
43     // generated by apisupport wizard
44

45     private int index;
46     
47     private WizardDescriptor wizard;
48     private WizardDescriptor.Panel[] panels;
49     
50     /**
51      * Initialize panels representing individual wizard's steps and sets
52      * various properties for them influencing wizard appearance.
53      */

54     private WizardDescriptor.Panel[] getPanels() {
55         if (panels == null) {
56             panels = new WizardDescriptor.Panel[] {
57                 new EjbJarXmlWizardPanel1()
58             };
59             String JavaDoc[] steps = createSteps();
60             for (int i = 0; i < panels.length; i++) {
61                 Component JavaDoc component = panels[i].getComponent();
62                 if (steps[i] == null) {
63                     // Default step name to component name of panel. Mainly
64
// useful for getting the name of the target chooser to
65
// appear in the list of steps.
66
steps[i] = component.getName();
67                 }
68                 if (component instanceof JComponent JavaDoc) { // assume Swing components
69
JComponent JavaDoc jComponent = (JComponent JavaDoc) component;
70                     // Sets step number of a component
71
jComponent.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i));
72                     // Sets steps names for a panel
73
jComponent.putClientProperty("WizardPanel_contentData", steps);
74                     // Turn on subtitle creation on each step
75
jComponent.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
76                     // Show steps on the left side with the image on the background
77
jComponent.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
78                     // Turn on numbering of all steps
79
jComponent.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
80                 }
81             }
82         }
83         return panels;
84     }
85     
86     public Set JavaDoc instantiate() throws IOException JavaDoc {
87         FileObject confRoot = ((EjbJarXmlWizardPanel1) panels[0]).getSelectedLocation();
88         Project project = ((EjbJarXmlWizardPanel1) panels[0]).getProject();
89         J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class);
90         J2eeModule j2eeModule = j2eeModuleProvider.getJ2eeModule();
91         if (confRoot != null) {
92             String JavaDoc resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-" + j2eeModule.getModuleVersion() + ".xml";
93             FileObject ddFile = FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource(resource), confRoot, "ejb-jar"); //NOI18N
94
return Collections.singleton(ddFile);
95         }
96         return Collections.EMPTY_SET;
97     }
98     
99     public void initialize(WizardDescriptor wizard) {
100         this.wizard = wizard;
101     }
102     
103     public void uninitialize(WizardDescriptor wizard) {
104         panels = null;
105     }
106     
107     public WizardDescriptor.Panel current() {
108         return getPanels()[index];
109     }
110     
111     public String JavaDoc name() {
112         return index + 1 + ". from " + getPanels().length;
113     }
114     
115     public boolean hasNext() {
116         return index < getPanels().length - 1;
117     }
118     
119     public boolean hasPrevious() {
120         return index > 0;
121     }
122     
123     public void nextPanel() {
124         if (!hasNext()) {
125             throw new NoSuchElementException JavaDoc();
126         }
127         index++;
128     }
129     
130     public void previousPanel() {
131         if (!hasPrevious()) {
132             throw new NoSuchElementException JavaDoc();
133         }
134         index--;
135     }
136     
137     // If nothing unusual changes in the middle of the wizard, simply:
138
public void addChangeListener(ChangeListener JavaDoc listener) {}
139     public void removeChangeListener(ChangeListener JavaDoc listener) {}
140     
141     // If something changes dynamically (besides moving between panels), e.g.
142
// the number of panels changes in response to user input, then uncomment
143
// the following and call when needed: fireChangeEvent();
144
/*
145     private Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
146     public final void addChangeListener(ChangeListener l) {
147         synchronized (listeners) {
148             listeners.add(l);
149         }
150     }
151     public final void removeChangeListener(ChangeListener l) {
152         synchronized (listeners) {
153             listeners.remove(l);
154         }
155     }
156     protected final void fireChangeEvent() {
157         Iterator<ChangeListener> it;
158         synchronized (listeners) {
159             it = new HashSet<ChangeListener>(listeners).iterator();
160         }
161         ChangeEvent ev = new ChangeEvent(this);
162         while (it.hasNext()) {
163             it.next().stateChanged(ev);
164         }
165     }
166      */

167     
168     // You could safely ignore this method. Is is here to keep steps which were
169
// there before this wizard was instantiated. It should be better handled
170
// by NetBeans Wizard API itself rather than needed to be implemented by a
171
// client code.
172
private String JavaDoc[] createSteps() {
173         String JavaDoc[] beforeSteps = null;
174         Object JavaDoc prop = wizard.getProperty("WizardPanel_contentData");
175         if (prop != null && prop instanceof String JavaDoc[]) {
176             beforeSteps = (String JavaDoc[]) prop;
177         }
178         
179         if (beforeSteps == null) {
180             beforeSteps = new String JavaDoc[0];
181         }
182         
183         String JavaDoc[] res = new String JavaDoc[(beforeSteps.length - 1) + panels.length];
184         for (int i = 0; i < res.length; i++) {
185             if (i < (beforeSteps.length - 1)) {
186                 res[i] = beforeSteps[i];
187             } else {
188                 res[i] = panels[i - beforeSteps.length + 1].getComponent().getName();
189             }
190         }
191         return res;
192     }
193     
194 }
195
Popular Tags