001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.ddloaders.web.multiview;
043:
044: import org.netbeans.modules.j2ee.dd.api.common.EnvEntry;
045: import org.netbeans.modules.j2ee.dd.api.web.WebApp;
046: import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
047: import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
048: import org.netbeans.modules.xml.multiview.ui.EditDialog;
049: import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel;
050: import org.openide.util.NbBundle;
051:
052: /** EnvEntriesTablePanel - panel containing table for env-entries
053: *
054: * @author mk115033
055: * Created on April 11, 2005
056: */
057: public class EnvEntriesTablePanel extends DefaultTablePanel {
058: private EnvEntryTableModel model;
059: private WebApp webApp;
060: private DDDataObject dObj;
061:
062: /** Creates new form ContextParamPanel */
063: public EnvEntriesTablePanel(final DDDataObject dObj,
064: final EnvEntryTableModel model) {
065: super (model);
066: this .model = model;
067: this .dObj = dObj;
068: removeButton
069: .addActionListener(new java.awt.event.ActionListener() {
070: public void actionPerformed(
071: java.awt.event.ActionEvent evt) {
072: dObj.modelUpdatedFromUI();
073: dObj.setChangedFromUI(true);
074: int row = getTable().getSelectedRow();
075: model.removeRow(row);
076: dObj.setChangedFromUI(false);
077: }
078: });
079: editButton.addActionListener(new TableActionListener(false));
080: addButton.addActionListener(new TableActionListener(true));
081: }
082:
083: void setModel(WebApp webApp, EnvEntry[] params) {
084: model.setData(webApp, params);
085: this .webApp = webApp;
086: }
087:
088: private class TableActionListener implements
089: java.awt.event.ActionListener {
090: private boolean add;
091:
092: TableActionListener(boolean add) {
093: this .add = add;
094: }
095:
096: public void actionPerformed(java.awt.event.ActionEvent evt) {
097:
098: final int row = (add ? -1 : getTable().getSelectedRow());
099: final EnvEntryPanel dialogPanel = new EnvEntryPanel();
100: if (!add) {
101: EnvEntry envEntry = model.getEnvEntry(row);
102: dialogPanel.setEnvEntryName(envEntry.getEnvEntryName());
103: dialogPanel.setEnvEntryType(envEntry.getEnvEntryType());
104: dialogPanel.setEnvEntryValue(envEntry
105: .getEnvEntryValue());
106: dialogPanel.setDescription(envEntry
107: .getDefaultDescription());
108: }
109: EditDialog dialog = new EditDialog(dialogPanel, NbBundle
110: .getMessage(EnvEntriesTablePanel.class,
111: "TTL_EnvEntry"), add) {
112: protected String validate() {
113: String name = dialogPanel.getEnvEntryName().trim();
114: if (name.length() == 0) {
115: return NbBundle.getMessage(
116: EnvEntriesTablePanel.class,
117: "TXT_EmptyEnvEntryName");
118: } else {
119: EnvEntry[] params = webApp.getEnvEntry();
120: boolean exists = false;
121: for (int i = 0; i < params.length; i++) {
122: if (row != i
123: && name.equals(params[i]
124: .getEnvEntryName())) {
125: exists = true;
126: break;
127: }
128: }
129: if (exists) {
130: return NbBundle.getMessage(
131: EnvEntriesTablePanel.class,
132: "TXT_EnvEntryNameExists", name);
133: }
134: }
135: return null;
136: }
137: };
138:
139: if (add)
140: dialog.setValid(false); // disable OK button
141: javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(
142: dialog);
143: dialogPanel.getNameTF().getDocument().addDocumentListener(
144: docListener);
145:
146: java.awt.Dialog d = org.openide.DialogDisplayer
147: .getDefault().createDialog(dialog);
148: d.setVisible(true);
149: dialogPanel.getNameTF().getDocument()
150: .removeDocumentListener(docListener);
151:
152: if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
153: dObj.modelUpdatedFromUI();
154: dObj.setChangedFromUI(true);
155: String name = dialogPanel.getEnvEntryName().trim();
156: String type = dialogPanel.getEnvEntryType();
157: String value = dialogPanel.getEnvEntryValue().trim();
158: String description = dialogPanel.getDescription();
159: if (add)
160: model.addRow(new String[] { name, type, value,
161: description });
162: else
163: model.editRow(row, new String[] { name, type,
164: value, description });
165: dObj.setChangedFromUI(false);
166: }
167: }
168: }
169: }
|