KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** EjbRefTableModel - table model for EJB references and EJB Local References
23  *
24  * Created on April 11, 2005
25  * @author mkuchtiak
26  */

27 import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
28 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef;
29 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
30 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
31 import org.openide.util.NbBundle;
32
33 public class EjbRefTableModel extends DDBeanTableModel
34 {
35     private static final String JavaDoc[] columnNames = {
36             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbRefName"),
37             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbRefType"),
38             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbInterfaceType"),
39             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbHome"),
40             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbInterface"),
41             NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbLink"),
42             NbBundle.getMessage(EjbRefTableModel.class,"TTL_Description")
43         };
44
45         protected String JavaDoc[] getColumnNames() {
46             return columnNames;
47         }
48
49     public void setValueAt(Object JavaDoc value, int row, int column)
50     {
51         CommonDDBean ref = getEjbRef(row);
52                 if (ref instanceof EjbRef) {
53                     EjbRef param = (EjbRef)ref;
54                     if (column == 0) param.setEjbRefName((String JavaDoc)value);
55                     else if (column == 1) param.setEjbRefType((String JavaDoc)value);
56                     else if (column == 3) param.setHome((String JavaDoc)value);
57                     else if (column == 4) param.setRemote((String JavaDoc)value);
58                     else if (column == 5) param.setEjbLink((String JavaDoc)value);
59                     else if (column == 6) param.setDescription((String JavaDoc)value);
60                 } else {
61                     EjbLocalRef param = (EjbLocalRef)ref;
62                     if (column == 0) param.setEjbRefName((String JavaDoc)value);
63                     else if (column == 1) param.setEjbRefType((String JavaDoc)value);
64                     else if (column == 3) param.setLocalHome((String JavaDoc)value);
65                     else if (column == 4) param.setLocal((String JavaDoc)value);
66                     else if (column == 5) param.setEjbLink((String JavaDoc)value);
67                     else if (column == 6) param.setDescription((String JavaDoc)value);
68                 }
69     }
70
71
72     public Object JavaDoc getValueAt(int row, int column)
73     {
74                 CommonDDBean ref = getEjbRef(row);
75                 if (ref instanceof EjbRef) {
76                     EjbRef param = (EjbRef)ref;
77                     if (column == 0) return param.getEjbRefName();
78                     else if (column == 1) return param.getEjbRefType();
79                     else if (column == 2) return "Remote"; //NOI18N
80
else if (column == 3) return param.getHome();
81                     else if (column == 4) return param.getRemote();
82                     else if (column == 5) return param.getEjbLink();
83                     else {
84                         String JavaDoc desc = param.getDefaultDescription();
85                         return desc==null?null:desc.trim();
86                     }
87                 } else {
88                     EjbLocalRef param = (EjbLocalRef)ref;
89                     if (column == 0) return param.getEjbRefName();
90                     else if (column == 1) return param.getEjbRefType();
91                     else if (column == 2) return "Local"; //NOI18N
92
else if (column == 3) return param.getLocalHome();
93                     else if (column == 4) return param.getLocal();
94                     else if (column == 5) return param.getEjbLink();
95                     else {
96                         String JavaDoc desc = param.getDefaultDescription();
97                         return desc==null?null:desc.trim();
98                     }
99                 }
100
101     }
102         
103     public CommonDDBean addRow(Object JavaDoc[] values)
104     {
105             try {
106                 CommonDDBean param=null;
107                 WebApp webApp = (WebApp)getParent();
108                 String JavaDoc interfaceType = (String JavaDoc)values[2];
109                 if ("Remote".equals(interfaceType)) {
110                     param=webApp.createBean("EjbRef"); //NOI18N
111
((EjbRef)param).setEjbRefName((String JavaDoc)values[0]);
112                     ((EjbRef)param).setEjbRefType((String JavaDoc)values[1]);
113                     ((EjbRef)param).setHome((String JavaDoc)values[3]);
114                     ((EjbRef)param).setRemote((String JavaDoc)values[4]);
115                     String JavaDoc link = (String JavaDoc)values[5];
116                     if (link.length()>0) ((EjbRef)param).setEjbLink(link);
117                     String JavaDoc desc = (String JavaDoc)values[6];
118                     if (desc.length()>0) ((EjbRef)param).setDescription(desc);
119                     int row = webApp.sizeEjbRef();
120                     webApp.addEjbRef((EjbRef)param);
121                     getChildren().add(row,param);
122                     fireTableRowsInserted(row, row);
123                 } else {
124                     param=webApp.createBean("EjbLocalRef"); //NOI18N
125
((EjbLocalRef)param).setEjbRefName((String JavaDoc)values[0]);
126                     ((EjbLocalRef)param).setEjbRefType((String JavaDoc)values[1]);
127                     ((EjbLocalRef)param).setLocalHome((String JavaDoc)values[3]);
128                     ((EjbLocalRef)param).setLocal((String JavaDoc)values[4]);
129                     String JavaDoc link = (String JavaDoc)values[5];
130                     if (link.length()>0) ((EjbLocalRef)param).setEjbLink(link);
131                     String JavaDoc desc = (String JavaDoc)values[6];
132                     if (desc.length()>0) ((EjbLocalRef)param).setDescription(desc);
133                     webApp.addEjbLocalRef((EjbLocalRef)param);
134                     getChildren().add(param);
135                     int row = getRowCount() - 1;
136                     fireTableRowsInserted(row, row);
137                 }
138                 return param;
139             } catch (ClassNotFoundException JavaDoc ex) {}
140             return null;
141     }
142
143     public void editRow(int row, Object JavaDoc[] values)
144     {
145             //try {
146
CommonDDBean ref = getEjbRef(row);
147                 WebApp webApp = (WebApp)getParent();
148                 String JavaDoc interfaceType = (String JavaDoc)values[2];
149                 if (ref instanceof EjbRef) {
150                     EjbRef param = (EjbRef)ref;
151                     //if ("Remote".equals(interfaceType)) { //NOI18N
152
param.setEjbRefName((String JavaDoc)values[0]);
153                         param.setEjbRefType((String JavaDoc)values[1]);
154                         param.setHome((String JavaDoc)values[3]);
155                         param.setRemote((String JavaDoc)values[4]);
156                         String JavaDoc ejbLink = (String JavaDoc)values[5];
157                         param.setEjbLink(ejbLink.length()>0?ejbLink:null);
158                         String JavaDoc desc = (String JavaDoc)values[6];
159                         param.setDescription(desc.length()>0?desc:null);
160                         fireTableRowsUpdated(row,row);
161                     /*} else {
162                         webApp.removeEjbRef(param);
163                         getChildren().remove(row);
164                         //fireTableRowsDeleted(row, row);
165                         EjbLocalRef localRef = (EjbLocalRef)webApp.createBean("EjbLocalRef"); //NOI18N
166                         localRef.setEjbRefName((String)values[0]);
167                         localRef.setEjbRefType((String)values[1]);
168                         localRef.setLocalHome((String)values[3]);
169                         localRef.setLocal((String)values[4]);
170                         localRef.setEjbLink((String)values[5]);
171                         String desc = (String)values[6];
172                         localRef.setDescription(desc.length()>0?desc:null);
173                         webApp.addEjbLocalRef(localRef);
174                         getChildren().add(row,param);
175                         //fireTableRowsInserted(row, row);
176                         fireTableRowsUpdated(row,row);
177                     }*/

178                 } else {
179                     EjbLocalRef param = (EjbLocalRef)ref;
180                     //if ("Local".equals(interfaceType)) { //NOI18N
181
param.setEjbRefName((String JavaDoc)values[0]);
182                         param.setEjbRefType((String JavaDoc)values[1]);
183                         param.setLocalHome((String JavaDoc)values[3]);
184                         param.setLocal((String JavaDoc)values[4]);
185                         String JavaDoc ejbLink = (String JavaDoc)values[5];
186                         param.setEjbLink(ejbLink.length()>0?ejbLink:null);
187                         String JavaDoc desc = (String JavaDoc)values[6];
188                         param.setDescription(desc.length()>0?desc:null);
189                         fireTableRowsUpdated(row,row);
190                     /*} else {
191                         webApp.removeEjbLocalRef(param);
192                         getChildren().remove(row);
193                         //fireTableRowsDeleted(row, row);
194                         EjbRef remoteRef = (EjbRef)webApp.createBean("EjbRef"); //NOI18N
195                         remoteRef.setEjbRefName((String)values[0]);
196                         remoteRef.setEjbRefType((String)values[1]);
197                         remoteRef.setHome((String)values[3]);
198                         remoteRef.setRemote((String)values[4]);
199                         remoteRef.setEjbLink((String)values[5]);
200                         String desc = (String)values[6];
201                         remoteRef.setDescription(desc.length()>0?desc:null);
202                         webApp.addEjbRef(remoteRef);
203                         getChildren().add(row,param);
204                         //fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
205                         fireTableRowsUpdated(row,row);
206                     }*/

207                 }
208             //} catch (ClassNotFoundException ex) {}
209
}
210         
211     public void removeRow(int row)
212     {
213             WebApp webApp = (WebApp)getParent();
214             CommonDDBean ref = getEjbRef(row);
215             if (ref instanceof EjbRef) {
216                 webApp.removeEjbRef((EjbRef)ref);
217             } else {
218                 webApp.removeEjbLocalRef((EjbLocalRef)ref);
219             }
220             getChildren().remove(row);
221             fireTableRowsDeleted(row, row);
222             
223     }
224         
225         CommonDDBean getEjbRef(int row) {
226             return (CommonDDBean)getChildren().get(row);
227         }
228 }
Popular Tags