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: package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui;
042:
043: import org.netbeans.modules.j2ee.websphere6.dd.beans.*;
044: import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject;
045:
046: import org.netbeans.modules.xml.multiview.ui.*;
047: import org.openide.util.NbBundle;
048: import javax.swing.JComboBox;
049:
050: /**
051: * PagesTablePanel - panel containing table for EJB references
052: *
053: *
054: * @author dlm198383
055: */
056: public class PagesTablePanel extends DefaultTablePanel {
057: private PageTableModel model;
058: private MarkupLanguagesType markupLanguage;
059: private WSMultiViewDataObject dObj;
060: private final JComboBox errorPageComboBox;
061: private final JComboBox defaultPageComboBox;
062:
063: /** Creates new form ContextParamPanel */
064: public PagesTablePanel(final WSMultiViewDataObject dObj,
065: final PageTableModel model,
066: final JComboBox errorPageComboBox,
067: final JComboBox defaultPageComboBox) {
068: super (model);
069: this .model = model;
070: this .dObj = dObj;
071: this .errorPageComboBox = errorPageComboBox;
072: this .defaultPageComboBox = defaultPageComboBox;
073: removeButton
074: .addActionListener(new java.awt.event.ActionListener() {
075: public void actionPerformed(
076: java.awt.event.ActionEvent evt) {
077: dObj.setChangedFromUI(true);
078: int row = getTable().getSelectedRow();
079:
080: String selectedItem = (String) errorPageComboBox
081: .getSelectedItem();
082: String deleteItem = (String) getModel()
083: .getValueAt(row, 0);
084:
085: errorPageComboBox.removeItem(deleteItem);
086: if (selectedItem.equals(deleteItem)) {
087: errorPageComboBox.setSelectedIndex(-1);
088: }
089: errorPageComboBox.updateUI();
090:
091: selectedItem = (String) defaultPageComboBox
092: .getSelectedItem();
093: defaultPageComboBox.removeItem(getModel()
094: .getValueAt(row, 0));
095: if (selectedItem.equals(deleteItem)) {
096: defaultPageComboBox.setSelectedIndex(-1);
097: }
098: defaultPageComboBox.updateUI();
099: model.removeRow(row);
100: dObj.modelUpdatedFromUI();
101: //dObj.setChangedFromUI(true);
102: dObj.setChangedFromUI(false);
103: }
104: });
105: editButton.addActionListener(new TableActionListener(false));
106: addButton.addActionListener(new TableActionListener(true));
107: }
108:
109: void setModel(MarkupLanguagesType markupLanguage, PageType[] params) {
110: this .markupLanguage = markupLanguage;
111: model.setData(markupLanguage, params);
112: }
113:
114: private class TableActionListener implements
115: java.awt.event.ActionListener {
116: private boolean add;
117:
118: TableActionListener(boolean add) {
119: this .add = add;
120: }
121:
122: public void actionPerformed(java.awt.event.ActionEvent evt) {
123:
124: final int row = (add ? -1 : getTable().getSelectedRow());
125:
126: final PagePanel dialogPanel = new PagePanel();
127: if (!add) {
128: dialogPanel.getIdField().setText(
129: (String) model.getValueAt(row, 0));
130: dialogPanel.getNameField().setText(
131: (String) model.getValueAt(row, 1));
132: dialogPanel.getUriField().setText(
133: (String) model.getValueAt(row, 2));
134: }
135:
136: EditDialog dialog = new EditDialog(dialogPanel,
137: NbBundle.getMessage(PagesTablePanel.class,
138: "TTL_PageParam"), add) {
139: protected String validate() {
140: String id = dialogPanel.getIdField().getText()
141: .trim();
142: String name = dialogPanel.getNameField().getText()
143: .trim();
144: String uri = dialogPanel.getUriField().getText()
145: .trim();
146: if (id.length() == 0) {
147: return NbBundle.getMessage(
148: PagesTablePanel.class,
149: "TXT_EmptyPageId");
150: } else {
151: PageType[] params = markupLanguage.getPages();
152: boolean exists = false;
153: for (int i = 0; i < params.length; i++) {
154: if (row != i
155: && id.equals(params[i].getXmiId())) {
156: exists = true;
157: break;
158: }
159: }
160: if (exists) {
161: return NbBundle.getMessage(
162: PagesTablePanel.class,
163: "TXT_PageIdExists", name);
164: }
165: }
166:
167: if (name.length() == 0) {
168: return NbBundle.getMessage(
169: PagesTablePanel.class,
170: "TXT_EmptyPageName");
171: }
172:
173: if (uri.length() == 0) {
174: return NbBundle.getMessage(
175: PagesTablePanel.class,
176: "TXT_EmptyPageUri");
177: }
178: return null;
179: }
180: };
181:
182: if (add)
183: dialog.setValid(false); // disable OK button
184: javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(
185: dialog);
186: dialogPanel.getNameField().getDocument()
187: .addDocumentListener(docListener);
188: dialogPanel.getIdField().getDocument().addDocumentListener(
189: docListener);
190: dialogPanel.getUriField().getDocument()
191: .addDocumentListener(docListener);
192:
193: java.awt.Dialog d = org.openide.DialogDisplayer
194: .getDefault().createDialog(dialog);
195: d.setVisible(true);
196: dialogPanel.getNameField().getDocument()
197: .removeDocumentListener(docListener);
198: dialogPanel.getIdField().getDocument()
199: .removeDocumentListener(docListener);
200: dialogPanel.getUriField().getDocument()
201: .removeDocumentListener(docListener);
202:
203: if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
204:
205: String id = dialogPanel.getIdField().getText().trim();
206: String name = dialogPanel.getNameField().getText()
207: .trim();
208: String uri = dialogPanel.getUriField().getText().trim();
209: dObj.setChangedFromUI(true);
210: if (add) {
211: model.addRow(new String[] { id, name, uri });
212: int selectedIndex = errorPageComboBox
213: .getSelectedIndex();
214: errorPageComboBox.addItem(id);
215: errorPageComboBox.setSelectedIndex(selectedIndex);
216: selectedIndex = defaultPageComboBox
217: .getSelectedIndex();
218: defaultPageComboBox.addItem(id);
219: defaultPageComboBox.setSelectedIndex(selectedIndex);
220: } else {
221: String oldPageId = (String) model
222: .getValueAt(row, 0);
223: model.editRow(row, new String[] { id, name, uri });
224: for (int i = 0; i < errorPageComboBox
225: .getItemCount(); i++) {
226: if (errorPageComboBox.getItemAt(i).equals(
227: oldPageId)) {
228: int selectedItem = errorPageComboBox
229: .getSelectedIndex();
230: errorPageComboBox.removeItemAt(i);
231: errorPageComboBox.insertItemAt(id, i);
232: errorPageComboBox
233: .setSelectedIndex(selectedItem);
234: errorPageComboBox.updateUI();
235:
236: selectedItem = defaultPageComboBox
237: .getSelectedIndex();
238: defaultPageComboBox.removeItemAt(i);
239: defaultPageComboBox.insertItemAt(id, i);
240: defaultPageComboBox
241: .setSelectedIndex(selectedItem);
242: defaultPageComboBox.updateUI();
243: break;
244: }
245: }
246: }
247: dObj.modelUpdatedFromUI();
248: //dObj.setChangedFromUI(true);
249: dObj.setChangedFromUI(false);
250: }
251: }
252: }
253: }
|