01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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;
21: import javax.swing.event.ListSelectionListener;
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 {
37: /**
38: * @param frameMediator
39: * @param name
40: */
41: public DefaultTableAction(IFrameMediator frameMediator, String 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 event) {
55: // return if selection change is in flux
56: if (event.getValueIsAdjusting()) {
57: return;
58: }
59:
60: Object[] uids = ((AddressbookFrameMediator) frameMediator)
61: .getTable().getUids();
62:
63: if (uids.length > 0) {
64: setEnabled(true);
65: } else {
66: setEnabled(false);
67: }
68: }
69: }
|