KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > VTable


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import javax.swing.*;
19 import javax.swing.table.*;
20 import java.beans.*;
21
22 import org.compiere.grid.ed.*;
23 import org.compiere.util.*;
24 import org.compiere.model.*;
25 import org.compiere.swing.*;
26
27 /**
28  * Table Grid based on MTable
29  *
30  * @author Jorg Janke
31  * @version $Id: VTable.java,v 1.9 2003/10/27 15:22:02 jjanke Exp $
32  */

33 public final class VTable extends CTable implements PropertyChangeListener
34 {
35     /**
36      * Default Constructor
37      */

38     public VTable()
39     {
40         super();
41     } // VTable
42

43     /**
44      * Property Change Listener for CurrentRow.
45      * - Selects the current row if not already selected
46      * - Required when navigating via Buttons
47      * @param evt event
48      */

49     public void propertyChange(PropertyChangeEvent evt)
50     {
51     // Log.trace(Log.l3_Util, "VTable.propertyChange", evt);
52
if (evt.getPropertyName().equals(MTab.PROPERTY))
53         {
54             int row = ((Integer JavaDoc)evt.getNewValue()).intValue();
55             int selRow = getSelectedRow();
56             if (row == selRow)
57                 return;
58             Log.trace(Log.l3_Util, "VTable.propertyChange", MTab.PROPERTY + "=" + row + " from " + selRow);
59             setRowSelectionInterval(row,row);
60         // Log.trace(Log.l3_Util, "VTable.propertyChange - fini", MTab.PROPERTY + "=" + row + " from " + selRow);
61
}
62     } // propertyChange
63

64     /**
65      * Get ColorCode for Row.
66      * <pre>
67      * If numerical value in compare column is
68      * negative = -1,
69      * positive = 1,
70      * otherwise = 0
71      * </pre>
72      * @param row row
73      * @return color code
74      */

75     public int getColorCode (int row)
76     {
77         return ((MTable)getModel()).getColorCode(row);
78     } // getColorCode
79

80     /**
81      * Sort Table
82      * @param modelColumnIndex model column sort index
83      */

84     protected void sort (int modelColumnIndex)
85     {
86         int rows = getRowCount();
87         if (rows == 0)
88             return;
89         //
90
TableModel model = getModel();
91         if (!(model instanceof MTable))
92         {
93             super.sort(modelColumnIndex);
94             return;
95         }
96
97         // other sort column
98
if (modelColumnIndex != p_lastSortIndex)
99             p_asc = true;
100         else
101             p_asc = !p_asc;
102
103         p_lastSortIndex = modelColumnIndex;
104         //
105
Log.trace(Log.l3_Util, "VTable.sort #" + modelColumnIndex,
106             "rows=" + rows + ", asc=" + p_asc);
107
108         ((MTable)model).sort(modelColumnIndex, p_asc);
109         // table model fires "Sorted" DataStatus event which causes MTab to position to row 0
110
} // sort
111

112     /**
113      * Transfer focus explicitly to editor due to editors with multiple components
114      *
115      * @param row row
116      * @param column column
117      * @param e event
118      * @return true if cell is editing
119      */

120     public boolean editCellAt (int row, int column, java.util.EventObject JavaDoc e)
121     {
122         if (!super.editCellAt(row, column, e))
123             return false;
124     // Log.trace(Log.l6_Database, "VTable.editCellAt", "r=" + row + ", c=" + column);
125

126         Object JavaDoc ed = getCellEditor();
127         if (ed instanceof VEditor)
128             ((Component)ed).requestFocus();
129         else if (ed instanceof VCellEditor)
130         {
131             ed = ((VCellEditor)ed).getEditor();
132             ((Component)ed).requestFocus();
133         }
134         return true;
135     } // editCellAt
136

137     /**
138      * toString
139      * @return String representation
140      */

141     public String JavaDoc toString()
142     {
143         return new StringBuffer JavaDoc("VTable[").append(getModel()).append("]").toString();
144     } // toString
145

146
147     /**
148      * Remove All - dispose
149      * @see java.awt.Container#removeAll()
150      */

151     public void removeAll()
152     {
153         super.removeAll();
154         /** Test
155         TableColumnModel tcm = getColumnModel();
156         for (int i = 0; i < tcm.getColumnCount(); i++)
157         {
158             TableColumn tc = tcm.getColumn(i);
159             TableCellEditor tce = tc.getCellEditor();
160             if (tce != null)
161             {
162                 if (tce instanceof VCellEditor)
163                     ((VCellEditor)tce).dispose();
164                 tc.setCellEditor(null);
165             }
166             TableCellRenderer tcr = tc.getCellRenderer();
167             if (tcr != null)
168             {
169                 if (tcr instanceof VCellRenderer)
170                     ((VCellRenderer)tcr).dispose();
171                 tc.setCellRenderer(null);
172             }
173         }
174         **/

175     } // removeAll
176
} // VTable
177
Popular Tags