01: package org.airtodo.gui_common.components.widgets;
02:
03: import java.awt.Dialog;
04: import java.util.Date;
05: import java.util.Map;
06:
07: import javax.swing.Box;
08: import javax.swing.JLabel;
09: import javax.swing.SwingUtilities;
10:
11: import org.air.framework.core.GuiUtils;
12: import org.air.framework.core.Utils;
13: import org.air.framework.date.PeriodFormatterUtils;
14: import org.air.framework.gui.box.BxX;
15: import org.air.framework.gui.box.BxY;
16: import org.air.framework.gui.dialogs.login.ConnectDialog;
17: import org.air.framework.i18n.NlsColumns;
18: import org.air.framework.i18n.NlsMessages;
19: import org.airtodo.db.types.Period;
20:
21: public class WidgetPeriodFieldTask extends BxY {
22: public static enum NLS {
23: LABEL_EXPIRED, //
24: ERROR_MESSAGE_TIME_INTERVAL
25: }
26:
27: private static final String NLS_LABEL_EXPIRED = NlsMessages
28: .getString(NLS.LABEL_EXPIRED);
29: private static final String NLS_ERROR_MESSAGE_TIME_INTERVAL = NlsMessages
30: .getString(NLS.ERROR_MESSAGE_TIME_INTERVAL);
31:
32: private Enum enumColumn;
33:
34: private Period interval;
35:
36: public WidgetPeriodFieldTask(Enum enumColumn) {
37: this .enumColumn = enumColumn;
38: add(new BxX(getLabel(), Box.createHorizontalGlue()));
39: }
40:
41: public void setInterval(final Period interval) {
42: this .interval = interval;
43: //
44: getLabel().setVisible(false);
45: //
46: if (interval != null && interval.isValid()) {
47: getLabel().setVisible(true);
48: getLabel().setText(
49: String.format("%s: %s.", NlsColumns
50: .getText(enumColumn), interval.toString()));
51: //
52: Date serverDateYMD = ConnectDialog.getServerDateYMD();
53: Period periodRest = new Period(
54: PeriodFormatterUtils.FIELD.DAY);
55: periodRest.setValue(serverDateYMD, interval.getDateEnd());
56: }
57: }
58:
59: public Period getInterval() {
60: return interval;
61: }
62:
63: public boolean isTextValid() {
64: if (interval != null && !interval.isValid()) {
65: GuiUtils.showErrorMessage((Dialog) SwingUtilities
66: .windowForComponent(this ),
67: NLS_ERROR_MESSAGE_TIME_INTERVAL);
68: return false;
69: }
70: return true;
71: }
72:
73: private JLabel label;
74:
75: private JLabel getLabel() {
76: if (label == null) {
77: label = new JLabel();
78: // label.setIcon(Icons.INFORMATION);
79: label.setVisible(false);
80: }
81: return label;
82: }
83:
84: public void fromGui(Map map) {
85: map.put(Utils.getColumnIdentifier(enumColumn), getInterval());
86: }
87:
88: public void toGui(Map map) {
89: setInterval((Period) map.get(Utils
90: .getColumnIdentifier(enumColumn)));
91: }
92: }
|