1 19 package org.netbeans.modules.j2ee.jboss4.ide.ui; 20 21 import java.awt.Component ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.MissingResourceException ; 27 import java.util.Set ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 31 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 32 import org.openide.WizardDescriptor; 33 import org.openide.util.HelpCtx; 34 import org.openide.util.NbBundle; 35 36 40 public class AddServerPropertiesPanel implements WizardDescriptor.Panel, ChangeListener { 41 42 private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; private WizardDescriptor wizard; 44 private AddServerPropertiesVisualPanel component; 45 private JBInstantiatingIterator instantiatingIterator; 46 47 48 public AddServerPropertiesPanel(JBInstantiatingIterator instantiatingIterator) { 49 this.instantiatingIterator = instantiatingIterator; 50 } 51 52 public boolean isValid() { 53 AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel)getComponent(); 54 55 String host = panel.getHost(); 56 String port = panel.getPort(); 57 58 if(panel.isLocalServer()){ 59 String path = panel.getDomainPath(); 61 if (!JBPluginUtils.isGoodJBInstanceLocation4x(new File (path)) && 62 !JBPluginUtils.isGoodJBInstanceLocation5x(new File (path))) 63 { 64 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_WrongDomainPath")); 65 return false; 66 } 67 68 ServerInstance[] si = ServerRegistry.getInstance().getServerInstances(); 69 70 for(int i=0;i<si.length;i++) { 71 try { 72 String property = si[i].getInstanceProperties().getProperty(JBPluginProperties.PROPERTY_SERVER_DIR); 73 74 if(property == null) 75 continue; 76 77 String root = new File (property).getCanonicalPath(); 78 79 if(root.equals(new File (path).getCanonicalPath())) { 80 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_InstanceExists")); 81 return false; 82 } 83 } catch (MissingResourceException ex) { 84 continue; 86 } catch (IOException ex) { 87 continue; 89 } 90 } 91 92 try{ 93 new Integer (port); 94 }catch(Exception e){ 95 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_InvalidPort")); 96 return false; 97 } 98 99 100 }else{ if ( (host.equals("")) ){ 102 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_EnterHost")); 103 return false; 104 } 105 if (port.equals("")) { 106 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_EnterPort")); 107 return false; 108 } 109 } 110 111 wizard.putProperty(PROP_ERROR_MESSAGE,null); 112 113 instantiatingIterator.setHost(host); 115 instantiatingIterator.setPort(port); 116 instantiatingIterator.setServer(panel.getDomain()); 117 instantiatingIterator.setServerPath(panel.getDomainPath()); 118 instantiatingIterator.setDeployDir(JBPluginUtils.getDeployDir( panel.getDomainPath())); 119 120 JBPluginProperties.getInstance().setDomainLocation(panel.getDomainPath()); 121 122 return true; 123 } 124 125 public Component getComponent() { 126 if (component == null) { 127 component = new AddServerPropertiesVisualPanel(); 128 component.addChangeListener(this); 129 } 130 return component; 131 } 132 133 public void stateChanged(ChangeEvent ev) { 134 fireChangeEvent(ev); 135 } 136 137 private void fireChangeEvent(ChangeEvent ev) { 138 Iterator it; 140 synchronized (listeners) { 141 it = new HashSet (listeners).iterator(); 142 } 143 while (it.hasNext()) { 144 ((ChangeListener )it.next()).stateChanged(ev); 145 } 146 } 147 148 private transient Set listeners = new HashSet (1); 149 public void removeChangeListener(ChangeListener l) { 150 synchronized (listeners) { 151 listeners.remove(l); 152 } 153 } 154 155 public void addChangeListener(ChangeListener l) { 156 synchronized (listeners) { 157 listeners.add(l); 158 } 159 } 160 161 public void readSettings(Object settings) { 162 if (wizard == null) 163 wizard = (WizardDescriptor)settings; 164 } 165 166 public void storeSettings(Object settings) { 167 } 168 169 public HelpCtx getHelp() { 170 return new HelpCtx("j2eeplugins_registering_app_server_jboss_properties"); } 172 173 void installLocationChanged() { 174 if (component != null) 175 component.installLocationChanged(); 176 } 177 } 178 | Popular Tags |