001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.ddloaders.web.multiview;
043:
044: /** EjbRefTableModel - table model for EJB references and EJB Local References
045: *
046: * Created on April 11, 2005
047: * @author mkuchtiak
048: */
049: import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
050: import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef;
051: import org.netbeans.modules.j2ee.dd.api.web.WebApp;
052: import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
053: import org.openide.util.NbBundle;
054:
055: public class EjbRefTableModel extends DDBeanTableModel {
056: private static final String[] columnNames = {
057: NbBundle.getMessage(EjbRefTableModel.class,
058: "TTL_EjbRefName"),
059: NbBundle.getMessage(EjbRefTableModel.class,
060: "TTL_EjbRefType"),
061: NbBundle.getMessage(EjbRefTableModel.class,
062: "TTL_EjbInterfaceType"),
063: NbBundle.getMessage(EjbRefTableModel.class, "TTL_EjbHome"),
064: NbBundle.getMessage(EjbRefTableModel.class,
065: "TTL_EjbInterface"),
066: NbBundle.getMessage(EjbRefTableModel.class, "TTL_EjbLink"),
067: NbBundle.getMessage(EjbRefTableModel.class,
068: "TTL_Description") };
069:
070: protected String[] getColumnNames() {
071: return columnNames;
072: }
073:
074: public void setValueAt(Object value, int row, int column) {
075: CommonDDBean ref = getEjbRef(row);
076: if (ref instanceof EjbRef) {
077: EjbRef param = (EjbRef) ref;
078: if (column == 0)
079: param.setEjbRefName((String) value);
080: else if (column == 1)
081: param.setEjbRefType((String) value);
082: else if (column == 3)
083: param.setHome((String) value);
084: else if (column == 4)
085: param.setRemote((String) value);
086: else if (column == 5)
087: param.setEjbLink((String) value);
088: else if (column == 6)
089: param.setDescription((String) value);
090: } else {
091: EjbLocalRef param = (EjbLocalRef) ref;
092: if (column == 0)
093: param.setEjbRefName((String) value);
094: else if (column == 1)
095: param.setEjbRefType((String) value);
096: else if (column == 3)
097: param.setLocalHome((String) value);
098: else if (column == 4)
099: param.setLocal((String) value);
100: else if (column == 5)
101: param.setEjbLink((String) value);
102: else if (column == 6)
103: param.setDescription((String) value);
104: }
105: }
106:
107: public Object getValueAt(int row, int column) {
108: CommonDDBean ref = getEjbRef(row);
109: if (ref instanceof EjbRef) {
110: EjbRef param = (EjbRef) ref;
111: if (column == 0)
112: return param.getEjbRefName();
113: else if (column == 1)
114: return param.getEjbRefType();
115: else if (column == 2)
116: return "Remote"; //NOI18N
117: else if (column == 3)
118: return param.getHome();
119: else if (column == 4)
120: return param.getRemote();
121: else if (column == 5)
122: return param.getEjbLink();
123: else {
124: String desc = param.getDefaultDescription();
125: return desc == null ? null : desc.trim();
126: }
127: } else {
128: EjbLocalRef param = (EjbLocalRef) ref;
129: if (column == 0)
130: return param.getEjbRefName();
131: else if (column == 1)
132: return param.getEjbRefType();
133: else if (column == 2)
134: return "Local"; //NOI18N
135: else if (column == 3)
136: return param.getLocalHome();
137: else if (column == 4)
138: return param.getLocal();
139: else if (column == 5)
140: return param.getEjbLink();
141: else {
142: String desc = param.getDefaultDescription();
143: return desc == null ? null : desc.trim();
144: }
145: }
146:
147: }
148:
149: public CommonDDBean addRow(Object[] values) {
150: try {
151: CommonDDBean param = null;
152: WebApp webApp = (WebApp) getParent();
153: String interfaceType = (String) values[2];
154: if ("Remote".equals(interfaceType)) {
155: param = webApp.createBean("EjbRef"); //NOI18N
156: ((EjbRef) param).setEjbRefName((String) values[0]);
157: ((EjbRef) param).setEjbRefType((String) values[1]);
158: ((EjbRef) param).setHome((String) values[3]);
159: ((EjbRef) param).setRemote((String) values[4]);
160: String link = (String) values[5];
161: if (link.length() > 0)
162: ((EjbRef) param).setEjbLink(link);
163: String desc = (String) values[6];
164: if (desc.length() > 0)
165: ((EjbRef) param).setDescription(desc);
166: int row = webApp.sizeEjbRef();
167: webApp.addEjbRef((EjbRef) param);
168: getChildren().add(row, param);
169: fireTableRowsInserted(row, row);
170: } else {
171: param = webApp.createBean("EjbLocalRef"); //NOI18N
172: ((EjbLocalRef) param).setEjbRefName((String) values[0]);
173: ((EjbLocalRef) param).setEjbRefType((String) values[1]);
174: ((EjbLocalRef) param).setLocalHome((String) values[3]);
175: ((EjbLocalRef) param).setLocal((String) values[4]);
176: String link = (String) values[5];
177: if (link.length() > 0)
178: ((EjbLocalRef) param).setEjbLink(link);
179: String desc = (String) values[6];
180: if (desc.length() > 0)
181: ((EjbLocalRef) param).setDescription(desc);
182: webApp.addEjbLocalRef((EjbLocalRef) param);
183: getChildren().add(param);
184: int row = getRowCount() - 1;
185: fireTableRowsInserted(row, row);
186: }
187: return param;
188: } catch (ClassNotFoundException ex) {
189: }
190: return null;
191: }
192:
193: public void editRow(int row, Object[] values) {
194: //try {
195: CommonDDBean ref = getEjbRef(row);
196: WebApp webApp = (WebApp) getParent();
197: String interfaceType = (String) values[2];
198: if (ref instanceof EjbRef) {
199: EjbRef param = (EjbRef) ref;
200: //if ("Remote".equals(interfaceType)) { //NOI18N
201: param.setEjbRefName((String) values[0]);
202: param.setEjbRefType((String) values[1]);
203: param.setHome((String) values[3]);
204: param.setRemote((String) values[4]);
205: String ejbLink = (String) values[5];
206: param.setEjbLink(ejbLink.length() > 0 ? ejbLink : null);
207: String desc = (String) values[6];
208: param.setDescription(desc.length() > 0 ? desc : null);
209: fireTableRowsUpdated(row, row);
210: /*} else {
211: webApp.removeEjbRef(param);
212: getChildren().remove(row);
213: //fireTableRowsDeleted(row, row);
214: EjbLocalRef localRef = (EjbLocalRef)webApp.createBean("EjbLocalRef"); //NOI18N
215: localRef.setEjbRefName((String)values[0]);
216: localRef.setEjbRefType((String)values[1]);
217: localRef.setLocalHome((String)values[3]);
218: localRef.setLocal((String)values[4]);
219: localRef.setEjbLink((String)values[5]);
220: String desc = (String)values[6];
221: localRef.setDescription(desc.length()>0?desc:null);
222: webApp.addEjbLocalRef(localRef);
223: getChildren().add(row,param);
224: //fireTableRowsInserted(row, row);
225: fireTableRowsUpdated(row,row);
226: }*/
227: } else {
228: EjbLocalRef param = (EjbLocalRef) ref;
229: //if ("Local".equals(interfaceType)) { //NOI18N
230: param.setEjbRefName((String) values[0]);
231: param.setEjbRefType((String) values[1]);
232: param.setLocalHome((String) values[3]);
233: param.setLocal((String) values[4]);
234: String ejbLink = (String) values[5];
235: param.setEjbLink(ejbLink.length() > 0 ? ejbLink : null);
236: String desc = (String) values[6];
237: param.setDescription(desc.length() > 0 ? desc : null);
238: fireTableRowsUpdated(row, row);
239: /*} else {
240: webApp.removeEjbLocalRef(param);
241: getChildren().remove(row);
242: //fireTableRowsDeleted(row, row);
243: EjbRef remoteRef = (EjbRef)webApp.createBean("EjbRef"); //NOI18N
244: remoteRef.setEjbRefName((String)values[0]);
245: remoteRef.setEjbRefType((String)values[1]);
246: remoteRef.setHome((String)values[3]);
247: remoteRef.setRemote((String)values[4]);
248: remoteRef.setEjbLink((String)values[5]);
249: String desc = (String)values[6];
250: remoteRef.setDescription(desc.length()>0?desc:null);
251: webApp.addEjbRef(remoteRef);
252: getChildren().add(row,param);
253: //fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
254: fireTableRowsUpdated(row,row);
255: }*/
256: }
257: //} catch (ClassNotFoundException ex) {}
258: }
259:
260: public void removeRow(int row) {
261: WebApp webApp = (WebApp) getParent();
262: CommonDDBean ref = getEjbRef(row);
263: if (ref instanceof EjbRef) {
264: webApp.removeEjbRef((EjbRef) ref);
265: } else {
266: webApp.removeEjbLocalRef((EjbLocalRef) ref);
267: }
268: getChildren().remove(row);
269: fireTableRowsDeleted(row, row);
270:
271: }
272:
273: CommonDDBean getEjbRef(int row) {
274: return (CommonDDBean) getChildren().get(row);
275: }
276: }
|