1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.web.Filter; 23 import org.netbeans.modules.j2ee.dd.api.web.FilterMapping; 24 import org.netbeans.modules.j2ee.ddloaders.web.*; 25 import org.netbeans.modules.xml.multiview.ui.*; 26 import org.netbeans.modules.xml.multiview.Utils; 27 import org.netbeans.modules.xml.multiview.Error; 28 import org.netbeans.api.project.SourceGroup; 29 import org.openide.util.NbBundle; 30 31 34 public class FilterPanel extends SectionInnerPanel { 35 private DDDataObject dObj; 36 private Filter filter; 37 private javax.swing.JButton linkButton; 38 private FilterParamsPanel filterParamsPanel; 39 private FilterMappingsTablePanel filterMappingsPanel; 40 41 42 public FilterPanel(SectionView sectionView, DDDataObject dObj,Filter filter) { 43 super(sectionView); 44 this.dObj=dObj; 45 this.filter=filter; 46 initComponents(); 47 48 filterNameTF.setText(filter.getFilterName()); 50 addValidatee(filterNameTF); 51 52 Utils.makeTextAreaLikeTextField(descriptionTA,filterNameTF); 54 descriptionTA.setText(filter.getDefaultDescription()); 55 addModifier(descriptionTA); 56 57 58 InitParamTableModel model = new InitParamTableModel(); 60 filterParamsPanel = new FilterParamsPanel(dObj, model); 61 filterParamsPanel.setModel(filter,filter.getInitParam()); 62 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 63 gridBagConstraints.gridx = 0; 64 gridBagConstraints.gridy = java.awt.GridBagConstraints.RELATIVE; 65 gridBagConstraints.gridwidth = 4; 66 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 67 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 68 gridBagConstraints.insets = new java.awt.Insets (2, 10, 0, 0); 69 add(filterParamsPanel, gridBagConstraints); 70 71 filterClassTF.setText(filter.getFilterClass()); 72 addValidatee(filterClassTF); 73 74 linkButton = new LinkButton(this, filter, "ClassName"); gridBagConstraints = new java.awt.GridBagConstraints (); 76 gridBagConstraints.gridx = 3; 77 gridBagConstraints.gridy = 2; 78 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 79 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 80 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 0); 81 linkButton.setText(NbBundle.getMessage(FilterPanel.class, "LBL_goToSource")); 82 add(linkButton, gridBagConstraints); 83 setAccessibility(); 84 } 85 86 private void setAccessibility() { 87 linkButton.setMnemonic(NbBundle.getMessage(FilterPanel.class, "LBL_goToSource_mnem").charAt(0)); 88 filterParamsLabel.setLabelFor(filterParamsPanel.getTable()); 89 } 90 91 public void linkButtonPressed(Object ddBean, String property) { 92 if ("ClassName".equals(property)) { DDUtils.openEditorFor(dObj,((Filter)ddBean).getFilterClass()); 94 } 95 } 96 97 102 private void initComponents() { 104 java.awt.GridBagConstraints gridBagConstraints; 105 106 filterNameLabel = new javax.swing.JLabel (); 107 filterNameTF = new javax.swing.JTextField (); 108 descriptionLabel = new javax.swing.JLabel (); 109 descriptionTA = new javax.swing.JTextArea (); 110 filterClassLabel = new javax.swing.JLabel (); 111 filterClassTF = new javax.swing.JTextField (); 112 browseButton = new javax.swing.JButton (); 113 filler = new javax.swing.JPanel (); 114 filterParamsLabel = new javax.swing.JLabel (); 115 116 setLayout(new java.awt.GridBagLayout ()); 117 118 filterNameLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterName_mnem").charAt(0)); 119 filterNameLabel.setLabelFor(filterNameTF); 120 filterNameLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterName")); 121 gridBagConstraints = new java.awt.GridBagConstraints (); 122 gridBagConstraints.gridx = 0; 123 gridBagConstraints.gridy = 0; 124 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 125 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 10); 126 add(filterNameLabel, gridBagConstraints); 127 128 filterNameTF.setColumns(30); 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 1; 131 gridBagConstraints.gridy = 0; 132 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 133 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 134 add(filterNameTF, gridBagConstraints); 135 136 descriptionLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_description_mnem").charAt(0)); 137 descriptionLabel.setLabelFor(descriptionTA); 138 descriptionLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_description")); 139 gridBagConstraints = new java.awt.GridBagConstraints (); 140 gridBagConstraints.gridx = 0; 141 gridBagConstraints.gridy = 1; 142 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 143 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 10); 144 add(descriptionLabel, gridBagConstraints); 145 146 descriptionTA.setRows(3); 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 1; 149 gridBagConstraints.gridy = 1; 150 gridBagConstraints.gridwidth = 3; 151 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 152 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 153 add(descriptionTA, gridBagConstraints); 154 155 filterClassLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterClass_mnem").charAt(0)); 156 filterClassLabel.setLabelFor(filterClassTF); 157 filterClassLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterClass")); 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 0; 160 gridBagConstraints.gridy = 2; 161 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 162 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 10); 163 add(filterClassLabel, gridBagConstraints); 164 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 1; 167 gridBagConstraints.gridy = 2; 168 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 169 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 170 add(filterClassTF, gridBagConstraints); 171 172 browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_browse_mnem").charAt(0)); 173 browseButton.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_browse")); 174 browseButton.setMargin(new java.awt.Insets (0, 14, 0, 14)); 175 browseButton.addActionListener(new java.awt.event.ActionListener () { 176 public void actionPerformed(java.awt.event.ActionEvent evt) { 177 browseButtonActionPerformed(evt); 178 } 179 }); 180 181 gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 2; 183 gridBagConstraints.gridy = 2; 184 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 185 gridBagConstraints.insets = new java.awt.Insets (3, 5, 0, 0); 186 add(browseButton, gridBagConstraints); 187 188 filler.setOpaque(false); 189 gridBagConstraints = new java.awt.GridBagConstraints (); 190 gridBagConstraints.gridx = 4; 191 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 192 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 193 gridBagConstraints.weightx = 1.0; 194 add(filler, gridBagConstraints); 195 196 filterParamsLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_initParams_mnem").charAt(0)); 197 filterParamsLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_initParams")); 198 gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.gridx = 0; 200 gridBagConstraints.gridy = 3; 201 gridBagConstraints.gridwidth = 5; 202 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 203 gridBagConstraints.insets = new java.awt.Insets (15, 10, 0, 0); 204 add(filterParamsLabel, gridBagConstraints); 205 206 } 207 209 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 212 SourceGroup[] groups = DDUtils.getJavaSourceGroups(dObj); 213 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 214 if (fo!=null) { 215 String className = DDUtils.getResourcePath(groups,fo); 216 if (className.length()>0 && !className.equals(filterClassTF.getText())) { 217 dObj.modelUpdatedFromUI(); 218 dObj.setChangedFromUI(true); 219 filterClassTF.setText(className); 220 filter.setFilterClass(className); 221 dObj.setChangedFromUI(false); 222 getSectionView().checkValidity(); 223 } 224 } 225 } catch (java.io.IOException ex) {} 226 } 228 229 private javax.swing.JButton browseButton; 231 private javax.swing.JLabel descriptionLabel; 232 private javax.swing.JTextArea descriptionTA; 233 private javax.swing.JPanel filler; 234 private javax.swing.JLabel filterClassLabel; 235 private javax.swing.JTextField filterClassTF; 236 private javax.swing.JLabel filterNameLabel; 237 private javax.swing.JTextField filterNameTF; 238 private javax.swing.JLabel filterParamsLabel; 239 241 public javax.swing.JComponent getErrorComponent(String name) { 242 if ("FilterName".equals(name)) return filterNameTF; else if ("FilterClass".equals(name)) return filterClassTF; return null; 245 } 246 247 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 248 if (comp==filterNameTF) { 249 String val = (String )value; 250 if (val.length()==0) { 251 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Filter Name",filterNameTF)); 252 return; 253 } 254 Filter[] filters = dObj.getWebApp().getFilter(); 255 for (int i=0;i<filters.length;i++) { 256 if (filter!=filters[i] && val.equals(filters[i].getFilterName())) { 257 getSectionView().getErrorPanel().setError(new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, filterNameTF)); 258 return; 259 } 260 } 261 getSectionView().getErrorPanel().clearError(); 262 } else if (comp==filterClassTF) { 263 String text = (String )value; 264 if (text.length()==0) { 265 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Filter Class",filterClassTF)); 266 return; 267 } 268 getSectionView().getErrorPanel().clearError(); 269 } 270 } 271 272 public void setValue(javax.swing.JComponent source, Object value) { 273 if (source==filterNameTF) { 274 String text = (String )value; 275 FilterMapping[] maps = DDUtils.getFilterMappings(dObj.getWebApp(), filter); 277 for (int i=0;i<maps.length;i++) { 278 maps[i].setFilterName(text); 279 } 280 filter.setFilterName(text); 282 SectionPanel enclosingPanel = getSectionView().findSectionPanel(filter); 284 enclosingPanel.setTitle(((FiltersMultiViewElement.FiltersView)getSectionView()).getFilterTitle(filter)); 285 enclosingPanel.getNode().setDisplayName(text); 286 } else if (source==filterClassTF) { 287 String text = (String )value; 288 filter.setFilterClass(text.length()==0?null:text); 289 } else if (source==descriptionTA) { 290 String text = (String )value; 291 filter.setDescription(text.length()==0?null:text); 292 } 293 } 294 295 public void rollbackValue(javax.swing.text.JTextComponent source) { 296 if (source==filterNameTF) { 297 filterNameTF.setText(filter.getFilterName()); 298 } else if (source==filterClassTF) { 299 filterClassTF.setText(filter.getFilterClass()); 300 } 301 } 302 303 305 protected void startUIChange() { 306 dObj.setChangedFromUI(true); 307 } 308 309 311 protected void endUIChange() { 312 dObj.modelUpdatedFromUI(); 313 dObj.setChangedFromUI(false); 314 } 315 316 } 317 | Popular Tags |