KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ui > ReferenceTablePanel


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 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui;
20
21 import org.netbeans.modules.j2ee.websphere6.dd.beans.*;
22 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject;
23
24 import org.netbeans.modules.xml.multiview.ui.*;
25 import org.openide.util.NbBundle;
26 import javax.swing.JComboBox JavaDoc;
27 /**
28  * ReferenceTablePanel - panel containing table for EJB references
29  *
30  *
31  * @author dlm198383
32  */

33 public class ReferenceTablePanel extends DefaultTablePanel implements DDXmiConstants{
34     private ReferencesTableModel model;
35     private EjbBindingsType ejbBinding;
36     private WSMultiViewDataObject dObj;
37     
38     
39     /** Creates new form ContextParamPanel */
40     public ReferenceTablePanel(final WSMultiViewDataObject dObj, final ReferencesTableModel model) {
41         super(model);
42         this.model=model;
43         this.dObj=dObj;
44     
45         
46         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
47             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
48                 dObj.setChangedFromUI(true);
49                 int row = getTable().getSelectedRow();
50                 model.removeRow(row);
51                 dObj.modelUpdatedFromUI();
52                 //dObj.setChangedFromUI(true);
53
dObj.setChangedFromUI(false);
54             }
55         });
56         editButton.addActionListener(new TableActionListener(false));
57         addButton.addActionListener(new TableActionListener(true));
58     }
59     
60     void setModel(EjbBindingsType ejbBinding, CommonRef []params) {
61         this.ejbBinding=ejbBinding;
62         model.setData(ejbBinding,params);
63     }
64     
65     
66     private class TableActionListener implements java.awt.event.ActionListener JavaDoc {
67         private boolean add;
68         TableActionListener(boolean add) {
69             this.add=add;
70         }
71         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
72             
73             final int row = (add?-1:getTable().getSelectedRow());
74             
75             final ReferencePanel dialogPanel = new ReferencePanel();
76             if(!add) {
77                 String JavaDoc type=(String JavaDoc)model.getValueAt(row,0);
78                 if(type.equals(BINDING_REFERENCE_TYPES[0])) {
79                     dialogPanel.getTypeComboBox().setSelectedIndex(0);
80                 }else if(type.equals(BINDING_REFERENCE_TYPES[1])) {
81                     dialogPanel.getTypeComboBox().setSelectedIndex(1);
82                 } else if(type.equals(BINDING_REFERENCE_TYPES[2])) {
83                     dialogPanel.getTypeComboBox().setSelectedIndex(2);
84                 }
85                 dialogPanel.getIdField().setText((String JavaDoc)model.getValueAt(row,1));
86                 dialogPanel.getJndiNameField().setText((String JavaDoc)model.getValueAt(row,2));
87                 dialogPanel.getHrefField().setText((String JavaDoc)model.getValueAt(row,3));
88                 dialogPanel.getTypeComboBox().setEnabled(false);
89             }
90             
91             EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ReferenceTablePanel.class,"TTL_PageParam"),add) {
92                 protected String JavaDoc validate() {
93                     String JavaDoc id = dialogPanel.getIdField().getText().trim();
94                     String JavaDoc jndiName = dialogPanel.getJndiNameField().getText().trim();
95                     String JavaDoc href = dialogPanel.getHrefField().getText().trim();
96                     if (id.length()==0) {
97                         return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceId");
98                     } else {
99                         CommonRef[] params = ejbBinding.getReferences();
100                         boolean exists=false;
101                         for (int i=0;i<params.length;i++) {
102                             if (row!=i && id.equals(params[i].getXmiId())) {
103                                 exists=true;
104                                 break;
105                             }
106                         }
107                         if (exists) {
108                             return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_ReferenceIdExists");
109                         }
110                     }
111                     
112                     if (jndiName.length()==0) {
113                         return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceJndiName");
114                     }
115                     
116                     if (href.length()==0) {
117                         return NbBundle.getMessage(ReferenceTablePanel.class,"TXT_EmptyReferenceHref");
118                     }
119                     return null;
120                 }
121             };
122             
123             if (add) dialog.setValid(false); // disable OK button
124
javax.swing.event.DocumentListener JavaDoc docListener = new EditDialog.DocListener(dialog);
125             dialogPanel.getJndiNameField().getDocument().addDocumentListener(docListener);
126             dialogPanel.getIdField().getDocument().addDocumentListener(docListener);
127             dialogPanel.getHrefField().getDocument().addDocumentListener(docListener);
128             
129             java.awt.Dialog JavaDoc d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
130             d.setVisible(true);
131             dialogPanel.getJndiNameField().getDocument().removeDocumentListener(docListener);
132             dialogPanel.getIdField().getDocument().removeDocumentListener(docListener);
133             dialogPanel.getHrefField().getDocument().removeDocumentListener(docListener);
134             
135             if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
136                 
137                 dObj.setChangedFromUI(true);
138                 String JavaDoc id = dialogPanel.getIdField().getText().trim();
139                 String JavaDoc jndiName = dialogPanel.getJndiNameField().getText().trim();
140                 String JavaDoc href = dialogPanel.getHrefField().getText().trim();
141                 String JavaDoc type=(String JavaDoc)dialogPanel.getTypeComboBox().getSelectedItem();
142                         
143                 if (add) {
144                     model.addRow(new String JavaDoc[]{type,id,jndiName,href});
145                 } else {
146                     model.editRow(row,new String JavaDoc[]{type,id,jndiName,href});
147                 }
148                 dObj.modelUpdatedFromUI();
149                 //dObj.setChangedFromUI(true);
150
dObj.setChangedFromUI(false);
151             }
152         }
153     }
154 }
155
Popular Tags