KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > ed > VRowIDEditor


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.ed;
15
16 import javax.swing.*;
17 import java.awt.*;
18 import java.util.EventObject JavaDoc;
19 import javax.swing.event.CellEditorListener JavaDoc;
20 import javax.swing.table.TableCellEditor JavaDoc;
21
22 import org.compiere.util.*;
23
24 /**
25  * RowID Cell Editor providing Selection
26  *
27  * @author Jorg Janke
28  * @version $Id: VRowIDEditor.java,v 1.3 2002/01/04 04:27:27 jjanke Exp $
29  */

30 public class VRowIDEditor extends AbstractCellEditor implements TableCellEditor JavaDoc
31 {
32     /**
33      * Constructor
34      */

35     public VRowIDEditor(boolean select)
36     {
37         super();
38         m_select = select;
39         m_cb.setMargin(new Insets(0,0,0,0));
40         m_cb.setHorizontalAlignment(JLabel.CENTER);
41     } // VRowIDEditor
42

43     private JCheckBox m_cb = new JCheckBox();
44     private Object JavaDoc[] m_rid;
45     private boolean m_select;
46
47     /**
48      * Enable Selection to be displayed
49      */

50     public void setEnableSelection(boolean showSelection)
51     {
52         m_select = showSelection;
53     } // setEnableSelection
54

55     /**
56      * Ask the editor if it can start editing using anEvent.
57      * This method is intended for the use of client to avoid the cost of
58      * setting up and installing the editor component if editing is not possible.
59      * If editing can be started this method returns true
60      */

61     public boolean isCellEditable(EventObject JavaDoc anEvent)
62     {
63         return m_select;
64     } // isCellEditable
65

66     /**
67      * Sets an initial value for the editor. This will cause the editor to
68      * stopEditing and lose any partially edited value if the editor is editing
69      * when this method is called.
70      * Returns the component that should be added to the client's Component hierarchy.
71      * Once installed in the client's hierarchy this component
72      * will then be able to draw and receive user input.
73      */

74     public Component getTableCellEditorComponent(JTable table, Object JavaDoc value, boolean isSelected, int row, int column)
75     {
76         m_rid = (Object JavaDoc[])value;
77         if (m_rid == null || m_rid[1] == null)
78             m_cb.setSelected(false);
79         else
80         {
81             Boolean JavaDoc sel = (Boolean JavaDoc)m_rid[1];
82             m_cb.setSelected(sel.booleanValue());
83         }
84         return m_cb;
85     } // getTableCellEditorComponent
86

87     /**
88      * The editing cell should be selected or not
89      */

90     public boolean shouldSelectCell(EventObject JavaDoc anEvent)
91     {
92         return m_select;
93     } // shouldSelectCell
94

95     /**
96      * Returns the value contained in the editor
97      */

98     public Object JavaDoc getCellEditorValue()
99     {
100         Log.trace(Log.l5_DData, "VRowIDEditor.getCellEditorValue - " + m_cb.isSelected());
101         if (m_rid == null)
102             return null;
103         m_rid[1] = new Boolean JavaDoc (m_cb.isSelected());
104         return m_rid;
105     } // getCellEditorValue
106

107 } // VRowIDEditor
108
Popular Tags