KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > search > FindValueEditor


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.apps.search;
15
16 import javax.swing.*;
17 import java.awt.*;
18 import java.util.*;
19 import javax.swing.event.*;
20 import javax.swing.table.*;
21
22 import org.compiere.util.*;
23 import org.compiere.grid.ed.*;
24 import org.compiere.model.*;
25
26 /**
27  * Cell editor for Find Value field.
28  * Editor depends on Column setting
29  * Has to save entries how they are used in the query, i.e. '' for strings
30  *
31  * @author Jorg Janke
32  * @version $Id: FindValueEditor.java,v 1.2 2002/08/14 04:22:51 jjanke Exp $
33  */

34 public final class FindValueEditor extends AbstractCellEditor implements TableCellEditor
35 {
36     /**
37      * Constructor
38      * @param find find
39      * @param value2 true if it is the "to" value column
40      */

41     public FindValueEditor (Find find, boolean value2)
42     {
43         super();
44         m_find = find;
45         m_value2 = value2;
46     }
47
48     private Find m_find;
49     private boolean m_value2;
50     private boolean m_between;
51
52     private VEditor m_editor = null;
53
54     /**
55      * Get Value
56      * Need to convert to String
57      * @return current value
58      */

59     public Object JavaDoc getCellEditorValue()
60     {
61     // Log.trace(Log.l4_Data, "FindValueEditor.getCellEditorValue");
62
if (m_editor == null)
63             return null;
64         Object JavaDoc obj = m_editor.getValue(); // returns Integer, BidDecimal, String
65
if (obj == null)
66             return null;
67         //
68
String JavaDoc retValue = obj.toString();
69         return retValue;
70     } // getCellEditorValue
71

72     /**
73      * Get Editor
74      *
75      * @param table Table
76      * @param value Value
77      * @param isSelected cell is selected
78      * @param row row
79      * @param col column
80      * @return Editor component
81      */

82     public Component getTableCellEditorComponent(JTable table, Object JavaDoc value, boolean isSelected, int row, int col)
83     {
84     // Log.trace(Log.l4_Data, "FindValueEditor.getTableCellEditorComponent", "r=" + row + ", c=" + col);
85
// Between - enables value2
86
m_between = false;
87         Object JavaDoc betw = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
88         if (betw != null && betw.toString().equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX].toString()))
89             m_between = true;
90
91         String JavaDoc columnName = null;
92         Object JavaDoc column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
93         if (column != null)
94             columnName = ((ValueNamePair)column).getValue();
95
96         // Create Editor
97
MField field = m_find.getTargetMField(columnName);
98     // Log.trace(Log.l5_DData, "Field=" + field);
99
m_editor = VEditorFactory.getEditor(field, true);
100         if (m_editor == null)
101             m_editor = new VString();
102
103         m_editor.setValue(value);
104         m_editor.setReadWrite(true);
105         m_editor.setBorder(null);
106         //
107
return (Component)m_editor;
108     } // getTableCellEditorComponent
109

110     /**
111      * Cell Editable
112      * @param e event
113      * @return true if editable
114      */

115     public boolean isCellEditable (EventObject e)
116     {
117         if (m_value2 && !m_between)
118             return false;
119         return true;
120     } // isCellEditable
121

122 } // FindValueEditor
123
Popular Tags