KickJava   Java API By Example, From Geeks To Geeks.

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


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
23
24 /**
25  * @author pfiala
26  */

27 public class EnvironmentEntriesTableModel extends InnerTableModel {
28
29     private EjbHelper ejbHelper;
30     private static final String JavaDoc[] COLUMN_NAMES = {Utils.getBundleMessage("LBL_EntryName"),
31                                                   Utils.getBundleMessage("LBL_EntryType"),
32                                                   Utils.getBundleMessage("LBL_EntryValue"),
33                                                   Utils.getBundleMessage("LBL_Description")};
34     private static final int[] COLUMN_WIDTHS = new int[]{100, 120, 100, 150};
35
36     public EnvironmentEntriesTableModel(EjbHelper ejbHelper) {
37         super(null, COLUMN_NAMES, COLUMN_WIDTHS);
38         this.ejbHelper = ejbHelper;
39     }
40
41     public void setValueAt(Object JavaDoc value, int rowIndex, int columnIndex) {
42         EjbHelper.EnvEntryHelper envEntryHelper = ejbHelper.getEnvEntryHelper(rowIndex);
43         switch (columnIndex) {
44             case 0:
45                 envEntryHelper.setEnvEntryName((String JavaDoc) value);
46                 break;
47             case 1:
48                 envEntryHelper.setEnvEntryType((String JavaDoc) value);
49                 break;
50             case 2:
51                 envEntryHelper.setEnvEntryValue((String JavaDoc) value);
52                 break;
53             case 3:
54                 envEntryHelper.setDescription((String JavaDoc) value);
55                 break;
56         }
57         fireTableCellUpdated(rowIndex, columnIndex);
58     }
59
60     public int getRowCount() {
61         return ejbHelper.getEnvEntryCount();
62     }
63
64     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
65         EjbHelper.EnvEntryHelper envEntryHelper = ejbHelper.getEnvEntryHelper(rowIndex);
66         switch (columnIndex) {
67             case 0:
68                 return envEntryHelper.getEnvEntryName();
69             case 1:
70                 return envEntryHelper.getEnvEntryType();
71             case 2:
72                 return envEntryHelper.getEnvEntryValue();
73             case 3:
74                 return envEntryHelper.getDefaultDescription();
75         }
76         return null;
77     }
78
79     public int addRow() {
80         ejbHelper.newEnvEntry();
81         int row = getRowCount() - 1;
82         return row;
83     }
84
85     public void removeRow(final int row) {
86         ejbHelper.removeEnvEntry(row);
87     }
88 }
89
Popular Tags