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.common.InitParam;
45
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
46
import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
47
import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
48
import org.netbeans.modules.xml.multiview.ui.EditDialog;
49
import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel;
50
import org.openide.util.NbBundle;
55
* Created on October 1, 2002, 3:52 PM
57
public class ContextParamsTablePanel extends DefaultTablePanel {
58
private InitParamTableModel model;
59
private WebApp webApp;
60
private DDDataObject dObj;
62
/** Creates new form ContextParamPanel */
63
public ContextParamsTablePanel(final DDDataObject dObj, final InitParamTableModel model) {
67
removeButton.addActionListener(new java.awt.event.ActionListener() {
68
public void actionPerformed(java.awt.event.ActionEvent evt) {
69
dObj.modelUpdatedFromUI();
70
dObj.setChangedFromUI(true);
71
int row = getTable().getSelectedRow();
73
dObj.setChangedFromUI(false);
76
editButton.addActionListener(new TableActionListener(false));
77
addButton.addActionListener(new TableActionListener(true));
80
void setModel(WebApp webApp, InitParam[] params) {
81
model.setData(webApp,params);
85
private class TableActionListener implements java.awt.event.ActionListener {
87
TableActionListener(boolean add) {
90
public void actionPerformed(java.awt.event.ActionEvent evt) {
91
final int row = (add?-1:getTable().getSelectedRow());
92
String[] labels = new String[]{
93
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_initParamName"),
94
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_initParamValue"),
95
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_description")
97
char[] mnem = new char[] {
98
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_initParamName_mnem").charAt(0),
99
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_initParamValue_mnem").charAt(0),
100
NbBundle.getMessage(ContextParamsTablePanel.class,"LBL_description_mnem").charAt(0)
102
String[] a11y_desc = new String[]{
103
NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_context_param_name"),
104
NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_context_param_value"),
105
NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_context_param_desc")
107
SimpleDialogPanel.DialogDescriptor descriptor = new SimpleDialogPanel.DialogDescriptor(labels);
109
String[] initValues = new String[] {
110
(String)model.getValueAt(row,0),
111
(String)model.getValueAt(row,1),
112
(String)model.getValueAt(row,2)
114
descriptor.setInitValues(initValues);
116
descriptor.setMnemonics(mnem);
117
descriptor.setTextField(new boolean[]{true,true,false});
118
descriptor.setA11yDesc(a11y_desc);
119
final SimpleDialogPanel dialogPanel = new SimpleDialogPanel(descriptor);
121
dialogPanel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_add_context_param"));
122
dialogPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_add_context_param"));
124
dialogPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_edit_context_param"));
125
dialogPanel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_edit_context_param"));
128
EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ContextParamsTablePanel.class,"TTL_ContextParam"),add) {
129
protected String validate() {
130
String[] values = dialogPanel.getValues();
131
String name = values[0];
132
String value = values[1];
133
if (name.length()==0) {
134
return NbBundle.getMessage(ContextParamsTablePanel.class,"TXT_EmptyInitParamName");
136
InitParam[] params = webApp.getContextParam();
137
boolean exists=false;
138
for (int i=0;i<params.length;i++) {
139
if (row!=i && name.equals(params[i].getParamName())) {
145
return NbBundle.getMessage(ContextParamsTablePanel.class,"TXT_InitParamNameExists",name);
148
if (value.length()==0) {
149
return NbBundle.getMessage(ContextParamsTablePanel.class,"TXT_EmptyInitParamValue");
155
if (add) dialog.setValid(false); // disable OK button
156
javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog);
157
dialogPanel.getTextComponents()[0].getDocument().addDocumentListener(docListener);
158
dialogPanel.getTextComponents()[1].getDocument().addDocumentListener(docListener);
160
java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
162
dialogPanel.getTextComponents()[0].getDocument().removeDocumentListener(docListener);
163
dialogPanel.getTextComponents()[1].getDocument().removeDocumentListener(docListener);
165
if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
166
dObj.modelUpdatedFromUI();
167
dObj.setChangedFromUI(true);
168
String[] values = dialogPanel.getValues();
169
String name = values[0];
170
String value = values[1];
171
String description = values[2];
172
if (add) model.addRow(new String[]{name,value,description});
173
else model.editRow(row,new String[]{name,value,description});
174
dObj.setChangedFromUI(false);