1 19 20 package org.netbeans.modules.web.struts.dialogs; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 import javax.swing.AbstractButton ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.text.JTextComponent ; 27 import org.netbeans.modules.web.api.webmodule.WebModule; 28 import org.netbeans.modules.web.struts.StrutsConfigDataObject; 29 import org.netbeans.modules.web.struts.StrutsConfigUtilities; 30 import org.netbeans.modules.web.struts.config.model.Action; 31 import org.openide.util.NbBundle; 32 33 37 public class AddForwardDialogPanel extends javax.swing.JPanel implements ValidatingPanel { 38 StrutsConfigDataObject config; 39 40 public AddForwardDialogPanel(StrutsConfigDataObject config, String targetActionPath) { 41 this.config=config; 42 initComponents(); 43 List actions = StrutsConfigUtilities.getAllActionsInModule(config); 44 DefaultComboBoxModel model = (DefaultComboBoxModel )jComboBoxFwdAction.getModel(); 45 DefaultComboBoxModel model1 = (DefaultComboBoxModel )jComboBoxLocationAction.getModel(); 46 Iterator iter = actions.iterator(); 47 while (iter.hasNext()) { 48 String actionPath=((Action)iter.next()).getAttributeValue("path"); model.addElement(actionPath); 50 model1.addElement(actionPath); 51 } 52 if (targetActionPath != null) { 53 jRadioButtonLocationAction.setSelected(true); 54 jComboBoxLocationAction.setSelectedItem(targetActionPath); 55 } 56 } 57 public AddForwardDialogPanel(StrutsConfigDataObject config) { 58 this(config,null); 59 } 60 61 public String validatePanel() { 62 if (getForwardName().length()==0) 63 return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyForwardName"); 64 if (jRadioButtonResFile.isSelected()) { 65 String resourceFile = jTextFieldResFile.getText().trim(); 66 if (resourceFile.length()==0 || resourceFile.equals("/")) return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyResourceFile"); 68 } else if (jComboBoxFwdAction.getSelectedItem()==null) { 69 return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyAction"); 70 } 71 if (jRadioButtonLocationAction.isSelected() && jComboBoxLocationAction.getSelectedItem()==null) { 72 return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyAction"); 73 } 74 return null; 75 } 76 77 public AbstractButton [] getStateChangeComponents() { 78 return new AbstractButton [] {jRadioButtonResFile, jRadioButtonGlobal}; 79 } 80 81 public JTextComponent [] getDocumentChangeComponents() { 82 return new JTextComponent []{jTextFieldFwdName, jTextFieldResFile}; 83 } 84 85 90 private void initComponents() { 92 java.awt.GridBagConstraints gridBagConstraints; 93 94 buttonGroup1 = new javax.swing.ButtonGroup (); 95 buttonGroup2 = new javax.swing.ButtonGroup (); 96 jLabelFwdName = new javax.swing.JLabel (); 97 jTextFieldFwdName = new javax.swing.JTextField (); 98 jLabelFwdTo = new javax.swing.JLabel (); 99 jRadioButtonResFile = new javax.swing.JRadioButton (); 100 jTextFieldResFile = new javax.swing.JTextField (); 101 jButtonBrowse = new javax.swing.JButton (); 102 jRadioButtonFwdAction = new javax.swing.JRadioButton (); 103 jComboBoxFwdAction = new javax.swing.JComboBox (); 104 jCheckBoxRedirect = new javax.swing.JCheckBox (); 105 jLabelLocation = new javax.swing.JLabel (); 106 jRadioButtonGlobal = new javax.swing.JRadioButton (); 107 jRadioButtonLocationAction = new javax.swing.JRadioButton (); 108 jComboBoxLocationAction = new javax.swing.JComboBox (); 109 110 setLayout(new java.awt.GridBagLayout ()); 111 112 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11)); 113 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_AddForwardDialog")); 114 jLabelFwdName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_FwdName").charAt(0)); 115 jLabelFwdName.setLabelFor(jTextFieldFwdName); 116 jLabelFwdName.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_ForwardName")); 117 gridBagConstraints = new java.awt.GridBagConstraints (); 118 gridBagConstraints.gridx = 0; 119 gridBagConstraints.gridy = 0; 120 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 121 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 122 add(jLabelFwdName, gridBagConstraints); 123 124 jTextFieldFwdName.setColumns(30); 125 gridBagConstraints = new java.awt.GridBagConstraints (); 126 gridBagConstraints.gridx = 1; 127 gridBagConstraints.gridy = 0; 128 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 129 gridBagConstraints.weightx = 1.0; 130 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 131 add(jTextFieldFwdName, gridBagConstraints); 132 jTextFieldFwdName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldFwdName")); 133 134 jLabelFwdTo.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_ForwardTo")); 135 gridBagConstraints = new java.awt.GridBagConstraints (); 136 gridBagConstraints.gridx = 0; 137 gridBagConstraints.gridy = 1; 138 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 140 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 141 add(jLabelFwdTo, gridBagConstraints); 142 143 buttonGroup1.add(jRadioButtonResFile); 144 jRadioButtonResFile.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_ResFile").charAt(0)); 145 jRadioButtonResFile.setSelected(true); 146 jRadioButtonResFile.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_ResourceFile")); 147 jRadioButtonResFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 148 jRadioButtonResFile.setMargin(new java.awt.Insets (0, 0, 0, 0)); 149 jRadioButtonResFile.addItemListener(new java.awt.event.ItemListener () { 150 public void itemStateChanged(java.awt.event.ItemEvent evt) { 151 jRadioButtonResFileItemStateChanged(evt); 152 } 153 }); 154 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridx = 0; 157 gridBagConstraints.gridy = 2; 158 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 159 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 160 add(jRadioButtonResFile, gridBagConstraints); 161 jRadioButtonResFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonResFile_Forward")); 162 163 jTextFieldResFile.setColumns(30); 164 jTextFieldResFile.setText("/"); 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 1; 167 gridBagConstraints.gridy = 2; 168 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 169 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 170 add(jTextFieldResFile, gridBagConstraints); 171 jTextFieldResFile.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSN_jTextFieldResFile")); 172 jTextFieldResFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldResFile_F")); 173 174 jButtonBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Browse").charAt(0)); 175 jButtonBrowse.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_BrowseButton")); 176 jButtonBrowse.addActionListener(new java.awt.event.ActionListener () { 177 public void actionPerformed(java.awt.event.ActionEvent evt) { 178 jButtonBrowseActionPerformed(evt); 179 } 180 }); 181 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridx = 2; 184 gridBagConstraints.gridy = 2; 185 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 186 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 187 add(jButtonBrowse, gridBagConstraints); 188 jButtonBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jButtonBrowse")); 189 190 buttonGroup1.add(jRadioButtonFwdAction); 191 jRadioButtonFwdAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_FwdAction").charAt(0)); 192 jRadioButtonFwdAction.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_Action")); 193 jRadioButtonFwdAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 194 jRadioButtonFwdAction.setMargin(new java.awt.Insets (0, 0, 0, 0)); 195 gridBagConstraints = new java.awt.GridBagConstraints (); 196 gridBagConstraints.gridx = 0; 197 gridBagConstraints.gridy = 3; 198 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 199 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 12); 200 add(jRadioButtonFwdAction, gridBagConstraints); 201 jRadioButtonFwdAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonFwdAction")); 202 203 jComboBoxFwdAction.setEditable(true); 204 jComboBoxFwdAction.setEnabled(false); 205 gridBagConstraints = new java.awt.GridBagConstraints (); 206 gridBagConstraints.gridx = 1; 207 gridBagConstraints.gridy = 3; 208 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 209 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 210 add(jComboBoxFwdAction, gridBagConstraints); 211 jComboBoxFwdAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jComboBoxFwdAction")); 212 213 jCheckBoxRedirect.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Redirect").charAt(0)); 214 jCheckBoxRedirect.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Redirect")); 215 jCheckBoxRedirect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 216 jCheckBoxRedirect.setMargin(new java.awt.Insets (0, 0, 0, 0)); 217 gridBagConstraints = new java.awt.GridBagConstraints (); 218 gridBagConstraints.gridx = 0; 219 gridBagConstraints.gridy = 4; 220 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 221 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 222 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 223 add(jCheckBoxRedirect, gridBagConstraints); 224 jCheckBoxRedirect.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jCheckBoxRedirect")); 225 226 jLabelLocation.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Location")); 227 gridBagConstraints = new java.awt.GridBagConstraints (); 228 gridBagConstraints.gridx = 0; 229 gridBagConstraints.gridy = 5; 230 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 231 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 232 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 233 add(jLabelLocation, gridBagConstraints); 234 235 buttonGroup2.add(jRadioButtonGlobal); 236 jRadioButtonGlobal.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Global").charAt(0)); 237 jRadioButtonGlobal.setSelected(true); 238 jRadioButtonGlobal.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Global")); 239 jRadioButtonGlobal.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 240 jRadioButtonGlobal.setMargin(new java.awt.Insets (0, 0, 0, 0)); 241 jRadioButtonGlobal.addItemListener(new java.awt.event.ItemListener () { 242 public void itemStateChanged(java.awt.event.ItemEvent evt) { 243 jRadioButtonGlobalItemStateChanged(evt); 244 } 245 }); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 0; 249 gridBagConstraints.gridy = 6; 250 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 251 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 252 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 253 add(jRadioButtonGlobal, gridBagConstraints); 254 jRadioButtonGlobal.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonGlobal")); 255 256 buttonGroup2.add(jRadioButtonLocationAction); 257 jRadioButtonLocationAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_LocationAction").charAt(0)); 258 jRadioButtonLocationAction.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_Action")); 259 jRadioButtonLocationAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 260 jRadioButtonLocationAction.setMargin(new java.awt.Insets (0, 0, 0, 0)); 261 gridBagConstraints = new java.awt.GridBagConstraints (); 262 gridBagConstraints.gridx = 0; 263 gridBagConstraints.gridy = 7; 264 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 265 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 266 add(jRadioButtonLocationAction, gridBagConstraints); 267 jRadioButtonLocationAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonLocationAction")); 268 269 jComboBoxLocationAction.setEnabled(false); 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 1; 272 gridBagConstraints.gridy = 7; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 add(jComboBoxLocationAction, gridBagConstraints); 275 jComboBoxLocationAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jComboBoxLocationAction")); 276 277 } 278 280 private void jRadioButtonGlobalItemStateChanged(java.awt.event.ItemEvent evt) { jComboBoxLocationAction.setEnabled(!jRadioButtonGlobal.isSelected()); 283 } 285 private void jRadioButtonResFileItemStateChanged(java.awt.event.ItemEvent evt) { boolean selected = jRadioButtonResFile.isSelected(); 288 jTextFieldResFile.setEditable(selected); 289 jButtonBrowse.setEnabled(selected); 290 jComboBoxFwdAction.setEnabled(!selected); 291 } 293 private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) { try{ 296 org.netbeans.api.project.SourceGroup[] groups = StrutsConfigUtilities.getDocBaseGroups(config.getPrimaryFile()); 297 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 298 if (fo!=null) { 299 String res = "/"+StrutsConfigUtilities.getResourcePath(groups,fo,'/',true); 300 jTextFieldResFile.setText(res); 301 } 302 } catch (java.io.IOException ex) {} 303 } 305 306 private javax.swing.ButtonGroup buttonGroup1; 308 private javax.swing.ButtonGroup buttonGroup2; 309 private javax.swing.JButton jButtonBrowse; 310 private javax.swing.JCheckBox jCheckBoxRedirect; 311 private javax.swing.JComboBox jComboBoxFwdAction; 312 private javax.swing.JComboBox jComboBoxLocationAction; 313 private javax.swing.JLabel jLabelFwdName; 314 private javax.swing.JLabel jLabelFwdTo; 315 private javax.swing.JLabel jLabelLocation; 316 private javax.swing.JRadioButton jRadioButtonFwdAction; 317 private javax.swing.JRadioButton jRadioButtonGlobal; 318 private javax.swing.JRadioButton jRadioButtonLocationAction; 319 private javax.swing.JRadioButton jRadioButtonResFile; 320 private javax.swing.JTextField jTextFieldFwdName; 321 private javax.swing.JTextField jTextFieldResFile; 322 324 public String getForwardName() { 325 return jTextFieldFwdName.getText().trim(); 326 } 327 328 public boolean isGlobal() { 329 return jRadioButtonGlobal.isSelected(); 330 } 331 332 public String getRedirect() { 333 return (jCheckBoxRedirect.isSelected()?"true":null); 334 } 335 336 public String getForwardTo() { 337 if (jRadioButtonResFile.isSelected()) { 338 return jTextFieldResFile.getText().trim(); 339 } else { 340 return StrutsConfigUtilities.getActionAsResource( 341 WebModule.getWebModule(config.getPrimaryFile()), 342 (String )jComboBoxFwdAction.getSelectedItem()); 343 } 344 } 345 346 public String getLocationAction() { 347 return (String )jComboBoxLocationAction.getSelectedItem(); 348 } 349 } 350 | Popular Tags |