KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > editors > ui > AbstractDDTableModel


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  * AbstractDDTableModel.java -- synopsis.
21  */

22 package org.netbeans.modules.j2ee.sun.ide.editors.ui;
23
24 import java.util.*;
25
26 import javax.swing.table.*;
27
28
29 /**
30  * Table model used for displaying Deployment
31  * Descriptor entries that contain multiple key/value
32  * pairs (ie. can be modeled as arrays).
33  *
34  * @author Joe Warzecha
35  */

36 //
37
// 29-may-2001
38
// Changes for bug 4457984. Changed the signature for addRowAt to
39
// match the interface and added null implementations of the
40
// new methods newElementCancelled and editsCancelled. (joecorto)
41
//
42
public abstract class AbstractDDTableModel extends AbstractTableModel
43 implements DDTableModel {
44
45     protected Vector data;
46
47     public AbstractDDTableModel (Object JavaDoc [] refs) {
48     data = new Vector ();
49     changeRefs(refs);
50     }
51
52     //
53
// This protected constructor is for the subclass
54
// AbstractBaseBeanDDTableModel which initializes differently.
55
//
56
protected AbstractDDTableModel() {
57     }
58
59     protected void changeRefs(Object JavaDoc[] refs) {
60         if (data == null) {
61         data = new Vector (refs.length);
62     } else {
63         data.removeAllElements();
64     }
65     for (int i = 0; i < refs.length; i++) {
66         data.addElement (refs [i]);
67     }
68     fireTableDataChanged();
69     }
70
71     public int getRowCount () {
72     return data.size ();
73     }
74
75     public Class JavaDoc getColumnClass (int col) {
76     return String JavaDoc.class;
77     }
78
79     protected boolean valueInColumn(Object JavaDoc value, int col, int skipRow) {
80         for (int i = data.size()-1; i >= 0; i--) {
81         if (i != skipRow && value.equals(getValueAt(i, col))) {
82             return true;
83         }
84         }
85     return false;
86     }
87
88     public Object JavaDoc getValueAt (int row) {
89     if (row >= data.size ()) {
90         return null;
91     }
92
93     Object JavaDoc o = data.elementAt (row);
94     return o;
95     }
96
97     protected abstract void setValueAt (String JavaDoc strVal, Object JavaDoc rowElement,
98                     int col);
99
100     public void setValueAt (Object JavaDoc value, int row, int col) {
101         String JavaDoc strVal = (String JavaDoc) value;
102
103         if (row >= data.size()) {
104             return;
105         }
106         Object JavaDoc o = data.elementAt (row);
107         if (o == null) {
108             return;
109         }
110
111     setValueAt (strVal, o, col);
112     fireTableCellUpdated (row, col);
113     }
114
115     public void setValueAt(int row, Object JavaDoc value) {
116     data.setElementAt(value, row);
117     fireTableRowsUpdated(row,row);
118     }
119
120     public void addRowAt (int row, Object JavaDoc newVal, Object JavaDoc editedVal) {
121         /*
122      * A value of -1 means there is no selected row in
123      * the table, so add to the end in that case.
124      * Otherwise we want to add after the given row.
125      */

126     if (row == -1) {
127         row = data.size();
128     } else {
129         row++;
130     }
131
132     data.insertElementAt(editedVal, row);
133     fireTableRowsInserted(row, row);
134     }
135
136     public void newElementCancelled(Object JavaDoc obj) {
137     // Nothing to do in the generic implementation.
138
}
139
140     public void editsCancelled() {
141     // Nothing to do in the generic implementation.
142
}
143
144     public boolean isEditValid (Object JavaDoc rowValue, int row) {
145     return true;
146     }
147
148     public java.util.List JavaDoc canRemoveRow (int row) {
149     return Collections.EMPTY_LIST;
150     }
151
152     public void removeRowAt(int row) {
153     data.removeElementAt(row);
154     fireTableRowsDeleted(row, row);
155     }
156 }
157
Popular Tags