1 19 package org.netbeans.modules.j2ee.jboss4.ide.ui; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.NoSuchElementException ; 26 import java.util.Properties ; 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.impl.ui.wizard.AddServerInstanceWizard; 33 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException; 34 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 35 import org.netbeans.modules.j2ee.jboss4.JBDeploymentFactory; 36 import org.openide.DialogDisplayer; 37 import org.openide.ErrorManager; 38 import org.openide.NotifyDescriptor; 39 import org.openide.WizardDescriptor; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileUtil; 42 import org.openide.util.NbBundle; 43 44 45 49 public class JBInstantiatingIterator implements WizardDescriptor.InstantiatingIterator, ChangeListener { 50 51 52 56 public final boolean skipServerLocationStep = false; 57 58 private transient AddServerLocationPanel locationPanel = null; 59 private transient AddServerPropertiesPanel propertiesPanel = null; 60 61 private WizardDescriptor wizard; 62 private transient int index = 0; 63 private transient WizardDescriptor.Panel[] panels = null; 64 65 66 private transient Set listeners = new HashSet (1); 68 public void removeChangeListener(ChangeListener l) { 69 synchronized (listeners) { 70 listeners.remove(l); 71 } 72 } 73 74 public void addChangeListener(ChangeListener l) { 75 synchronized (listeners) { 76 listeners.add(l); 77 } 78 } 79 80 public void uninitialize(WizardDescriptor wizard) { 81 } 82 83 public void initialize(WizardDescriptor wizard) { 84 this.wizard = wizard; 85 } 86 87 public void previousPanel() { 88 index--; 89 } 90 91 public void nextPanel() { 92 if (!hasNext()) throw new NoSuchElementException (); 93 index++; 94 } 95 96 public String name() { 97 return "JBoss Server AddInstanceIterator"; } 99 100 public static void showInformation(final String msg, final String title){ 101 SwingUtilities.invokeLater(new Runnable () { 102 public void run() { 103 NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); 104 d.setTitle(title); 105 DialogDisplayer.getDefault().notify(d); 106 } 107 }); 108 109 } 110 111 public Set instantiate() throws IOException { 112 Set result = new HashSet (); 113 114 String displayName = (String )wizard.getProperty(org.netbeans.modules.j2ee.deployment.impl.ui.wizard.AddServerInstanceWizard.PROP_DISPLAY_NAME); 115 116 String url = JBDeploymentFactory.URI_PREFIX + host + ":" + port; if (server != null && !server.equals("")) url += "#" + server; url += "&"+ installLocation; 121 try { 122 InstanceProperties ip = InstanceProperties.createInstanceProperties(url, userName, password, displayName); 123 ip.setProperty(JBPluginProperties.PROPERTY_SERVER, server); 124 ip.setProperty(JBPluginProperties.PROPERTY_DEPLOY_DIR, deployDir); 125 ip.setProperty(JBPluginProperties.PROPERTY_SERVER_DIR, serverPath); 126 ip.setProperty(JBPluginProperties.PROPERTY_ROOT_DIR, installLocation); 127 128 ip.setProperty(JBPluginProperties.PROPERTY_HOST, host); 129 ip.setProperty(JBPluginProperties.PROPERTY_PORT, port); 130 131 result.add(ip); 132 } catch (InstanceCreationException e){ 133 showInformation(e.getLocalizedMessage(), NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "MSG_INSTANCE_REGISTRATION_FAILED")); ErrorManager.getDefault().log(ErrorManager.EXCEPTION, e.getMessage()); 135 } 136 137 return result; 138 } 139 140 public boolean hasPrevious() { 141 return index > 0; 142 } 143 144 public boolean hasNext() { 145 return index < getPanels().length - 1; 146 } 147 148 protected String [] createSteps() { 149 if(!skipServerLocationStep){ 150 return new String [] { NbBundle.getMessage(JBInstantiatingIterator.class, "STEP_ServerLocation"), NbBundle.getMessage(JBInstantiatingIterator.class, "STEP_Properties") }; }else{ 153 if (!JBPluginProperties.getInstance().isCurrentServerLocationValid()){ 154 return new String [] { NbBundle.getMessage(JBInstantiatingIterator.class, "STEP_ServerLocation"), NbBundle.getMessage(JBInstantiatingIterator.class, "STEP_Properties") }; } else { 157 return new String [] { NbBundle.getMessage(JBInstantiatingIterator.class, "STEP_Properties") }; } 159 } 160 } 161 162 protected final String [] getSteps() { 163 if (steps == null) { 164 steps = createSteps(); 165 } 166 return steps; 167 } 168 169 protected final WizardDescriptor.Panel[] getPanels() { 170 if (panels == null) { 171 panels = createPanels(); 172 } 173 return panels; 174 } 175 176 protected WizardDescriptor.Panel[] createPanels() { 177 if (locationPanel == null) { 178 locationPanel = new AddServerLocationPanel(this); 179 180 locationPanel.addChangeListener(this); 181 } 182 if (propertiesPanel == null) { 183 propertiesPanel = new AddServerPropertiesPanel(this); 184 185 propertiesPanel.addChangeListener(this); 186 } 187 188 if (skipServerLocationStep){ 189 if (!JBPluginProperties.getInstance().isCurrentServerLocationValid()){ 190 return new WizardDescriptor.Panel[] { 191 (WizardDescriptor.Panel)locationPanel, 192 (WizardDescriptor.Panel)propertiesPanel 193 }; 194 } else { 195 return new WizardDescriptor.Panel[] { 196 (WizardDescriptor.Panel)propertiesPanel 197 }; 198 } 199 }else{ 200 return new WizardDescriptor.Panel[] { 201 (WizardDescriptor.Panel)locationPanel, 202 (WizardDescriptor.Panel)propertiesPanel 203 }; 204 } 205 } 206 207 private transient String [] steps = null; 208 209 protected final int getIndex() { 210 return index; 211 } 212 213 public WizardDescriptor.Panel current() { 214 WizardDescriptor.Panel result = getPanels()[index]; 215 JComponent component = (JComponent )result.getComponent(); 216 component.putClientProperty("WizardPanel_contentData", getSteps()); component.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (getIndex())); return result; 219 } 220 221 public void stateChanged(javax.swing.event.ChangeEvent changeEvent) { 222 fireChangeEvent(); 223 } 224 225 protected final void fireChangeEvent() { 226 Iterator it; 227 synchronized (listeners) { 228 it = new HashSet (listeners).iterator(); 229 } 230 ChangeEvent ev = new ChangeEvent (this); 231 while (it.hasNext()) { 232 ((ChangeListener ) it.next()).stateChanged(ev); 233 } 234 } 235 236 private String host; 237 private String port; 238 private String userName=""; 239 private String password=""; 240 private String server; 241 private String installLocation; 242 private String deployDir; 243 private String serverPath; 244 245 246 public void setHost(String host){ 247 this.host = host.trim(); 248 } 249 250 public void setPort(String port){ 251 this.port = port.trim(); 252 } 253 254 public void setServer(String server){ 255 this.server = server; 256 } 257 258 public void setServerPath(String serverPath){ 259 this.serverPath = serverPath; 260 } 261 262 public void setDeployDir(String deployDir){ 263 this.deployDir = deployDir; 264 } 265 266 public void setInstallLocation(String installLocation){ 267 this.installLocation = installLocation; 268 propertiesPanel.installLocationChanged(); 269 } 270 271 } 272 | Popular Tags |