001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
014: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
015: //Portions created by Celso Pinto are Copyright (C) 2004.
016: //
017: //All Rights Reserved.
018:
019: package org.columba.addressbook.gui.table;
020:
021: import java.awt.event.MouseEvent;
022:
023: import org.columba.addressbook.folder.AbstractFolder;
024: import org.columba.addressbook.folder.GroupFolder;
025: import org.columba.addressbook.folder.IContactStorage;
026: import org.columba.addressbook.gui.dialog.contact.ContactEditorDialog;
027: import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
028: import org.columba.addressbook.model.ContactModel;
029: import org.columba.addressbook.model.IContactModel;
030: import org.columba.core.gui.base.DoubleClickListener;
031: import org.columba.core.gui.dialog.ErrorDialog;
032: import org.columba.core.logging.Logging;
033:
034: /**
035: * @author Celso Pinto <cpinto@yimports.com>
036: */
037: public class TableMouseListener extends DoubleClickListener {
038: private TableController controller = null;
039: private AddressbookFrameMediator mediator = null;
040:
041: public TableMouseListener(TableController tableController) {
042: controller = tableController;
043: mediator = controller.getMediator();
044: }
045:
046: public void doubleClick(MouseEvent e) {
047: /*
048: * does exactly the same thing as EditPropertiesAction when contact
049: * table is focused
050: * */
051: if (e.getButton() == MouseEvent.BUTTON1
052: && e.getClickCount() > 1) {
053:
054: // get selected contact/group card
055: String[] uids = mediator.getTable().getUids();
056:
057: // get selected folder
058: IContactStorage folder = (IContactStorage) mediator
059: .getTree().getSelectedFolder();
060:
061: if (uids.length == 0)
062: return;
063:
064: // FIXME: ugly cast to ContactModel
065: IContactModel card = null;
066: try {
067: card = (IContactModel) folder.get(uids[0]);
068: } catch (Exception ex) {
069:
070: if (Logging.DEBUG)
071: ex.printStackTrace();
072:
073: ErrorDialog.createDialog(ex.getMessage(), ex);
074: }
075:
076: ContactEditorDialog dialog = new ContactEditorDialog(
077: mediator.getView().getFrame(), (ContactModel) card);
078:
079: if (dialog.getResult()) {
080:
081: try {
082: // modify card properties in folder
083: folder.modify(uids[0], dialog.getDestModel());
084: } catch (Exception e1) {
085: if (Logging.DEBUG)
086: e1.printStackTrace();
087:
088: ErrorDialog.createDialog(e1.getMessage(), e1);
089: }
090:
091: if (folder instanceof GroupFolder)
092: // re-select folder
093: mediator.getTree().setSelectedFolder(
094: (AbstractFolder) folder);
095:
096: }
097:
098: }
099: }
100: }
|