KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > FilterPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
32  * @author mkuchtiak
33  */

34 public class FilterPanel extends SectionInnerPanel {
35     private DDDataObject dObj;
36     private Filter filter;
37     private javax.swing.JButton JavaDoc linkButton;
38     private FilterParamsPanel filterParamsPanel;
39     private FilterMappingsTablePanel filterMappingsPanel;
40     
41     /** Creates new form FilterPanel */
42     public FilterPanel(SectionView sectionView, DDDataObject dObj,Filter filter) {
43         super(sectionView);
44         this.dObj=dObj;
45         this.filter=filter;
46         initComponents();
47
48         // Filter Name
49
filterNameTF.setText(filter.getFilterName());
50         addValidatee(filterNameTF);
51         
52         // description
53
Utils.makeTextAreaLikeTextField(descriptionTA,filterNameTF);
54         descriptionTA.setText(filter.getDefaultDescription());
55         addModifier(descriptionTA);
56         
57
58         // Init Params
59
InitParamTableModel model = new InitParamTableModel();
60         filterParamsPanel = new FilterParamsPanel(dObj, model);
61         filterParamsPanel.setModel(filter,filter.getInitParam());
62         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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"); //NOI18N
75
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc ddBean, String JavaDoc property) {
92         if ("ClassName".equals(property)) { // NOI18N
93
DDUtils.openEditorFor(dObj,((Filter)ddBean).getFilterClass());
94         }
95     }
96     
97     /** This method is called from within the constructor to
98      * initialize the form.
99      * WARNING: Do NOT modify this code. The content of this method is
100      * always regenerated by the Form Editor.
101      */

102     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
103
private void initComponents() {
104         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
105
106         filterNameLabel = new javax.swing.JLabel JavaDoc();
107         filterNameTF = new javax.swing.JTextField JavaDoc();
108         descriptionLabel = new javax.swing.JLabel JavaDoc();
109         descriptionTA = new javax.swing.JTextArea JavaDoc();
110         filterClassLabel = new javax.swing.JLabel JavaDoc();
111         filterClassTF = new javax.swing.JTextField JavaDoc();
112         browseButton = new javax.swing.JButton JavaDoc();
113         filler = new javax.swing.JPanel JavaDoc();
114         filterParamsLabel = new javax.swing.JLabel JavaDoc();
115
116         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
122         gridBagConstraints.gridx = 0;
123         gridBagConstraints.gridy = 0;
124         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
126         add(filterNameLabel, gridBagConstraints);
127
128         filterNameTF.setColumns(30);
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 1;
131         gridBagConstraints.gridy = 0;
132         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
140         gridBagConstraints.gridx = 0;
141         gridBagConstraints.gridy = 1;
142         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
144         add(descriptionLabel, gridBagConstraints);
145
146         descriptionTA.setRows(3);
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
159         gridBagConstraints.gridx = 0;
160         gridBagConstraints.gridy = 2;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
163         add(filterClassLabel, gridBagConstraints);
164
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 1;
167         gridBagConstraints.gridy = 2;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc(0, 14, 0, 14));
175         browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
176             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
177                 browseButtonActionPerformed(evt);
178             }
179         });
180
181         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
182         gridBagConstraints.gridx = 2;
183         gridBagConstraints.gridy = 2;
184         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 5, 0, 0);
186         add(browseButton, gridBagConstraints);
187
188         filler.setOpaque(false);
189         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc();
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 JavaDoc(15, 10, 0, 0);
204         add(filterParamsLabel, gridBagConstraints);
205
206     }
207     // </editor-fold>//GEN-END:initComponents
208

209     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
210
// TODO add your handling code here:
211
try {
212             SourceGroup[] groups = DDUtils.getJavaSourceGroups(dObj);
213             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
214             if (fo!=null) {
215                 String JavaDoc 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 JavaDoc ex) {}
226     }//GEN-LAST:event_browseButtonActionPerformed
227

228     
229     // Variables declaration - do not modify//GEN-BEGIN:variables
230
private javax.swing.JButton JavaDoc browseButton;
231     private javax.swing.JLabel JavaDoc descriptionLabel;
232     private javax.swing.JTextArea JavaDoc descriptionTA;
233     private javax.swing.JPanel JavaDoc filler;
234     private javax.swing.JLabel JavaDoc filterClassLabel;
235     private javax.swing.JTextField JavaDoc filterClassTF;
236     private javax.swing.JLabel JavaDoc filterNameLabel;
237     private javax.swing.JTextField JavaDoc filterNameTF;
238     private javax.swing.JLabel JavaDoc filterParamsLabel;
239     // End of variables declaration//GEN-END:variables
240

241     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc name) {
242         if ("FilterName".equals(name)) return filterNameTF; //NOI18N
243
else if ("FilterClass".equals(name)) return filterClassTF; //NOI18N
244
return null;
245     }
246     
247     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
248         if (comp==filterNameTF) {
249             String JavaDoc val = (String JavaDoc)value;
250             if (val.length()==0) {
251                 getSectionView().getErrorPanel().setError(new Error JavaDoc(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 JavaDoc(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, filterNameTF));
258                     return;
259                 }
260             }
261             getSectionView().getErrorPanel().clearError();
262         } else if (comp==filterClassTF) {
263             String JavaDoc text = (String JavaDoc)value;
264             if (text.length()==0) {
265                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Filter Class",filterClassTF));
266                 return;
267             }
268             getSectionView().getErrorPanel().clearError();
269         }
270     }
271     
272     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
273         if (source==filterNameTF) {
274             String JavaDoc text = (String JavaDoc)value;
275             // change Filter-mappings
276
FilterMapping[] maps = DDUtils.getFilterMappings(dObj.getWebApp(), filter);
277             for (int i=0;i<maps.length;i++) {
278                 maps[i].setFilterName(text);
279             }
280             // change Filter-name
281
filter.setFilterName(text);
282             //change panel title, node name
283
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 JavaDoc text = (String JavaDoc)value;
288             filter.setFilterClass(text.length()==0?null:text);
289         } else if (source==descriptionTA) {
290             String JavaDoc text = (String JavaDoc)value;
291             filter.setDescription(text.length()==0?null:text);
292         }
293     }
294     
295     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
296         if (source==filterNameTF) {
297             filterNameTF.setText(filter.getFilterName());
298         } else if (source==filterClassTF) {
299             filterClassTF.setText(filter.getFilterClass());
300         }
301     }
302     
303     /** This will be called before model is changed from this panel
304      */

305     protected void startUIChange() {
306         dObj.setChangedFromUI(true);
307     }
308     
309     /** This will be called after model is changed from this panel
310      */

311     protected void endUIChange() {
312         dObj.modelUpdatedFromUI();
313         dObj.setChangedFromUI(false);
314     }
315     
316  }
317
Popular Tags