2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.ddloaders.web.multiview;
44
import org.netbeans.modules.j2ee.dd.api.web.Filter;
45
import org.netbeans.modules.j2ee.dd.api.web.FilterMapping;
46
import org.netbeans.modules.j2ee.ddloaders.web.*;
47
import org.netbeans.modules.xml.multiview.ui.*;
48
import org.netbeans.modules.xml.multiview.Utils;
49
import org.netbeans.modules.xml.multiview.Error;
50
import org.netbeans.api.project.SourceGroup;
51
import org.openide.util.NbBundle;
56
public class FilterPanel extends SectionInnerPanel {
57
private DDDataObject dObj;
58
private Filter filter;
59
private javax.swing.JButton linkButton;
60
private FilterParamsPanel filterParamsPanel;
61
private FilterMappingsTablePanel filterMappingsPanel;
63
/** Creates new form FilterPanel */
64
public FilterPanel(SectionView sectionView, DDDataObject dObj,Filter filter) {
71
filterNameTF.setText(filter.getFilterName());
72
addValidatee(filterNameTF);
75
Utils.makeTextAreaLikeTextField(descriptionTA,filterNameTF);
76
descriptionTA.setText(filter.getDefaultDescription());
77
addModifier(descriptionTA);
81
InitParamTableModel model = new InitParamTableModel();
82
filterParamsPanel = new FilterParamsPanel(dObj, model);
83
filterParamsPanel.setModel(filter,filter.getInitParam());
84
java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
85
gridBagConstraints.gridx = 0;
86
gridBagConstraints.gridy = java.awt.GridBagConstraints.RELATIVE;
87
gridBagConstraints.gridwidth = 4;
88
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
89
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
90
gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
91
add(filterParamsPanel, gridBagConstraints);
93
filterClassTF.setText(filter.getFilterClass());
94
addValidatee(filterClassTF);
96
linkButton = new LinkButton(this, filter, "ClassName"); //NOI18N
97
gridBagConstraints = new java.awt.GridBagConstraints();
98
gridBagConstraints.gridx = 3;
99
gridBagConstraints.gridy = 2;
100
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
101
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
102
gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
103
linkButton.setText(NbBundle.getMessage(FilterPanel.class, "LBL_goToSource"));
104
add(linkButton, gridBagConstraints);
108
private void setAccessibility() {
109
linkButton.setMnemonic(NbBundle.getMessage(FilterPanel.class, "LBL_goToSource_mnem").charAt(0));
110
filterParamsLabel.setLabelFor(filterParamsPanel.getTable());
113
public void linkButtonPressed(Object ddBean, String property) {
114
if ("ClassName".equals(property)) { // NOI18N
115
DDUtils.openEditorFor(dObj,((Filter)ddBean).getFilterClass());
119
/** This method is called from within the constructor to
120
* initialize the form.
121
* WARNING: Do NOT modify this code. The content of this method is
122
* always regenerated by the Form Editor.
124
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
125
private void initComponents() {
126
java.awt.GridBagConstraints gridBagConstraints;
128
filterNameLabel = new javax.swing.JLabel();
129
filterNameTF = new javax.swing.JTextField();
130
descriptionLabel = new javax.swing.JLabel();
131
descriptionTA = new javax.swing.JTextArea();
132
filterClassLabel = new javax.swing.JLabel();
133
filterClassTF = new javax.swing.JTextField();
134
browseButton = new javax.swing.JButton();
135
filler = new javax.swing.JPanel();
136
filterParamsLabel = new javax.swing.JLabel();
138
setLayout(new java.awt.GridBagLayout());
140
filterNameLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterName_mnem").charAt(0));
141
filterNameLabel.setLabelFor(filterNameTF);
142
filterNameLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterName"));
143
gridBagConstraints = new java.awt.GridBagConstraints();
144
gridBagConstraints.gridx = 0;
145
gridBagConstraints.gridy = 0;
146
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
147
gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 10);
148
add(filterNameLabel, gridBagConstraints);
150
filterNameTF.setColumns(30);
151
gridBagConstraints = new java.awt.GridBagConstraints();
152
gridBagConstraints.gridx = 1;
153
gridBagConstraints.gridy = 0;
154
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
156
add(filterNameTF, gridBagConstraints);
158
descriptionLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_description_mnem").charAt(0));
159
descriptionLabel.setLabelFor(descriptionTA);
160
descriptionLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_description"));
161
gridBagConstraints = new java.awt.GridBagConstraints();
162
gridBagConstraints.gridx = 0;
163
gridBagConstraints.gridy = 1;
164
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165
gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 10);
166
add(descriptionLabel, gridBagConstraints);
168
descriptionTA.setRows(3);
169
gridBagConstraints = new java.awt.GridBagConstraints();
170
gridBagConstraints.gridx = 1;
171
gridBagConstraints.gridy = 1;
172
gridBagConstraints.gridwidth = 3;
173
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
174
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
175
add(descriptionTA, gridBagConstraints);
177
filterClassLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterClass_mnem").charAt(0));
178
filterClassLabel.setLabelFor(filterClassTF);
179
filterClassLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_filterClass"));
180
gridBagConstraints = new java.awt.GridBagConstraints();
181
gridBagConstraints.gridx = 0;
182
gridBagConstraints.gridy = 2;
183
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
184
gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 10);
185
add(filterClassLabel, gridBagConstraints);
187
gridBagConstraints = new java.awt.GridBagConstraints();
188
gridBagConstraints.gridx = 1;
189
gridBagConstraints.gridy = 2;
190
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
192
add(filterClassTF, gridBagConstraints);
194
browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_browse_mnem").charAt(0));
195
browseButton.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_browse"));
196
browseButton.setMargin(new java.awt.Insets(0, 14, 0, 14));
197
browseButton.addActionListener(new java.awt.event.ActionListener() {
198
public void actionPerformed(java.awt.event.ActionEvent evt) {
199
browseButtonActionPerformed(evt);
203
gridBagConstraints = new java.awt.GridBagConstraints();
204
gridBagConstraints.gridx = 2;
205
gridBagConstraints.gridy = 2;
206
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
207
gridBagConstraints.insets = new java.awt.Insets(3, 5, 0, 0);
208
add(browseButton, gridBagConstraints);
210
filler.setOpaque(false);
211
gridBagConstraints = new java.awt.GridBagConstraints();
212
gridBagConstraints.gridx = 4;
213
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
214
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
215
gridBagConstraints.weightx = 1.0;
216
add(filler, gridBagConstraints);
218
filterParamsLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_initParams_mnem").charAt(0));
219
filterParamsLabel.setText(org.openide.util.NbBundle.getMessage(FilterPanel.class, "LBL_initParams"));
220
gridBagConstraints = new java.awt.GridBagConstraints();
221
gridBagConstraints.gridx = 0;
222
gridBagConstraints.gridy = 3;
223
gridBagConstraints.gridwidth = 5;
224
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
225
gridBagConstraints.insets = new java.awt.Insets(15, 10, 0, 0);
226
add(filterParamsLabel, gridBagConstraints);
229
// </editor-fold>//GEN-END:initComponents
231
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
232
// TODO add your handling code here:
234
SourceGroup[] groups = DDUtils.getJavaSourceGroups(dObj);
235
org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
237
String className = DDUtils.getResourcePath(groups,fo);
238
if (className.length()>0 && !className.equals(filterClassTF.getText())) {
239
dObj.modelUpdatedFromUI();
240
dObj.setChangedFromUI(true);
241
filterClassTF.setText(className);
242
filter.setFilterClass(className);
243
dObj.setChangedFromUI(false);
244
getSectionView().checkValidity();
247
} catch (java.io.IOException ex) {}
248
}//GEN-LAST:event_browseButtonActionPerformed
251
// Variables declaration - do not modify//GEN-BEGIN:variables
252
private javax.swing.JButton browseButton;
253
private javax.swing.JLabel descriptionLabel;
254
private javax.swing.JTextArea descriptionTA;
255
private javax.swing.JPanel filler;
256
private javax.swing.JLabel filterClassLabel;
257
private javax.swing.JTextField filterClassTF;
258
private javax.swing.JLabel filterNameLabel;
259
private javax.swing.JTextField filterNameTF;
260
private javax.swing.JLabel filterParamsLabel;
261
// End of variables declaration//GEN-END:variables
263
public javax.swing.JComponent getErrorComponent(String name) {
264
if ("FilterName".equals(name)) return filterNameTF; //NOI18N
265
else if ("FilterClass".equals(name)) return filterClassTF; //NOI18N
269
public void documentChanged(javax.swing.text.JTextComponent comp, String value) {
270
if (comp==filterNameTF) {
271
String val = (String)value;
272
if (val.length()==0) {
273
getSectionView().getErrorPanel().setError(new Error(Error.MISSING_VALUE_MESSAGE, "Filter Name",filterNameTF));
276
Filter[] filters = dObj.getWebApp().getFilter();
277
for (int i=0;i<filters.length;i++) {
278
if (filter!=filters[i] && val.equals(filters[i].getFilterName())) {
279
getSectionView().getErrorPanel().setError(new Error(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, filterNameTF));
283
getSectionView().getErrorPanel().clearError();
284
} else if (comp==filterClassTF) {
285
String text = (String)value;
286
if (text.length()==0) {
287
getSectionView().getErrorPanel().setError(new Error(Error.MISSING_VALUE_MESSAGE, "Filter Class",filterClassTF));
290
getSectionView().getErrorPanel().clearError();
294
public void setValue(javax.swing.JComponent source, Object value) {
295
if (source==filterNameTF) {
296
String text = (String)value;
297
// change Filter-mappings
298
FilterMapping[] maps = DDUtils.getFilterMappings(dObj.getWebApp(), filter);
299
for (int i=0;i<maps.length;i++) {
300
maps[i].setFilterName(text);
302
// change Filter-name
303
filter.setFilterName(text);
304
//change panel title, node name
305
SectionPanel enclosingPanel = getSectionView().findSectionPanel(filter);
306
enclosingPanel.setTitle(((FiltersMultiViewElement.FiltersView)getSectionView()).getFilterTitle(filter));
307
enclosingPanel.getNode().setDisplayName(text);
308
} else if (source==filterClassTF) {
309
String text = (String)value;
310
filter.setFilterClass(text.length()==0?null:text);
311
} else if (source==descriptionTA) {
312
String text = (String)value;
313
filter.setDescription(text.length()==0?null:text);
317
public void rollbackValue(javax.swing.text.JTextComponent source) {
318
if (source==filterNameTF) {
319
filterNameTF.setText(filter.getFilterName());
320
} else if (source==filterClassTF) {
321
filterClassTF.setText(filter.getFilterClass());
325
/** This will be called before model is changed from this panel
327
protected void startUIChange() {
328
dObj.setChangedFromUI(true);
331
/** This will be called after model is changed from this panel
333
protected void endUIChange() {
334
dObj.modelUpdatedFromUI();
335
dObj.setChangedFromUI(false);