KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > MessageDestRefsTablePanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ddloaders.web.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef;
23 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
24 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
25 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
26 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
27 import org.netbeans.modules.xml.multiview.ui.EditDialog;
28 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel;
29 import org.openide.util.NbBundle;
30
31 /** MessageDestRefsTablePanel - panel containing table for message destination references
32  *
33  * @author mk115033
34  * Created on April 14, 2005
35  */

36 public class MessageDestRefsTablePanel extends DefaultTablePanel {
37     private MessageDestRefTableModel model;
38     private WebApp webApp;
39     private DDDataObject dObj;
40     
41     /** Creates new form ContextParamPanel */
42     public MessageDestRefsTablePanel(final DDDataObject dObj, final MessageDestRefTableModel model) {
43         super(model);
44         this.model=model;
45         this.dObj=dObj;
46         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
47             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
48                 dObj.modelUpdatedFromUI();
49                 dObj.setChangedFromUI(true);
50                 int row = getTable().getSelectedRow();
51                 model.removeRow(row);
52                 dObj.setChangedFromUI(false);
53             }
54         });
55         editButton.addActionListener(new TableActionListener(false));
56         addButton.addActionListener(new TableActionListener(true));
57     }
58
59     void setModel(WebApp webApp, MessageDestinationRef[] params) {
60         model.setData(webApp,params);
61         this.webApp=webApp;
62     }
63     
64     private class TableActionListener implements java.awt.event.ActionListener JavaDoc {
65         private boolean add;
66         TableActionListener(boolean add) {
67             this.add=add;
68         }
69         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
70             
71             final int row = (add?-1:getTable().getSelectedRow());
72             final MessageDestRefPanel dialogPanel = new MessageDestRefPanel();
73             if (!add) {
74                 MessageDestinationRef resRef = model.getMessageDestRef(row);
75                 dialogPanel.setMessageDestRefName(resRef.getMessageDestinationRefName());
76                 dialogPanel.setMessageDestRefType(resRef.getMessageDestinationType());
77                 dialogPanel.setUsage(resRef.getMessageDestinationUsage());
78                 dialogPanel.setLink(resRef.getMessageDestinationLink()); //NOI18N
79
dialogPanel.setDescription(resRef.getDefaultDescription());
80             }
81             EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(MessageDestRefsTablePanel.class,"TTL_MessageDestRef"),add) {
82                 protected String JavaDoc validate() {
83                     String JavaDoc name = dialogPanel.getMessageDestRefName().trim();
84                     if (name.length()==0) {
85                         return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_EmptyMessageDestRefName");
86                     } else {
87                         try {
88                             MessageDestinationRef[] params = webApp.getMessageDestinationRef();
89                             boolean exists=false;
90                             for (int i=0;i<params.length;i++) {
91                                 if (row!=i && name.equals(params[i].getMessageDestinationRefName())) {
92                                     exists=true;
93                                     break;
94                                 }
95                             }
96                             if (exists) {
97                                 return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestRefNameExists",name);
98                             }
99                         } catch (VersionNotSupportedException ex) {
100                             return NbBundle.getMessage(MessageDestRefsTablePanel.class,"TXT_MessageDestNotSupported");
101                         }
102                     }
103                     return null;
104                 }
105             };
106             
107             if (add) dialog.setValid(false); // disable OK button
108
javax.swing.event.DocumentListener JavaDoc docListener = new EditDialog.DocListener(dialog);
109             dialogPanel.getNameTF().getDocument().addDocumentListener(docListener);;
110             
111             java.awt.Dialog JavaDoc d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
112             d.setVisible(true);
113             dialogPanel.getNameTF().getDocument().removeDocumentListener(docListener);
114             
115             if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
116                 dObj.modelUpdatedFromUI();
117                 dObj.setChangedFromUI(true);
118                 String JavaDoc name = dialogPanel.getMessageDestRefName().trim();
119                 String JavaDoc type = dialogPanel.getMessageDestRefType();
120                 String JavaDoc usage = dialogPanel.getUsage();
121                 String JavaDoc link = dialogPanel.getLink().trim();
122                 String JavaDoc description = dialogPanel.getDescription();
123                 if (add) model.addRow(new String JavaDoc[]{name,type,usage,link,description});
124                 else model.editRow(row,new String JavaDoc[]{name,type,usage,link,description});
125                 dObj.setChangedFromUI(false);
126             }
127         }
128     }
129 }
130
Popular Tags