KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** ResEnvRefTableModel - table model for resource env. references
23  *
24  * Created on April 11, 2005
25  * @author mkuchtiak
26  */

27 import org.netbeans.modules.j2ee.dd.api.common.ResourceEnvRef;
28 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
29 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
30 import org.openide.util.NbBundle;
31
32 public class ResEnvRefTableModel extends DDBeanTableModel
33 {
34     private static final String JavaDoc[] columnNames = {
35             NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_ResRefName"),
36             NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_ResType"),
37             NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_Description")
38         };
39
40         protected String JavaDoc[] getColumnNames() {
41             return columnNames;
42         }
43
44     public void setValueAt(Object JavaDoc value, int row, int column)
45     {
46         ResourceEnvRef param = getResourceEnvRef(row);
47
48         if (column == 0) param.setResourceEnvRefName((String JavaDoc)value);
49         else if (column == 1) param.setResourceEnvRefType((String JavaDoc)value);
50         else param.setDescription((String JavaDoc)value);
51     }
52
53
54     public Object JavaDoc getValueAt(int row, int column)
55     {
56         ResourceEnvRef param = getResourceEnvRef(row);
57
58         if (column == 0) return param.getResourceEnvRefName();
59         else if (column == 1) return param.getResourceEnvRefType();
60         else {
61                     String JavaDoc desc = param.getDefaultDescription();
62                     return desc==null?null:desc.trim();
63                 }
64     }
65         
66     public CommonDDBean addRow(Object JavaDoc[] values)
67     {
68             try {
69                 WebApp webApp = (WebApp)getParent();
70                 ResourceEnvRef param=(ResourceEnvRef)webApp.createBean("ResourceEnvRef"); //NOI18N
71
param.setResourceEnvRefName((String JavaDoc)values[0]);
72                 param.setResourceEnvRefType((String JavaDoc)values[1]);
73                 String JavaDoc desc = (String JavaDoc)values[2];
74                 param.setDescription(desc.length()>0?desc:null);
75                 webApp.addResourceEnvRef(param);
76                 getChildren().add(param);
77                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
78                 return param;
79             } catch (ClassNotFoundException JavaDoc ex) {}
80             return null;
81     }
82
83     public void editRow(int row, Object JavaDoc[] values)
84     {
85                 ResourceEnvRef param = getResourceEnvRef(row);
86                 param.setResourceEnvRefName((String JavaDoc)values[0]);
87                 param.setResourceEnvRefType((String JavaDoc)values[1]);
88                 String JavaDoc desc = (String JavaDoc)values[2];
89                 param.setDescription(desc.length()>0?desc:null);
90                 fireTableRowsUpdated(row,row);
91     }
92         
93     public void removeRow(int row)
94     {
95             WebApp webApp = (WebApp)getParent();
96             webApp.removeResourceEnvRef(getResourceEnvRef(row));
97             getChildren().remove(row);
98             fireTableRowsDeleted(row, row);
99             
100     }
101         
102         ResourceEnvRef getResourceEnvRef(int row) {
103             return (ResourceEnvRef)getChildren().get(row);
104         }
105 }
Popular Tags