1 19 20 package org.netbeans.modules.web.jsf.dialogs; 21 22 import java.util.Hashtable ; 23 import java.util.Iterator ; 24 import org.netbeans.api.project.SourceGroup; 25 import org.netbeans.modules.web.jsf.JSFConfigDataObject; 26 import org.netbeans.modules.web.jsf.JSFConfigUtilities; 27 import org.netbeans.modules.web.jsf.api.ConfigurationUtils; 28 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig; 29 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationRule; 30 import org.openide.ErrorManager; 31 import org.openide.util.NbBundle; 32 33 37 public class AddNavigationRuleDialog extends javax.swing.JPanel implements ValidatingPanel{ 38 private JSFConfigDataObject config; 39 private Hashtable existingRules = null; 40 41 public AddNavigationRuleDialog(JSFConfigDataObject config) { 42 initComponents(); 43 this.config = config; 44 } 45 46 public javax.swing.text.JTextComponent [] getDocumentChangeComponents() { 47 return new javax.swing.text.JTextComponent []{jTextFieldFromView}; 48 } 49 50 public javax.swing.AbstractButton [] getStateChangeComponents() { 51 return new javax.swing.AbstractButton []{ }; 52 } 53 54 public String validatePanel() { 55 if (getFromView().length()==0) 56 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationRule_EmptyFromView"); 57 if(existingRules == null){ 58 existingRules = new Hashtable (); 59 NavigationRule rule; 60 FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), true).getRootComponent(); 61 62 Iterator iter = facesConfig.getNavigationRules().iterator(); 63 while (iter.hasNext()){ 64 rule = (NavigationRule) iter.next(); 65 if (rule.getFromViewId() != null) 66 existingRules.put(rule.getFromViewId(), ""); 67 } 68 } 69 if (existingRules.get(getFromView())!=null) 70 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationRule_RuleExist"); 71 return null; 72 } 73 74 79 private void initComponents() { 81 java.awt.GridBagConstraints gridBagConstraints; 82 83 jLabelFromView = new javax.swing.JLabel (); 84 jTextFieldFromView = new javax.swing.JTextField (); 85 jButtonBrowse = new javax.swing.JButton (); 86 jLabelDesc = new javax.swing.JLabel (); 87 jScrollPaneDesc = new javax.swing.JScrollPane (); 88 jTextAreaDesc = new javax.swing.JTextArea (); 89 90 setLayout(new java.awt.GridBagLayout ()); 91 92 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_AddNavigationRuleDialog")); 93 jLabelFromView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_FromView").charAt(0)); 94 jLabelFromView.setLabelFor(jTextFieldFromView); 95 jLabelFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_FromView")); 96 gridBagConstraints = new java.awt.GridBagConstraints (); 97 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 98 gridBagConstraints.insets = new java.awt.Insets (12, 12, 5, 12); 99 add(jLabelFromView, gridBagConstraints); 100 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 103 gridBagConstraints.insets = new java.awt.Insets (12, 0, 5, 0); 104 add(jTextFieldFromView, gridBagConstraints); 105 jTextFieldFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleFromFiew")); 106 107 jButtonBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_Browse").charAt(0)); 108 jButtonBrowse.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_Browse")); 109 jButtonBrowse.addActionListener(new java.awt.event.ActionListener () { 110 public void actionPerformed(java.awt.event.ActionEvent evt) { 111 jButtonBrowseActionPerformed(evt); 112 } 113 }); 114 115 gridBagConstraints = new java.awt.GridBagConstraints (); 116 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 117 gridBagConstraints.insets = new java.awt.Insets (12, 12, 5, 11); 118 add(jButtonBrowse, gridBagConstraints); 119 jButtonBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleBrowse")); 120 121 jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_BeanDescription").charAt(0)); 122 jLabelDesc.setLabelFor(jTextAreaDesc); 123 jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_RuleDescription")); 124 gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.gridx = 0; 126 gridBagConstraints.gridy = 1; 127 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 128 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 129 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 130 add(jLabelDesc, gridBagConstraints); 131 132 jTextAreaDesc.setColumns(20); 133 jTextAreaDesc.setRows(5); 134 jScrollPaneDesc.setViewportView(jTextAreaDesc); 135 jTextAreaDesc.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleDescription")); 136 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.gridx = 1; 139 gridBagConstraints.gridy = 1; 140 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 141 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 142 gridBagConstraints.weightx = 1.0; 143 gridBagConstraints.weighty = 1.0; 144 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 145 add(jScrollPaneDesc, gridBagConstraints); 146 147 } 148 150 private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) { try{ 152 org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile()); 153 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 154 if (fo!=null) { 155 String res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true); 156 jTextFieldFromView.setText(res); 157 } 158 } catch (java.io.IOException ex) { 159 ErrorManager.getDefault().notify(ex); 160 } 161 } 163 164 private javax.swing.JButton jButtonBrowse; 166 private javax.swing.JLabel jLabelDesc; 167 private javax.swing.JLabel jLabelFromView; 168 private javax.swing.JScrollPane jScrollPaneDesc; 169 private javax.swing.JTextArea jTextAreaDesc; 170 private javax.swing.JTextField jTextFieldFromView; 171 173 public String getFromView(){ 174 return jTextFieldFromView.getText(); 175 } 176 177 public String getDescription(){ 178 return jTextAreaDesc.getText(); 179 } 180 } 181 | Popular Tags |