1 19 20 21 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 22 23 import org.netbeans.modules.j2ee.dd.api.web.SecurityConstraint; 24 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 25 import org.netbeans.modules.j2ee.dd.api.web.WebResourceCollection; 26 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 27 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 28 import org.netbeans.modules.xml.multiview.ui.EditDialog; 29 import org.openide.util.NbBundle; 30 31 38 public class WebResourceCollectionTablePanel extends DefaultTablePanel { 39 private DDDataObject dObj; 40 private WebResourceCollectionTableModel model; 41 private SecurityConstraint constraint; 42 43 46 public WebResourceCollectionTablePanel(final DDDataObject dObj, 47 final WebResourceCollectionTableModel model) { 48 super(model); 49 this.dObj = dObj; 50 this.model = model; 51 52 removeButton.addActionListener(new java.awt.event.ActionListener () { 53 public void actionPerformed(java.awt.event.ActionEvent evt) { 54 dObj.modelUpdatedFromUI(); 55 dObj.setChangedFromUI(true); 56 int row = getTable().getSelectedRow(); 57 model.removeRow(row); 58 dObj.setChangedFromUI(false); 59 } 60 }); 61 62 editButton.addActionListener(new TableActionListener(false)); 63 addButton.addActionListener(new TableActionListener(true)); 64 } 65 66 void setModel(WebApp webApp, SecurityConstraint constraint, 67 WebResourceCollection[] collections) { 68 model.setData(constraint, collections); 69 model.setWebApp(webApp); 70 this.constraint = constraint; 71 } 72 73 private class TableActionListener implements java.awt.event.ActionListener { 74 private boolean add; 75 76 TableActionListener(boolean add) { 77 this.add=add; 78 } 79 80 public void actionPerformed(java.awt.event.ActionEvent evt) { 81 final int row = (add?-1:getTable().getSelectedRow()); 82 final WebResourceCollectionPanel dialogPanel = new WebResourceCollectionPanel(); 83 84 if (!add) { 85 WebResourceCollection col = model.getWebResourceCollection(row); 86 dialogPanel.setResourceName(col.getWebResourceName()); 87 dialogPanel.setDescription(col.getDefaultDescription()); 88 dialogPanel.setUrlPatterns(col.getUrlPattern()); 89 dialogPanel.setHttpMethods(col.getHttpMethod()); 90 } 91 92 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(EjbRefsTablePanel.class,"TTL_WebResource"),add) { 93 protected String validate() { 94 String name = dialogPanel.getResourceName().trim(); 95 WebResourceCollection webResource = null; 96 97 if (row != -1) 98 webResource = model.getWebResourceCollection(row); 99 100 if (name.length()==0) { 101 return NbBundle.getMessage(WebResourceCollectionTablePanel.class,"TXT_EmptyWebResourceName"); 102 } else { 103 WebResourceCollection[] col = constraint.getWebResourceCollection(); 104 105 for (int i = 0; i < col.length; i++) { 106 if (col[i] != webResource && name.equals(col[i].getWebResourceName())) { 107 return NbBundle.getMessage(WebResourceCollectionTablePanel.class,"TXT_WebResourceNameExists",name); 108 } 109 } 110 } 111 112 String [] urlPatterns = dialogPanel.getUrlPatterns(); 113 if (urlPatterns.length == 0) { 114 return NbBundle.getMessage(WebResourceCollectionTablePanel.class,"TXT_EmptyUrlPatterns",name); 115 } 116 return null; 117 } 118 }; 119 120 if (add) 121 dialog.setValid(false); 123 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 124 dialogPanel.getResourceNameTF().getDocument().addDocumentListener(docListener); 125 dialogPanel.getDescriptionTF().getDocument().addDocumentListener(docListener); 126 dialogPanel.getUrlPatternsTF().getDocument().addDocumentListener(docListener); 127 128 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 129 d.setVisible(true); 130 131 dialogPanel.getResourceNameTF().getDocument().removeDocumentListener(docListener); 132 dialogPanel.getDescriptionTF().getDocument().removeDocumentListener(docListener); 133 dialogPanel.getUrlPatternsTF().getDocument().removeDocumentListener(docListener); 134 135 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 136 dObj.modelUpdatedFromUI(); 137 dObj.setChangedFromUI(true); 138 139 String resourceName = dialogPanel.getResourceName(); 140 String [] urlPatterns = dialogPanel.getUrlPatterns(); 141 String [] httpMethods = dialogPanel.getSelectedHttpMethods(); 142 String description = dialogPanel.getDescription(); 143 144 145 if (add) 146 model.addRow(new Object [] {resourceName, urlPatterns, 147 httpMethods, description}); 148 else 149 model.editRow(row, new Object []{resourceName, 150 urlPatterns, httpMethods, description}); 151 152 dObj.setChangedFromUI(false); 153 } 154 } 155 } 156 157 162 private void initComponents() { 164 165 setLayout(new java.awt.GridBagLayout ()); 166 167 } 169 170 173 } 174 | Popular Tags |