1 19 20 package org.netbeans.modules.j2ee.oc4j.ui.wizards; 21 22 import java.io.File ; 23 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils; 24 import org.openide.WizardDescriptor; 25 import org.openide.util.HelpCtx; 26 import java.awt.Component ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 import javax.swing.event.ChangeEvent ; 31 import javax.swing.event.ChangeListener ; 32 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentFactory; 33 import org.openide.util.NbBundle; 34 import org.openide.util.NbPreferences; 35 36 39 public class AddServerLocationPanel implements WizardDescriptor.Panel, ChangeListener { 40 41 private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; 43 private OC4JInstantiatingIterator instantiatingIterator; 44 private AddServerLocationVisualPanel component; 45 private WizardDescriptor wizard; 46 private transient Set <ChangeListener >listeners = new HashSet <ChangeListener >(1); 47 48 public AddServerLocationPanel(OC4JInstantiatingIterator instantiatingIterator){ 49 this.instantiatingIterator = instantiatingIterator; 50 } 51 52 public void stateChanged(ChangeEvent ev) { 53 fireChangeEvent(ev); 54 } 55 56 private void fireChangeEvent(ChangeEvent ev) { 57 Iterator it; 58 synchronized (listeners) { 59 it = new HashSet <ChangeListener >(listeners).iterator(); 60 } 61 while (it.hasNext()) { 62 ((ChangeListener )it.next()).stateChanged(ev); 63 } 64 } 65 66 public Component getComponent() { 67 if (component == null) { 68 component = new AddServerLocationVisualPanel(); 69 component.addChangeListener(this); 70 } 71 return component; 72 } 73 74 public HelpCtx getHelp() { 75 return new HelpCtx("j2eeplugins_registering_app_server_oc4j_location"); } 77 78 public boolean isValid() { 79 String locationStr = ((AddServerLocationVisualPanel)getComponent()).getOC4JHomeLocation(); 80 if (!OC4JPluginUtils.isGoodOC4JHomeLocation(new File (locationStr))) { 81 wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerLocationPanel.class, "MSG_InvalidServerLocation")); return false; 83 } else { 84 wizard.putProperty(PROP_ERROR_MESSAGE, null); 85 instantiatingIterator.setOC4JHomeLocation(locationStr); 86 NbPreferences.forModule(OC4JDeploymentFactory.class).put(OC4JDeploymentFactory.PROP_SERVER_ROOT, locationStr); 87 return true; 88 } 89 } 90 91 public void removeChangeListener(ChangeListener l) { 92 synchronized (listeners) { 93 listeners.remove(l); 94 } 95 } 96 97 public void addChangeListener(ChangeListener l) { 98 synchronized (listeners) { 99 listeners.add(l); 100 } 101 } 102 103 public void readSettings(Object settings) { 104 if (wizard == null) 105 wizard = (WizardDescriptor)settings; 106 } 107 108 public void storeSettings(Object settings) { 109 } 110 } | Popular Tags |