KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > action > DefaultTableAction


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
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.gui.action;
19
20 import javax.swing.event.ListSelectionEvent JavaDoc;
21 import javax.swing.event.ListSelectionListener JavaDoc;
22
23 import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
24 import org.columba.api.gui.frame.IFrameMediator;
25 import org.columba.core.gui.action.AbstractColumbaAction;
26
27 /**
28  * Adds a table selection listener to DefaultTreeAction.
29  * <p>
30  * Table selection listener additionally disables this action if no
31  * contact/group card is selected.
32  *
33  * @author fdietz
34  */

35 public abstract class DefaultTableAction extends AbstractColumbaAction
36         implements ListSelectionListener JavaDoc {
37     /**
38      * @param frameMediator
39      * @param name
40      */

41     public DefaultTableAction(IFrameMediator frameMediator, String JavaDoc name) {
42         super(frameMediator, name);
43
44         // register interest on table selection changes
45
((AddressbookFrameMediator) frameMediator)
46                 .addTableSelectionListener(this);
47     }
48
49     /**
50      * Enable or disable action on selection change.
51      *
52      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
53      */

54     public void valueChanged(ListSelectionEvent JavaDoc event) {
55         // return if selection change is in flux
56
if (event.getValueIsAdjusting()) {
57             return;
58         }
59
60         Object JavaDoc[] uids = ((AddressbookFrameMediator) frameMediator).getTable()
61                 .getUids();
62
63         if (uids.length > 0) {
64             setEnabled(true);
65         } else {
66             setEnabled(false);
67         }
68     }
69 }
Popular Tags