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.CustomerDeleteDialog;
024: import org.airtodo.gui.dialog_open.CustomerOpenDialog;
025: import org.airtodo.headers.Customer;
026: import org.airtodo.records.Customers;
027:
028: public class CustomerGridNonSelectableDialog extends AbstractGridDialog
029: implements IAddDeleteGridDialog, IOpenGridDialog {
030: //
031: // C O N S T R U C T O R
032: //
033: public CustomerGridNonSelectableDialog() {
034: super ();
035: }
036:
037: //
038: // C O N S T R U C T O R
039: //
040: public CustomerGridNonSelectableDialog(Dialog owner) {
041: super (owner, new Customer());
042: init();
043: }
044:
045: //
046: // C O N S T R U C T O R
047: //
048: public CustomerGridNonSelectableDialog(Dialog owner, Long id) {
049: super (owner, new Customer(), 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(Customers.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 ,
078: Customers.class);
079: return menuItem;
080: }
081:
082: @Override
083: public Vector<Map> getDataVector() throws SQLException {
084: return DbUtils.selectCustomer();
085: }
086:
087: public AbstractDeleteDialog getDeleteDialog(AbstractGridDialog owner) {
088: return new CustomerDeleteDialog(owner);
089: }
090:
091: public Window getOpenDialog(
092: AbstractGridDialog abstractAddDeleteOpenDialog) {
093: return new CustomerOpenDialog(abstractAddDeleteOpenDialog);
094: }
095:
096: @Override
097: public String getDialogTitle() {
098: return NlsRecords.getTextPluralImenitelniy(Customers.class);
099: }
100:
101: public int insert(Map map) throws SQLException {
102: return DbUtilsCommon.insert(map, Customers.class);
103: }
104: }
|