1 19 20 package org.netbeans.modules.web.jsf.dialogs; 21 22 import java.util.Collection ; 23 import java.util.Hashtable ; 24 import java.util.Iterator ; 25 import javax.swing.SwingUtilities ; 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.ManagedBean; 31 import org.netbeans.modules.web.jsf.api.facesmodel.ManagedBean; 32 import org.openide.util.NbBundle; 33 34 38 public class AddManagedBeanDialog extends javax.swing.JPanel implements ValidatingPanel { 39 private JSFConfigDataObject config; 40 private Hashtable existingBeans = null; 41 42 public AddManagedBeanDialog(JSFConfigDataObject config) { 43 initComponents(); 44 this.config = config; 45 } 46 47 public javax.swing.text.JTextComponent [] getDocumentChangeComponents() { 48 return new javax.swing.text.JTextComponent []{jTextFieldName, jTextFieldClass}; 49 } 50 51 public javax.swing.AbstractButton [] getStateChangeComponents() { 52 return new javax.swing.AbstractButton []{ }; 53 } 54 55 public String validatePanel() { 56 if (getName().length()==0) 57 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_EmptyName"); 58 if (existingBeans == null){ 59 existingBeans = new Hashtable (); 60 ManagedBean bean; 61 FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), false).getRootComponent(); 63 Collection <ManagedBean> beans = facesConfig.getManagedBeans(); 64 for (Iterator <ManagedBean> it = beans.iterator(); it.hasNext();) { 65 ManagedBean managedBean = it.next(); 66 existingBeans.put(managedBean.getManagedBeanName(), ""); 67 } 68 } 69 if (existingBeans.get(getName()) != null) 70 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_BeanExist"); 71 if (getBeanClass().length()==0) 72 return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddManagedBean_EmptyClass"); 73 return null; 74 } 75 76 81 private void initComponents() { 83 java.awt.GridBagConstraints gridBagConstraints; 84 85 jLabelClass = new javax.swing.JLabel (); 86 jTextFieldClass = new javax.swing.JTextField (); 87 jButtonClass = new javax.swing.JButton (); 88 jLabelScope = new javax.swing.JLabel (); 89 jComboBoxScope = new javax.swing.JComboBox (); 90 jLabelDesc = new javax.swing.JLabel (); 91 jScrollPaneDesc = new javax.swing.JScrollPane (); 92 jTextAreaDesc = new javax.swing.JTextArea (); 93 jLabelName = new javax.swing.JLabel (); 94 jTextFieldName = new javax.swing.JTextField (); 95 96 setLayout(new java.awt.GridBagLayout ()); 97 98 jLabelClass.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_ManagedBeanClass").charAt(0)); 99 jLabelClass.setLabelFor(jTextFieldClass); 100 jLabelClass.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_ManagedBeanClass")); gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 0; 103 gridBagConstraints.gridy = 1; 104 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 105 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 106 add(jLabelClass, gridBagConstraints); 107 gridBagConstraints = new java.awt.GridBagConstraints (); 108 gridBagConstraints.gridx = 1; 109 gridBagConstraints.gridy = 1; 110 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 111 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 112 add(jTextFieldClass, gridBagConstraints); 113 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle"); jTextFieldClass.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_BeanClass")); jTextFieldClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanClass")); 117 jButtonClass.setMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_Browse").charAt(0)); 118 jButtonClass.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_Browse")); jButtonClass.setEnabled(false); 120 jButtonClass.addActionListener(new java.awt.event.ActionListener () { 121 public void actionPerformed(java.awt.event.ActionEvent evt) { 122 jButtonClassActionPerformed(evt); 123 } 124 }); 125 gridBagConstraints = new java.awt.GridBagConstraints (); 126 gridBagConstraints.gridx = 2; 127 gridBagConstraints.gridy = 1; 128 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 129 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 11); 130 add(jButtonClass, gridBagConstraints); 131 jButtonClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Browse")); 133 jLabelScope.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_Scope").charAt(0)); 134 jLabelScope.setLabelFor(jComboBoxScope); 135 jLabelScope.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_Scope")); gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.gridx = 0; 138 gridBagConstraints.gridy = 2; 139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 140 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 12); 141 add(jLabelScope, gridBagConstraints); 142 143 jComboBoxScope.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "request", "session", "application", "none" })); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 1; 146 gridBagConstraints.gridy = 2; 147 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 148 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 149 add(jComboBoxScope, gridBagConstraints); 150 jComboBoxScope.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_ManagedBeanScope")); jComboBoxScope.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Scope")); 153 jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "MNE_BeanDescription").charAt(0)); 154 jLabelDesc.setLabelFor(jTextAreaDesc); 155 jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddManagedBeanDialog.class, "LBL_BeanDescription")); gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 0; 158 gridBagConstraints.gridy = 3; 159 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 160 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 161 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 162 add(jLabelDesc, gridBagConstraints); 163 164 jTextAreaDesc.setColumns(20); 165 jTextAreaDesc.setRows(5); 166 jScrollPaneDesc.setViewportView(jTextAreaDesc); 167 jTextAreaDesc.getAccessibleContext().setAccessibleName(bundle.getString("ACN_ManagedBeanDescription")); jTextAreaDesc.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanDescription")); 170 gridBagConstraints = new java.awt.GridBagConstraints (); 171 gridBagConstraints.gridx = 1; 172 gridBagConstraints.gridy = 3; 173 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 174 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 175 gridBagConstraints.weightx = 1.0; 176 gridBagConstraints.weighty = 1.0; 177 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 178 add(jScrollPaneDesc, gridBagConstraints); 179 180 jLabelName.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("MNE_ManagedBeanName").charAt(0)); 181 jLabelName.setLabelFor(jTextFieldName); 182 jLabelName.setText(bundle.getString("LBL_Bean_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 184 gridBagConstraints.gridx = 0; 185 gridBagConstraints.gridy = 0; 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 187 gridBagConstraints.insets = new java.awt.Insets (12, 12, 5, 0); 188 add(jLabelName, gridBagConstraints); 189 gridBagConstraints = new java.awt.GridBagConstraints (); 190 gridBagConstraints.gridx = 1; 191 gridBagConstraints.gridy = 0; 192 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 193 gridBagConstraints.insets = new java.awt.Insets (12, 0, 5, 0); 194 add(jTextFieldName, gridBagConstraints); 195 jTextFieldName.getAccessibleContext().setAccessibleName(bundle.getString("ACS_BeanName")); jTextFieldName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_BeanName")); 198 getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddManagedBeanDialog")); getAccessibleContext().setAccessibleParent(this); 200 } 202 private void jButtonClassActionPerformed(java.awt.event.ActionEvent evt) { SwingUtilities.invokeLater(new Runnable () { 204 public void run() { 205 } 208 }); 209 } 211 212 private javax.swing.JButton jButtonClass; 214 private javax.swing.JComboBox jComboBoxScope; 215 private javax.swing.JLabel jLabelClass; 216 private javax.swing.JLabel jLabelDesc; 217 private javax.swing.JLabel jLabelName; 218 private javax.swing.JLabel jLabelScope; 219 private javax.swing.JScrollPane jScrollPaneDesc; 220 private javax.swing.JTextArea jTextAreaDesc; 221 private javax.swing.JTextField jTextFieldClass; 222 private javax.swing.JTextField jTextFieldName; 223 225 public String getBeanClass(){ 226 return jTextFieldClass.getText(); 227 } 228 229 public String getScope(){ 230 return (String )jComboBoxScope.getSelectedItem(); 231 } 232 233 public String getDescription(){ 234 return jTextAreaDesc.getText(); 235 } 236 237 public String getName(){ 238 return jTextFieldName.getText(); 239 } 240 } 241 | Popular Tags |