KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
23 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField;
24
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27
28 /**
29  * @author pfiala
30  */

31 public class CmpFieldsTableModel extends InnerTableModel {
32
33     private EntityHelper.CmpFields cmpFields;
34     private static final String JavaDoc[] COLUMN_NAMES = {Utils.getBundleMessage("LBL_FieldName"),
35                                                   Utils.getBundleMessage("LBL_Type"),
36                                                   Utils.getBundleMessage("LBL_LocalGetter"),
37                                                   Utils.getBundleMessage("LBL_LocalSetter"),
38                                                   Utils.getBundleMessage("LBL_RemoteGetter"),
39                                                   Utils.getBundleMessage("LBL_RemoteSetter"),
40                                                   Utils.getBundleMessage("LBL_Description")};
41     private static final int[] COLUMN_WIDTHS = new int[]{120, 160, 70, 70, 70, 70, 220};
42
43     public CmpFieldsTableModel(EntityHelper.CmpFields cmpFields) {
44         super(null, COLUMN_NAMES, COLUMN_WIDTHS);
45         this.cmpFields = cmpFields;
46         cmpFields.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
47             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
48                 if (evt != null && evt.getSource() instanceof Entity &&
49                         (evt.getOldValue() instanceof CmpField || evt.getNewValue() instanceof CmpField)) {
50                     tableChanged();
51                 }
52             }
53         });
54     }
55
56     public int addRow() {
57         cmpFields.addCmpField();
58         int row = getRowCount() - 1;
59         //fireTableRowsInserted(row, row);
60
return row;
61     }
62
63     public void editRow(int row) {
64         if (cmpFields.getCmpFieldHelper(row).edit()) {
65             fireTableRowsUpdated(row, row);
66         }
67     }
68
69     public void removeRow(int row) {
70         cmpFields.getCmpFieldHelper(row).deleteCmpField();
71     }
72
73     public void refreshView() {
74         super.refreshView();
75     }
76
77     public int getRowCount() {
78         return cmpFields.getCmpFieldCount();
79     }
80
81     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
82         CmpFieldHelper helper = cmpFields.getCmpFieldHelper(rowIndex);
83         switch (columnIndex) {
84             case 0:
85                 return helper.getFieldName();
86 // case 1:
87
// return helper.getTypeString();
88
// case 2:
89
// return new Boolean(helper.hasLocalGetter());
90
// case 3:
91
// return new Boolean(helper.hasLocalSetter());
92
// case 4:
93
// return new Boolean(helper.hasRemoteGetter());
94
// case 5:
95
// return new Boolean(helper.hasRemoteSetter());
96
case 6:
97                 return helper.getDefaultDescription();
98         }
99         return null;
100     }
101
102     public void setValueAt(Object JavaDoc value, int rowIndex, int columnIndex) {
103         CmpFieldHelper helper = cmpFields.getCmpFieldHelper(rowIndex);
104         switch (columnIndex) {
105             case 0:
106                 helper.setFieldName((String JavaDoc) value);
107                 break;
108 // case 1:
109
// helper.setType((String) value);
110
// break;
111
case 2:
112                 helper.setLocalGetter(((Boolean JavaDoc) value).booleanValue());
113                 break;
114             case 3:
115                 helper.setLocalSetter(((Boolean JavaDoc) value).booleanValue());
116                 break;
117             case 4:
118                 helper.setRemoteGetter(((Boolean JavaDoc) value).booleanValue());
119                 break;
120             case 5:
121                 helper.setRemoteSetter(((Boolean JavaDoc) value).booleanValue());
122                 break;
123             case 6:
124                 helper.setDescription((String JavaDoc) value);
125                 break;
126         }
127         fireTableRowsUpdated(rowIndex, rowIndex);
128     }
129
130     public boolean isCellEditable(int rowIndex, int columnIndex) {
131         return true;
132     }
133
134     public Class JavaDoc getColumnClass(int columnIndex) {
135         switch (columnIndex) {
136             case 0:
137                 return String JavaDoc.class;
138             case 1:
139                 return String JavaDoc.class;
140             case 2:
141                 return Boolean JavaDoc.class;
142             case 3:
143                 return Boolean JavaDoc.class;
144             case 4:
145                 return Boolean JavaDoc.class;
146             case 5:
147                 return Boolean JavaDoc.class;
148             case 6:
149                 return String JavaDoc.class;
150         }
151         return super.getColumnClass(columnIndex);
152     }
153 }
154
Popular Tags