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.MessageDestinationRef;
45
import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
46
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
47
import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
48
import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
49
import org.netbeans.modules.xml.multiview.ui.EditDialog;
50
import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel;
51
import org.openide.util.NbBundle;
53
/** MessageDestRefsTablePanel - panel containing table for message destination references
56
* Created on April 14, 2005
58
public class MessageDestRefsTablePanel extends DefaultTablePanel {
59
private MessageDestRefTableModel model;
60
private WebApp webApp;
61
private DDDataObject dObj;
63
/** Creates new form ContextParamPanel */
64
public MessageDestRefsTablePanel(final DDDataObject dObj, final MessageDestRefTableModel model) {
68
removeButton.addActionListener(new java.awt.event.ActionListener() {
69
public void actionPerformed(java.awt.event.ActionEvent evt) {
70
dObj.modelUpdatedFromUI();
71
dObj.setChangedFromUI(true);
72
int row = getTable().getSelectedRow();
74
dObj.setChangedFromUI(false);
77
editButton.addActionListener(new TableActionListener(false));
78
addButton.addActionListener(new TableActionListener(true));
81
void setModel(WebApp webApp, MessageDestinationRef[] params) {
82
model.setData(webApp,params);
86
private class TableActionListener implements java.awt.event.ActionListener {
88
TableActionListener(boolean add) {
91
public void actionPerformed(java.awt.event.ActionEvent evt) {
93
final int row = (add?-1:getTable().getSelectedRow());
94
final MessageDestRefPanel dialogPanel = new MessageDestRefPanel();
96
MessageDestinationRef resRef = model.getMessageDestRef(row);
97
dialogPanel.setMessageDestRefName(resRef.getMessageDestinationRefName());
98
dialogPanel.setMessageDestRefType(resRef.getMessageDestinationType());
99
dialogPanel.setUsage(resRef.getMessageDestinationUsage());
100
dialogPanel.setLink(resRef.getMessageDestinationLink()); //NOI18N
101
dialogPanel.setDescription(resRef.getDefaultDescription());
103
EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(MessageDestRefsTablePanel.class,"TTL_MessageDestRef"),add) {
104
protected String validate() {
105
String name = dialogPanel.getMessageDestRefName().trim();
106
if (name.length()==0) {
107
return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_EmptyMessageDestRefName");
110
MessageDestinationRef[] params = webApp.getMessageDestinationRef();
111
boolean exists=false;
112
for (int i=0;i<params.length;i++) {
113
if (row!=i && name.equals(params[i].getMessageDestinationRefName())) {
119
return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestRefNameExists",name);
121
} catch (VersionNotSupportedException ex) {
122
return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestNotSupported");
129
if (add) dialog.setValid(false); // disable OK button
130
javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog);
131
dialogPanel.getNameTF().getDocument().addDocumentListener(docListener);;
133
java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
135
dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener);
137
if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
138
dObj.modelUpdatedFromUI();
139
dObj.setChangedFromUI(true);
140
String name = dialogPanel.getMessageDestRefName().trim();
141
String type = dialogPanel.getMessageDestRefType();
142
String usage = dialogPanel.getUsage();
143
String link = dialogPanel.getLink().trim();
144
String description = dialogPanel.getDescription();
145
if (add) model.addRow(new String[]{name,type,usage,link,description});
146
else model.editRow(row,new String[]{name,type,usage,link,description});
147
dObj.setChangedFromUI(false);