1 19 20 package org.netbeans.modules.web.wizards; 21 22 23 import javax.swing.DefaultCellEditor ; 24 import javax.swing.ListSelectionModel ; 25 import javax.swing.event.ListSelectionListener ; 26 import javax.swing.table.JTableHeader ; 27 import javax.swing.table.TableColumnModel ; 28 import javax.swing.DefaultCellEditor ; 29 import org.netbeans.api.project.ProjectUtils; 30 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.NbBundle; 34 import org.openide.ErrorManager; 35 import org.openide.DialogDisplayer; 36 import org.openide.NotifyDescriptor; 37 38 import org.netbeans.api.project.Project; 39 import org.netbeans.api.project.Sources; 40 import org.netbeans.api.project.SourceGroup; 41 import org.netbeans.modules.web.api.webmodule.WebProjectConstants; 42 import org.netbeans.modules.web.api.webmodule.WebModule; 43 import org.netbeans.spi.project.support.GenericSources; 44 45 import org.openide.loaders.TemplateWizard; 46 47 import org.netbeans.modules.web.taglib.TLDDataObject; 48 import org.netbeans.spi.project.ui.templates.support.Templates; 49 50 import org.netbeans.modules.web.core.Util; 51 import org.netbeans.modules.xml.multiview.ui.EditDialog; 52 53 56 public class TagHandlerPanelGUI extends javax.swing.JPanel implements ListSelectionListener { 57 58 private TagInfoPanel panel; 59 private TemplateWizard wiz; 60 private Project proj; 61 private SourceGroup[] folders; 62 private String target; 63 private FileObject tldFo; 64 private java.util.Set tagValues; 65 66 67 public TagHandlerPanelGUI(TemplateWizard wiz, final TagInfoPanel panel, Project proj, SourceGroup[] folders) { 68 initComponents(); 69 this.wiz=wiz; 70 this.panel=panel; 71 this.proj=proj; 72 this.folders=folders; 73 attrTable.setModel(new AttrTableModel( 74 new String []{"attrName","attrType","attrRequired","attrRtexprvalue"})); attrTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 76 attrTable.setIntercellSpacing(new java.awt.Dimension (6, 6)); 77 attrTable.setPreferredScrollableViewportSize(new java.awt.Dimension (300, 200)); 83 setName( org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class,"LBL_configure_TLD")); 84 attrTable.getSelectionModel().addListSelectionListener(this); 85 nameTextField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener () { 86 public void removeUpdate(javax.swing.event.DocumentEvent evt) { 87 panel.fireChangeEvent(); 88 } 89 public void insertUpdate(javax.swing.event.DocumentEvent evt) { 90 panel.fireChangeEvent(); 91 } 92 public void changedUpdate(javax.swing.event.DocumentEvent evt) { 93 panel.fireChangeEvent(); 94 } 95 }); 96 } 97 98 103 private void initComponents() { 105 java.awt.GridBagConstraints gridBagConstraints; 106 107 buttonGroup1 = new javax.swing.ButtonGroup (); 108 tldTextField = new javax.swing.JTextField (); 109 browseButton = new javax.swing.JButton (); 110 tldFileLabel = new javax.swing.JLabel (); 111 tagNameLabel = new javax.swing.JLabel (); 112 nameTextField = new javax.swing.JTextField (); 113 tagClassLabel = new javax.swing.JLabel (); 114 classTextField = new javax.swing.JTextField (); 115 jPanel1 = new javax.swing.JPanel (); 116 emptyButton = new javax.swing.JRadioButton (); 117 scriptlessButton = new javax.swing.JRadioButton (); 118 tegdependentButton = new javax.swing.JRadioButton (); 119 jPanel2 = new javax.swing.JPanel (); 120 attrLabel = new javax.swing.JLabel (); 121 jPanel3 = new javax.swing.JPanel (); 122 newButton = new javax.swing.JButton (); 123 editButton = new javax.swing.JButton (); 124 deleteButton = new javax.swing.JButton (); 125 bodyContentLb = new javax.swing.JLabel (); 126 jCheckBox1 = new javax.swing.JCheckBox (); 127 descriptionLabel = new javax.swing.JLabel (); 128 jScrollPane1 = new javax.swing.JScrollPane (); 129 attrTable = new javax.swing.JTable (); 130 131 setLayout(new java.awt.GridBagLayout ()); 132 133 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagHandlerPanel2")); 134 tldTextField.setEditable(false); 135 gridBagConstraints = new java.awt.GridBagConstraints (); 136 gridBagConstraints.gridx = 1; 137 gridBagConstraints.gridy = 2; 138 gridBagConstraints.gridwidth = 2; 139 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 140 gridBagConstraints.weightx = 2.0; 141 gridBagConstraints.insets = new java.awt.Insets (0, 6, 12, 0); 142 add(tldTextField, gridBagConstraints); 143 tldTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TLDFile")); 144 145 browseButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_Browse_Mnemonic").charAt(0)); 146 browseButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_Browse")); 147 browseButton.addActionListener(new java.awt.event.ActionListener () { 148 public void actionPerformed(java.awt.event.ActionEvent evt) { 149 browseButtonActionPerformed(evt); 150 } 151 }); 152 153 gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridx = 3; 155 gridBagConstraints.gridy = 2; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.insets = new java.awt.Insets (0, 6, 12, 6); 158 add(browseButton, gridBagConstraints); 159 browseButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_Browse")); 160 161 tldFileLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TLDName_mnem").charAt(0)); 162 tldFileLabel.setLabelFor(tldTextField); 163 tldFileLabel.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_tldFile")); 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 0; 166 gridBagConstraints.gridy = 2; 167 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 168 gridBagConstraints.insets = new java.awt.Insets (0, 6, 12, 0); 169 add(tldFileLabel, gridBagConstraints); 170 171 tagNameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TagName_mnem").charAt(0)); 172 tagNameLabel.setLabelFor(nameTextField); 173 tagNameLabel.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_tagName")); 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, 6, 6, 0); 179 add(tagNameLabel, 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.weightx = 1.0; 186 gridBagConstraints.insets = new java.awt.Insets (0, 6, 6, 0); 187 add(nameTextField, gridBagConstraints); 188 nameTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagName")); 189 190 tagClassLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_ClassName_mnem").charAt(0)); 191 tagClassLabel.setLabelFor(classTextField); 192 tagClassLabel.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_tagHandlerClass")); 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridx = 0; 195 gridBagConstraints.gridy = 4; 196 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 197 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 198 add(tagClassLabel, gridBagConstraints); 199 200 classTextField.setEditable(false); 201 gridBagConstraints = new java.awt.GridBagConstraints (); 202 gridBagConstraints.gridx = 1; 203 gridBagConstraints.gridy = 4; 204 gridBagConstraints.gridwidth = 2; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 206 gridBagConstraints.weightx = 2.0; 207 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 208 add(classTextField, gridBagConstraints); 209 classTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagClass")); 210 211 buttonGroup1.add(emptyButton); 212 emptyButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TagEmpty_mnem").charAt(0)); 213 emptyButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_emptyBodyContent")); 214 jPanel1.add(emptyButton); 215 emptyButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagEmpty")); 216 217 buttonGroup1.add(scriptlessButton); 218 scriptlessButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TagScriptless_mnem").charAt(0)); 219 scriptlessButton.setSelected(true); 220 scriptlessButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_scriptlessBodyContent")); 221 jPanel1.add(scriptlessButton); 222 scriptlessButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagScriptless")); 223 224 buttonGroup1.add(tegdependentButton); 225 tegdependentButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TagTagdependent_mnem").charAt(0)); 226 tegdependentButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_tagdependentBodyContent")); 227 jPanel1.add(tegdependentButton); 228 tegdependentButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagTagdependent")); 229 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 1; 232 gridBagConstraints.gridy = 6; 233 gridBagConstraints.gridwidth = 2; 234 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 237 add(jPanel1, gridBagConstraints); 238 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 2; 241 gridBagConstraints.gridy = 3; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 243 gridBagConstraints.weightx = 1.0; 244 add(jPanel2, gridBagConstraints); 245 246 attrLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_Attribs_mnem").charAt(0)); 247 attrLabel.setLabelFor(attrTable); 248 attrLabel.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "TITLE_attributes")); 249 gridBagConstraints = new java.awt.GridBagConstraints (); 250 gridBagConstraints.gridx = 0; 251 gridBagConstraints.gridy = 7; 252 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 253 gridBagConstraints.insets = new java.awt.Insets (12, 6, 6, 0); 254 add(attrLabel, gridBagConstraints); 255 256 jPanel3.setLayout(new java.awt.GridBagLayout ()); 257 258 newButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_new_mnemonic").charAt(0)); 259 newButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_newButton")); 260 newButton.addActionListener(new java.awt.event.ActionListener () { 261 public void actionPerformed(java.awt.event.ActionEvent evt) { 262 newButtonActionPerformed(evt); 263 } 264 }); 265 266 gridBagConstraints = new java.awt.GridBagConstraints (); 267 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 268 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 269 jPanel3.add(newButton, gridBagConstraints); 270 newButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_newButton")); 271 272 editButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_edit_mnemonic").charAt(0)); 273 editButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_editButton")); 274 editButton.setEnabled(false); 275 editButton.addActionListener(new java.awt.event.ActionListener () { 276 public void actionPerformed(java.awt.event.ActionEvent evt) { 277 editButtonActionPerformed(evt); 278 } 279 }); 280 281 gridBagConstraints = new java.awt.GridBagConstraints (); 282 gridBagConstraints.gridx = 0; 283 gridBagConstraints.gridy = 1; 284 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 285 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 286 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 287 jPanel3.add(editButton, gridBagConstraints); 288 editButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_editButton")); 289 290 deleteButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_delete_mnemonic").charAt(0)); 291 deleteButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_deleteButton")); 292 deleteButton.setEnabled(false); 293 deleteButton.addActionListener(new java.awt.event.ActionListener () { 294 public void actionPerformed(java.awt.event.ActionEvent evt) { 295 deleteButtonActionPerformed(evt); 296 } 297 }); 298 299 gridBagConstraints = new java.awt.GridBagConstraints (); 300 gridBagConstraints.gridx = 0; 301 gridBagConstraints.gridy = 2; 302 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 303 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 304 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 305 jPanel3.add(deleteButton, gridBagConstraints); 306 deleteButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_deleteButton")); 307 308 gridBagConstraints = new java.awt.GridBagConstraints (); 309 gridBagConstraints.gridx = 3; 310 gridBagConstraints.gridy = 8; 311 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 312 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 313 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 314 add(jPanel3, gridBagConstraints); 315 316 bodyContentLb.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "LBL_bodyContent")); 317 gridBagConstraints = new java.awt.GridBagConstraints (); 318 gridBagConstraints.gridx = 0; 319 gridBagConstraints.gridy = 6; 320 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 321 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 0); 322 add(bodyContentLb, gridBagConstraints); 323 324 jCheckBox1.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_AddToTLD_mnem").charAt(0)); 325 jCheckBox1.setSelected(true); 326 jCheckBox1.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_addToTLD")); 327 jCheckBox1.addItemListener(new java.awt.event.ItemListener () { 328 public void itemStateChanged(java.awt.event.ItemEvent evt) { 329 jCheckBox1ItemStateChanged(evt); 330 } 331 }); 332 333 gridBagConstraints = new java.awt.GridBagConstraints (); 334 gridBagConstraints.gridx = 0; 335 gridBagConstraints.gridy = 0; 336 gridBagConstraints.gridwidth = 4; 337 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 338 gridBagConstraints.insets = new java.awt.Insets (0, 6, 12, 0); 339 add(jCheckBox1, gridBagConstraints); 340 jCheckBox1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("OPT_addToTLD")); 341 342 descriptionLabel.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "HINT_tldFile")); 343 gridBagConstraints = new java.awt.GridBagConstraints (); 344 gridBagConstraints.gridx = 0; 345 gridBagConstraints.gridy = 1; 346 gridBagConstraints.gridwidth = 4; 347 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 348 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 349 gridBagConstraints.insets = new java.awt.Insets (0, 6, 6, 6); 350 add(descriptionLabel, gridBagConstraints); 351 352 jScrollPane1.setViewportView(attrTable); 353 attrTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_AttrTable")); 354 355 gridBagConstraints = new java.awt.GridBagConstraints (); 356 gridBagConstraints.gridx = 0; 357 gridBagConstraints.gridy = 8; 358 gridBagConstraints.gridwidth = 3; 359 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 360 gridBagConstraints.weightx = 1.0; 361 gridBagConstraints.weighty = 1.0; 362 gridBagConstraints.insets = new java.awt.Insets (0, 6, 6, 0); 363 add(jScrollPane1, gridBagConstraints); 364 365 } 366 368 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { int row = attrTable.getSelectedRow(); 371 if (row>=0) { 372 ((AttrTableModel)attrTable.getModel()).removeRow(row); 373 ((AttrTableModel)attrTable.getModel()).fireTableRowsDeleted(row, row); 374 } 375 } 377 private void newButtonActionPerformed(java.awt.event.ActionEvent evt) { String title = org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "TITLE_attr_add"); final AttrDialog panel = new AttrDialog(); 381 final AttrTableModel tableModel = (AttrTableModel)attrTable.getModel(); 382 EditDialog editDialog = new EditDialog(panel,title, true) { 383 protected String validate() { 384 String newAttrName = panel.getAttrName(); 385 if (newAttrName.length()==0) { 387 return NbBundle.getMessage(TagHandlerPanelGUI.class, 388 "MSG_attr_no_name"); 389 } else if (!isJavaIdentifier(newAttrName)) { 390 return NbBundle.getMessage(TagHandlerPanelGUI.class, 391 "MSG_wrong_attr_name",newAttrName); 392 } else { 393 Object [][] attrs = tableModel.getAttributes(); 394 for (int i=0;i<attrs.length;i++){ 395 if (newAttrName.equals(attrs[i][0])) { 396 return NbBundle.getMessage(TagHandlerPanelGUI.class, 397 "MSG_attr_exists"); 398 } 399 } 400 } 401 return null; 402 } 403 }; 404 editDialog.setValid(false); 405 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(editDialog); 406 panel.getAttrNameTF().getDocument().addDocumentListener(docListener); 407 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(editDialog); 408 d.getAccessibleContext().setAccessibleDescription(editDialog.getDialogPanel().getAccessibleContext().getAccessibleDescription()); 409 d.show(); 410 panel.getAttrNameTF().getDocument().removeDocumentListener(docListener); 411 412 if (editDialog.getValue().equals(EditDialog.OK_OPTION)) { 413 int rowCount = tableModel.getRowCount(); 414 tableModel.addRow(panel.getAttrName(),panel.getAttrType(),panel.isRequired(),panel.isRtexpr()); 415 tableModel.fireTableRowsInserted(rowCount, rowCount); 416 } 417 } 419 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { if ( browseButton == evt.getSource() ) { 422 org.openide.filesystems.FileObject fo=null; 423 if (folders!=null) fo = BrowseFolders.showDialog(folders, 425 TLDDataObject.class, 426 ""); 427 else { 428 Sources sources = ProjectUtils.getSources(proj); 429 fo = BrowseFolders.showDialog( sources.getSourceGroups( Sources.TYPE_GENERIC ), 430 org.openide.loaders.DataFolder.class, 431 ""); 432 } 433 434 if ( fo != null) { 435 tldFo=fo; 436 FileObject targetFolder=Templates.getTargetFolder(wiz); 437 WebModule wm = WebModule.getWebModule(targetFolder); 438 tldTextField.setText( FileUtil.getRelativePath( (wm==null?proj.getProjectDirectory():wm.getDocumentBase()), fo ) ); 440 try { 441 java.io.InputStream is = tldFo.getInputStream(); 442 tagValues = Util.getTagValues(is, new String []{"tag","tag-file"},"name"); is.close(); 445 } catch (java.io.IOException ex) {} 446 catch (org.xml.sax.SAXException ex ){} 447 panel.fireChangeEvent(); 448 } 449 450 } 451 } 453 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 454 if (e.getValueIsAdjusting()) return; 455 if (attrTable.getSelectionModel().isSelectionEmpty()) { 456 editButton.setEnabled(false); 457 deleteButton.setEnabled(false); 458 } else { 459 editButton.setEnabled(true); 460 deleteButton.setEnabled(true); 461 } 462 } 463 464 private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) { if (jCheckBox1.isSelected()) { 467 browseButton.setEnabled(true); 469 nameTextField.setEnabled(true); 470 emptyButton.setEnabled(true); 471 scriptlessButton.setEnabled(true); 472 tegdependentButton.setEnabled(true); 473 } else { 474 browseButton.setEnabled(false); 476 nameTextField.setEnabled(false); 477 emptyButton.setEnabled(false); 478 scriptlessButton.setEnabled(false); 479 tegdependentButton.setEnabled(false); 480 } 481 panel.fireChangeEvent(); 482 } 484 private void editButtonActionPerformed(java.awt.event.ActionEvent evt) { String title = org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "TITLE_attr_edit"); final AttrTableModel tableModel = (AttrTableModel)attrTable.getModel(); 488 final int row = attrTable.getSelectedRow(); 489 String attrName = (String )tableModel.getValueAt(row,0); 490 String attrType = (String )tableModel.getValueAt(row,1); 491 boolean required = ((Boolean )tableModel.getValueAt(row,2)).booleanValue(); 492 boolean rtexpr = ((Boolean )tableModel.getValueAt(row,3)).booleanValue(); 493 final AttrDialog panel = new AttrDialog(attrName,attrType,required,rtexpr); 494 EditDialog editDialog = new EditDialog(panel,title, false) { 495 protected String validate() { 496 String newAttrName = panel.getAttrName(); 497 if (newAttrName.length()==0) { 498 return NbBundle.getMessage(TagHandlerPanelGUI.class, 499 "MSG_attr_no_name"); 500 } else if (!isJavaIdentifier(newAttrName)) { 501 return NbBundle.getMessage(TagHandlerPanelGUI.class, 502 "MSG_wrong_attr_name",newAttrName); 503 } else { 504 Object [][] attrs = tableModel.getAttributes(); 505 for (int i=0;i<attrs.length;i++){ 506 if (i!=row && newAttrName.equals(attrs[i][0])) { 507 return NbBundle.getMessage(TagHandlerPanelGUI.class, 508 "MSG_attr_exists"); 509 } 510 } 511 } 512 return null; 513 } 514 }; 515 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(editDialog); 516 panel.getAttrNameTF().getDocument().addDocumentListener(docListener); 517 518 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(editDialog); 519 d.getAccessibleContext().setAccessibleDescription(editDialog.getDialogPanel().getAccessibleContext().getAccessibleDescription()); 520 d.show(); 521 panel.getAttrNameTF().getDocument().removeDocumentListener(docListener); 522 if (editDialog.getValue().equals(EditDialog.OK_OPTION)) { 523 tableModel.setData(panel.getAttrName(),panel.getAttrType(),panel.isRequired(),panel.isRtexpr(),row); 524 tableModel.fireTableRowsUpdated(row, row); 525 } 526 } 528 529 private javax.swing.JLabel attrLabel; 531 private javax.swing.JTable attrTable; 532 private javax.swing.JLabel bodyContentLb; 533 private javax.swing.JButton browseButton; 534 private javax.swing.ButtonGroup buttonGroup1; 535 private javax.swing.JTextField classTextField; 536 private javax.swing.JButton deleteButton; 537 private javax.swing.JLabel descriptionLabel; 538 private javax.swing.JButton editButton; 539 private javax.swing.JRadioButton emptyButton; 540 private javax.swing.JCheckBox jCheckBox1; 541 private javax.swing.JPanel jPanel1; 542 private javax.swing.JPanel jPanel2; 543 private javax.swing.JPanel jPanel3; 544 private javax.swing.JScrollPane jScrollPane1; 545 private javax.swing.JTextField nameTextField; 546 private javax.swing.JButton newButton; 547 private javax.swing.JRadioButton scriptlessButton; 548 private javax.swing.JLabel tagClassLabel; 549 private javax.swing.JLabel tagNameLabel; 550 private javax.swing.JRadioButton tegdependentButton; 551 private javax.swing.JLabel tldFileLabel; 552 private javax.swing.JTextField tldTextField; 553 555 556 String getTagName() { 557 return nameTextField.getText(); 558 } 559 560 void setTagName(String name) { 561 nameTextField.setText(name); 562 } 563 564 void setClassName(String name) { 565 classTextField.setText(name); 566 } 567 568 FileObject getTLDFile() { 569 return tldFo; 570 } 571 572 java.util.Set getTagValues() { 573 return tagValues; 574 } 575 576 boolean isEmpty() { 577 return emptyButton.isSelected(); 578 } 579 boolean isScriptless() { 580 return scriptlessButton.isSelected(); 581 } 582 boolean isTegdependent() { 583 return tegdependentButton.isSelected(); 584 } 585 586 boolean writeToTLD() { 587 return jCheckBox1.isSelected(); 588 } 589 590 Object [][] getAttributes() { 591 return ((AttrTableModel)attrTable.getModel()).getAttributes(); 592 } 593 594 void setBodySupport(boolean bodySupport) { 595 if (bodySupport) scriptlessButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_jspBodyContent")); 596 else scriptlessButton.setText(org.openide.util.NbBundle.getMessage(TagHandlerPanelGUI.class, "OPT_scriptlessBodyContent")); 597 } 598 599 private boolean isJavaIdentifier(String s) { 600 if (s.length()==0) return false; 601 if (!Character.isJavaIdentifierStart(s.charAt(0))) return false; 602 for (int i=1;i<s.length();i++) 603 if (!Character.isJavaIdentifierPart(s.charAt(i))) return false; 604 return true; 605 } 606 607 } 608 | Popular Tags |