KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > table > TableMouseListener


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
14
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
15
//Portions created by Celso Pinto are Copyright (C) 2004.
16
//
17
//All Rights Reserved.
18

19 package org.columba.addressbook.gui.table;
20
21 import java.awt.event.MouseEvent JavaDoc;
22
23 import org.columba.addressbook.folder.AbstractFolder;
24 import org.columba.addressbook.folder.GroupFolder;
25 import org.columba.addressbook.folder.IContactStorage;
26 import org.columba.addressbook.gui.dialog.contact.ContactEditorDialog;
27 import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
28 import org.columba.addressbook.model.ContactModel;
29 import org.columba.addressbook.model.IContactModel;
30 import org.columba.core.gui.base.DoubleClickListener;
31 import org.columba.core.gui.dialog.ErrorDialog;
32 import org.columba.core.logging.Logging;
33
34
35 /**
36  * @author Celso Pinto <cpinto@yimports.com>
37  */

38 public class TableMouseListener extends DoubleClickListener
39 {
40     private TableController controller = null;
41     private AddressbookFrameMediator mediator = null;
42     public TableMouseListener(TableController tableController)
43     {
44         controller = tableController;
45         mediator = controller.getMediator();
46     }
47
48   public void doubleClick(MouseEvent JavaDoc e)
49   {
50       /*
51        * does exactly the same thing as EditPropertiesAction when contact
52        * table is focused
53        * */

54       if (e.getButton()==MouseEvent.BUTTON1 &&
55           e.getClickCount() > 1)
56       {
57         
58             // get selected contact/group card
59
String JavaDoc[] uids = mediator.getTable().getUids();
60
61       // get selected folder
62
IContactStorage folder = (IContactStorage) mediator.getTree()
63                                                        .getSelectedFolder();
64
65       if (uids.length == 0)
66         return;
67
68       // FIXME: ugly cast to ContactModel
69
IContactModel card = null;
70       try
71       {
72         card = (IContactModel) folder.get(uids[0]);
73       }
74       catch (Exception JavaDoc ex)
75       {
76
77         if (Logging.DEBUG)
78           ex.printStackTrace();
79
80         ErrorDialog.createDialog(ex.getMessage(), ex);
81       }
82
83       ContactEditorDialog dialog = new ContactEditorDialog(mediator.getView().getFrame(),
84                                                (ContactModel) card);
85
86       if (dialog.getResult())
87       {
88
89         try
90         {
91           // modify card properties in folder
92
folder.modify(uids[0], dialog.getDestModel());
93         }
94         catch (Exception JavaDoc e1)
95         {
96           if (Logging.DEBUG)
97             e1.printStackTrace();
98
99           ErrorDialog.createDialog(e1.getMessage(), e1);
100         }
101
102         if (folder instanceof GroupFolder)
103           // re-select folder
104
mediator.getTree().setSelectedFolder((AbstractFolder) folder);
105
106             }
107         
108       }
109   }
110 }
111
Popular Tags