001: package org.airtodo.gui.dialog_table;
002:
003: import java.awt.Dialog;
004: import java.awt.Window;
005: import java.sql.SQLException;
006: import java.util.Map;
007: import java.util.Vector;
008:
009: import javax.swing.JCheckBoxMenuItem;
010: import javax.swing.JSeparator;
011: import javax.swing.event.ListSelectionEvent;
012: import javax.swing.event.ListSelectionListener;
013:
014: import org.air.framework.core.Registry;
015: import org.air.framework.core.Utils;
016: import org.air.framework.db.DbUtilsCommon;
017: import org.air.framework.db.DefaultUtils;
018: import org.air.framework.gui.actions.other.CheckBoxMenuItemDefault;
019: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
020: import org.air.framework.gui.dialogs.grid.IAddDeleteGridDialog;
021: import org.air.framework.gui.dialogs.grid.IOpenGridDialog;
022: import org.air.framework.gui.dialogs.input.AbstractDeleteDialog;
023: import org.air.framework.i18n.NlsRecords;
024: import org.airtodo.db.DbUtils;
025: import org.airtodo.gui.dialog_delete.ProjectDeleteDialog;
026: import org.airtodo.gui.dialog_open.ProjectOpenDialog;
027: import org.airtodo.headers.Project;
028: import org.airtodo.records.Customers;
029: import org.airtodo.records.Employees;
030: import org.airtodo.records.Projects;
031: import org.airtodo.records.TaskTypes;
032: import org.airtodo.records.Tasks;
033:
034: public class ProjectGridNonSelectableDialog extends AbstractGridDialog
035: implements IAddDeleteGridDialog, IOpenGridDialog {
036: //
037: // C O N S T R U C T O R
038: //
039: public ProjectGridNonSelectableDialog() {
040: super ();
041: }
042:
043: public ProjectGridNonSelectableDialog(Dialog owner) {
044: super (owner, new Project());
045: init();
046: }
047:
048: public ProjectGridNonSelectableDialog(Dialog owner, Long id) {
049: super (owner, new Project(), id);
050: init();
051: }
052:
053: private void init() {
054: getPopupMenu().add(getCheckBoxMenuItemDefault(), 4);
055: getPopupMenu().add(new JSeparator(), 5);
056: getTable().getSelectionModel().addListSelectionListener(
057: new ListSelectionListener() {
058: public void valueChanged(ListSelectionEvent e) {
059: Map map = getTable().getSelectedRecord();
060: boolean b = map != null;
061: getCheckBoxMenuItemDefault().setEnabled(b);
062: if (b) {
063: boolean dflt = DefaultUtils
064: .isDefaultRecord(Projects.class,
065: map);
066: getCheckBoxMenuItemDefault().setSelected(
067: dflt);
068: }
069: }
070: });
071: }
072:
073: private JCheckBoxMenuItem menuItem;
074:
075: private JCheckBoxMenuItem getCheckBoxMenuItemDefault() {
076: if (menuItem == null)
077: menuItem = new CheckBoxMenuItemDefault(this , Projects.class);
078: return menuItem;
079: }
080:
081: @Override
082: public Vector<Map> getDataVector() throws SQLException {
083: return DbUtils.selectProjectsByFilter();
084: }
085:
086: public AbstractDeleteDialog getDeleteDialog(AbstractGridDialog owner) {
087: return new ProjectDeleteDialog(owner);
088: }
089:
090: public Window getOpenDialog(
091: AbstractGridDialog abstractAddDeleteOpenDialog) {
092: return new ProjectOpenDialog(abstractAddDeleteOpenDialog);
093: }
094:
095: public int insert(Map map) throws SQLException {
096: if (Registry.getFilterId().containsKey(Projects.class)) {
097: map.put(Utils.getColumnIdentifier(Tasks.PROJECT_ID),
098: Registry.getFilterId().get(Projects.class));
099: map.putAll(Registry.getFilterMap().get(Projects.class));
100: }
101: if (Registry.getFilterId().containsKey(TaskTypes.class)) {
102: map.put(Utils.getColumnIdentifier(Tasks.TASK_TYPE_ID),
103: Registry.getFilterId().get(TaskTypes.class));
104: map.putAll(Registry.getFilterMap().get(TaskTypes.class));
105: }
106: if (Registry.getFilterId().containsKey(Employees.class)) {
107: map.put(Utils.getColumnIdentifier(Tasks.EMPLOYEE_ID),
108: Registry.getFilterId().get(Employees.class));
109: map.putAll(Registry.getFilterMap().get(Employees.class));
110: }
111: if (Registry.getDefaultId().containsKey(Customers.class)) {
112: map.put(Utils.getColumnIdentifier(Projects.CUSTOMER_ID),
113: Registry.getDefaultId().get(Customers.class));
114: map.putAll(Registry.getDefaultMap().get(Customers.class));
115: }
116: if (Registry.getFilterId().containsKey(Customers.class)) {
117: map.put(Utils.getColumnIdentifier(Projects.CUSTOMER_ID),
118: Registry.getFilterId().get(Customers.class));
119: map.putAll(Registry.getFilterMap().get(Customers.class));
120: }
121: return DbUtilsCommon.insert(map, Projects.class);
122: }
123:
124: @Override
125: public void setVisible(boolean b) {
126: if (Registry.getFilterId().containsKey(Projects.class))
127: setTitle(Registry.getFilterMap().get(Projects.class).get(
128: Utils.getColumnIdentifier(Projects.NAME))
129: + " - " + getTitle());
130: else if (Registry.getFilterId().containsKey(TaskTypes.class))
131: setTitle(Registry.getFilterMap().get(TaskTypes.class).get(
132: Utils.getColumnIdentifier(TaskTypes.NAME))
133: + " - " + getTitle());
134: else if (Registry.getFilterId().containsKey(Employees.class))
135: setTitle(Registry.getFilterMap().get(Employees.class).get(
136: Utils.getColumnIdentifier(Employees.NAME))
137: + " - " + getTitle());
138: super .setVisible(b);
139: }
140:
141: @Override
142: public String getDialogTitle() {
143: return NlsRecords.getTextPluralImenitelniy(Projects.class);
144: }
145: }
|