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.Utils;
020: import org.air.framework.db.DbUtilsCommon;
021: import org.air.framework.gui.actions.basic.BasicAbstractAction;
022: import org.air.framework.gui.actions.other.ActionLaunch;
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.widgets.Button;
028: import org.air.framework.i18n.NlsRecords;
029: import org.air.framework.records.Attachments;
030: import org.airtodo.LinkUtils;
031: import org.airtodo.db.DbUtils;
032: import org.airtodo.db.types.AttachmentType;
033: import org.airtodo.gui.dialog_delete.AttachmentDeleteDialog;
034: import org.airtodo.gui.dialog_open.AttachmentOpenDialog;
035: import org.airtodo.headers.Attachment;
036:
037: public class AttachmentGridNonSelectableDialog extends
038: AbstractGridDialog implements IAddDeleteGridDialog,
039: IOpenGridDialog {
040: private long masterId;
041:
042: //
043: // C O N S T R U C T O R
044: //
045: public AttachmentGridNonSelectableDialog() {
046: super ();
047: }
048:
049: //
050: // C O N S T R U C T O R
051: //
052: public AttachmentGridNonSelectableDialog(Dialog owner, String title) {
053: super (owner, new Attachment());
054: setTitle(title
055: + " - "
056: + NlsRecords
057: .getTextPluralImenitelniy(Attachments.class));
058: getButtonPanelTop().add(large(), 5);
059: getButtonPanelTop().add(new Button(getActionLaunch()), 6);
060: getPopupMenu().add(new JMenuItem(getActionLaunch()), 4);
061: getPopupMenu().add(new JSeparator(), 5);
062: attachKeyboardActions(getActionLaunch());
063: getTable().getSelectionModel().addListSelectionListener(
064: new ListSelectionListener() {
065: public void valueChanged(ListSelectionEvent e) {
066: getActionLaunch().setEnabled(
067: getTable().getSelectedRowCount() != 0);
068: }
069: });
070: }
071:
072: //
073: // C O N S T R U C T O R
074: //
075: public AttachmentGridNonSelectableDialog(Dialog owner, Long id) {
076: super (owner, new Attachment(), id);
077: }
078:
079: private BasicAbstractAction actionLaunch;
080:
081: private Action getActionLaunch() {
082: if (actionLaunch == null)
083: actionLaunch = new ActionLaunch() {
084: public void actionPerformed(ActionEvent e) {
085: final AbstractGridDialog owner = AttachmentGridNonSelectableDialog.this ;
086: Set set = owner.getTable().getSelectedRecords();
087: for (Object object : set) {
088: Map map = (Map) object;
089: String text = (String) map.get(Utils
090: .getColumnIdentifier(Attachments.NAME));
091: AttachmentType type = (AttachmentType) map
092: .get(Utils
093: .getColumnIdentifier(Attachments.TYPE));
094: LinkUtils.launch(owner, type, text);
095: }
096: }
097: };
098: return actionLaunch;
099: }
100:
101: @Override
102: public Vector<Map> getDataVector() throws SQLException {
103: return DbUtils.selectAttachmentsByMasterId(masterId);
104: }
105:
106: public AbstractDeleteDialog getDeleteDialog(AbstractGridDialog owner) {
107: return new AttachmentDeleteDialog(owner);
108: }
109:
110: public Window getOpenDialog(
111: AbstractGridDialog abstractAddDeleteOpenDialog) {
112: return new AttachmentOpenDialog(abstractAddDeleteOpenDialog);
113: }
114:
115: @Override
116: public String getDialogTitle() {
117: return NlsRecords.getTextPluralImenitelniy(Attachments.class);
118: }
119:
120: public int insert(Map map) throws SQLException {
121: map.put(Utils.getColumnIdentifier(Attachments.MASTER_ID),
122: masterId);
123: return DbUtilsCommon.insert(map, Attachments.class);
124: }
125:
126: public void setMasterId(long masterId) {
127: this.masterId = masterId;
128: }
129: }
|