KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querybuilder > QueryBuilderTableModel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  *
22  * @author Sanjay Dhamankar
23  */

24
25 package org.netbeans.modules.db.sql.visualeditor.querybuilder;
26
27 import javax.swing.JTable JavaDoc;
28
29 import javax.swing.table.DefaultTableModel JavaDoc;
30
31 // The model for a QueryBuilderTable
32

33 // This is a table with one row for each DB column (plus one for "all columns").
34
// The table has three columns:
35
// 0 - selected status
36
// 1 - URL for icon for key status
37
// 2 - column name.
38

39 public class QueryBuilderTableModel extends DefaultTableModel JavaDoc {
40
41     // Private variables
42

43     private boolean DEBUG = false;
44
45     // tableSpec may be redundant with tableName
46
private String JavaDoc _tableName = null;
47     private String JavaDoc _corrName = null;
48     private String JavaDoc _schemaName = null;
49
50     // Constructor
51

52     public QueryBuilderTableModel ( String JavaDoc fullTableName, String JavaDoc corrName,
53                                     String JavaDoc[] iColumnNames, Object JavaDoc[][] iData )
54     {
55         super ( iData, iColumnNames );
56         String JavaDoc[] table = fullTableName.split("\\."); // NOI18N
57
if (table.length>1) {
58             _schemaName=table[0];
59             _tableName = table[1];
60         } else
61             _tableName=table[0];
62
63         _corrName = corrName;
64     }
65
66     /*
67      * JTable uses this method to determine the default renderer/
68      * editor for each cell. If we didn't implement this method,
69      * then the last column would contain text ("true"/"false"),
70      * rather than a check box.
71      */

72     public Class JavaDoc getColumnClass(int c) {
73         if ( c == 1 )
74             return javax.swing.ImageIcon JavaDoc.class;
75         Object JavaDoc o = getValueAt(0, c);
76         if ( o != null )
77         {
78             return o.getClass();
79         }
80         else return Object JavaDoc.class;
81     }
82
83     public String JavaDoc getTableName () {
84         return ( _tableName );
85     }
86
87     public String JavaDoc getFullTableName () {
88         return ( (_schemaName!=null ? _schemaName+"." : "") // NOI18N
89
+ _tableName);
90     }
91
92     public String JavaDoc getCorrName () {
93         return ( _corrName );
94     }
95
96     public String JavaDoc getTableSpec () {
97         return ( (_corrName!=null) ?
98          _corrName :
99          getFullTableName());
100     }
101
102     // Mark a particular column as Selected/Deselected
103
void selectColumn (String JavaDoc columnName, Boolean JavaDoc select) {
104         int row=-1;
105         int size = getRowCount();
106         for (int i=0; i<size; i++)
107             if (getValueAt(i,2).equals(columnName)) {
108                 row=i;
109                 break;
110             }
111
112         if (row!=-1) {
113             // Prevent loops - Only make a change to the model if the current value is wrong
114
if ((select==Boolean.TRUE) && (getValueAt(row,0)!=Boolean.TRUE))
115                 setValueAt(Boolean.TRUE,row,0);
116             else if ((select==Boolean.FALSE) && (getValueAt(row,0)!=Boolean.FALSE))
117                 setValueAt(Boolean.FALSE,row,0);
118         }
119     }
120
121     /*
122      * Don't need to implement this method unless your table's
123      * editable.
124      */

125     public boolean isCellEditable(int row, int col) {
126         // Temporary fix to make "*{All Columns}" unselectable.
127
/*
128         if (row == 0)
129             return false;
130         */

131         //Note that the data/cell address is constant,
132
//no matter where the cell appears onscreen.
133
if (col > 0) {
134             return false;
135         } else {
136             return true;
137         }
138     }
139 }
140
141
Popular Tags