KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > EjbReferencesTableModel


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.multiview;
21
22 import org.netbeans.modules.j2ee.ejbcore.api.ui.CallEjb;
23 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef;
24 import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
25 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
26 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
27 import org.netbeans.modules.xml.multiview.ui.ConfirmDialog;
28 import org.openide.util.NbBundle;
29
30 /**
31  * @author pfiala
32  */

33 public class EjbReferencesTableModel extends InnerTableModel {
34     
35     private XmlMultiViewDataObject dataObject;
36     Ejb ejb;
37     private static final String JavaDoc[] COLUMN_NAMES = {
38         NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_ReferenceName"),
39         NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_LinkedEjb"),
40         NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_Interface"),
41         NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_Description")};
42     private static final int[] COLUMN_WIDTHS = new int[]{170, 260, 70, 250};
43     
44     public EjbReferencesTableModel(XmlMultiViewDataObject dataObject, Ejb ejb) {
45         super(((EjbJarMultiViewDataObject)dataObject).getModelSynchronizer(), COLUMN_NAMES, COLUMN_WIDTHS);
46         this.dataObject = dataObject;
47         this.ejb = ejb;
48     }
49     
50     public int getRowCount() {
51         return ejb.getEjbLocalRef().length + ejb.getEjbRef().length;
52     }
53     
54     public boolean isCellEditable(int row, int column) {
55         return isColumnEditable(column);
56     }
57     
58     public int addRow() {
59 // JavaClass beanClass = (JavaClass) JMIUtils.resolveType(ejb.getEjbClass());
60
// if (CallEjb.showCallEjbDialog(beanClass, NbBundle.getMessage(EjbReferencesTableModel.class, "LBL_AddEjbReference"))) { // NOI18N
61
// modelUpdatedFromUI();
62
// }
63
return -1;
64     }
65     
66     public void removeRow(int selectedRow) {
67         org.openide.DialogDescriptor desc = new ConfirmDialog(NbBundle.getMessage(EjbReferencesTableModel.class,"LBL_RemoveEjbRefWarning"));
68         java.awt.Dialog JavaDoc dialog = org.openide.DialogDisplayer.getDefault().createDialog(desc);
69         dialog.setVisible(true);
70         if (org.openide.DialogDescriptor.OK_OPTION.equals(desc.getValue())) {
71             EjbLocalRef localRef = ejb.getEjbLocalRef(selectedRow);
72             if (localRef != null){
73                 ejb.removeEjbLocalRef(localRef);
74             } else {
75                 EjbRef ref = ejb.getEjbRef(selectedRow);
76                 if (ref != null){
77                     ejb.removeEjbRef(ref);
78                 }
79             }
80             modelUpdatedFromUI();
81         }
82     }
83     
84     
85     
86     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
87         int n = ejb.getEjbLocalRef().length;
88         if (rowIndex < n) {
89             EjbLocalRef ref = ejb.getEjbLocalRef(rowIndex);
90             switch (columnIndex) {
91                 case 0:
92                     return ref.getEjbRefName();
93                 case 1:
94                     return ref.getEjbLink();
95                 case 2:
96                     return "local"; //NOI18N
97
case 3:
98                     return ref.getDefaultDescription();
99             }
100         } else {
101             EjbRef ref = ejb.getEjbRef(rowIndex - n);
102             switch (columnIndex) {
103                 case 0:
104                     return ref.getEjbRefName();
105                 case 1:
106                     return ref.getEjbLink();
107                 case 2:
108                     return "remote"; //NOI18N
109
case 3:
110                     return ref.getDefaultDescription();
111             }
112         }
113         return null;
114     }
115     
116     public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {
117         if (!isColumnEditable(columnIndex)){
118             return;
119         }
120         EjbRef ref = ejb.getEjbRef(rowIndex);
121         if (ref != null){
122             ref.setDescription((String JavaDoc) aValue);
123         } else {
124             EjbLocalRef localRef = ejb.getEjbLocalRef(rowIndex);
125             if (localRef != null){
126                 localRef.setDescription((String JavaDoc) aValue);
127             }
128         }
129         modelUpdatedFromUI();
130     }
131     
132     
133     private boolean isColumnEditable(int columnIndex){
134         // only description is editable
135
return columnIndex == 3;
136     }
137     
138 }
139
Popular Tags