KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > minigrid > IDColumnEditor


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.minigrid;
15
16 import javax.swing.*;
17 import java.awt.*;
18 import java.awt.event.*;
19 import java.util.*;
20 import javax.swing.event.*;
21 import javax.swing.table.*;
22
23 import org.compiere.util.*;
24 import org.compiere.swing.*;
25
26 /**
27  * ID Column Editor (with Select Box).
28  * CheckBox change is only detected, if you move out of the cell.
29  * A ActionListener is added to the check box and the table forced
30  * to notice the change immediately.
31  *
32  * @author Jorg Janke
33  * @version $Id: IDColumnEditor.java,v 1.5 2002/02/09 06:18:44 jjanke Exp $
34  */

35 public class IDColumnEditor extends AbstractCellEditor
36     implements TableCellEditor, ActionListener
37 {
38     /**
39      * Constructor
40      */

41     public IDColumnEditor()
42     {
43         m_check.setMargin(new Insets(0,0,0,0));
44         m_check.setHorizontalAlignment(JLabel.CENTER);
45         m_check.addActionListener(this);
46     } // IDColumnEditor
47

48     /** the selection */
49     private JCheckBox m_check = new CCheckBox();
50     /** temporary value */
51     private IDColumn m_value = null;
52
53     private JTable m_table;
54
55     /**
56      * Return Selection Status as IDColumn
57      * @return value
58      */

59     public Object JavaDoc getCellEditorValue()
60     {
61     // Log.trace(Log.l5_DData, "IDColumnEditor.getCellEditorValue - " + m_check.isSelected());
62
if (m_value != null)
63             m_value.setSelected (m_check.isSelected());
64         return m_value;
65     } // getCellEditorValue
66

67     /**
68      * Get visual Component
69      * @param table
70      * @param value
71      * @param isSelected
72      * @param row
73      * @param column
74      * @return Component
75      */

76     public Component getTableCellEditorComponent (JTable table, Object JavaDoc value, boolean isSelected, int row, int column)
77     {
78     // Log.trace(Log.l5_DData, "IDColumnEditor.getTableCellEditorComponent", value);
79
m_table = table;
80         // set value
81
if (value != null && value instanceof IDColumn)
82             m_value = (IDColumn)value;
83         else
84         {
85             m_value = null;
86             throw new IllegalArgumentException JavaDoc("ICColumnEditor.getTableCellEditorComponent - value=" + value);
87         }
88         // set editor value
89
m_check.setSelected(m_value.isSelected());
90         return m_check;
91     } // getTableCellEditorComponent
92

93     /**
94      * Can we edit it
95      * @param anEvent
96      * @return true (cobstant)
97      */

98     public boolean isCellEditable (EventObject anEvent)
99     {
100         return true;
101     } // isCellEditable
102

103     /**
104      * Can the cell be selected
105      * @param anEvent
106      * @return true (constant)
107      */

108     public boolean shouldSelectCell (EventObject anEvent)
109     {
110         return true;
111     } // shouldSelectCell
112

113     /**
114      * Action Listener
115      * @param e
116      */

117     public void actionPerformed (ActionEvent e)
118     {
119         if (m_table != null)
120             m_table.editingStopped(new ChangeEvent(this));
121     } // actionPerformed
122

123 } // IDColumnEditor
124
Popular Tags