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.Color;
007: import java.awt.Component;
008: import java.awt.Dialog;
009: import java.awt.event.ActionEvent;
010: import java.awt.event.ItemEvent;
011: import java.awt.event.ItemListener;
012: import java.beans.PropertyChangeEvent;
013: import java.beans.PropertyChangeListener;
014: import java.util.Date;
015: import java.util.Map;
016:
017: import javax.swing.Box;
018: import javax.swing.JLabel;
019: import javax.swing.SwingUtilities;
020:
021: import org.air.framework.core.Registry;
022: import org.air.framework.core.Utils;
023: import org.air.framework.date.PeriodFormatterUtils;
024: import org.air.framework.gui.actions.basic.BasicAbstractAction;
025: import org.air.framework.gui.box.BxX;
026: import org.air.framework.gui.box.BxY;
027: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
028: import org.air.framework.gui.dialogs.input.AbstractOpenTabbedPanel;
029: import org.air.framework.gui.lookup.WidgetComboLookup;
030: import org.air.framework.gui.timechooser.WidgetChooseFromCalendar;
031: import org.air.framework.gui.widgets.Button;
032: import org.air.framework.gui.widgets.WidgetChooseFromTable;
033: import org.air.framework.gui.widgets.WidgetTextArea;
034: import org.air.framework.gui.widgets.WidgetTextField;
035: import org.air.framework.i18n.NlsMessages;
036: import org.air.framework.properties.IRgbProperties;
037: import org.air.framework.properties.Icons;
038: import org.air.framework.records.Common;
039: import org.airtodo.db.types.Period;
040: import org.airtodo.db.types.Stage;
041: import org.airtodo.gui.dialog_table.AttachmentGridNonSelectableDialog;
042: import org.airtodo.gui.dialog_table.CustomerGridSelectableSingleDialog;
043: import org.airtodo.gui.dialog_table.ModuleGridNonSelectableDialog;
044: import org.airtodo.gui.dialog_table.NoteGridNonSelectableDialog;
045: import org.airtodo.gui.dialog_table.TaskGridNonSelectableDialog;
046: import org.airtodo.gui_common.actions.other.ActionAttachments;
047: import org.airtodo.gui_common.actions.other.ActionModules;
048: import org.airtodo.gui_common.actions.other.ActionNotes;
049: import org.airtodo.gui_common.components.lookup_data.LookupDataPriorityProject;
050: import org.airtodo.gui_common.components.lookup_data.LookupDataStage;
051: import org.airtodo.gui_common.components.widgets.WidgetPeriodFieldProject;
052: import org.airtodo.gui_common.components.widgets.WidgetProgressPanel;
053: import org.airtodo.records.Customers;
054: import org.airtodo.records.Projects;
055:
056: public class ProjectPanel extends AbstractOpenTabbedPanel {
057:
058: public static enum NLS {
059: TITLE_PROJECT, //
060: TITLE_PERIOD, //
061: TITLE_STAGE, //
062: LABEL_PMBOK_G0, //
063: LABEL_PMBOK_G1, //
064: LABEL_PMBOK_G2, //
065: LABEL_PMBOK_G3, //
066: LABEL_PMBOK_G4, //
067: LABEL_PMBOK_TITLE, //
068: LABEL_PMBOK_COPYRIGHT
069: //
070: }
071:
072: private static final String NLS_TITLE_PROJECT = NlsMessages
073: .getString(NLS.TITLE_PROJECT);
074: private static final String NLS_TITLE_PERIOD = NlsMessages
075: .getString(NLS.TITLE_PERIOD);
076: private static final String NLS_TITLE_STAGE = NlsMessages
077: .getString(NLS.TITLE_STAGE);
078: private static final String NLS_LABEL_PMBOK_TITLE = NlsMessages
079: .getString(NLS.LABEL_PMBOK_TITLE);
080: private static final String NLS_LABEL_PMBOK_COPYRIGHT = NlsMessages
081: .getString(NLS.LABEL_PMBOK_COPYRIGHT);
082: private static final String NLS_LABEL_PMBOK_G0 = NlsMessages
083: .getString(NLS.LABEL_PMBOK_G0);
084: private static final String NLS_LABEL_PMBOK_G1 = NlsMessages
085: .getString(NLS.LABEL_PMBOK_G1);
086: private static final String NLS_LABEL_PMBOK_G2 = NlsMessages
087: .getString(NLS.LABEL_PMBOK_G2);
088: private static final String NLS_LABEL_PMBOK_G3 = NlsMessages
089: .getString(NLS.LABEL_PMBOK_G3);
090: private static final String NLS_LABEL_PMBOK_G4 = NlsMessages
091: .getString(NLS.LABEL_PMBOK_G4);
092: //
093: private long projectId;
094:
095: //
096: public ProjectPanel() {
097: BxY bxYProject = new BxY(NLS_TITLE_PROJECT);
098: bxYProject.add(getWidgetTextFieldName());
099: bxYProject.add(getWidgetTextFieldCustomerName());
100: bxYProject.add(getWidgetPriorityCombo());
101: bxYProject.add(getWidgetTextAreaComment());
102: getTabGeneral().add(bxYProject);
103: //
104: getTabGeneral().add(medium());
105: //
106: BxY bxYPeriod = new BxY(NLS_TITLE_PERIOD);
107: bxYPeriod.add(getWidgetChooseFromCalendar0());
108: bxYPeriod.add(getWidgetChooseFromCalendar1());
109: bxYPeriod.add(getWidgetTextFieldInterval());
110: getTabGeneral().add(bxYPeriod);
111: getTabProperties().add(getWidgetProgressPanel());
112: getTabProperties().add(medium());
113: BxY bxYStage = new BxY(NLS_TITLE_STAGE);
114: bxYStage.add(getWidgetStageCombo());
115: bxYStage.add(new BxX(getLabelPmbok(), Box
116: .createHorizontalGlue()));
117: bxYStage.add(small());
118: bxYStage.add(new BxX(getLabelDescription(), Box
119: .createHorizontalGlue()));
120: getTabProperties().add(bxYStage);
121: //
122: getButtonPanel()
123: .addAll(getButtonNotes(), small(),
124: getButtonAttachments(), small(),
125: getButtonTasks(), small(), getButtonModules(),
126: Box.createHorizontalGlue());
127: }
128:
129: //
130: // getButtonNotes
131: //
132: private Button buttonNotes;
133:
134: private Component getButtonNotes() {
135: if (buttonNotes == null) {
136: buttonNotes = new Button(new ActionNotes() {
137: public void actionPerformed(ActionEvent e) {
138: Dialog owner = (Dialog) SwingUtilities
139: .windowForComponent(getOwner());
140: NoteGridNonSelectableDialog dialog = new NoteGridNonSelectableDialog(
141: owner, getWidgetTextFieldName().getText());
142: dialog.setMasterId(projectId);
143: dialog.loadAndSelect();
144: dialog.setVisible(true);
145: }
146: });
147: }
148: return buttonNotes;
149: }
150:
151: //
152: // getWidgetChooseFromCalendar0
153: //
154: private WidgetChooseFromCalendar widgetTextFieldTime0;
155:
156: protected WidgetChooseFromCalendar getWidgetChooseFromCalendar0() {
157: if (widgetTextFieldTime0 == null) {
158: widgetTextFieldTime0 = new WidgetChooseFromCalendar(
159: PeriodFormatterUtils.FIELD.DAY, Projects.DATE_START);
160: widgetTextFieldTime0.addPropertyChangeListener(
161: WidgetChooseFromCalendar.PROPETY_TIME_UPDATED,
162: new PropertyChangeListener() {
163: public void propertyChange(
164: PropertyChangeEvent evt) {
165: updateTimeInterval();
166: }
167: });
168: }
169: return widgetTextFieldTime0;
170: }
171:
172: //
173: // getWidgetChooseFromCalendar1
174: //
175: private WidgetChooseFromCalendar widgetTextFieldTime1;
176:
177: protected WidgetChooseFromCalendar getWidgetChooseFromCalendar1() {
178: if (widgetTextFieldTime1 == null) {
179: widgetTextFieldTime1 = new WidgetChooseFromCalendar(
180: PeriodFormatterUtils.FIELD.DAY, Projects.DATE_END);
181: widgetTextFieldTime1.addPropertyChangeListener(
182: WidgetChooseFromCalendar.PROPETY_TIME_UPDATED,
183: new PropertyChangeListener() {
184: public void propertyChange(
185: PropertyChangeEvent evt) {
186: updateTimeInterval();
187: }
188: });
189: }
190: return widgetTextFieldTime1;
191: }
192:
193: private void updateTimeInterval() {
194: Date dateStart = (Date) getWidgetChooseFromCalendar0()
195: .getSelectedMap().get(
196: Utils.getColumnIdentifier(Projects.DATE_START));
197: Date dateEnd = (Date) getWidgetChooseFromCalendar1()
198: .getSelectedMap().get(
199: Utils.getColumnIdentifier(Projects.DATE_END));
200: Period period = new Period(PeriodFormatterUtils.FIELD.DAY);
201: period.setValue(dateStart, dateEnd);
202: getWidgetTextFieldInterval().setInterval(period);
203: }
204:
205: //
206: // getWidgetTextFieldInterval
207: //
208: private WidgetPeriodFieldProject widgetTextFieldInterval;
209:
210: private WidgetPeriodFieldProject getWidgetTextFieldInterval() {
211: if (widgetTextFieldInterval == null)
212: widgetTextFieldInterval = new WidgetPeriodFieldProject(
213: Projects.PERIOD);
214: return widgetTextFieldInterval;
215: }
216:
217: //
218: // getWidgetProgressPanel
219: //
220: private WidgetProgressPanel widgetProgressPanel;
221:
222: private WidgetProgressPanel getWidgetProgressPanel() {
223: if (widgetProgressPanel == null)
224: widgetProgressPanel = new WidgetProgressPanel(
225: Projects.PROGRESS, Projects.FREEZED);
226: return widgetProgressPanel;
227: }
228:
229: //
230: // getWidgetTextFieldAlias
231: //
232: private WidgetTextField widgetTextFieldName;
233:
234: private WidgetTextField getWidgetTextFieldName() {
235: if (widgetTextFieldName == null)
236: widgetTextFieldName = new WidgetTextField(Projects.NAME,
237: true);
238: return widgetTextFieldName;
239: }
240:
241: //
242: // getWidgetPriorityCombo
243: //
244: private WidgetComboLookup widgetPriorityCombo;
245:
246: private WidgetComboLookup getWidgetPriorityCombo() {
247: if (widgetPriorityCombo == null)
248: widgetPriorityCombo = new WidgetComboLookup(
249: new LookupDataPriorityProject());
250: return widgetPriorityCombo;
251: }
252:
253: //
254: // getWidgetStageCombo
255: //
256: private WidgetComboLookup widgetStageCombo;
257:
258: private WidgetComboLookup getWidgetStageCombo() {
259: if (widgetStageCombo == null) {
260: widgetStageCombo = new WidgetComboLookup(
261: new LookupDataStage());
262: widgetStageCombo.getComboBox().addItemListener(
263: new ItemListener() {
264: public void itemStateChanged(ItemEvent e) {
265: int intValue = ((Stage) e.getItem())
266: .getValue();
267: if (intValue == 0)
268: return;
269: String text = null;
270: switch (intValue) {
271: case 1:
272: text = NLS_LABEL_PMBOK_G0;
273: break;
274: case 2:
275: text = NLS_LABEL_PMBOK_G1;
276: break;
277: case 3:
278: text = NLS_LABEL_PMBOK_G2;
279: break;
280: case 4:
281: text = NLS_LABEL_PMBOK_G3;
282: break;
283: case 5:
284: text = NLS_LABEL_PMBOK_G4;
285: break;
286: }
287: getLabelDescription()
288: .setText(
289: "<HTML> "
290: + text
291: + "</I><BR><BR><SMALL>"
292: + NLS_LABEL_PMBOK_COPYRIGHT);
293: getLabelPmbok().setVisible(true);
294: }
295:
296: });
297: }
298: return widgetStageCombo;
299: }
300:
301: private JLabel labelDescription;
302:
303: private JLabel getLabelDescription() {
304: if (labelDescription == null) {
305: labelDescription = new JLabel();
306: labelDescription.setForeground(new Color(
307: IRgbProperties.FOREGROUND_INFORMATION));
308: }
309: return labelDescription;
310: }
311:
312: private JLabel labelPmbok;
313:
314: private JLabel getLabelPmbok() {
315: if (labelPmbok == null) {
316: labelPmbok = new JLabel(NLS_LABEL_PMBOK_TITLE,
317: Icons.INFORMATION, JLabel.LEFT);
318: labelPmbok.setForeground(new Color(
319: IRgbProperties.FOREGROUND_INFORMATION));
320: labelPmbok.setVisible(false);
321: }
322: return labelPmbok;
323: }
324:
325: //
326: // getWidgetTextAreaComment
327: //
328: private WidgetTextArea widgetTextAreaComment;
329:
330: private WidgetTextArea getWidgetTextAreaComment() {
331: if (widgetTextAreaComment == null)
332: widgetTextAreaComment = new WidgetTextArea(Projects.COMMENT);
333: return widgetTextAreaComment;
334: }
335:
336: //
337: // getWidgetTextFieldCustomerName
338: //
339: private WidgetChooseFromTable widgetTextFieldCustomerName;
340:
341: protected WidgetChooseFromTable getWidgetTextFieldCustomerName() {
342: if (widgetTextFieldCustomerName == null)
343: widgetTextFieldCustomerName = new WidgetChooseFromTable(
344: Customers.NAME, Customers.class,
345: CustomerGridSelectableSingleDialog.class,
346: Projects.CUSTOMER_ID);
347: return widgetTextFieldCustomerName;
348: }
349:
350: //
351: // getButtonTasks
352: //
353: private Button buttonTasks;
354:
355: private Component getButtonTasks() {
356: if (buttonTasks == null) {
357: buttonTasks = new Button(
358: new BasicAbstractAction(
359: new TaskGridNonSelectableDialog()
360: .getDialogTitle()
361: + BasicAbstractAction.ELLIPSIS,
362: Icons.TABLE) {
363: public void actionPerformed(ActionEvent e) {
364: Dialog owner = (Dialog) SwingUtilities
365: .windowForComponent(ProjectPanel.this );
366: TaskGridNonSelectableDialog taskDialog = new TaskGridNonSelectableDialog(
367: owner);
368: Registry.getFilterId().put(Projects.class,
369: projectId);
370: Map map = ((AbstractGridDialog) owner
371: .getOwner()).getTable()
372: .getSelectedRecord();
373: Registry.getFilterMap().put(Projects.class,
374: map);
375: fromGui(map);
376: taskDialog.loadAndSelect();
377: taskDialog.setVisible(true);
378: Registry.getFilterId().remove(
379: Projects.class);
380: Registry.getFilterMap().remove(
381: Projects.class);
382: }
383: });
384: }
385: return buttonTasks;
386: }
387:
388: //
389: // getButtonAttachments
390: //
391: private Button buttonAttachments;
392:
393: private Component getButtonAttachments() {
394: if (buttonAttachments == null) {
395: buttonAttachments = new Button(new ActionAttachments() {
396: public void actionPerformed(ActionEvent e) {
397: Dialog owner = (Dialog) SwingUtilities
398: .windowForComponent(ProjectPanel.this );
399: AttachmentGridNonSelectableDialog dialog = new AttachmentGridNonSelectableDialog(
400: owner, getWidgetTextFieldName().getText());
401: dialog.setMasterId(projectId);
402: dialog.loadAndSelect();
403: dialog.setVisible(true);
404: }
405: });
406: }
407: return buttonAttachments;
408: }
409:
410: //
411: // getButtonModules
412: //
413: private Button buttonModules;
414:
415: private Component getButtonModules() {
416: if (buttonModules == null) {
417: buttonModules = new Button(new ActionModules() {
418: public void actionPerformed(ActionEvent e) {
419: Dialog owner = (Dialog) SwingUtilities
420: .windowForComponent(ProjectPanel.this );
421: ModuleGridNonSelectableDialog linksDialog = new ModuleGridNonSelectableDialog(
422: owner, getWidgetTextFieldName().getText());
423: Registry.getFilterId().put(Projects.class,
424: projectId);
425: Map map = ((AbstractGridDialog) owner.getOwner())
426: .getTable().getSelectedRecord();
427: Registry.getFilterMap().put(Projects.class, map);
428: linksDialog.setProjectId(projectId);
429: linksDialog.loadAndSelect();
430: linksDialog.setVisible(true);
431: Registry.getFilterId().remove(Projects.class);
432: Registry.getFilterMap().remove(Projects.class);
433: }
434: });
435: }
436: return buttonModules;
437: }
438:
439: //
440: // isFormValid
441: //
442: @Override
443: public boolean isFormValid() {
444: if (!getWidgetTextFieldName().isTextValid())
445: return false;
446: if (!getWidgetTextFieldCustomerName().isTextValid())
447: return false;
448: if (!getWidgetTextFieldInterval().isTextValid())
449: return false;
450: return true;
451: }
452:
453: @Override
454: public void fromGui(Map map) {
455: getWidgetTextFieldName().fromGui(map);
456: getWidgetPriorityCombo().fromGui(map);
457: getWidgetTextAreaComment().fromGui(map);
458: getWidgetProgressPanel().fromGui(map);
459: getWidgetStageCombo().fromGui(map);
460: getWidgetTextFieldInterval().fromGui(map);
461: //
462: Map timeMap0 = getWidgetChooseFromCalendar0().getSelectedMap();
463: if (getWidgetChooseFromCalendar0().isUpdated()) {
464: map.put(Utils.getColumnIdentifier(Projects.DATE_START),
465: timeMap0.get(Utils
466: .getColumnIdentifier(Projects.DATE_START)));
467: }
468: //
469: Map timeMap1 = getWidgetChooseFromCalendar1().getSelectedMap();
470: if (getWidgetChooseFromCalendar1().isUpdated()) {
471: map.put(Utils.getColumnIdentifier(Projects.DATE_END),
472: timeMap1.get(Utils
473: .getColumnIdentifier(Projects.DATE_END)));
474: }
475: //
476: Map customerMap = getWidgetTextFieldCustomerName()
477: .getSelectedMap();
478: if (getWidgetTextFieldCustomerName().isUpdated()) {
479: map.put(Utils.getColumnIdentifier(Projects.CUSTOMER_ID),
480: customerMap.get(Utils
481: .getColumnIdentifier(Common.ID)));
482: map.put(Utils.getColumnIdentifier(Customers.NAME),
483: customerMap.get(Utils
484: .getColumnIdentifier(Customers.NAME)));
485: map.put(Utils.getColumnIdentifier(Customers.ADDRESS),
486: customerMap.get(Utils
487: .getColumnIdentifier(Customers.ADDRESS)));
488: map.put(Utils.getColumnIdentifier(Customers.PHONE),
489: customerMap.get(Utils
490: .getColumnIdentifier(Customers.PHONE)));
491: map.put(Utils.getColumnIdentifier(Customers.EMAIL),
492: customerMap.get(Utils
493: .getColumnIdentifier(Customers.EMAIL)));
494: map.put(Utils.getColumnIdentifier(Customers.COMMENT),
495: customerMap.get(Utils
496: .getColumnIdentifier(Customers.COMMENT)));
497: }
498: }
499:
500: @Override
501: public void toGui(Map map) {
502: getWidgetChooseFromCalendar0().toGui(map);
503: getWidgetChooseFromCalendar1().toGui(map);
504: getWidgetTextFieldInterval().toGui(map);
505: getWidgetTextFieldCustomerName().toGui(map);
506: getWidgetTextFieldName().toGui(map);
507: getWidgetPriorityCombo().toGui(map);
508: getWidgetStageCombo().toGui(map);
509: getWidgetTextAreaComment().toGui(map);
510: getWidgetProgressPanel().toGui(map);
511: //
512: projectId = (Long) map
513: .get(Utils.getColumnIdentifier(Common.ID));
514: }
515: }
|