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.db.DbUtilsCommon;
015: import org.air.framework.db.DefaultUtils;
016: import org.air.framework.gui.actions.other.CheckBoxMenuItemDefault;
017: import org.air.framework.gui.dialogs.grid.AbstractGridDialog;
018: import org.air.framework.gui.dialogs.grid.IAddDeleteGridDialog;
019: import org.air.framework.gui.dialogs.grid.IOpenGridDialog;
020: import org.air.framework.gui.dialogs.input.AbstractDeleteDialog;
021: import org.air.framework.i18n.NlsRecords;
022: import org.airtodo.db.DbUtils;
023: import org.airtodo.gui.dialog_delete.EmployeeDeleteDialog;
024: import org.airtodo.gui.dialog_open.EmployeeOpenDialog;
025: import org.airtodo.headers.Employee;
026: import org.airtodo.records.Employees;
027: import org.airtodo.records.Initiators;
028:
029: public class EmployeeGridNonSelectableDialog extends AbstractGridDialog
030: implements IAddDeleteGridDialog, IOpenGridDialog {
031: //
032: // C O N S T R U C T O R
033: //
034: public EmployeeGridNonSelectableDialog() {
035: super ();
036: }
037:
038: //
039: // C O N S T R U C T O R
040: //
041: public EmployeeGridNonSelectableDialog(Dialog owner) {
042: super (owner, new Employee());
043: init();
044: }
045:
046: //
047: // C O N S T R U C T O R
048: //
049: public EmployeeGridNonSelectableDialog(Dialog owner, Long id) {
050: super (owner, new Employee(), id);
051: init();
052: }
053:
054: private void init() {
055: getPopupMenu().add(getCheckBoxMenuItemDefaultEmployee(), 4);
056: getPopupMenu().add(getCheckBoxMenuItemDefaultInitiator(), 5);
057: getPopupMenu().add(new JSeparator(), 6);
058: getTable().getSelectionModel().addListSelectionListener(
059: new ListSelectionListener() {
060: public void valueChanged(ListSelectionEvent e) {
061: Map map = getTable().getSelectedRecord();
062: boolean b = map != null;
063: getCheckBoxMenuItemDefaultEmployee()
064: .setEnabled(b);
065: getCheckBoxMenuItemDefaultInitiator()
066: .setEnabled(b);
067: if (b) {
068: boolean dflt = DefaultUtils
069: .isDefaultRecord(Employees.class,
070: map);
071: getCheckBoxMenuItemDefaultEmployee()
072: .setSelected(dflt);
073: //
074: dflt = DefaultUtils.isDefaultRecord(
075: Initiators.class, map);
076: getCheckBoxMenuItemDefaultInitiator()
077: .setSelected(dflt);
078: }
079: }
080: });
081: }
082:
083: private JCheckBoxMenuItem menuItemEmployee;
084:
085: private JCheckBoxMenuItem getCheckBoxMenuItemDefaultEmployee() {
086: if (menuItemEmployee == null)
087: menuItemEmployee = new CheckBoxMenuItemDefault(this ,
088: Employees.class);
089: return menuItemEmployee;
090: }
091:
092: private JCheckBoxMenuItem menuItemInitiator;
093:
094: private JCheckBoxMenuItem getCheckBoxMenuItemDefaultInitiator() {
095: if (menuItemInitiator == null)
096: menuItemInitiator = new CheckBoxMenuItemDefault(this ,
097: Initiators.class);
098: return menuItemInitiator;
099: }
100:
101: @Override
102: public Vector<Map> getDataVector() throws SQLException {
103: return DbUtils.selectEmployee();
104: }
105:
106: public AbstractDeleteDialog getDeleteDialog(AbstractGridDialog owner) {
107: return new EmployeeDeleteDialog(owner);
108: }
109:
110: public Window getOpenDialog(
111: AbstractGridDialog abstractAddDeleteOpenDialog) {
112: return new EmployeeOpenDialog(abstractAddDeleteOpenDialog);
113: }
114:
115: @Override
116: public String getDialogTitle() {
117: return NlsRecords.getTextPluralImenitelniy(Employees.class);
118: }
119:
120: public int insert(Map map) throws SQLException {
121: return DbUtilsCommon.insert(map, Employees.class);
122: }
123: }
|