KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.List JavaDoc;
23 // Swing
24
import javax.swing.table.AbstractTableModel JavaDoc;
25 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
26
27 public abstract class DDBeanTableModel extends AbstractTableModel JavaDoc
28 {
29     private List JavaDoc children;
30         private CommonDDBean parent;
31
32         protected abstract String JavaDoc[] getColumnNames();
33
34         protected CommonDDBean getParent() {
35             return parent;
36         }
37
38         protected List JavaDoc getChildren() {
39             return children;
40         }
41
42     public int getColumnCount()
43     {
44         return getColumnNames().length;
45     }
46
47
48     public int getRowCount()
49     {
50         if (children != null)
51         {
52             return (children.size());
53         }
54         else
55         {
56             return (0);
57         }
58     }
59
60
61         public String JavaDoc getColumnName(int column)
62         {
63         return getColumnNames()[column];
64     }
65         
66     public boolean isCellEditable(int row, int column)
67     {
68         return (false);
69     }
70
71     public int getRowWithValue(int column, Object JavaDoc value)
72     {
73         for(int row = 0; row < getRowCount(); row++)
74         {
75             Object JavaDoc obj = getValueAt(row, column);
76             if (obj.equals(value))
77             {
78                 return (row);
79             }
80         }
81
82         return (-1);
83     }
84         
85     public abstract CommonDDBean addRow(Object JavaDoc[] values);
86
87     public abstract void editRow(int row, Object JavaDoc[] values);
88         
89     public abstract void removeRow(int row);
90         
91     public void setData(CommonDDBean parent,CommonDDBean[] children) {
92         this.parent = parent;
93                 this.children = new java.util.ArrayList JavaDoc();
94                 if (children==null) return;
95                 for(int i=0;i<children.length;i++)
96                 this.children.add(children[i]);
97         fireTableDataChanged();
98         }
99         
100 }
Popular Tags