1 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 ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.NoSuchElementException ; 27 import java.util.Set ; 28 import javax.swing.JComponent ; 29 import javax.swing.SwingUtilities ; 30 import javax.swing.event.ChangeEvent ; 31 import javax.swing.event.ChangeListener ; 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 45 public class OC4JInstantiatingIterator implements WizardDescriptor.InstantiatingIterator, ChangeListener { 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 <ChangeListener > listeners = new HashSet <ChangeListener >(1); 56 57 public void removeChangeListener(ChangeListener l) { 58 synchronized (listeners) { 59 listeners.remove(l); 60 } 61 } 62 63 public void addChangeListener(ChangeListener 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 (); 82 index++; 83 } 84 85 public String name() { 86 return "OC4J Server AddInstanceIterator"; } 88 89 public static void showInformation(final String msg, final String title){ 90 SwingUtilities.invokeLater(new Runnable () { 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 instantiate() throws IOException { 101 Set <InstanceProperties> result = new HashSet <InstanceProperties>(); 102 String displayName = (String )wizard.getProperty("ServInstWizard_displayName"); String url = OC4JDeploymentFactory.URI_PREFIX + ":" + host + ":" + adminPort; 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 OC4JPluginUtils.registerOracleJdbcDriver(oc4jHomeLocation); 116 } catch (InstanceCreationException e){ 117 showInformation(e.getLocalizedMessage(), NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "MSG_INSTANCE_REGISTRATION_FAILED")); 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 [] createSteps() { 133 return new String [] { 134 NbBundle.getMessage(OC4JInstantiatingIterator.class, "STEP_ServerLocation"), NbBundle.getMessage(OC4JInstantiatingIterator.class, "STEP_Properties") }; } 137 138 protected final String [] 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 [] 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 component = (JComponent )result.getComponent(); 177 component.putClientProperty("WizardPanel_contentData", getSteps()); component.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (getIndex())); return result; 180 } 181 182 public void stateChanged(javax.swing.event.ChangeEvent changeEvent) { 183 fireChangeEvent(); 184 } 185 186 protected final void fireChangeEvent() { 187 Iterator it; 188 synchronized (listeners) { 189 it = new HashSet <ChangeListener >(listeners).iterator(); 190 } 191 ChangeEvent ev = new ChangeEvent (this); 192 while (it.hasNext()) { 193 ((ChangeListener ) it.next()).stateChanged(ev); 194 } 195 } 196 197 private int httpPort; 198 private int adminPort; 199 private String host; 200 private String userName; 201 private String password; 202 private String oc4jHomeLocation; 203 private String webSite; 204 205 public void setHost(String 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 userName) { 218 this.userName = userName; 219 } 220 221 public void setPassword(String password) { 222 this.password = password; 223 } 224 225 public void setOC4JHomeLocation(String oc4jHomeLocation) { 226 this.oc4jHomeLocation = oc4jHomeLocation; 227 } 228 229 public String getOC4JHomeLocation() { 230 return oc4jHomeLocation; 231 } 232 233 public void setWebSite(String webSite) { 234 this.webSite = webSite; 235 } 236 } | Popular Tags |