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.util.Map;
009:
010: import javax.swing.Box;
011: import javax.swing.SwingUtilities;
012:
013: import org.air.framework.core.Registry;
014: import org.air.framework.core.Utils;
015: import org.air.framework.gui.actions.basic.BasicAbstractAction;
016: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
017: import org.air.framework.gui.dialogs.input.AbstractOpenTabbedPanel;
018: import org.air.framework.gui.widgets.Button;
019: import org.air.framework.gui.widgets.WidgetTextArea;
020: import org.air.framework.gui.widgets.WidgetTextField;
021: import org.air.framework.properties.Icons;
022: import org.air.framework.records.Common;
023: import org.airtodo.gui.dialog_table.AttachmentGridNonSelectableDialog;
024: import org.airtodo.gui.dialog_table.NoteGridNonSelectableDialog;
025: import org.airtodo.gui.dialog_table.TaskGridNonSelectableDialog;
026: import org.airtodo.gui_common.actions.other.ActionAttachments;
027: import org.airtodo.gui_common.actions.other.ActionNotes;
028: import org.airtodo.records.TaskTypes;
029:
030: public class TaskTypePanel extends AbstractOpenTabbedPanel {
031: //
032: private long taskTypeId;
033:
034: //
035: public TaskTypePanel() {
036: getTabGeneral().add(getWidgetTextFieldName());
037: getTabGeneral().add(getWidgetTextAreaComment());
038: getButtonPanel().addAll(getButtonNotes(), small(),
039: getButtonAttachments(), small(), getButtonTasks(),
040: Box.createHorizontalGlue());
041: }
042:
043: //
044: // getButtonNotes
045: //
046: private Button buttonNotes;
047:
048: private Component getButtonNotes() {
049: if (buttonNotes == null) {
050: buttonNotes = new Button(new ActionNotes() {
051: public void actionPerformed(ActionEvent e) {
052: Dialog owner = (Dialog) SwingUtilities
053: .windowForComponent(getOwner());
054: NoteGridNonSelectableDialog dialog = new NoteGridNonSelectableDialog(
055: owner, getWidgetTextFieldName().getText());
056: dialog.setMasterId(taskTypeId);
057: dialog.loadAndSelect();
058: dialog.setVisible(true);
059: }
060: });
061: }
062: return buttonNotes;
063: }
064:
065: //
066: // getWidgetTextFieldName
067: //
068: private WidgetTextField widgetTextFieldName;
069:
070: private WidgetTextField getWidgetTextFieldName() {
071: if (widgetTextFieldName == null)
072: widgetTextFieldName = new WidgetTextField(TaskTypes.NAME,
073: true);
074: return widgetTextFieldName;
075: }
076:
077: //
078: // getWidgetTextAreaComment
079: //
080: private WidgetTextArea widgetTextAreaComment;
081:
082: private WidgetTextArea getWidgetTextAreaComment() {
083: if (widgetTextAreaComment == null)
084: widgetTextAreaComment = new WidgetTextArea(
085: TaskTypes.COMMENT);
086: return widgetTextAreaComment;
087: }
088:
089: //
090: // getButtonTasks
091: //
092: private Button buttonTasks;
093:
094: private Component getButtonTasks() {
095: if (buttonTasks == null) {
096: buttonTasks = new Button(
097: new BasicAbstractAction(
098: new TaskGridNonSelectableDialog()
099: .getDialogTitle()
100: + BasicAbstractAction.ELLIPSIS,
101: Icons.TABLE) {
102: public void actionPerformed(ActionEvent e) {
103: Dialog owner = (Dialog) SwingUtilities
104: .windowForComponent(TaskTypePanel.this );
105: final TaskGridNonSelectableDialog taskDialog = new TaskGridNonSelectableDialog(
106: owner);
107: Registry.getFilterId().put(TaskTypes.class,
108: taskTypeId);
109: Map map = ((AbstractGridDialog) owner
110: .getOwner()).getTable()
111: .getSelectedRecord();
112: Registry.getFilterMap().put(
113: TaskTypes.class, map);
114: fromGui(map);
115: taskDialog.loadAndSelect();
116: taskDialog.setVisible(true);
117: Registry.getFilterId().remove(
118: TaskTypes.class);
119: Registry.getFilterMap().remove(
120: TaskTypes.class);
121: }
122: });
123: }
124: return buttonTasks;
125: }
126:
127: //
128: // getButtonAttachments
129: //
130: private Button buttonAttachments;
131:
132: private Component getButtonAttachments() {
133: if (buttonAttachments == null) {
134: buttonAttachments = new Button(new ActionAttachments() {
135: public void actionPerformed(ActionEvent e) {
136: Dialog owner = (Dialog) SwingUtilities
137: .windowForComponent(TaskTypePanel.this );
138: final AttachmentGridNonSelectableDialog linksDialog = new AttachmentGridNonSelectableDialog(
139: owner, getWidgetTextFieldName().getText());
140: linksDialog.setMasterId(taskTypeId);
141: linksDialog.loadAndSelect();
142: linksDialog.setVisible(true);
143: }
144: });
145: }
146: return buttonAttachments;
147: }
148:
149: //
150: // isFormValid
151: //
152: @Override
153: public boolean isFormValid() {
154: if (!getWidgetTextFieldName().isTextValid())
155: return false;
156: return true;
157: }
158:
159: @Override
160: public void fromGui(Map map) {
161: getWidgetTextFieldName().fromGui(map);
162: getWidgetTextAreaComment().fromGui(map);
163: }
164:
165: @Override
166: public void toGui(Map map) {
167: getWidgetTextFieldName().toGui(map);
168: getWidgetTextAreaComment().toGui(map);
169: //
170: taskTypeId = (Long) map.get(Utils
171: .getColumnIdentifier(Common.ID));
172: }
173: }
|