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.Employees;
029:
030: public class EmployeePanel extends AbstractOpenTabbedPanel {
031: //
032: private long employeeId;
033:
034: //
035: public EmployeePanel() {
036: getTabGeneral().add(getWidgetTextFieldName());
037: getTabGeneral().add(getWidgetTextFieldAddress());
038: getTabGeneral().add(getWidgetTextFieldPhone());
039: getTabGeneral().add(getWidgetTextFieldEmail());
040: getTabGeneral().add(getWidgetTextAreaComment());
041: getButtonPanel().addAll(getButtonNotes(), small(),
042: getButtonAttachments(), small(), getButtonTasks(),
043: Box.createHorizontalGlue());
044: }
045:
046: //
047: // getButtonNotes
048: //
049: private Button buttonNotes;
050:
051: private Component getButtonNotes() {
052: if (buttonNotes == null) {
053: buttonNotes = new Button(new ActionNotes() {
054: public void actionPerformed(ActionEvent e) {
055: Dialog owner = (Dialog) SwingUtilities
056: .windowForComponent(getOwner());
057: NoteGridNonSelectableDialog dialog = new NoteGridNonSelectableDialog(
058: owner, getWidgetTextFieldName().getText());
059: dialog.setMasterId(employeeId);
060: dialog.loadAndSelect();
061: dialog.setVisible(true);
062: }
063: });
064: }
065: return buttonNotes;
066: }
067:
068: //
069: // getWidgetOpenEstimates
070: //
071: private Button buttonTasks;
072:
073: private Component getButtonTasks() {
074: if (buttonTasks == null) {
075: buttonTasks = new Button(
076: new BasicAbstractAction(
077: new TaskGridNonSelectableDialog()
078: .getDialogTitle()
079: + BasicAbstractAction.ELLIPSIS,
080: Icons.TABLE) {
081: public void actionPerformed(ActionEvent e) {
082: Dialog owner = (Dialog) SwingUtilities
083: .windowForComponent(EmployeePanel.this );
084: final TaskGridNonSelectableDialog taskDialog = new TaskGridNonSelectableDialog(
085: owner);
086: Registry.getFilterId().put(Employees.class,
087: employeeId);
088: Map map = ((AbstractGridDialog) owner
089: .getOwner()).getTable()
090: .getSelectedRecord();
091: Registry.getFilterMap().put(
092: Employees.class, map);
093: fromGui(map);
094: taskDialog.loadAndSelect();
095: taskDialog.setVisible(true);
096: Registry.getFilterId().remove(
097: Employees.class);
098: Registry.getFilterMap().remove(
099: Employees.class);
100: }
101: });
102: }
103: return buttonTasks;
104: }
105:
106: //
107: // getButtonAttachments
108: //
109: private Button buttonAttachments;
110:
111: private Component getButtonAttachments() {
112: if (buttonAttachments == null) {
113: buttonAttachments = new Button(new ActionAttachments() {
114: public void actionPerformed(ActionEvent e) {
115: Dialog owner = (Dialog) SwingUtilities
116: .windowForComponent(EmployeePanel.this );
117: final AttachmentGridNonSelectableDialog linksDialog = new AttachmentGridNonSelectableDialog(
118: owner, getWidgetTextFieldName().getText());
119: linksDialog.setMasterId(employeeId);
120: linksDialog.loadAndSelect();
121: linksDialog.setVisible(true);
122: }
123: });
124: }
125: return buttonAttachments;
126: }
127:
128: //
129: // getWidgetTextFieldName
130: //
131: private WidgetTextField widgetTextFieldName;
132:
133: private WidgetTextField getWidgetTextFieldName() {
134: if (widgetTextFieldName == null)
135: widgetTextFieldName = new WidgetTextField(Employees.NAME,
136: true);
137: return widgetTextFieldName;
138: }
139:
140: //
141: // getWidgetTextFieldAddress
142: //
143: private WidgetTextField widgetTextFieldAddress;
144:
145: private WidgetTextField getWidgetTextFieldAddress() {
146: if (widgetTextFieldAddress == null)
147: widgetTextFieldAddress = new WidgetTextField(
148: Employees.ADDRESS);
149: return widgetTextFieldAddress;
150: }
151:
152: //
153: // getWidgetTextFieldPhone
154: //
155: private WidgetTextField widgetTextFieldPhone;
156:
157: private WidgetTextField getWidgetTextFieldPhone() {
158: if (widgetTextFieldPhone == null)
159: widgetTextFieldPhone = new WidgetTextField(Employees.PHONE);
160: return widgetTextFieldPhone;
161: }
162:
163: //
164: // getWidgetTextFieldEmail
165: //
166: private WidgetTextField widgetTextFieldEmail;
167:
168: private WidgetTextField getWidgetTextFieldEmail() {
169: if (widgetTextFieldEmail == null)
170: widgetTextFieldEmail = new WidgetTextField(Employees.EMAIL);
171: return widgetTextFieldEmail;
172: }
173:
174: //
175: // getWidgetTextAreaComment
176: //
177: private WidgetTextArea widgetTextAreaComment;
178:
179: private WidgetTextArea getWidgetTextAreaComment() {
180: if (widgetTextAreaComment == null)
181: widgetTextAreaComment = new WidgetTextArea(
182: Employees.COMMENT);
183: return widgetTextAreaComment;
184: }
185:
186: //
187: // isFormValid
188: //
189: @Override
190: public boolean isFormValid() {
191: if (!getWidgetTextFieldName().isTextValid())
192: return false;
193: return true;
194: }
195:
196: @Override
197: public void fromGui(Map map) {
198: getWidgetTextFieldName().fromGui(map);
199: getWidgetTextFieldAddress().fromGui(map);
200: getWidgetTextFieldPhone().fromGui(map);
201: getWidgetTextFieldEmail().fromGui(map);
202: getWidgetTextAreaComment().fromGui(map);
203: }
204:
205: @Override
206: public void toGui(Map map) {
207: getWidgetTextFieldName().toGui(map);
208: getWidgetTextFieldAddress().toGui(map);
209: getWidgetTextFieldPhone().toGui(map);
210: getWidgetTextFieldEmail().toGui(map);
211: getWidgetTextAreaComment().toGui(map);
212: //
213: employeeId = (Long) map.get(Utils
214: .getColumnIdentifier(Common.ID));
215: }
216: }
|