KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > ui > wizards > OC4JInstantiatingIterator


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.oc4j.ui.wizards;
21
22 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
23 import java.io.IOException JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException;
33 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
34 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentFactory;
35 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils;
36 import org.openide.DialogDisplayer;
37 import org.openide.ErrorManager;
38 import org.openide.NotifyDescriptor;
39 import org.openide.WizardDescriptor;
40 import org.openide.util.NbBundle;
41
42 /**
43  * @author pblaha
44  */

45 public class OC4JInstantiatingIterator implements WizardDescriptor.InstantiatingIterator, ChangeListener JavaDoc {
46     
47     private transient AddServerLocationPanel locationPanel = null;
48     private transient AddServerPropertiesPanel propertiesPanel = null;
49     
50     private WizardDescriptor wizard;
51     private transient int index = 0;
52     private transient WizardDescriptor.Panel[] panels = null;
53     
54     
55     private transient Set JavaDoc <ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
56     
57     public void removeChangeListener(ChangeListener JavaDoc l) {
58         synchronized (listeners) {
59             listeners.remove(l);
60         }
61     }
62     
63     public void addChangeListener(ChangeListener JavaDoc l) {
64         synchronized (listeners) {
65             listeners.add(l);
66         }
67     }
68     
69     public void uninitialize(WizardDescriptor wizard) {
70     }
71     
72     public void initialize(WizardDescriptor wizard) {
73         this.wizard = wizard;
74     }
75     
76     public void previousPanel() {
77         index--;
78     }
79     
80     public void nextPanel() {
81         if (!hasNext()) throw new NoSuchElementException JavaDoc();
82         index++;
83     }
84     
85     public String JavaDoc name() {
86         return "OC4J Server AddInstanceIterator"; // NOI18N
87
}
88     
89     public static void showInformation(final String JavaDoc msg, final String JavaDoc title){
90         SwingUtilities.invokeLater(new Runnable JavaDoc() {
91             public void run() {
92                 NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
93                 d.setTitle(title);
94                 DialogDisplayer.getDefault().notify(d);
95             }
96         });
97         
98     }
99     
100     public Set JavaDoc instantiate() throws IOException JavaDoc {
101         Set JavaDoc <InstanceProperties> result = new HashSet JavaDoc<InstanceProperties>();
102         String JavaDoc displayName = (String JavaDoc)wizard.getProperty("ServInstWizard_displayName"); // NOI18N
103
String JavaDoc url = OC4JDeploymentFactory.URI_PREFIX + ":" + host + ":" + adminPort; // NOI18N
104

105         try {
106             InstanceProperties ip = InstanceProperties.createInstanceProperties(url, userName, password, displayName);
107             ip.setProperty(OC4JPluginProperties.PROPERTY_ADMIN_PORT, Integer.toString(adminPort));
108             ip.setProperty(OC4JPluginProperties.PROPERTY_WEB_SITE, webSite);
109             ip.setProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME, oc4jHomeLocation);
110             ip.setProperty(InstanceProperties.HTTP_PORT_NUMBER, Integer.toString(httpPort));
111             ip.setProperty(OC4JPluginProperties.PROPERTY_HOST, host);
112             result.add(ip);
113             
114             // Registering of the Oracle 10g JDBC driver
115
OC4JPluginUtils.registerOracleJdbcDriver(oc4jHomeLocation);
116         } catch (InstanceCreationException e){
117             showInformation(e.getLocalizedMessage(), NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "MSG_INSTANCE_REGISTRATION_FAILED")); //NOI18N
118
ErrorManager.getDefault().log(ErrorManager.EXCEPTION, e.getMessage());
119         }
120         
121         return result;
122     }
123     
124     public boolean hasPrevious() {
125         return index > 0;
126     }
127     
128     public boolean hasNext() {
129         return index < getPanels().length - 1;
130     }
131     
132     protected String JavaDoc[] createSteps() {
133         return new String JavaDoc[] {
134             NbBundle.getMessage(OC4JInstantiatingIterator.class, "STEP_ServerLocation"), // NOI18N
135
NbBundle.getMessage(OC4JInstantiatingIterator.class, "STEP_Properties") }; // NOI18N
136
}
137     
138     protected final String JavaDoc[] getSteps() {
139         if (steps == null) {
140             steps = createSteps();
141         }
142         return steps;
143     }
144     
145     protected final WizardDescriptor.Panel[] getPanels() {
146         if (panels == null) {
147             panels = createPanels();
148         }
149         return panels;
150     }
151     
152     protected WizardDescriptor.Panel[] createPanels() {
153         if (locationPanel == null) {
154             locationPanel = new AddServerLocationPanel(this);
155             locationPanel.addChangeListener(this);
156         }
157         if (propertiesPanel == null) {
158             propertiesPanel = new AddServerPropertiesPanel(this);
159             propertiesPanel.addChangeListener(this);
160         }
161         
162         return new WizardDescriptor.Panel[] {
163             (WizardDescriptor.Panel)locationPanel,
164             (WizardDescriptor.Panel)propertiesPanel
165         };
166     }
167     
168     private transient String JavaDoc[] steps = null;
169     
170     protected final int getIndex() {
171         return index;
172     }
173     
174     public WizardDescriptor.Panel current() {
175         WizardDescriptor.Panel result = getPanels()[index];
176         JComponent JavaDoc component = (JComponent JavaDoc)result.getComponent();
177         component.putClientProperty("WizardPanel_contentData", getSteps()); // NOI18N
178
component.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(getIndex()));// NOI18N
179
return result;
180     }
181     
182     public void stateChanged(javax.swing.event.ChangeEvent JavaDoc changeEvent) {
183         fireChangeEvent();
184     }
185     
186     protected final void fireChangeEvent() {
187         Iterator JavaDoc it;
188         synchronized (listeners) {
189             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
190         }
191         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
192         while (it.hasNext()) {
193             ((ChangeListener JavaDoc) it.next()).stateChanged(ev);
194         }
195     }
196     
197     private int httpPort;
198     private int adminPort;
199     private String JavaDoc host;
200     private String JavaDoc userName;
201     private String JavaDoc password;
202     private String JavaDoc oc4jHomeLocation;
203     private String JavaDoc webSite;
204     
205     public void setHost(String JavaDoc host) {
206         this.host = host;
207     }
208     
209     public void setHttpPort(int httpPort) {
210         this.httpPort = httpPort;
211     }
212     
213     public void setAdminPort(int adminPort) {
214         this.adminPort = adminPort;
215     }
216     
217     public void setUserName(String JavaDoc userName) {
218         this.userName = userName;
219     }
220     
221     public void setPassword(String JavaDoc password) {
222         this.password = password;
223     }
224     
225     public void setOC4JHomeLocation(String JavaDoc oc4jHomeLocation) {
226         this.oc4jHomeLocation = oc4jHomeLocation;
227     }
228     
229     public String JavaDoc getOC4JHomeLocation() {
230         return oc4jHomeLocation;
231     }
232     
233     public void setWebSite(String JavaDoc webSite) {
234         this.webSite = webSite;
235     }
236 }
Popular Tags