1 19 22 23 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards; 24 25 import java.awt.Component ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.ResourceBundle ; 29 import java.util.Set ; 30 import javax.swing.JTextField ; 31 import javax.swing.event.ChangeEvent ; 32 import javax.swing.event.ChangeListener ; 33 34 import org.openide.loaders.TemplateWizard; 35 import org.openide.WizardDescriptor; 36 import org.openide.util.HelpCtx; 37 import org.openide.util.NbBundle; 38 39 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ResourceUtils; 40 41 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 42 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard; 43 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants; 44 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper; 45 46 52 public class CommonGeneralFinishPanel implements WizardDescriptor.FinishablePanel, WS70WizardConstants { 53 protected ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); 55 56 60 private CommonGeneralFinishVisualPanel component; 61 private ResourceConfigHelper helper; 62 private Wizard wizardInfo; 63 private String [] groupNames; 64 65 66 public CommonGeneralFinishPanel(ResourceConfigHelper helper, Wizard wizardInfo, String [] groupNames) { 67 this.helper = helper; 68 this.wizardInfo = wizardInfo; 69 this.groupNames = groupNames; 70 } 71 72 public Component getComponent() { 77 if (component == null) { 78 FieldGroup[] groups = new FieldGroup[groupNames.length]; 79 for (int i = 0; i < this.groupNames.length; i++) { 80 groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); } 82 String panelType = null; 83 if (wizardInfo.getName().equals(__MailResource)) { 84 panelType = CommonGeneralFinishVisualPanel.TYPE_MAIL_RESOURCE; 85 }else if(wizardInfo.getName().equals(__CustomResource)) { 86 panelType = CommonGeneralFinishVisualPanel.TYPE_CUSTOM_RESOURCE; 87 }else if(wizardInfo.getName().equals(__ExternalJndiResource)) { 88 panelType = CommonGeneralFinishVisualPanel.TYPE_EXTERNAL_RESOURCE; 89 }else if(wizardInfo.getName().equals(WS70WizardConstants.__JdbcResource)) { 90 panelType = CommonGeneralFinishVisualPanel.TYPE_JDBC_RESOURCE; 91 } 92 component = new CommonGeneralFinishVisualPanel(this, groups, panelType); 93 } 94 return component; 95 } 96 97 public boolean createNew() { 98 if (component == null) 99 return false; 100 else 101 return component.createNew(); 102 } 103 104 public String getResourceName() { 105 return this.wizardInfo.getName(); 106 } 107 108 public HelpCtx getHelp() { 109 if (wizardInfo.getName().equals(__MailResource)) { 110 return new HelpCtx("AS_Wiz_Mail_general"); }else{ 112 return HelpCtx.DEFAULT_HELP; 113 } 114 115 } 116 117 public ResourceConfigHelper getHelper() { 118 return helper; 119 } 120 121 public boolean isValid() { 122 if (component != null && component.jLabels != null && component.jFields != null) { 124 int i; 125 for (i=0; i < component.jLabels.length; i++) { 126 String jLabel = (String )component.jLabels[i].getText(); 127 if (jLabel.equals(bundle.getString("LBL_" + __JndiName))) { String jndiName = (String )((JTextField )component.jFields[i]).getText(); 129 if (jndiName == null || jndiName.trim().length() == 0) { 130 return false; 131 }else if(! WS70ResourceUtils.isLegalResourceName(jndiName)){ 132 return false; 133 } 134 } 135 if (wizardInfo.getName().equals(__MailResource)) { 136 if (jLabel.equals(bundle.getString("LBL_" + __Host))) { String host = (String )((JTextField )component.jFields[i]).getText(); 138 if (host == null || host.trim().length() == 0) { 139 return false; 140 } 141 } 142 if (jLabel.equals(bundle.getString("LBL_" + __MailUser))) { String user = (String )((JTextField )component.jFields[i]).getText(); 144 if (user == null || user.trim().length() == 0) { 145 return false; 146 } 147 } 148 if (jLabel.equals(bundle.getString("LBL_" + __From))) { String from = (String )((JTextField )component.jFields[i]).getText(); 150 if (from == null || from.trim().length() == 0) { 151 return false; 152 } 153 } 154 }else if(wizardInfo.getName().equals(this.__CustomResource)){ 155 if (jLabel.equals(bundle.getString("LBL_" + this.__ResType))) { String restype = (String )((JTextField )component.jFields[i]).getText(); 157 if (restype == null || restype.trim().length() == 0) { 158 return false; 159 } 160 } 161 if (jLabel.equals(bundle.getString("LBL_" + this.__FactoryClass))) { String factclass = (String )((JTextField )component.jFields[i]).getText(); 163 if (factclass == null || factclass.trim().length() == 0) { 164 return false; 165 } 166 } 167 168 }else if(wizardInfo.getName().equals(this.__ExternalJndiResource)){ 169 if (jLabel.equals(bundle.getString("LBL_" + this.__ResType))) { String restype = (String )((JTextField )component.jFields[i]).getText(); 171 if (restype == null || restype.trim().length() == 0) { 172 return false; 173 } 174 } 175 if (jLabel.equals(bundle.getString("LBL_" + this.__FactoryClass))) { String factclass = (String )((JTextField )component.jFields[i]).getText(); 177 if (factclass == null || factclass.trim().length() == 0) { 178 return false; 179 } 180 } 181 if (jLabel.equals(bundle.getString("LBL_" + this.__ExternalJndiName))) { String extjndiname = (String )((JTextField )component.jFields[i]).getText(); 183 if (extjndiname == null || extjndiname.trim().length() == 0) { 184 return false; 185 } 186 } 187 188 }else if(wizardInfo.getName().equals(this.__JdbcResource)){ 189 if (jLabel.equals(bundle.getString("LBL_" + this.__DatasourceClassname))) { String dsclassname = (String )((JTextField )component.jFields[i]).getText(); 191 if (dsclassname == null || dsclassname.trim().length() == 0) { 192 return false; 193 } 194 } 195 } 196 } } 198 return true; 199 } 205 206 public boolean isFinishPanel() { 207 return isValid(); 208 } 209 210 private final Set listeners = new HashSet (1); 211 public final void addChangeListener (ChangeListener l) { 212 synchronized (listeners) { 213 listeners.add (l); 214 } 215 } 216 public final void removeChangeListener (ChangeListener l) { 217 synchronized (listeners) { 218 listeners.remove (l); 219 } 220 } 221 protected final void fireChangeEvent () { 222 Iterator it; 223 synchronized (listeners) { 224 it = new HashSet (listeners).iterator (); 225 } 226 ChangeEvent ev = new ChangeEvent (this); 227 while (it.hasNext ()) { 228 ((ChangeListener ) it.next ()).stateChanged (ev); 229 } 230 } 231 232 233 public void readSettings(Object settings) { 238 if (wizardInfo.getName().equals(__MailResource)) { 239 TemplateWizard wizard = (TemplateWizard)settings; 240 String targetName = wizard.getTargetName(); 241 targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __MAILResource); 242 this.helper.getData().setTargetFile(targetName); 243 if(component == null) 244 getComponent(); 245 component.setHelper(this.helper); 246 }else if (wizardInfo.getName().equals(__CustomResource)) { 247 TemplateWizard wizard = (TemplateWizard)settings; 248 String targetName = wizard.getTargetName(); 249 targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __CUSTOMResource); 250 this.helper.getData().setTargetFile(targetName); 251 if(component == null) 252 getComponent(); 253 component.setHelper(this.helper); 254 }else if (wizardInfo.getName().equals(__ExternalJndiResource)) { 255 TemplateWizard wizard = (TemplateWizard)settings; 256 String targetName = wizard.getTargetName(); 257 targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __EXTERNALResource); 258 this.helper.getData().setTargetFile(targetName); 259 if(component == null) 260 getComponent(); 261 component.setHelper(this.helper); 262 }else if (wizardInfo.getName().equals(__JdbcResource)) { 263 TemplateWizard wizard = (TemplateWizard)settings; 264 String targetName = wizard.getTargetName(); 265 targetName = WS70ResourceUtils.createUniqueFileName(targetName, WS70ResourceUtils.setUpExists(this.helper.getData().getTargetFileObject()), __JDBCResource); 266 this.helper.getData().setTargetFile(targetName); 267 if(component == null) 268 getComponent(); 269 component.setHelper(this.helper); 270 } 271 } 272 public void storeSettings(Object settings) { 273 } 274 275 public void initData() { 276 this.component.initData(); 277 } 278 } 279 280 | Popular Tags |