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