KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > BeanTableModel


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  * BeanTableModel.java
21  *
22  * Created on October 3, 2003, 10:47 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
26
27 /**
28  * DBeanTableModel.java - table model over the base bean array
29  *
30  * @author Rajeshwar Patil
31  * @version %I%, %G%
32  */

33
34 import java.util.ArrayList JavaDoc;
35 import java.util.List JavaDoc;
36
37 import javax.swing.table.AbstractTableModel JavaDoc;
38
39 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
40
41
42 public abstract class BeanTableModel extends AbstractTableModel JavaDoc {
43     /* A class implementation comment can go here. */
44     private List JavaDoc children;
45     private Object JavaDoc parent;
46
47
48     // AbstractTableModel methods
49
public int getColumnCount() {
50         return getColumnNames().length;
51     }
52
53
54     public int getRowCount() {
55         if (children != null){
56             return children.size();
57         } else {
58             return 0;
59         }
60     }
61
62
63     public String JavaDoc getColumnName(int column) {
64         return getColumnNames()[column];
65     }
66
67
68     public boolean isCellEditable(int row, int column) {
69         return false;
70     }
71
72
73     // BeanTableModel methods
74
protected abstract String JavaDoc[] getColumnNames();
75
76     public abstract Object JavaDoc addRow(Object JavaDoc[] values);
77
78     public abstract void editRow(int row, Object JavaDoc[] values);
79
80     public abstract void removeRow(int row);
81
82     public abstract boolean alreadyExists(Object JavaDoc[] values);
83
84     public abstract Object JavaDoc[] getValues(int row);
85
86
87     public void setData(Object JavaDoc parent, CommonDDBean[] children) {
88         this.parent = parent;
89         this.children = new ArrayList JavaDoc();
90         
91         if (children == null) {
92             return;
93         }
94         
95         for(int i = 0;i < children.length; i++) {
96             this.children.add(children[i]);
97         }
98         
99         fireTableDataChanged();
100     }
101
102
103     public int getRowWithValue(int column, Object JavaDoc value) {
104         for(int row = 0, max = getRowCount(); row < max; row++) {
105             Object JavaDoc obj = getValueAt(row, column);
106             if (obj.equals(value)) {
107                 return row;
108             }
109         }
110         return -1;
111     }
112
113
114     protected Object JavaDoc getParent() {
115         return parent;
116     }
117
118
119     protected List JavaDoc getChildren() {
120         return children;
121     }
122 }
123
Popular Tags