01: /*
02: * Created on 12/10/2004
03: *
04: * ============================================================================
05: * GNU Lesser General Public License
06: * ============================================================================
07: *
08: * Swing Components - visit http://sf.net/projects/gfd
09: *
10: * Copyright (C) 2004 Igor Regis da Silva Simões
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25: */
26:
27: package br.com.gfpshare.beans;
28:
29: import java.awt.Component;
30:
31: import javax.swing.ComboBoxEditor;
32: import javax.swing.JTextField;
33:
34: import br.com.gfpshare.db.PersistentObject;
35: import br.com.gfpshare.db.formatter.GeneralFormatter;
36:
37: /**
38: * @author Igor Regis da Silva Simoes
39: */
40: public class DBComboBoxEditor extends JTextField implements
41: ComboBoxEditor {
42: private Object editedItem = null;
43:
44: static GeneralFormatter generalFormatter = new GeneralFormatter();
45:
46: /**
47: * @see javax.swing.ComboBoxEditor#getEditorComponent()
48: */
49: public Component getEditorComponent() {
50: return this ;
51: }
52:
53: /**
54: * @see javax.swing.ComboBoxEditor#getItem()
55: */
56: public Object getItem() {
57: return editedItem;
58: }
59:
60: /**
61: * Ao sobrescrever este método oferecemos a este editor a capacidade de exigir
62: * os dados que nele são inseridos com a aparencia formatada
63: * @see javax.swing.ComboBoxEditor#setItem(java.lang.Object)
64: */
65: public void setItem(Object anObject) {
66: if (anObject != null) {
67: editedItem = anObject;
68: String tipo = anObject.getClass().getSimpleName();
69: String valor = generalFormatter.format(anObject,
70: GeneralFormatter.FORMATO_CURTO, tipo);
71: if (valor == null && anObject instanceof PersistentObject)
72: valor = ((PersistentObject) anObject)
73: .getAsString(PersistentObject.CURTO);
74: else if (valor == null)
75: valor = anObject.toString();
76: setText(valor);
77: } else {
78: editedItem = null;
79: setText(null);
80: }
81: }
82: }
|