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 30 import org.openide.loaders.TemplateWizard; 31 import org.openide.util.HelpCtx; 32 33 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 34 35 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 36 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard; 37 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper; 38 import org.openide.WizardDescriptor; 39 import org.openide.filesystems.FileObject; 40 41 46 public class CommonGeneralFinishPanel extends ResourceWizardPanel { 47 48 52 private CommonGeneralFinishVisualPanel component; 53 private ResourceConfigHelper helper; 54 private Wizard wizardInfo; 55 private String [] groupNames; 56 private boolean setupValid = true; 57 58 59 public CommonGeneralFinishPanel(ResourceConfigHelper helper, Wizard wizardInfo, String [] groupNames) { 60 this.helper = helper; 61 this.wizardInfo = wizardInfo; 62 this.groupNames = groupNames; 63 } 64 65 public Component getComponent() { 70 if (component == null) { 71 FieldGroup[] groups = new FieldGroup[groupNames.length]; 72 for (int i = 0; i < this.groupNames.length; i++) { 73 groups[i] = FieldGroupHelper.getFieldGroup(wizardInfo, this.groupNames[i]); } 75 String panelType = null; 76 if (wizardInfo.getName().equals(__MailResource)) { 77 panelType = CommonGeneralFinishVisualPanel.TYPE_MAIL_RESOUCE; 78 } 79 component = new CommonGeneralFinishVisualPanel(this, groups, panelType); 80 } 81 return component; 82 } 83 84 public boolean createNew() { 85 if (component == null) 86 return false; 87 else 88 return component.createNew(); 89 } 90 91 public String getResourceName() { 92 return this.wizardInfo.getName(); 93 } 94 95 public HelpCtx getHelp() { 96 if (wizardInfo.getName().equals(__MailResource)) { 97 return new HelpCtx("AS_Wiz_Mail_general"); }else{ 99 return HelpCtx.DEFAULT_HELP; 100 } 101 102 } 103 104 public ResourceConfigHelper getHelper() { 105 return helper; 106 } 107 108 public boolean isValid() { 109 if(! setupValid){ 111 setErrorMsg(bundle.getString("Err_InvalidSetup")); 112 return false; 113 } 114 setErrorMsg(bundle.getString("Empty_String")); 115 if (component != null && component.jLabels != null && component.jFields != null) { 116 int i; 117 for (i=0; i < component.jLabels.length; i++) { 118 String jLabel = (String )component.jLabels[i].getText(); 119 if (jLabel.equals(bundle.getString("LBL_" + __JndiName))) { String jndiName = (String )((JTextField )component.jFields[i]).getText(); 121 if (jndiName == null || jndiName.length() == 0) { 122 setErrorMsg(bundle.getString("Err_InvalidJndiName")); 123 return false; 124 }else if(! ResourceUtils.isLegalResourceName(jndiName)){ 125 return false; 126 }else if(! ResourceUtils.isUniqueFileName(jndiName, this.helper.getData().getTargetFileObject(), __MAILResource)){ 127 setErrorMsg(bundle.getString("Err_DuplFileJndiName")); 128 return false; 129 } 130 } 131 if (wizardInfo.getName().equals(__MailResource)) { 132 if (jLabel.equals(bundle.getString("LBL_" + __Host))) { String host = (String )((JTextField )component.jFields[i]).getText(); 134 if (host == null || host.length() == 0) { 135 setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel); 136 return false; 137 } 138 } 139 if (jLabel.equals(bundle.getString("LBL_" + __MailUser))) { String user = (String )((JTextField )component.jFields[i]).getText(); 141 if (user == null || user.length() == 0) { 142 setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel); 143 return false; 144 } 145 } 146 if (jLabel.equals(bundle.getString("LBL_" + __From))) { String from = (String )((JTextField )component.jFields[i]).getText(); 148 if (from == null || from.length() == 0) { 149 setErrorMessage(bundle.getString("Err_EmptyValue"), jLabel); 150 return false; 151 } 152 } 153 } } } 156 return true; 157 } 158 159 public boolean isFinishPanel() { 160 return isValid(); 161 } 162 163 public void readSettings(Object settings) { 164 this.wizDescriptor = (WizardDescriptor)settings; 165 if (wizardInfo.getName().equals(__MailResource)) { 166 TemplateWizard wizard = (TemplateWizard)settings; 167 String targetName = wizard.getTargetName(); 168 FileObject resFolder = ResourceUtils.getResourceDirectory(this.helper.getData().getTargetFileObject()); 169 this.helper.getData().setTargetFileObject (resFolder); 170 if(resFolder != null){ 171 targetName = ResourceUtils.createUniqueFileName (targetName, resFolder, __MAILResource); 172 this.helper.getData ().setTargetFile (targetName); 173 if(component == null) 174 getComponent (); 175 component.setHelper (this.helper); 176 }else 177 setupValid = false; 178 } 179 } 180 181 public void initData() { 182 this.component.initData(); 183 } 184 185 private boolean setupValid(){ 186 return setupValid; 187 } 188 } 189 190 | Popular Tags |