1 19 20 package org.netbeans.modules.web.struts.ui; 21 22 import javax.swing.event.DocumentListener ; 23 import javax.swing.text.JTextComponent ; 24 25 import org.openide.WizardDescriptor; 26 import org.openide.WizardValidationException; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 30 public class StrutsConfigurationPanelVisual extends javax.swing.JPanel implements HelpCtx.Provider, DocumentListener { 31 32 private StrutsConfigurationPanel panel; 33 34 35 public StrutsConfigurationPanelVisual(StrutsConfigurationPanel panel, boolean customizer) { 36 this.panel = panel; 37 initComponents(); 38 39 jTextFieldAppResource.getDocument().addDocumentListener(this); 40 jCheckBoxWAR.setVisible(false); 41 if (customizer) { 42 jCheckBoxTLD.setVisible(false); 43 enableComponents(false); 45 } 46 else { 47 jCheckBoxTLD.setVisible(true); 48 enableComponents(true); 50 } 51 52 ((JTextComponent )jComboBoxURLPattern.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 53 } 54 55 60 private void initComponents() { 62 java.awt.GridBagConstraints gridBagConstraints; 63 64 jLabelServletName = new javax.swing.JLabel (); 65 jTextFieldServletName = new javax.swing.JTextField (); 66 jLabelURLPattern = new javax.swing.JLabel (); 67 jComboBoxURLPattern = new javax.swing.JComboBox (); 68 jLabelAppResource = new javax.swing.JLabel (); 69 jTextFieldAppResource = new javax.swing.JTextField (); 70 jCheckBoxTLD = new javax.swing.JCheckBox (); 71 jCheckBoxWAR = new javax.swing.JCheckBox (); 72 73 setLayout(new java.awt.GridBagLayout ()); 74 75 jLabelServletName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_ActionServletName_Mnemonic").charAt(0)); 76 jLabelServletName.setLabelFor(jTextFieldServletName); 77 jLabelServletName.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_ActionServletName")); 78 gridBagConstraints = new java.awt.GridBagConstraints (); 79 gridBagConstraints.gridx = 0; 80 gridBagConstraints.gridy = 0; 81 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 82 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 12); 83 add(jLabelServletName, gridBagConstraints); 84 85 jTextFieldServletName.setEditable(false); 86 jTextFieldServletName.setText("action"); 87 gridBagConstraints = new java.awt.GridBagConstraints (); 88 gridBagConstraints.gridx = 1; 89 gridBagConstraints.gridy = 0; 90 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 91 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 92 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 93 add(jTextFieldServletName, gridBagConstraints); 94 jTextFieldServletName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jTextFieldServletName")); 95 96 jLabelURLPattern.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_URLPattern_Mnemonic").charAt(0)); 97 jLabelURLPattern.setLabelFor(jComboBoxURLPattern); 98 jLabelURLPattern.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_URLPattern")); 99 gridBagConstraints = new java.awt.GridBagConstraints (); 100 gridBagConstraints.gridx = 0; 101 gridBagConstraints.gridy = 1; 102 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 103 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 104 add(jLabelURLPattern, gridBagConstraints); 105 106 jComboBoxURLPattern.setEditable(true); 107 jComboBoxURLPattern.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "*.do", "/do/*" })); 108 gridBagConstraints = new java.awt.GridBagConstraints (); 109 gridBagConstraints.gridx = 1; 110 gridBagConstraints.gridy = 1; 111 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 112 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 113 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 114 add(jComboBoxURLPattern, gridBagConstraints); 115 jComboBoxURLPattern.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jComboBoxURLPattern")); 116 117 jLabelAppResource.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_ApplicationResource_Mnemonic").charAt(0)); 118 jLabelAppResource.setLabelFor(jTextFieldAppResource); 119 jLabelAppResource.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_ApplicationResource")); 120 gridBagConstraints = new java.awt.GridBagConstraints (); 121 gridBagConstraints.gridx = 0; 122 gridBagConstraints.gridy = 2; 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 124 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 125 add(jLabelAppResource, gridBagConstraints); 126 127 gridBagConstraints = new java.awt.GridBagConstraints (); 128 gridBagConstraints.gridx = 1; 129 gridBagConstraints.gridy = 2; 130 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 131 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 132 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 133 gridBagConstraints.weightx = 1.0; 134 gridBagConstraints.weighty = 0.01; 135 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 136 add(jTextFieldAppResource, gridBagConstraints); 137 jTextFieldAppResource.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jTextFieldAppResource")); 138 139 jCheckBoxTLD.setMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_InstallStrutsTLDs_Mnemonic").charAt(0)); 140 jCheckBoxTLD.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_InstallStrutsTLDs")); 141 jCheckBoxTLD.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 142 jCheckBoxTLD.setMargin(new java.awt.Insets (0, 0, 0, 0)); 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridx = 0; 145 gridBagConstraints.gridy = 3; 146 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 148 gridBagConstraints.weighty = 1.0; 149 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 150 add(jCheckBoxTLD, gridBagConstraints); 151 jCheckBoxTLD.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jCheckBoxTLD")); 152 153 jCheckBoxWAR.setMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_PackageStrutsJars_Mnemonic").charAt(0)); 154 jCheckBoxWAR.setSelected(true); 155 jCheckBoxWAR.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_PackageStrutsJars")); 156 jCheckBoxWAR.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 157 jCheckBoxWAR.setMargin(new java.awt.Insets (0, 0, 0, 0)); 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 0; 160 gridBagConstraints.gridy = 4; 161 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 162 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 163 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 164 gridBagConstraints.weighty = 1.0; 165 add(jCheckBoxWAR, gridBagConstraints); 166 167 } 169 170 private javax.swing.JCheckBox jCheckBoxTLD; 172 private javax.swing.JCheckBox jCheckBoxWAR; 173 private javax.swing.JComboBox jComboBoxURLPattern; 174 private javax.swing.JLabel jLabelAppResource; 175 private javax.swing.JLabel jLabelServletName; 176 private javax.swing.JLabel jLabelURLPattern; 177 private javax.swing.JTextField jTextFieldAppResource; 178 private javax.swing.JTextField jTextFieldServletName; 179 181 boolean valid(WizardDescriptor wizardDescriptor) { 182 String urlPattern = (String )jComboBoxURLPattern.getEditor().getItem(); 183 if (urlPattern == null || urlPattern.trim().equals("")){ 184 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_URLPatternIsEmpty")); 186 return false; 187 } 188 if (!isPatternValid(urlPattern)){ 189 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_URLPatternIsNotValid")); 191 return false; 192 } 193 if (getAppResource() == null || getAppResource().trim().length() == 0) { 194 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_ApplicationResourceNotValid")); 196 return false; 197 } 198 if (wizardDescriptor != null) 199 wizardDescriptor.putProperty("WizardPanel_errorMessage", null); return true; 201 } 202 203 private boolean isPatternValid(String pattern){ 204 if (pattern.startsWith("*.")){ 205 String p = pattern.substring(2); 206 if (p.indexOf('.') == -1 && p.indexOf('*') == -1 207 && p.indexOf('/') == -1 && !p.trim().equals("")) 208 return true; 209 } 210 if (pattern.endsWith("/*") && pattern.startsWith("/")) 211 return true; 212 return false; 213 } 214 215 void validate (WizardDescriptor d) throws WizardValidationException { 216 } 218 219 void read (WizardDescriptor d) { 220 } 223 224 void store(WizardDescriptor d) { 225 } 228 229 void enableComponents(boolean enable) { 230 jComboBoxURLPattern.setEnabled(enable); 231 jTextFieldAppResource.setEnabled(enable); 232 jTextFieldServletName.setEnabled(enable); 233 jCheckBoxTLD.setEnabled(enable); 234 jCheckBoxWAR.setEnabled(enable); 235 jLabelAppResource.setEnabled(enable); 236 jLabelServletName.setEnabled(enable); 237 jLabelURLPattern.setEnabled(enable); 238 239 } 240 241 public String getURLPattern(){ 242 return (String )jComboBoxURLPattern.getSelectedItem(); 243 } 244 245 public void setURLPattern(String pattern){ 246 jComboBoxURLPattern.setSelectedItem(pattern); 247 } 248 249 public String getServletName(){ 250 return jTextFieldServletName.getText(); 251 } 252 253 public void setServletName(String name){ 254 jTextFieldServletName.setText(name); 255 } 256 257 public String getAppResource(){ 258 return jTextFieldAppResource.getText(); 259 } 260 261 public void setAppResource(String resource){ 262 jTextFieldAppResource.setText(resource); 263 } 264 265 public boolean addTLDs(){ 266 return jCheckBoxTLD.isSelected(); 267 } 268 269 public boolean packageWars(){ 270 return jCheckBoxWAR.isSelected(); 271 } 272 275 public HelpCtx getHelpCtx() { 276 return new HelpCtx(StrutsConfigurationPanelVisual.class); 277 } 278 279 public void removeUpdate(javax.swing.event.DocumentEvent e) { 280 panel.fireChangeEvent(); 281 } 282 283 public void insertUpdate(javax.swing.event.DocumentEvent e) { 284 panel.fireChangeEvent(); 285 } 286 287 public void changedUpdate(javax.swing.event.DocumentEvent e) { 288 panel.fireChangeEvent(); 289 } 290 291 } 292 | Popular Tags |