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.DefaultComboBoxModel ; 25 import org.netbeans.modules.web.api.webmodule.WebModule; 26 import org.netbeans.modules.web.struts.StrutsConfigDataObject; 27 import org.netbeans.modules.web.struts.StrutsConfigUtilities; 28 import org.netbeans.modules.web.struts.config.model.Action; 29 import org.openide.util.NbBundle; 30 31 35 public class AddFIActionPanel extends javax.swing.JPanel implements ValidatingPanel { 36 private StrutsConfigDataObject config; 37 38 public AddFIActionPanel(StrutsConfigDataObject dObject) { 39 config = dObject; 40 initComponents(); 41 List actions = StrutsConfigUtilities.getAllActionsInModule(config); 42 DefaultComboBoxModel model = (DefaultComboBoxModel )cbAction.getModel(); 43 Iterator iter = actions.iterator(); 45 while (iter.hasNext()) 46 model.addElement(((Action)iter.next()).getAttributeValue("path")); 47 } 48 49 public String validatePanel() { 50 String actionPath = getActionPath(); 51 if (actionPath==null || actionPath.equals("/")) return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyActionPath"); 53 if (!actionPath.startsWith("/") ) return NbBundle.getMessage(AddFIActionPanel.class,"MSG_IncorrectActionPath", actionPath); 55 if (containsActionPath(actionPath)) return NbBundle.getMessage(AddFIActionPanel.class,"MSG_DupliciteActionPath",actionPath); 57 if (rbResourceFile.isSelected() && tResourceFile.getText().trim().length()==0) { 58 return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyResourceFile"); 59 } else if (rbAction.isSelected() && cbAction.getSelectedItem()==null) { 60 return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyAction"); 61 } else return null; 62 } 63 64 public javax.swing.AbstractButton [] getStateChangeComponents() { 65 return new javax.swing.AbstractButton []{ rbResourceFile }; 66 } 67 68 public javax.swing.text.JTextComponent [] getDocumentChangeComponents() { 69 return new javax.swing.text.JTextComponent []{jTextFieldPath, tResourceFile}; 70 } 71 72 77 private void initComponents() { 79 java.awt.GridBagConstraints gridBagConstraints; 80 81 bgActionType = new javax.swing.ButtonGroup (); 82 bgCall = new javax.swing.ButtonGroup (); 83 jPopupMenu1 = new javax.swing.JPopupMenu (); 84 lActionType = new javax.swing.JLabel (); 85 rbIncludeAction = new javax.swing.JRadioButton (); 86 rbForwardAction = new javax.swing.JRadioButton (); 87 lCall = new javax.swing.JLabel (); 88 rbResourceFile = new javax.swing.JRadioButton (); 89 rbAction = new javax.swing.JRadioButton (); 90 tResourceFile = new javax.swing.JTextField (); 91 bBrowse = new javax.swing.JButton (); 92 cbAction = new javax.swing.JComboBox (); 93 jLabelPath = new javax.swing.JLabel (); 94 jTextFieldPath = new javax.swing.JTextField (); 95 96 setLayout(new java.awt.GridBagLayout ()); 97 98 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11)); 99 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_AddFIActionPanel")); 100 lActionType.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionType")); 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 0; 103 gridBagConstraints.gridy = 1; 104 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 105 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 106 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 107 add(lActionType, gridBagConstraints); 108 109 bgActionType.add(rbIncludeAction); 110 rbIncludeAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Include_mnem").charAt(0)); 111 rbIncludeAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Include")); 112 rbIncludeAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 113 rbIncludeAction.setMargin(new java.awt.Insets (0, 0, 0, 0)); 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 0; 116 gridBagConstraints.gridy = 3; 117 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 118 gridBagConstraints.insets = new java.awt.Insets (6, 20, 0, 0); 119 add(rbIncludeAction, gridBagConstraints); 120 rbIncludeAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbIncudeAction")); 121 122 bgActionType.add(rbForwardAction); 123 rbForwardAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Forward_mnem").charAt(0)); 124 rbForwardAction.setSelected(true); 125 rbForwardAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Forward")); 126 rbForwardAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 127 rbForwardAction.setMargin(new java.awt.Insets (0, 0, 0, 0)); 128 gridBagConstraints = new java.awt.GridBagConstraints (); 129 gridBagConstraints.gridx = 0; 130 gridBagConstraints.gridy = 2; 131 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 132 gridBagConstraints.insets = new java.awt.Insets (6, 20, 0, 0); 133 add(rbForwardAction, gridBagConstraints); 134 rbForwardAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbForwardAction")); 135 136 lCall.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_Call")); 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.gridx = 0; 139 gridBagConstraints.gridy = 4; 140 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 141 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 142 add(lCall, gridBagConstraints); 143 144 bgCall.add(rbResourceFile); 145 rbResourceFile.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_ResourceFile_mnem").charAt(0)); 146 rbResourceFile.setSelected(true); 147 rbResourceFile.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_ResourceFile")); 148 rbResourceFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 149 rbResourceFile.setMargin(new java.awt.Insets (0, 0, 0, 0)); 150 rbResourceFile.addItemListener(new java.awt.event.ItemListener () { 151 public void itemStateChanged(java.awt.event.ItemEvent evt) { 152 rbResourceFileItemStateChanged(evt); 153 } 154 }); 155 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 0; 158 gridBagConstraints.gridy = 5; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 160 gridBagConstraints.insets = new java.awt.Insets (6, 20, 0, 0); 161 add(rbResourceFile, gridBagConstraints); 162 rbResourceFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbResourceFile2")); 163 164 bgCall.add(rbAction); 165 rbAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Action_mnem").charAt(0)); 166 rbAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Action")); 167 rbAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 168 rbAction.setMargin(new java.awt.Insets (0, 0, 0, 0)); 169 rbAction.addItemListener(new java.awt.event.ItemListener () { 170 public void itemStateChanged(java.awt.event.ItemEvent evt) { 171 rbActionItemStateChanged(evt); 172 } 173 }); 174 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 0; 177 gridBagConstraints.gridy = 6; 178 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 179 gridBagConstraints.insets = new java.awt.Insets (6, 20, 0, 0); 180 add(rbAction, gridBagConstraints); 181 rbAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbAction")); 182 183 tResourceFile.setMinimumSize(new java.awt.Dimension (200, 24)); 184 tResourceFile.setPreferredSize(new java.awt.Dimension (200, 24)); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridx = 1; 187 gridBagConstraints.gridy = 5; 188 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 189 gridBagConstraints.weightx = 1.0; 190 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 191 add(tResourceFile, gridBagConstraints); 192 tResourceFile.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_tResourceFile")); 193 tResourceFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_tResourceFile")); 194 195 bBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_Browse_mnem").charAt(0)); 196 bBrowse.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_BrowseButton")); 197 bBrowse.addActionListener(new java.awt.event.ActionListener () { 198 public void actionPerformed(java.awt.event.ActionEvent evt) { 199 bBrowseActionPerformed(evt); 200 } 201 }); 202 203 gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 2; 205 gridBagConstraints.gridy = 5; 206 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 207 add(bBrowse, gridBagConstraints); 208 bBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_bBrowse")); 209 210 cbAction.setEnabled(false); 211 gridBagConstraints = new java.awt.GridBagConstraints (); 212 gridBagConstraints.gridx = 1; 213 gridBagConstraints.gridy = 6; 214 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 215 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 216 add(cbAction, gridBagConstraints); 217 cbAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_cbAction")); 218 219 jLabelPath.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionPath_mnem").charAt(0)); 220 jLabelPath.setLabelFor(jTextFieldPath); 221 jLabelPath.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionPath")); 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.gridx = 0; 224 gridBagConstraints.gridy = 0; 225 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 226 add(jLabelPath, gridBagConstraints); 227 228 jTextFieldPath.setColumns(30); 229 jTextFieldPath.setText("/"); 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 1; 232 gridBagConstraints.gridy = 0; 233 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 234 gridBagConstraints.weightx = 1.0; 235 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 236 add(jTextFieldPath, gridBagConstraints); 237 jTextFieldPath.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldPath")); 238 239 } 240 242 private void bBrowseActionPerformed(java.awt.event.ActionEvent evt) { try{ 244 org.netbeans.api.project.SourceGroup[] groups = StrutsConfigUtilities.getDocBaseGroups(config.getPrimaryFile()); 245 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 246 if (fo!=null) { 247 String res = "/"+StrutsConfigUtilities.getResourcePath(groups,fo,'/',true); 248 tResourceFile.setText(res); 249 } 250 } catch (java.io.IOException ex) {} 251 } 253 private void rbResourceFileItemStateChanged(java.awt.event.ItemEvent evt) { tResourceFile.setEnabled(true); 255 bBrowse.setEnabled(true); 256 cbAction.setEnabled(false); 257 } 259 private void rbActionItemStateChanged(java.awt.event.ItemEvent evt) { tResourceFile.setEnabled(false); 261 bBrowse.setEnabled(false); 262 cbAction.setEnabled(true); 263 } 265 266 private javax.swing.JButton bBrowse; 268 private javax.swing.ButtonGroup bgActionType; 269 private javax.swing.ButtonGroup bgCall; 270 private javax.swing.JComboBox cbAction; 271 private javax.swing.JLabel jLabelPath; 272 private javax.swing.JPopupMenu jPopupMenu1; 273 private javax.swing.JTextField jTextFieldPath; 274 private javax.swing.JLabel lActionType; 275 private javax.swing.JLabel lCall; 276 private javax.swing.JRadioButton rbAction; 277 private javax.swing.JRadioButton rbForwardAction; 278 private javax.swing.JRadioButton rbIncludeAction; 279 private javax.swing.JRadioButton rbResourceFile; 280 private javax.swing.JTextField tResourceFile; 281 283 public String getActionPath() { 284 String path = jTextFieldPath.getText().trim(); 285 return path.length()==0?null:path; 286 } 287 288 public boolean isForward() { 289 return rbForwardAction.isSelected(); 290 } 291 292 public String getResource() { 293 if (rbResourceFile.isSelected()) { 294 String resource=tResourceFile.getText().trim(); 295 return resource.length()==0?null:resource; 296 } else { 297 return StrutsConfigUtilities.getActionAsResource( 298 WebModule.getWebModule(config.getPrimaryFile()), 299 (String )cbAction.getSelectedItem()); 300 } 301 } 302 303 private boolean containsActionPath(String path) { 304 DefaultComboBoxModel model = (DefaultComboBoxModel )cbAction.getModel(); 305 for (int i=0; i<model.getSize(); i++) { 306 if (path.equals(model.getElementAt(i))) return true; 307 } 308 return false; 309 } 310 } 311 | Popular Tags |