~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/ddloaders/src/org/netbeans/modules/j2ee/ddloaders/web/multiview/ContextParamsTablePanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.j2ee.ddloaders.web.multiview;
 
43
 
 
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;
 
51
 
 
52
/**
 
53
 *
 
54
 * @author  mk115033
 
55
 * Created on October 1, 2002, 3:52 PM
 
56
 */
 
57
public class ContextParamsTablePanel extends DefaultTablePanel {
 
58
    private InitParamTableModel model;
 
59
    private WebApp webApp;
 
60
    private DDDataObject dObj;
 
61
    
 
62
    /** Creates new form ContextParamPanel */
 
63
    public ContextParamsTablePanel(final DDDataObject dObj, final InitParamTableModel model) {
 
64
        super(model);
 
65
        this.model=model;
 
66
        this.dObj=dObj;
 
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();
 
72
                model.removeRow(row);
 
73
                dObj.setChangedFromUI(false);
 
74
            }
 
75
        });
 
76
        editButton.addActionListener(new TableActionListener(false));
 
77
        addButton.addActionListener(new TableActionListener(true));
 
78
    }
 
79
 
 
80
    void setModel(WebApp webApp, InitParam[] params) {
 
81
        model.setData(webApp,params);
 
82
        this.webApp=webApp;
 
83
    }
 
84
    
 
85
    private class TableActionListener implements java.awt.event.ActionListener {
 
86
        private boolean add;
 
87
        TableActionListener(boolean add) {
 
88
            this.add=add;
 
89
        }
 
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")
 
96
            };
 
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)
 
101
            };
 
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")
 
106
            };
 
107
            SimpleDialogPanel.DialogDescriptor descriptor = new SimpleDialogPanel.DialogDescriptor(labels);
 
108
            if (!add) {
 
109
                String[] initValues = new String[] {
 
110
                    (String)model.getValueAt(row,0),
 
111
                    (String)model.getValueAt(row,1),
 
112
                    (String)model.getValueAt(row,2)
 
113
                };
 
114
                descriptor.setInitValues(initValues);
 
115
            }
 
116
            descriptor.setMnemonics(mnem);
 
117
            descriptor.setTextField(new boolean[]{true,true,false});
 
118
            descriptor.setA11yDesc(a11y_desc);
 
119
            final SimpleDialogPanel dialogPanel = new SimpleDialogPanel(descriptor);
 
120
            if (add) {
 
121
                dialogPanel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_add_context_param"));
 
122
                dialogPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_add_context_param"));
 
123
            }else {
 
124
                dialogPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_edit_context_param"));
 
125
                dialogPanel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ContextParamsTablePanel.class,"ACSD_edit_context_param"));
 
126
            }
 
127
            
 
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");
 
135
                    } else {
 
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())) {
 
140
                                exists=true;
 
141
                                break;
 
142
                            }
 
143
                        }
 
144
                        if (exists) {
 
145
                            return NbBundle.getMessage(ContextParamsTablePanel.class,"TXT_InitParamNameExists",name);
 
146
                        }
 
147
                    }
 
148
                    if (value.length()==0) {
 
149
                        return NbBundle.getMessage(ContextParamsTablePanel.class,"TXT_EmptyInitParamValue");
 
150
                    }
 
151
                    return null;
 
152
                }
 
153
            };
 
154
            
 
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);
 
159
            
 
160
            java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
 
161
            d.setVisible(true);
 
162
            dialogPanel.getTextComponents()[0].getDocument().removeDocumentListener(docListener);
 
163
            dialogPanel.getTextComponents()[1].getDocument().removeDocumentListener(docListener);
 
164
            
 
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);
 
175
            }
 
176
        }
 
177
    }
 
178
}