001: /*
002: * Created on 04/01/2005 Swing Components - visit http://sf.net/projects/gfd Copyright (C) 2004 Igor Regis da
003: * Silva Simões This program is free software; you can redistribute it and/or modify it under the terms of the
004: * GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
005: * or (at your option) any later version. This program is distributed in the hope that it will be useful, but
006: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
007: * PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU
008: * General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59
009: * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
010: */
011:
012: package br.com.gfp.beans.property.editor;
013:
014: import java.sql.SQLException;
015: import java.util.Locale;
016:
017: import br.com.gfp.dao.GFPController;
018: import br.com.gfp.data.CheckingAccount;
019: import br.com.gfp.util.SimpleLog;
020: import br.com.gfpshare.beans.DBComboBox;
021: import br.com.gfpshare.db.PersistentObject;
022:
023: import com.l2fprod.common.beans.editor.AbstractPropertyEditor;
024:
025: /**
026: * Date Property Editor based on <a href="http://sf.net/projects/gfd">GFP ICalendarChooser </a> component.
027: * <br>
028: */
029: public class ContaPropertyEditor extends AbstractPropertyEditor {
030:
031: /**
032: * Constructor for JCalendarDatePropertyEditor
033: */
034: public ContaPropertyEditor() {
035: editor = new DBComboBox(new CheckingAccount());
036: }
037:
038: /**
039: * Constructor for JCalendarDatePropertyEditor
040: *
041: * @param locale Locale used to display the Date object
042: * @throws SQLException
043: */
044: public ContaPropertyEditor(Integer value) throws SQLException {
045: this ();
046: ((DBComboBox) editor).setSelectedItem(value, "Id");
047: }
048:
049: /**
050: * Returns the Date of the Calendar
051: *
052: * @return the date choosed as a <b>java.util.Date </b>b> object or null is the date is not set
053: */
054: @Override
055: public Object getValue() {
056: try {
057: PersistentObject p = ((DBComboBox) editor)
058: .getPersistentObject(((DBComboBox) editor)
059: .getSelectedIndex());
060: return p == null ? Integer.valueOf("0")
061: : ((CheckingAccount) p).getId();
062: } catch (SQLException e) {
063: ((SimpleLog) GFPController.getGFPController().getContexto()
064: .get(GFPController.LOG))
065: .log("Erro ao pegar conta selecionada no TipoContaPropertyEditor!");
066: ((SimpleLog) GFPController.getGFPController().getContexto()
067: .get(GFPController.LOG)).log(e
068: .getLocalizedMessage());
069: ((SimpleLog) GFPController.getGFPController().getContexto()
070: .get(GFPController.LOG)).log(e);
071: return null;
072: }
073: }
074:
075: /**
076: * Sets the Date of the Calendar
077: *
078: * @param value the Date object
079: */
080: @Override
081: public void setValue(Object value) {
082: try {
083: ((DBComboBox) editor).setSelectedItem(value, "Id");
084: } catch (SQLException e) {
085: ((SimpleLog) GFPController.getGFPController().getContexto()
086: .get(GFPController.LOG))
087: .log("Erro ao selecionar conta no TipoContaPropertyEditor!");
088: ((SimpleLog) GFPController.getGFPController().getContexto()
089: .get(GFPController.LOG)).log(e
090: .getLocalizedMessage());
091: ((SimpleLog) GFPController.getGFPController().getContexto()
092: .get(GFPController.LOG)).log(e);
093: }
094: }
095:
096: /**
097: * Returns the Date formated with the locale and formatString set.
098: *
099: * @return the choosen Date as String
100: */
101: @Override
102: public String getAsText() {
103: return ((DBComboBox) editor).getSelectedItem().toString();
104: }
105:
106: /**
107: * Sets the locale.
108: *
109: * @param l The new locale value
110: */
111: public void setLocale(Locale l) {
112: ((DBComboBox) editor).setLocale(l);
113: }
114:
115: /**
116: * Returns the Locale used.
117: *
118: * @return the Locale object
119: */
120: public Locale getLocale() {
121: return ((DBComboBox) editor).getLocale();
122: }
123:
124: }
|