1 19 20 package org.netbeans.modules.web.jsf.dialogs; 21 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import javax.swing.DefaultComboBoxModel ; 25 import javax.swing.text.JTextComponent ; 26 import org.netbeans.modules.web.jsf.JSFConfigDataObject; 27 import org.netbeans.modules.web.jsf.JSFConfigUtilities; 28 import org.netbeans.modules.web.jsf.api.ConfigurationUtils; 29 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig; 30 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationCase; 31 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationRule; 32 import org.openide.ErrorManager; 33 import org.openide.util.NbBundle; 34 35 39 public class AddNavigationCaseDialog extends javax.swing.JPanel implements ValidatingPanel{ 40 private JSFConfigDataObject config; 41 42 public AddNavigationCaseDialog(JSFConfigDataObject config, String rule) { 43 initComponents(); 44 this.config = config; 45 FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), false).getRootComponent(); 46 47 DefaultComboBoxModel modelF = (DefaultComboBoxModel )jComboBoxFromView.getModel(); 48 DefaultComboBoxModel modelT = (DefaultComboBoxModel )jComboBoxToView.getModel(); 49 modelF.addElement(""); 50 modelT.addElement(""); 51 Iterator iter = facesConfig.getNavigationRules().iterator(); 52 while (iter.hasNext()) { 53 String fromViewID=((NavigationRule)iter.next()).getFromViewId(); 54 modelF.addElement(fromViewID); 55 modelT.addElement(fromViewID); 56 } 57 if (rule != null) 58 jComboBoxFromView.setSelectedItem(rule); 59 } 60 61 public javax.swing.text.JTextComponent [] getDocumentChangeComponents() { 62 return new javax.swing.text.JTextComponent []{(JTextComponent )jComboBoxFromView.getEditor().getEditorComponent(), 63 (JTextComponent ) jComboBoxToView.getEditor().getEditorComponent(), jTextFieldFromAction, jTextFieldFromOutcome}; 64 } 65 66 public javax.swing.AbstractButton [] getStateChangeComponents() { 67 return new javax.swing.AbstractButton []{ }; 68 } 69 70 public String validatePanel() { 71 if (getRule().length()==0) 72 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyRule"); 73 if (getToView().length()==0) 74 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyToView"); 75 if (getFromAction().length() == 0 && getFromOutcome().length() == 0) 76 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyFromActionOutcome"); 77 NavigationRule rule = JSFConfigUtilities.findNavigationRule(config, getRule()); 78 if (rule != null){ 80 81 Collection <NavigationCase> cases = rule.getNavigationCases(); 82 String from; 83 for (Iterator <NavigationCase> it = cases.iterator(); it.hasNext();) { 84 NavigationCase navigationCase = it.next(); 85 from = navigationCase.getFromAction(); 86 if (from != null && from.equals(getFromAction())) 87 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_FromActionExist"); 88 from = navigationCase.getFromOutcome(); 89 if (from != null && from.equals(getFromOutcome())) 90 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_FromOutcomeExist"); 91 } 92 } 93 return null; 94 } 95 96 101 private void initComponents() { 103 java.awt.GridBagConstraints gridBagConstraints; 104 105 jLabelFromView = new javax.swing.JLabel (); 106 jComboBoxFromView = new javax.swing.JComboBox (); 107 jButtonFromView = new javax.swing.JButton (); 108 jLabelFromAction = new javax.swing.JLabel (); 109 jTextFieldFromAction = new javax.swing.JTextField (); 110 jLabelFromOutcome = new javax.swing.JLabel (); 111 jTextFieldFromOutcome = new javax.swing.JTextField (); 112 jLabelToView = new javax.swing.JLabel (); 113 jButtonToView = new javax.swing.JButton (); 114 jCheckBoxRedirect = new javax.swing.JCheckBox (); 115 jLabelDesc = new javax.swing.JLabel (); 116 jScrollPaneDesc = new javax.swing.JScrollPane (); 117 jTextAreaDesc = new javax.swing.JTextArea (); 118 jSeparator1 = new javax.swing.JSeparator (); 119 jComboBoxToView = new javax.swing.JComboBox (); 120 121 setLayout(new java.awt.GridBagLayout ()); 122 123 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_AddNavigationCaseDialog")); 124 jLabelFromView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromView").charAt(0)); 125 jLabelFromView.setLabelFor(jComboBoxFromView); 126 jLabelFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_CaseFromView")); 127 gridBagConstraints = new java.awt.GridBagConstraints (); 128 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 129 gridBagConstraints.insets = new java.awt.Insets (12, 12, 5, 12); 130 add(jLabelFromView, gridBagConstraints); 131 132 jComboBoxFromView.setEditable(true); 133 gridBagConstraints = new java.awt.GridBagConstraints (); 134 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 135 gridBagConstraints.insets = new java.awt.Insets (12, 0, 5, 0); 136 add(jComboBoxFromView, gridBagConstraints); 137 jComboBoxFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromView")); 138 139 jButtonFromView.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_Browse").charAt(0)); 140 jButtonFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Browse")); 141 jButtonFromView.addActionListener(new java.awt.event.ActionListener () { 142 public void actionPerformed(java.awt.event.ActionEvent evt) { 143 jButtonFromViewActionPerformed(evt); 144 } 145 }); 146 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 149 gridBagConstraints.insets = new java.awt.Insets (12, 12, 5, 11); 150 add(jButtonFromView, gridBagConstraints); 151 jButtonFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_BrowseFromView")); 152 153 jLabelFromAction.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromAction").charAt(0)); 154 jLabelFromAction.setLabelFor(jTextFieldFromAction); 155 jLabelFromAction.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_FromAction")); 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 0; 158 gridBagConstraints.gridy = 2; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 160 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 161 add(jLabelFromAction, gridBagConstraints); 162 163 gridBagConstraints = new java.awt.GridBagConstraints (); 164 gridBagConstraints.gridx = 1; 165 gridBagConstraints.gridy = 2; 166 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 167 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 168 add(jTextFieldFromAction, gridBagConstraints); 169 jTextFieldFromAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromAction")); 170 171 jLabelFromOutcome.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromOutcome").charAt(0)); 172 jLabelFromOutcome.setLabelFor(jTextFieldFromOutcome); 173 jLabelFromOutcome.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_FromOutcome")); 174 gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = 3; 177 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 178 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 179 add(jLabelFromOutcome, gridBagConstraints); 180 181 gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 1; 183 gridBagConstraints.gridy = 3; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 185 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 186 add(jTextFieldFromOutcome, gridBagConstraints); 187 jTextFieldFromOutcome.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromOutcome")); 188 189 jLabelToView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_ToView").charAt(0)); 190 jLabelToView.setLabelFor(jComboBoxToView); 191 jLabelToView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_ToView")); 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 0; 194 gridBagConstraints.gridy = 4; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 196 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 197 add(jLabelToView, gridBagConstraints); 198 199 jButtonToView.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_BrowseToView").charAt(0)); 200 jButtonToView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Browse")); 201 jButtonToView.addActionListener(new java.awt.event.ActionListener () { 202 public void actionPerformed(java.awt.event.ActionEvent evt) { 203 jButtonToViewActionPerformed(evt); 204 } 205 }); 206 207 gridBagConstraints = new java.awt.GridBagConstraints (); 208 gridBagConstraints.gridx = 2; 209 gridBagConstraints.gridy = 4; 210 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 211 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 11); 212 add(jButtonToView, gridBagConstraints); 213 jButtonToView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_BrowseToView")); 214 215 jCheckBoxRedirect.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_Redirect").charAt(0)); 216 jCheckBoxRedirect.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Redirect")); 217 jCheckBoxRedirect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 218 jCheckBoxRedirect.setMargin(new java.awt.Insets (0, 0, 0, 0)); 219 gridBagConstraints = new java.awt.GridBagConstraints (); 220 gridBagConstraints.gridx = 0; 221 gridBagConstraints.gridy = 5; 222 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 223 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 224 add(jCheckBoxRedirect, gridBagConstraints); 225 jCheckBoxRedirect.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_Redirect")); 226 227 jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_BeanDescription").charAt(0)); 228 jLabelDesc.setLabelFor(jTextAreaDesc); 229 jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_RuleDescription")); 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 0; 232 gridBagConstraints.gridy = 6; 233 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 234 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 235 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 12); 236 add(jLabelDesc, gridBagConstraints); 237 238 jTextAreaDesc.setColumns(20); 239 jTextAreaDesc.setRows(5); 240 jScrollPaneDesc.setViewportView(jTextAreaDesc); 241 jTextAreaDesc.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_CaseDescription")); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 1; 245 gridBagConstraints.gridy = 6; 246 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 247 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 248 gridBagConstraints.weightx = 1.0; 249 gridBagConstraints.weighty = 1.0; 250 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 251 add(jScrollPaneDesc, gridBagConstraints); 252 253 gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.gridx = 0; 255 gridBagConstraints.gridy = 1; 256 gridBagConstraints.gridwidth = 3; 257 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 258 gridBagConstraints.insets = new java.awt.Insets (0, 12, 6, 11); 259 add(jSeparator1, gridBagConstraints); 260 261 jComboBoxToView.setEditable(true); 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 1; 264 gridBagConstraints.gridy = 4; 265 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 266 add(jComboBoxToView, gridBagConstraints); 267 jComboBoxToView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_ToViewSelect")); 268 269 } 270 272 private void jButtonToViewActionPerformed(java.awt.event.ActionEvent evt) { try{ 274 org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile()); 275 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 276 if (fo!=null) { 277 String res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true); 278 jComboBoxToView.setSelectedItem(res); 279 } 280 } catch (java.io.IOException ex) { 281 ErrorManager.getDefault().notify(ex); 282 } 283 } 285 private void jButtonFromViewActionPerformed(java.awt.event.ActionEvent evt) { try{ 287 org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile()); 288 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 289 if (fo!=null) { 290 String res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true); 291 jComboBoxFromView.setSelectedItem(res); 292 } 293 } catch (java.io.IOException ex) { 294 ErrorManager.getDefault().notify(ex); 295 } 296 } 298 299 private javax.swing.JButton jButtonFromView; 301 private javax.swing.JButton jButtonToView; 302 private javax.swing.JCheckBox jCheckBoxRedirect; 303 private javax.swing.JComboBox jComboBoxFromView; 304 private javax.swing.JComboBox jComboBoxToView; 305 private javax.swing.JLabel jLabelDesc; 306 private javax.swing.JLabel jLabelFromAction; 307 private javax.swing.JLabel jLabelFromOutcome; 308 private javax.swing.JLabel jLabelFromView; 309 private javax.swing.JLabel jLabelToView; 310 private javax.swing.JScrollPane jScrollPaneDesc; 311 private javax.swing.JSeparator jSeparator1; 312 private javax.swing.JTextArea jTextAreaDesc; 313 private javax.swing.JTextField jTextFieldFromAction; 314 private javax.swing.JTextField jTextFieldFromOutcome; 315 317 public String getRule(){ 318 return (String )jComboBoxFromView.getSelectedItem(); 319 } 320 321 public String getFromAction(){ 322 return jTextFieldFromAction.getText(); 323 } 324 325 public String getFromOutcome(){ 326 return jTextFieldFromOutcome.getText(); 327 } 328 329 public String getToView(){ 330 return (String )jComboBoxToView.getEditor().getItem(); 331 } 332 333 public boolean isRedirect(){ 334 return jCheckBoxRedirect.isSelected(); 335 } 336 337 public String getDescription(){ 338 return jTextAreaDesc.getText(); 339 } 340 } 341 | Popular Tags |