001: package org.airtodo.gui.panel_open;
002:
003: import static org.air.framework.gui.box.Gap.medium;
004: import static org.air.framework.gui.box.Gap.small;
005:
006: import java.awt.Component;
007: import java.awt.Dialog;
008: import java.awt.event.ActionEvent;
009: import java.beans.PropertyChangeEvent;
010: import java.beans.PropertyChangeListener;
011: import java.util.Date;
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: import javax.swing.Box;
016: import javax.swing.SwingUtilities;
017:
018: import org.air.framework.core.Registry;
019: import org.air.framework.core.Utils;
020: import org.air.framework.date.PeriodFormatterUtils;
021: import org.air.framework.db.MapCleaner;
022: import org.air.framework.gui.box.BxY;
023: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
024: import org.air.framework.gui.dialogs.input.AbstractOpenTabbedPanel;
025: import org.air.framework.gui.lookup.WidgetComboLookup;
026: import org.air.framework.gui.timechooser.WidgetChooseFromCalendar;
027: import org.air.framework.gui.widgets.Button;
028: import org.air.framework.gui.widgets.WidgetChoose;
029: import org.air.framework.gui.widgets.WidgetChooseFromTable;
030: import org.air.framework.gui.widgets.WidgetTextArea;
031: import org.air.framework.gui.widgets.WidgetTextField;
032: import org.air.framework.i18n.NlsColumns;
033: import org.air.framework.i18n.NlsMessages;
034: import org.air.framework.i18n.NlsRecords;
035: import org.air.framework.records.Common;
036: import org.airtodo.db.DbUtils;
037: import org.airtodo.db.types.Period;
038: import org.airtodo.gui.dialog_table.AttachmentGridNonSelectableDialog;
039: import org.airtodo.gui.dialog_table.EmployeeGridSelectableDialog;
040: import org.airtodo.gui.dialog_table.ModuleGridSelectableDialog;
041: import org.airtodo.gui.dialog_table.NoteGridNonSelectableDialog;
042: import org.airtodo.gui.dialog_table.ProjectGridSelectableDialog;
043: import org.airtodo.gui.dialog_table.TaskTypeGridSelectableDialog;
044: import org.airtodo.gui_common.actions.other.ActionAttachments;
045: import org.airtodo.gui_common.actions.other.ActionNotes;
046: import org.airtodo.gui_common.components.lookup_data.LookupDataPriorityTask;
047: import org.airtodo.gui_common.components.widgets.WidgetPeriodFieldTask;
048: import org.airtodo.gui_common.components.widgets.WidgetProgressPanel;
049: import org.airtodo.records.Customers;
050: import org.airtodo.records.Employees;
051: import org.airtodo.records.Initiators;
052: import org.airtodo.records.Modules;
053: import org.airtodo.records.Projects;
054: import org.airtodo.records.TaskTypes;
055: import org.airtodo.records.Tasks;
056:
057: public class TaskPanel extends AbstractOpenTabbedPanel {
058: public static enum NLS {
059: TITLE_PERIOD, //
060: }
061:
062: private static final String NLS_TITLE_PERIOD = NlsMessages
063: .getString(NLS.TITLE_PERIOD);
064:
065: //
066: private long taskId;
067:
068: //
069: public TaskPanel() {
070: getTabGeneral().add(getWidgetTextFieldName());
071: getTabGeneral().add(getChooseInitiator());
072: getTabGeneral().add(getWidgetTextFieldItemName());
073: getTabGeneral().add(getWidgetTextFieldProjectName());
074: getTabGeneral().add(getChooseModule());
075: getTabGeneral().add(getWidgetTextFieldEmployeeName());
076: getTabGeneral().add(getWidgetPriorityCombo());
077: getTabGeneral().add(getWidgetTextAreaComment());
078: //
079: BxY bxYPeriod = new BxY(NLS_TITLE_PERIOD);
080: bxYPeriod.add(getWidgetChooseFromCalendar0());
081: bxYPeriod.add(getWidgetChooseFromCalendar1());
082: bxYPeriod.add(getWidgetTextFieldInterval());
083: bxYPeriod.add(medium());
084: getTabProperties().add(bxYPeriod);
085: getTabProperties().add(medium());
086: getTabProperties().add(getWidgetProgressPanel());
087: //
088: getButtonPanel().addAll(getButtonNotes(), small(),
089: getButtonAttachments(), Box.createHorizontalGlue());
090: //
091: getChooseModule().setEnabled(
092: !Registry.getFilterId().containsKey(Modules.class));
093: }
094:
095: //
096: // getWidgetPriorityCombo
097: //
098: private WidgetComboLookup widgetPriorityCombo;
099:
100: private WidgetComboLookup getWidgetPriorityCombo() {
101: if (widgetPriorityCombo == null)
102: widgetPriorityCombo = new WidgetComboLookup(
103: new LookupDataPriorityTask());
104: return widgetPriorityCombo;
105: }
106:
107: //
108: // getButtonNotes
109: //
110: private Button buttonNotes;
111:
112: private Component getButtonNotes() {
113: if (buttonNotes == null) {
114: buttonNotes = new Button(new ActionNotes() {
115: public void actionPerformed(ActionEvent e) {
116: Dialog owner = (Dialog) SwingUtilities
117: .windowForComponent(getOwner());
118: NoteGridNonSelectableDialog dialog = new NoteGridNonSelectableDialog(
119: owner, getWidgetTextFieldName().getText());
120: dialog.setMasterId(taskId);
121: dialog.loadAndSelect();
122: dialog.setVisible(true);
123: }
124: });
125: }
126: return buttonNotes;
127: }
128:
129: //
130: // getButtonAttachments
131: //
132: private Button buttonAttachments;
133:
134: private Component getButtonAttachments() {
135: if (buttonAttachments == null) {
136: buttonAttachments = new Button(new ActionAttachments() {
137: public void actionPerformed(ActionEvent e) {
138: Dialog owner = (Dialog) SwingUtilities
139: .windowForComponent(TaskPanel.this );
140: AttachmentGridNonSelectableDialog dialog = new AttachmentGridNonSelectableDialog(
141: owner, getWidgetTextFieldName().getText());
142: dialog.setMasterId(taskId);
143: dialog.loadAndSelect();
144: dialog.setVisible(true);
145: }
146: });
147: }
148: return buttonAttachments;
149: }
150:
151: //
152: // getChooseModule
153: //
154: private Long moduleId;
155:
156: private WidgetChoose chooseModule;
157:
158: private Map moduleMap = new HashMap();
159:
160: private WidgetChoose getChooseModule() {
161: if (chooseModule == null) {
162: chooseModule = new WidgetChoose(NlsRecords
163: .getTextSingleImenitelniy(Modules.NAME.getClass())) {
164: @Override
165: protected void action() {
166: Dialog owner = getOwner();
167: ModuleGridSelectableDialog dialog;
168: if (moduleId == null)
169: dialog = new ModuleGridSelectableDialog(owner);
170: else
171: dialog = new ModuleGridSelectableDialog(owner,
172: moduleId);
173: //
174: long projectId = (Long) getWidgetTextFieldProjectName()
175: .getSelectedMap()
176: .get(
177: Utils
178: .getColumnIdentifier(Tasks.PROJECT_ID));
179: dialog.setProjectId(projectId);
180: dialog.loadAndSelect();
181: dialog.setVisible(true);
182: if (!dialog.isFinish())
183: return;
184: Map selectedMap = dialog.getSelectedMap();
185: moduleId = (Long) selectedMap.get(Utils
186: .getColumnIdentifier(Common.ID));
187: moduleMap = MapCleaner.buildNativeMap(selectedMap,
188: Modules.class);
189: moduleMap.put(Utils
190: .getColumnIdentifier(Tasks.MODULE_ID),
191: moduleId);
192: String name = (String) moduleMap.get(Utils
193: .getColumnIdentifier(Modules.NAME));
194: chooseModule.setText(name);
195: }
196: };
197: chooseModule.setEnabled(!Registry.getFilterId()
198: .containsKey(Modules.class));
199: chooseModule
200: .setVisible(NlsColumns.getText(Modules.NAME) != null);
201: }
202: return chooseModule;
203: }
204:
205: //
206: // getWidgetChooseFromCalendar0
207: //
208: private WidgetChooseFromCalendar widgetTextFieldTime0;
209:
210: protected WidgetChooseFromCalendar getWidgetChooseFromCalendar0() {
211: if (widgetTextFieldTime0 == null) {
212: widgetTextFieldTime0 = new WidgetChooseFromCalendar(
213: PeriodFormatterUtils.FIELD.MINUTE, Tasks.TIME);
214: widgetTextFieldTime0.addPropertyChangeListener(
215: WidgetChooseFromCalendar.PROPETY_TIME_UPDATED,
216: new PropertyChangeListener() {
217: public void propertyChange(
218: PropertyChangeEvent evt) {
219: updateTimeInterval();
220: }
221: });
222: }
223: return widgetTextFieldTime0;
224: }
225:
226: //
227: // getWidgetChooseFromCalendar1
228: //
229: private WidgetChooseFromCalendar widgetTextFieldTime1;
230:
231: protected WidgetChooseFromCalendar getWidgetChooseFromCalendar1() {
232: if (widgetTextFieldTime1 == null) {
233: widgetTextFieldTime1 = new WidgetChooseFromCalendar(
234: PeriodFormatterUtils.FIELD.MINUTE, Tasks.TIME_END);
235: widgetTextFieldTime1.addPropertyChangeListener(
236: WidgetChooseFromCalendar.PROPETY_TIME_UPDATED,
237: new PropertyChangeListener() {
238: public void propertyChange(
239: PropertyChangeEvent evt) {
240: updateTimeInterval();
241: }
242: });
243: }
244: return widgetTextFieldTime1;
245: }
246:
247: private void updateTimeInterval() {
248: Date dateStart = (Date) getWidgetChooseFromCalendar0()
249: .getSelectedMap().get(
250: Utils.getColumnIdentifier(Tasks.TIME));
251: Date dateEnd = (Date) getWidgetChooseFromCalendar1()
252: .getSelectedMap().get(
253: Utils.getColumnIdentifier(Tasks.TIME_END));
254: Period period = new Period(PeriodFormatterUtils.FIELD.MINUTE);
255: period.setValue(dateStart, dateEnd);
256: getWidgetTextFieldInterval().setInterval(period);
257: }
258:
259: //
260: // getWidgetTextFieldInterval
261: //
262: private WidgetPeriodFieldTask widgetTextFieldInterval;
263:
264: private WidgetPeriodFieldTask getWidgetTextFieldInterval() {
265: if (widgetTextFieldInterval == null)
266: widgetTextFieldInterval = new WidgetPeriodFieldTask(
267: Tasks.PERIOD);
268: return widgetTextFieldInterval;
269: }
270:
271: //
272: // getWidgetTextFieldName
273: //
274: private WidgetTextField widgetTextFieldName;
275:
276: private WidgetTextField getWidgetTextFieldName() {
277: if (widgetTextFieldName == null)
278: widgetTextFieldName = new WidgetTextField(Tasks.NAME, true);
279: return widgetTextFieldName;
280: }
281:
282: //
283: // getWidgetTextAreaComment
284: //
285: private WidgetTextArea widgetTextAreaComment;
286:
287: private WidgetTextArea getWidgetTextAreaComment() {
288: if (widgetTextAreaComment == null)
289: widgetTextAreaComment = new WidgetTextArea(Tasks.COMMENT);
290: return widgetTextAreaComment;
291: }
292:
293: //
294: // getWidgetProgressPanel
295: //
296: private WidgetProgressPanel widgetProgressPanel;
297:
298: private WidgetProgressPanel getWidgetProgressPanel() {
299: if (widgetProgressPanel == null)
300: widgetProgressPanel = new WidgetProgressPanel(
301: Tasks.PROGRESS, Tasks.FREEZED);
302: return widgetProgressPanel;
303: }
304:
305: //
306: // getWidgetTextFieldItemName
307: //
308: private WidgetChooseFromTable widgetTextFieldItemName;
309:
310: protected WidgetChooseFromTable getWidgetTextFieldItemName() {
311: if (widgetTextFieldItemName == null)
312: widgetTextFieldItemName = new WidgetChooseFromTable(
313: TaskTypes.NAME, TaskTypes.class,
314: TaskTypeGridSelectableDialog.class,
315: Tasks.TASK_TYPE_ID);
316: return widgetTextFieldItemName;
317: }
318:
319: //
320: // getWidgetTextFieldProjectName
321: //
322: private WidgetChooseFromTable widgetTextFieldProjectName;
323:
324: private WidgetChooseFromTable getWidgetTextFieldProjectName() {
325: if (widgetTextFieldProjectName == null) {
326: widgetTextFieldProjectName = new WidgetChooseFromTable(
327: Projects.NAME, Projects.class,
328: ProjectGridSelectableDialog.class, Tasks.PROJECT_ID);
329: widgetTextFieldProjectName.addPropertyChangeListener(
330: WidgetChooseFromTable.PROPERTY_CHANGED,
331: new PropertyChangeListener() {
332: public void propertyChange(
333: PropertyChangeEvent arg0) {
334: getChooseModule().getTextComponent()
335: .setText("");
336: }
337: });
338: }
339: return widgetTextFieldProjectName;
340: }
341:
342: //
343: // getWidgetTextFieldEmployeeName
344: //
345: private WidgetChooseFromTable widgetTextFieldEmployeeName;
346:
347: protected WidgetChooseFromTable getWidgetTextFieldEmployeeName() {
348: if (widgetTextFieldEmployeeName == null)
349: widgetTextFieldEmployeeName = new WidgetChooseFromTable(
350: Employees.NAME, Employees.class,
351: EmployeeGridSelectableDialog.class,
352: Tasks.EMPLOYEE_ID);
353: return widgetTextFieldEmployeeName;
354: }
355:
356: //
357: // getChooseInitiator
358: //
359: private Long initiatorId;
360:
361: private WidgetChoose chooseInitiator;
362:
363: private Map initiatorMap = new HashMap();
364:
365: private WidgetChoose getChooseInitiator() {
366: if (chooseInitiator == null) {
367: chooseInitiator = new WidgetChoose(NlsColumns
368: .getText(Initiators.NAME)) {
369: @Override
370: protected void action() {
371: Dialog owner = getOwner();
372: AbstractGridDialog dialog;
373: if (initiatorId == null)
374: dialog = new EmployeeGridSelectableDialog(owner);
375: else
376: dialog = new EmployeeGridSelectableDialog(
377: owner, initiatorId);
378: dialog.setVisible(true);
379: if (!dialog.isFinish())
380: return;
381: Map selectedMap = dialog.getSelectedMap();
382: Object employeeId = selectedMap.get(Utils
383: .getColumnIdentifier(Common.ID));
384: Map employeeMap = MapCleaner.buildNativeMap(
385: selectedMap, Employees.class);
386: initiatorMap.put(Utils
387: .getColumnIdentifier(Tasks.INITIATOR_ID),
388: employeeId);
389: initiatorId = (Long) initiatorMap.get(Utils
390: .getColumnIdentifier(Tasks.INITIATOR_ID));
391: Map m = DbUtils
392: .convertEmployeesMapToInitiatorsMap(employeeMap);
393: initiatorMap.putAll(m);
394: String name = (String) initiatorMap.get(Utils
395: .getColumnIdentifier(Initiators.NAME));
396: chooseInitiator.setText(name);
397: }
398: };
399: chooseInitiator.setEnabled(!Registry.getFilterId()
400: .containsKey(Initiators.class));
401: chooseInitiator.setVisible(NlsColumns
402: .getText(Initiators.NAME) != null);
403: }
404: return chooseInitiator;
405: }
406:
407: //
408: // isFormValid
409: //
410: @Override
411: public boolean isFormValid() {
412: if (!getWidgetTextFieldName().isTextValid())
413: return false;
414: if (!getWidgetTextFieldItemName().isTextValid())
415: return false;
416: if (!getWidgetTextFieldProjectName().isTextValid())
417: return false;
418: if (!getChooseModule().isTextValid())
419: return false;
420: if (!getChooseInitiator().isTextValid())
421: return false;
422: if (!getWidgetTextFieldInterval().isTextValid())
423: return false;
424: return true;
425: }
426:
427: @Override
428: public void fromGui(Map map) {
429: getWidgetTextAreaComment().fromGui(map);
430: getWidgetTextFieldName().fromGui(map);
431: getWidgetPriorityCombo().fromGui(map);
432: getWidgetTextFieldInterval().fromGui(map);
433: getWidgetProgressPanel().fromGui(map);
434: //
435: Map timeMap0 = getWidgetChooseFromCalendar0().getSelectedMap();
436: if (getWidgetChooseFromCalendar0().isUpdated()) {
437: map.put(Utils.getColumnIdentifier(Tasks.TIME), timeMap0
438: .get(Utils.getColumnIdentifier(Tasks.TIME)));
439: }
440: //
441: Map timeMap1 = getWidgetChooseFromCalendar1().getSelectedMap();
442: if (getWidgetChooseFromCalendar1().isUpdated()) {
443: map.put(Utils.getColumnIdentifier(Tasks.TIME_END), timeMap1
444: .get(Utils.getColumnIdentifier(Tasks.TIME_END)));
445: }
446: //
447: Map itemMap = getWidgetTextFieldItemName().getSelectedMap();
448: if (getWidgetTextFieldItemName().isUpdated()) {
449: map.put(Utils.getColumnIdentifier(Tasks.TASK_TYPE_ID),
450: itemMap.get(Utils.getColumnIdentifier(Common.ID)));
451: map.put(Utils.getColumnIdentifier(TaskTypes.NAME), itemMap
452: .get(Utils.getColumnIdentifier(TaskTypes.NAME)));
453: map.put(Utils.getColumnIdentifier(TaskTypes.COMMENT),
454: itemMap.get(Utils
455: .getColumnIdentifier(TaskTypes.COMMENT)));
456: }
457: //
458: Map projectMap = getWidgetTextFieldProjectName()
459: .getSelectedMap();
460: if (getWidgetTextFieldProjectName().isUpdated()) {
461: map.put(Utils.getColumnIdentifier(Tasks.PROJECT_ID),
462: projectMap
463: .get(Utils.getColumnIdentifier(Common.ID)));
464: map.put(Utils.getColumnIdentifier(Projects.NAME),
465: projectMap.get(Utils
466: .getColumnIdentifier(Projects.NAME)));
467: map.put(Utils.getColumnIdentifier(Projects.COMMENT),
468: projectMap.get(Utils
469: .getColumnIdentifier(Projects.COMMENT)));
470: map.put(Utils.getColumnIdentifier(Customers.NAME),
471: projectMap.get(Utils
472: .getColumnIdentifier(Customers.NAME)));
473: map.put(Utils.getColumnIdentifier(Customers.ADDRESS),
474: projectMap.get(Utils
475: .getColumnIdentifier(Customers.ADDRESS)));
476: map.put(Utils.getColumnIdentifier(Customers.PHONE),
477: projectMap.get(Utils
478: .getColumnIdentifier(Customers.PHONE)));
479: map.put(Utils.getColumnIdentifier(Customers.COMMENT),
480: projectMap.get(Utils
481: .getColumnIdentifier(Customers.COMMENT)));
482: }
483: //
484: Map employeeMap = getWidgetTextFieldEmployeeName()
485: .getSelectedMap();
486: if (getWidgetTextFieldEmployeeName().isUpdated()) {
487: map.put(Utils.getColumnIdentifier(Tasks.EMPLOYEE_ID),
488: employeeMap.get(Utils
489: .getColumnIdentifier(Common.ID)));
490: map.put(Utils.getColumnIdentifier(Employees.NAME),
491: employeeMap.get(Utils
492: .getColumnIdentifier(Employees.NAME)));
493: map.put(Utils.getColumnIdentifier(Employees.COMMENT),
494: employeeMap.get(Utils
495: .getColumnIdentifier(Employees.COMMENT)));
496: }
497: //
498: map.putAll(initiatorMap);
499: map.putAll(moduleMap);
500: }
501:
502: @Override
503: public void toGui(Map map) {
504: getWidgetChooseFromCalendar0().toGui(map);
505: getWidgetChooseFromCalendar1().toGui(map);
506: getWidgetTextFieldItemName().toGui(map);
507: //
508: String name = (String) map.get(Utils
509: .getColumnIdentifier(Initiators.NAME));
510: if (name != null)
511: getChooseInitiator().setText(name);
512: initiatorId = (Long) map.get(Utils
513: .getColumnIdentifier(Tasks.INITIATOR_ID));
514: //
515: //
516: String moduleNmame = (String) map.get(Utils
517: .getColumnIdentifier(Modules.NAME));
518: if (moduleNmame != null)
519: getChooseModule().setText(moduleNmame);
520: moduleId = (Long) map.get(Utils
521: .getColumnIdentifier(Tasks.MODULE_ID));
522: //
523: getWidgetPriorityCombo().toGui(map);
524: getWidgetTextFieldInterval().toGui(map);
525: getWidgetTextFieldProjectName().toGui(map);
526: getWidgetTextFieldEmployeeName().toGui(map);
527: getWidgetTextFieldName().toGui(map);
528: getWidgetTextAreaComment().toGui(map);
529: getWidgetProgressPanel().toGui(map);
530: //
531: taskId = (Long) map.get(Utils.getColumnIdentifier(Common.ID));
532: //
533: }
534: }
|