KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 import org.netbeans.modules.j2ee.dd.api.common.EnvEntry;
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 EnvEntryTableModel extends DDBeanTableModel
33 {
34     private static final String JavaDoc[] columnNames = {
35             NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryName"),
36             NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryType"),
37             NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryValue"),
38             NbBundle.getMessage(EnvEntryTableModel.class,"TTL_Description")
39         };
40
41         protected String JavaDoc[] getColumnNames() {
42             return columnNames;
43         }
44
45     public void setValueAt(Object JavaDoc value, int row, int column)
46     {
47         EnvEntry param = (EnvEntry)getChildren().get(row);
48
49         if (column == 0) param.setEnvEntryName((String JavaDoc)value);
50         else if (column == 1) param.setEnvEntryType((String JavaDoc)value);
51         else if (column == 2) param.setEnvEntryValue((String JavaDoc)value);
52         else param.setDescription((String JavaDoc)value);
53     }
54
55
56     public Object JavaDoc getValueAt(int row, int column)
57     {
58         EnvEntry param = (EnvEntry)getChildren().get(row);
59
60         if (column == 0) return param.getEnvEntryName();
61         else if (column == 1) return param.getEnvEntryType();
62         else if (column == 2) return param.getEnvEntryValue();
63         else {
64                     String JavaDoc desc = param.getDefaultDescription();
65                     return desc==null?null:desc.trim();
66                 }
67     }
68         
69     public CommonDDBean addRow(Object JavaDoc[] values)
70     {
71             try {
72                 WebApp webApp = (WebApp)getParent();
73                 EnvEntry param=(EnvEntry)webApp.createBean("EnvEntry"); //NOI18N
74
param.setEnvEntryName((String JavaDoc)values[0]);
75                 param.setEnvEntryType((String JavaDoc)values[1]);
76                 String JavaDoc value = (String JavaDoc)values[2];
77                 param.setEnvEntryValue(value.length()>0?value:null);
78                 String JavaDoc desc = (String JavaDoc)values[3];
79                 param.setDescription(desc.length()>0?desc:null);
80                 webApp.addEnvEntry(param);
81                 getChildren().add(param);
82                 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
83                 return param;
84             } catch (ClassNotFoundException JavaDoc ex) {}
85             return null;
86     }
87
88     public void editRow(int row, Object JavaDoc[] values)
89     {
90                 EnvEntry param = (EnvEntry)getChildren().get(row);
91                 param.setEnvEntryName((String JavaDoc)values[0]);
92                 param.setEnvEntryType((String JavaDoc)values[1]);
93                 String JavaDoc value = (String JavaDoc)values[2];
94                 param.setEnvEntryValue(value.length()>0?value:null);
95                 String JavaDoc desc = (String JavaDoc)values[3];
96                 param.setDescription(desc.length()>0?desc:null);
97                 fireTableRowsUpdated(row,row);
98     }
99         
100     public void removeRow(int row)
101     {
102             WebApp webApp = (WebApp)getParent();
103             webApp.removeEnvEntry((EnvEntry)getChildren().get(row));
104             getChildren().remove(row);
105             fireTableRowsDeleted(row, row);
106             
107     }
108         
109         EnvEntry getEnvEntry(int row) {
110             return (EnvEntry)getChildren().get(row);
111         }
112 }
Popular Tags