001: package org.airtodo.gui.panel_open;
002:
003: import static org.air.framework.gui.box.Gap.small;
004:
005: import java.awt.Component;
006: import java.awt.Dialog;
007: import java.awt.event.ActionEvent;
008: import java.sql.Timestamp;
009: import java.util.HashMap;
010: import java.util.Map;
011:
012: import javax.swing.Box;
013: import javax.swing.SwingUtilities;
014:
015: import org.air.framework.core.Registry;
016: import org.air.framework.core.Utils;
017: import org.air.framework.date.MyDate;
018: import org.air.framework.date.PeriodFormatterUtils;
019: import org.air.framework.db.MapCleaner;
020: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
021: import org.air.framework.gui.dialogs.input.AbstractOpenTabbedPanel;
022: import org.air.framework.gui.lookup.WidgetComboLookup;
023: import org.air.framework.gui.widgets.Button;
024: import org.air.framework.gui.widgets.WidgetChoose;
025: import org.air.framework.gui.widgets.WidgetTextArea;
026: import org.air.framework.gui.widgets.WidgetTextField;
027: import org.air.framework.i18n.NlsColumns;
028: import org.air.framework.records.Common;
029: import org.airtodo.db.DbUtils;
030: import org.airtodo.gui.dialog_table.AttachmentGridNonSelectableDialog;
031: import org.airtodo.gui.dialog_table.EmployeeGridSelectableDialog;
032: import org.airtodo.gui.dialog_table.NoteGridNonSelectableDialog;
033: import org.airtodo.gui_common.actions.other.ActionAttachments;
034: import org.airtodo.gui_common.actions.other.ActionNotes;
035: import org.airtodo.gui_common.components.lookup_data.LookupDataPriorityNote;
036: import org.airtodo.records.Employees;
037: import org.airtodo.records.Initiators;
038: import org.airtodo.records.Notes;
039:
040: public class NotePanel extends AbstractOpenTabbedPanel {
041: private long masterId;
042:
043: private long noteId;
044:
045: public NotePanel() {
046: getTabGeneral().add(getChooseInitiator());
047: getTabGeneral().add(getWidgetPriorityCombo());
048: getTabGeneral().add(getWidgetTextFieldName());
049: getTabGeneral().add(getWidgetTextAreaComment());
050: //
051: getButtonPanel().addAll(getButtonNotes(), small(),
052: getButtonAttachments(), Box.createHorizontalGlue());
053: }
054:
055: //
056: // getButtonNotes
057: //
058: private Button buttonNotes;
059:
060: private Component getButtonNotes() {
061: if (buttonNotes == null) {
062: buttonNotes = new Button(new ActionNotes() {
063: public void actionPerformed(ActionEvent e) {
064: Dialog owner = (Dialog) SwingUtilities
065: .windowForComponent(getOwner());
066: NoteGridNonSelectableDialog dialog = new NoteGridNonSelectableDialog(
067: owner, getWidgetTextFieldName().getText());
068: dialog.setMasterId(noteId);
069: dialog.loadAndSelect();
070: dialog.setVisible(true);
071: }
072: });
073: }
074: return buttonNotes;
075: }
076:
077: //
078: // getWidgetPriorityCombo
079: //
080: private WidgetComboLookup widgetPriorityCombo;
081:
082: private WidgetComboLookup getWidgetPriorityCombo() {
083: if (widgetPriorityCombo == null)
084: widgetPriorityCombo = new WidgetComboLookup(
085: new LookupDataPriorityNote());
086: return widgetPriorityCombo;
087: }
088:
089: //
090: // getChooseInitiator
091: //
092: private Long initiatorId;
093:
094: private WidgetChoose chooseInitiator;
095:
096: private Map initiatorMap = new HashMap();
097:
098: private WidgetChoose getChooseInitiator() {
099: if (chooseInitiator == null) {
100: chooseInitiator = new WidgetChoose(NlsColumns
101: .getText(Initiators.NAME)) {
102: @Override
103: protected void action() {
104: Dialog owner = getOwner();
105: AbstractGridDialog dialog;
106: if (initiatorId == null)
107: dialog = new EmployeeGridSelectableDialog(owner);
108: else
109: dialog = new EmployeeGridSelectableDialog(
110: owner, initiatorId);
111: dialog.setVisible(true);
112: if (!dialog.isFinish())
113: return;
114: Map selectedMap = dialog.getSelectedMap();
115: Object employeeId = selectedMap.get(Utils
116: .getColumnIdentifier(Common.ID));
117: Map employeeMap = MapCleaner.buildNativeMap(
118: selectedMap, Employees.class);
119: initiatorMap.put(Utils
120: .getColumnIdentifier(Notes.INITIATOR_ID),
121: employeeId);
122: initiatorId = (Long) initiatorMap.get(Utils
123: .getColumnIdentifier(Notes.INITIATOR_ID));
124: Map m = DbUtils
125: .convertEmployeesMapToInitiatorsMap(employeeMap);
126: initiatorMap.putAll(m);
127: String name = (String) initiatorMap.get(Utils
128: .getColumnIdentifier(Initiators.NAME));
129: chooseInitiator.setText(name);
130: }
131: };
132: chooseInitiator.setEnabled(!Registry.getFilterId()
133: .containsKey(Initiators.class));
134: chooseInitiator.setVisible(NlsColumns
135: .getText(Initiators.NAME) != null);
136: }
137: return chooseInitiator;
138: }
139:
140: //
141: // getButtonAttachments
142: //
143: private Button buttonAttachments;
144:
145: private Component getButtonAttachments() {
146: if (buttonAttachments == null) {
147: buttonAttachments = new Button(new ActionAttachments() {
148: public void actionPerformed(ActionEvent e) {
149: Dialog owner = (Dialog) SwingUtilities
150: .windowForComponent(NotePanel.this );
151: AttachmentGridNonSelectableDialog dialog = new AttachmentGridNonSelectableDialog(
152: owner, getWidgetTextFieldName().getText());
153: dialog.setMasterId(noteId);
154: dialog.loadAndSelect();
155: dialog.setVisible(true);
156: }
157: });
158: }
159: return buttonAttachments;
160: }
161:
162: //
163: // getWidgetTextFieldName
164: //
165: private WidgetTextField widgetTextFieldName;
166:
167: private WidgetTextField getWidgetTextFieldName() {
168: if (widgetTextFieldName == null)
169: widgetTextFieldName = new WidgetTextField(Notes.SUBJECT,
170: true);
171: return widgetTextFieldName;
172: }
173:
174: //
175: // getWidgetTextAreaComment
176: //
177: private WidgetTextArea widgetTextAreaComment;
178:
179: private WidgetTextArea getWidgetTextAreaComment() {
180: if (widgetTextAreaComment == null)
181: widgetTextAreaComment = new WidgetTextArea(Notes.NOTE);
182: return widgetTextAreaComment;
183: }
184:
185: //
186: // isFormValid
187: //
188: @Override
189: public boolean isFormValid() {
190: return getWidgetTextFieldName().isTextValid() && //;
191: getChooseInitiator().isTextValid();
192: }
193:
194: @Override
195: public void fromGui(Map map) {
196: Timestamp timestamp = (Timestamp) map.get(Utils
197: .getColumnIdentifier(Common.TIMESTAMP));
198: map.put(Utils.getColumnIdentifier(Notes.TIMESTAMP), new MyDate(
199: timestamp, PeriodFormatterUtils.FIELD.MINUTE));
200: getWidgetPriorityCombo().fromGui(map);
201: map.put(Utils.getColumnIdentifier(Notes.MASTER_ID), masterId);
202: getWidgetTextFieldName().fromGui(map);
203: getWidgetTextAreaComment().fromGui(map);
204: map.putAll(initiatorMap);
205: }
206:
207: @Override
208: public void toGui(Map map) {
209: Timestamp timestamp = (Timestamp) map.get(Utils
210: .getColumnIdentifier(Common.TIMESTAMP));
211: getTabbedPane()
212: .setTitleAt(
213: 0,
214: new MyDate(timestamp,
215: PeriodFormatterUtils.FIELD.MINUTE)
216: .toString());
217:
218: //
219: String name = (String) map.get(Utils
220: .getColumnIdentifier(Initiators.NAME));
221: if (name != null)
222: getChooseInitiator().setText(name);
223: initiatorId = (Long) map.get(Utils
224: .getColumnIdentifier(Notes.INITIATOR_ID));
225: //
226: getWidgetPriorityCombo().toGui(map);
227: masterId = (Long) map.get(Utils
228: .getColumnIdentifier(Notes.MASTER_ID));
229: getWidgetTextFieldName().toGui(map);
230: getWidgetTextAreaComment().toGui(map);
231: //
232: noteId = (Long) map.get(Utils.getColumnIdentifier(Common.ID));
233: }
234: }
|