001: package org.airtodo.gui.dialog_table;
002:
003: import static org.air.framework.gui.box.Gap.large;
004:
005: import java.awt.Dialog;
006: import java.awt.Window;
007: import java.awt.event.ActionEvent;
008: import java.sql.SQLException;
009: import java.util.Map;
010: import java.util.Set;
011: import java.util.Vector;
012:
013: import javax.swing.Action;
014: import javax.swing.JMenuItem;
015: import javax.swing.JSeparator;
016: import javax.swing.event.ListSelectionEvent;
017: import javax.swing.event.ListSelectionListener;
018:
019: import org.air.framework.core.Registry;
020: import org.air.framework.core.Utils;
021: import org.air.framework.db.DbUtilsCommon;
022: import org.air.framework.gui.actions.basic.BasicAbstractAction;
023: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
024: import org.air.framework.gui.dialogs.grid.IAddDeleteGridDialog;
025: import org.air.framework.gui.dialogs.grid.IOpenGridDialog;
026: import org.air.framework.gui.dialogs.input.AbstractDeleteDialog;
027: import org.air.framework.gui.dialogs.text.TotalTimeDialog;
028: import org.air.framework.gui.widgets.Button;
029: import org.air.framework.i18n.NlsRecords;
030: import org.airtodo.db.DbUtils;
031: import org.airtodo.db.types.Period;
032: import org.airtodo.gui.dialog_delete.TaskDeleteDialog;
033: import org.airtodo.gui.dialog_open.TaskOpenDialog;
034: import org.airtodo.gui_common.actions.other.ActionInfo;
035: import org.airtodo.headers.Task;
036: import org.airtodo.records.Employees;
037: import org.airtodo.records.Initiators;
038: import org.airtodo.records.Modules;
039: import org.airtodo.records.Projects;
040: import org.airtodo.records.TaskTypes;
041: import org.airtodo.records.Tasks;
042:
043: public class TaskGridNonSelectableDialog extends AbstractGridDialog
044: implements IAddDeleteGridDialog, IOpenGridDialog {
045: //
046: // C O N S T R U C T O R
047: //
048: public TaskGridNonSelectableDialog() {
049: super ();
050: }
051:
052: public TaskGridNonSelectableDialog(Dialog owner) {
053: super (owner, new Task());
054: getButtonPanelTop().add(large(), 5);
055: getButtonPanelTop().add(new Button(getActionInfo()), 6);
056: getPopupMenu().add(new JMenuItem(getActionInfo()), 4);
057: getPopupMenu().add(new JSeparator(), 5);
058: attachKeyboardActions(getActionInfo());
059: getTable().getSelectionModel().addListSelectionListener(
060: new ListSelectionListener() {
061: public void valueChanged(ListSelectionEvent e) {
062: getActionInfo().setEnabled(
063: getTable().getSelectedRowCount() != 0);
064: }
065: });
066: }
067:
068: private BasicAbstractAction actionInfo;
069:
070: private Action getActionInfo() {
071: if (actionInfo == null)
072: actionInfo = new ActionInfo() {
073: public void actionPerformed(ActionEvent e) {
074: final AbstractGridDialog owner = TaskGridNonSelectableDialog.this ;
075: Set set = owner.getTable().getSelectedRecords();
076: long sum = 0;
077: for (Object object : set) {
078: Map map = (Map) object;
079: Period interval = (Period) map.get(Utils
080: .getColumnIdentifier(Tasks.PERIOD));
081: if (interval != null)
082: sum += interval.getValue();
083: }
084: new TotalTimeDialog(owner, set.size(), sum)
085: .setVisible(true);
086: }
087: };
088: return actionInfo;
089: }
090:
091: @Override
092: public Vector<Map> getDataVector() throws SQLException {
093: return DbUtils.selectTasksByFilter();
094: }
095:
096: public AbstractDeleteDialog getDeleteDialog(AbstractGridDialog owner) {
097: return new TaskDeleteDialog(owner);
098: }
099:
100: public Window getOpenDialog(
101: AbstractGridDialog abstractAddDeleteOpenDialog) {
102: return new TaskOpenDialog(abstractAddDeleteOpenDialog);
103: }
104:
105: public int insert(Map map) throws SQLException {
106: if (Registry.getDefaultId().containsKey(Projects.class)) {
107: map.put(Utils.getColumnIdentifier(Tasks.PROJECT_ID),
108: Registry.getDefaultId().get(Projects.class));
109: map.putAll(Registry.getDefaultMap().get(Projects.class));
110: }
111: if (Registry.getFilterId().containsKey(Projects.class)) {
112: map.put(Utils.getColumnIdentifier(Tasks.PROJECT_ID),
113: Registry.getFilterId().get(Projects.class));
114: map.putAll(Registry.getFilterMap().get(Projects.class));
115: }
116: if (Registry.getDefaultId().containsKey(Modules.class)) {
117: map.put(Utils.getColumnIdentifier(Tasks.MODULE_ID),
118: Registry.getDefaultId().get(Modules.class));
119: map.putAll(Registry.getDefaultMap().get(Modules.class));
120: }
121: if (Registry.getFilterId().containsKey(Modules.class)) {
122: map.put(Utils.getColumnIdentifier(Tasks.MODULE_ID),
123: Registry.getFilterId().get(Modules.class));
124: map.putAll(Registry.getFilterMap().get(Modules.class));
125: }
126: if (Registry.getDefaultId().containsKey(TaskTypes.class)) {
127: map.put(Utils.getColumnIdentifier(Tasks.TASK_TYPE_ID),
128: Registry.getDefaultId().get(TaskTypes.class));
129: map.putAll(Registry.getDefaultMap().get(TaskTypes.class));
130: }
131: if (Registry.getFilterId().containsKey(TaskTypes.class)) {
132: map.put(Utils.getColumnIdentifier(Tasks.TASK_TYPE_ID),
133: Registry.getFilterId().get(TaskTypes.class));
134: map.putAll(Registry.getFilterMap().get(TaskTypes.class));
135: }
136: if (Registry.getDefaultId().containsKey(Employees.class)) {
137: map.put(Utils.getColumnIdentifier(Tasks.EMPLOYEE_ID),
138: Registry.getDefaultId().get(Employees.class));
139: map.putAll(Registry.getDefaultMap().get(Employees.class));
140: }
141: if (Registry.getFilterId().containsKey(Employees.class)) {
142: map.put(Utils.getColumnIdentifier(Tasks.EMPLOYEE_ID),
143: Registry.getFilterId().get(Employees.class));
144: map.putAll(Registry.getFilterMap().get(Employees.class));
145: }
146: if (Registry.getDefaultId().containsKey(Initiators.class)) {
147: map.put(Utils.getColumnIdentifier(Tasks.INITIATOR_ID),
148: Registry.getDefaultId().get(Initiators.class));
149: Map employeeMap = Registry.getDefaultMap().get(
150: Initiators.class);
151: Map initiatorMap = DbUtils
152: .convertEmployeesMapToInitiatorsMap(employeeMap);
153: map.putAll(initiatorMap);
154: }
155: return DbUtilsCommon.insert(map, Tasks.class);
156: }
157:
158: @Override
159: public void setVisible(boolean b) {
160: if (Registry.getFilterId().containsKey(Projects.class))
161: setTitle(Registry.getFilterMap().get(Projects.class).get(
162: Utils.getColumnIdentifier(Projects.NAME))
163: + " - " + getTitle());
164: else if (Registry.getFilterId().containsKey(TaskTypes.class))
165: setTitle(Registry.getFilterMap().get(TaskTypes.class).get(
166: Utils.getColumnIdentifier(TaskTypes.NAME))
167: + " - " + getTitle());
168: else if (Registry.getFilterId().containsKey(Employees.class))
169: setTitle(Registry.getFilterMap().get(Employees.class).get(
170: Utils.getColumnIdentifier(Employees.NAME))
171: + " - " + getTitle());
172: super .setVisible(b);
173: }
174:
175: @Override
176: public String getDialogTitle() {
177: return NlsRecords.getTextPluralImenitelniy(Tasks.class);
178: }
179: }
|