1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards; 26 27 import java.awt.Component ; 28 import javax.swing.JTextField ; 29 import java.util.Set ; 30 import java.util.Arrays ; 31 import java.util.HashSet ; 32 import org.openide.filesystems.FileObject; 33 34 import org.openide.loaders.TemplateWizard; 35 import org.openide.WizardDescriptor; 36 import org.openide.util.HelpCtx; 37 38 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 39 40 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 41 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard; 42 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper; 43 44 49 public class CommonAttributePanel extends ResourceWizardPanel { 50 51 55 private CommonAttributeVisualPanel component; 56 private ResourceConfigHelper helper; 57 private Wizard wizardInfo; 58 private String [] groupNames; 59 private boolean setupValid = true; 60 61 62 public CommonAttributePanel(ResourceConfigHelper helper, Wizard wizardInfo, String [] groupNames) { 63 this.helper = helper; 64 this.wizardInfo = wizardInfo; 65 this.groupNames = groupNames; 66 } 67 68 public Component getComponent() { 73 if (component == null) { 74 FieldGroup[] groups = new FieldGroup[groupNames.length]; 75 for (int i = 0; i < this.groupNames.length; i++) { 76 groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); } 78 String panelType = CommonAttributeVisualPanel.TYPE_JDBC_RESOURCE; 79 if (wizardInfo.getName().equals(__JdbcConnectionPool)) { 80 panelType = CommonAttributeVisualPanel.TYPE_CP_POOL_SETTING; 81 }else if (wizardInfo.getName().equals(__PersistenceManagerFactoryResource)) { 82 panelType = CommonAttributeVisualPanel.TYPE_PERSISTENCE_MANAGER; 83 } 84 component = new CommonAttributeVisualPanel(this, groups, panelType, this.helper); 85 } 86 return component; 87 } 88 89 public boolean isNewResourceSelected() { 90 if (component == null) 91 return false; 92 else 93 return component.isNewResourceSelected(); 94 } 95 96 public void setInitialFocus(){ 97 if(component != null) { 98 component.setInitialFocus(); 99 } 100 } 101 102 public void setPropInitialFocus(){ 103 if(component != null) { 104 component.setPropInitialFocus(); 105 } 106 } 107 108 public String getResourceName() { 109 return this.wizardInfo.getName(); 110 } 111 112 public HelpCtx getHelp() { 113 if (wizardInfo.getName().equals(__JdbcConnectionPool)) { 114 return new HelpCtx("AS_Wiz_ConnPool_poolSettings"); }else if (wizardInfo.getName().equals(__JdbcResource)) { 116 return new HelpCtx("AS_Wiz_DataSource_general"); }else if (wizardInfo.getName().equals(__PersistenceManagerFactoryResource)) { 118 return new HelpCtx("AS_Wiz_PMF_general"); }else { 120 return HelpCtx.DEFAULT_HELP; 121 } 122 } 123 124 public ResourceConfigHelper getHelper() { 125 return helper; 126 } 127 128 public String getJndiName() { 129 if (component != null && component.jLabels != null && component.jFields != null) { 130 int i; 131 for (i=0; i < component.jLabels.length; i++) { 132 String jLabel = (String )component.jLabels[i].getText(); 133 if (jLabel.equals(bundle.getString("LBL_" + __JndiName))) { return (String )((JTextField )component.jFields[i]).getText(); 135 } 136 } 137 } 138 return null; 139 } 140 141 149 public boolean isValid () { 150 if(! setupValid){ 152 setErrorMsg (bundle.getString ("Err_InvalidSetup")); 153 return false; 154 } 155 setErrorMsg (bundle.getString ("Empty_String")); 156 if (component != null && component.jLabels != null && component.jFields != null) { 157 int i; 158 for (i=0; i < component.jLabels.length; i++) { 159 String jLabel = (String )component.jLabels[i].getText (); 160 if (jLabel.equals (bundle.getString ("LBL_" + __JndiName))) { String jndiName = (String )((JTextField )component.jFields[i]).getText (); 162 if (jndiName == null || jndiName.length () == 0) { 163 setErrorMsg (bundle.getString ("Err_InvalidJndiName")); 164 return false; 165 }else if(! ResourceUtils.isLegalResourceName (jndiName)){ 166 return false; 167 }else{ 168 FileObject resFolder = this.helper.getData ().getTargetFileObject (); 169 if(resFolder != null){ 170 if (wizardInfo.getName ().equals (__JdbcResource)){ 171 if(! ResourceUtils.isUniqueFileName (jndiName, resFolder, __JDBCResource)){ 172 setErrorMsg (bundle.getString ("Err_DuplFileJndiName")); 173 return false; 174 } 175 }else if(wizardInfo.getName ().equals (__PersistenceManagerFactoryResource)){ 176 if(! ResourceUtils.isUniqueFileName (jndiName, resFolder, __PersistenceResource)){ 177 setErrorMsg (bundle.getString ("Err_DuplFileJndiName")); 178 return false; 179 } 180 } 181 } 182 } 183 }else{ 184 Set commonAttr = new HashSet (Arrays.asList (COMMON_ATTR_INTEGER)); 185 if(commonAttr.contains (jLabel.trim ())){ 186 String fieldValue = (String )((JTextField )component.jFields[i]).getText (); 187 if (fieldValue == null || fieldValue.length () == 0) { 188 setErrorMessage (bundle.getString ("Err_EmptyValue"), jLabel); 189 return false; 190 } 191 } 192 } 193 } 194 195 } 196 if(!isNewResourceSelected ()){ 197 if((this.helper.getData ().getResourceName ()).equals (__JdbcResource)){ 199 String cpname = this.helper.getData ().getString (__PoolName); 200 if(cpname == null || cpname.trim ().equals ("") ) { setErrorMsg (bundle.getString ("Err_ChooseOrCreatePool")); 202 return false; 203 } 204 } 205 if((this.helper.getData ().getResourceName ()).equals (__PersistenceManagerFactoryResource)){ 207 if(this.helper.getData ().getHolder ().hasDSHelper ()){ 208 String cpname = this.helper.getData ().getHolder ().getDSHelper ().getData ().getString (__PoolName); 209 if(cpname == null || cpname.trim ().equals ("") ) { setErrorMsg (bundle.getString ("Err_ChooseOrCreatePool")); 211 return false; 212 } 213 }else{ 214 String dsname = this.helper.getData ().getString (__JdbcResourceJndiName); 215 if(dsname == null || dsname.trim ().equals ("") ) { setErrorMsg (bundle.getString ("Err_ChooseOrCreateDS")); 217 return false; 218 } 219 } 220 } 221 } 222 return true; 223 } 224 225 public void initData() { 226 this.component.initData(); 227 } 228 229 public void readSettings(Object settings) { 230 this.wizDescriptor = (WizardDescriptor)settings; 231 TemplateWizard wizard = (TemplateWizard)settings; 232 String targetName = wizard.getTargetName(); 233 FileObject resFolder = ResourceUtils.getResourceDirectory(this.helper.getData().getTargetFileObject()); 234 this.helper.getData().setTargetFileObject (resFolder); 235 if(component == null) 236 getComponent(); 237 if(resFolder != null){ 238 if (wizardInfo.getName ().equals (__JdbcResource)){ 239 if(this.helper.getData ().getString (__DynamicWizPanel).equals ("true")){ targetName = null; 241 } 242 targetName = ResourceUtils.createUniqueFileName (targetName, resFolder, __JDBCResource); 243 this.helper.getData ().setTargetFile (targetName); 244 component.setHelper (this.helper); 245 }else if(wizardInfo.getName ().equals (__PersistenceManagerFactoryResource)){ 246 targetName = ResourceUtils.createUniqueFileName (targetName, resFolder, __PersistenceResource); 247 this.helper.getData ().setTargetFile (targetName); 248 component.setHelper (this.helper); 249 } 250 }else 251 setupValid = false; 252 } 253 254 public boolean isFinishPanel() { 255 if(isNewResourceSelected()) 256 return false; 257 else 258 return isValid(); 259 } 260 261 private boolean setupValid(){ 262 return setupValid; 263 } 264 } 265 266 | Popular Tags |