1 19 20 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import org.openide.WizardDescriptor; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.NbBundle; 32 33 36 class AddDomainDirectoryPanel implements WizardDescriptor.FinishablePanel, 37 ChangeListener { 38 39 43 private AddInstanceVisualDirectoryPanel component; 44 private WizardDescriptor wiz; 45 private boolean creatingPersonalInstance; 46 47 AddDomainDirectoryPanel(boolean creatingPersonalInstance) { 48 this.creatingPersonalInstance = creatingPersonalInstance; 49 } 50 51 public Component getComponent() { 56 if (component == null) { 57 component = new AddInstanceVisualDirectoryPanel(creatingPersonalInstance); 58 component.addChangeListener(this); 59 } 60 return component; 61 } 62 63 public HelpCtx getHelp() { 64 if (creatingPersonalInstance) 65 return new HelpCtx("AS_RegServ_EnterPIDir"); else 67 return new HelpCtx("AS_RegServ_EnterDomainDir"); 68 } 69 70 75 public boolean isValid() { 76 File domainDir = new File (component.getInstanceDirectory()); 77 if (!creatingPersonalInstance) { 78 if (component.getInstanceDirectory().length() < 1) { 79 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 80 NbBundle.getMessage(AddDomainDirectoryPanel.class, 81 "Msg_EneterValidDomainDir", component.getInstanceDirectory())); 83 component.setAdminPort(""); 84 return false; 85 } 86 if (!Util.rootOfUsableDomain(domainDir)) { 87 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 88 NbBundle.getMessage(AddDomainDirectoryPanel.class, 89 "Msg_InValidDomainDir", component.getInstanceDirectory())); 91 component.setAdminPort(""); return false; 93 } 94 Util.fillDescriptorFromDomainXml(wiz, domainDir); 95 String port = (String )wiz.getProperty(AddDomainWizardIterator.PORT); 96 component.setAdminPort(port); 97 if ("".equals(port)) { wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 99 NbBundle.getMessage(AddDomainDirectoryPanel.class, 100 "Msg_UnsupportedDomain", component.getInstanceDirectory())); 102 return false; 103 } 104 return true; 105 } else { 106 File parent = domainDir.getParentFile(); 107 if (domainDir.exists()) { 108 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 109 NbBundle.getMessage(AddDomainDirectoryPanel.class, 110 "Msg_ExistingDomainDir", domainDir.getAbsolutePath())); 112 return false; 113 } 114 if (null == parent) { 115 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 116 NbBundle.getMessage(AddDomainDirectoryPanel.class, 117 "Msg_InValidDomainDir", component.getInstanceDirectory())); 119 return false; 120 } 121 if (!parent.exists()) { 122 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 123 NbBundle.getMessage(AddDomainDirectoryPanel.class, 124 "Msg_InValidDomainDirParent", parent.getAbsolutePath())); 126 return false; 127 } 128 if (!parent.canWrite()) { 129 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 130 NbBundle.getMessage(AddDomainDirectoryPanel.class, 131 "Msg_InValidDomainDirParent", parent.getAbsolutePath())); 133 return false; 134 } 135 wiz.putProperty(AddDomainWizardIterator.DOMAIN,domainDir.getName()); 136 wiz.putProperty(AddDomainWizardIterator.INSTALL_LOCATION, 137 domainDir.getParentFile().getAbsolutePath()); 138 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,null); 139 return true; 140 } 141 } 142 143 private final Set listeners = 146 new HashSet (1); 147 public final void addChangeListener(ChangeListener l) { 148 synchronized (listeners) { 149 listeners.add(l); 150 } 151 } 152 public final void removeChangeListener(ChangeListener l) { 153 synchronized (listeners) { 154 listeners.remove(l); 155 } 156 } 157 protected final void fireChangeEvent() { 158 Iterator it; 159 synchronized (listeners) { 160 it = new HashSet (listeners).iterator(); 161 } 162 ChangeEvent ev = new ChangeEvent (this); 163 while (it.hasNext()) { 164 ((ChangeListener )it.next()).stateChanged(ev); 165 } 166 } 167 168 public void readSettings(Object settings) { 173 wiz = (WizardDescriptor) settings; 174 } 175 176 public void storeSettings(Object settings) { 177 } 179 180 public void stateChanged(ChangeEvent e) { 181 fireChangeEvent(); 182 } 183 184 188 public boolean isFinishPanel() { 189 return !creatingPersonalInstance; 190 } 191 } 192 | Popular Tags |