KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ui > InnerTableModel


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 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui;
20
21 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
22
23 import javax.swing.table.AbstractTableModel JavaDoc;
24 import javax.swing.table.TableCellEditor JavaDoc;
25 import javax.swing.*;
26
27 /**
28  * @author pfiala
29  */

30 public abstract class InnerTableModel extends AbstractTableModel JavaDoc {
31
32     private XmlMultiViewDataSynchronizer synchronizer;
33     protected final String JavaDoc[] columnNames;
34     private int[] columnWidths;
35     private int rowCount = -1;
36
37     public InnerTableModel(XmlMultiViewDataSynchronizer synchronizer, String JavaDoc[] columnNames, int[] columnWidths) {
38         this.synchronizer = synchronizer;
39         this.columnNames = columnNames;
40         this.columnWidths = columnWidths;
41     }
42
43     public boolean isCellEditable(int rowIndex, int columnIndex) {
44         return true;
45     }
46
47     public String JavaDoc getColumnName(int column) {
48         return columnNames[column];
49     }
50
51     public TableCellEditor JavaDoc getCellEditor(int columnIndex) {
52         return null;
53     }
54
55     public int getColumnCount() {
56         return columnNames.length;
57     }
58
59     public int[] getColumnWidths() {
60         return columnWidths;
61     }
62
63     public abstract int addRow();
64
65     public abstract void removeRow(int selectedRow);
66
67     public int getDefaultColumnWidth(int i) {
68         return columnWidths[i];
69     }
70
71     public void refreshView() {
72         fireTableDataChanged();
73     }
74
75     protected void tableChanged() {
76         if (!checkRowCount()) {
77             fireTableDataChanged();
78         }
79     }
80
81     private boolean checkRowCount() {
82         int n = getRowCount();
83         if (rowCount == -1) {
84             rowCount = n;
85         }
86         if (n != rowCount) {
87             while (rowCount < n) {
88                 rowCount++;
89                 fireTableRowsInserted(0, 0);
90             }
91             while (rowCount > n) {
92                 rowCount--;
93                 fireTableRowsDeleted(0, 0);
94             }
95             return true;
96         } else {
97             return false;
98         }
99     }
100
101     protected void modelUpdatedFromUI() {
102         if (synchronizer != null) {
103             synchronizer.requestUpdateData();
104         }
105     }
106
107     public TableCellEditor JavaDoc getTableCellEditor(int column) {
108         return null;
109     }
110
111     protected TableCellEditor JavaDoc createComboBoxCellEditor(Object JavaDoc[] items) {
112         return createComboBoxCellEditor(items, false);
113     }
114
115     private static TableCellEditor JavaDoc createComboBoxCellEditor(Object JavaDoc[] items, final boolean editable) {
116         final JComboBox comboBox = new JComboBox(items);
117         comboBox.setEditable(editable);
118         return new DefaultCellEditor(comboBox);
119     }
120 }
121
Popular Tags