001: /*
002: * $Id: ColumnControlButtonIssues.java,v 1.8 2006/06/13 10:04:18 kleopatra Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: */
007: package org.jdesktop.swingx.table;
008:
009: import java.beans.PropertyChangeListener;
010: import java.util.logging.Logger;
011:
012: import javax.swing.AbstractButton;
013: import javax.swing.Action;
014: import javax.swing.JCheckBoxMenuItem;
015: import javax.swing.JToggleButton;
016: import javax.swing.table.DefaultTableModel;
017:
018: import org.jdesktop.swingx.JXTable;
019: import org.jdesktop.swingx.action.AbstractActionExt;
020: import org.jdesktop.swingx.action.ActionContainerFactory;
021:
022: public class ColumnControlButtonIssues extends ColumnControlButtonTest {
023: private static final Logger LOG = Logger
024: .getLogger(ColumnControlButtonIssues.class.getName());
025:
026: /**
027: * Issue #229-swingx: increasing listener list in column actions.
028: *
029: */
030: public void testActionListenerCount() {
031: JXTable table = new JXTable(10, 1);
032: Action action = table.getActionMap().get(
033: JXTable.HORIZONTALSCROLL_ACTION_COMMAND);
034: if (!(action instanceof AbstractActionExt)) {
035: LOG
036: .info("cannot run testColumnActionListenerCount - action not of type AbstractAction");
037: return;
038: }
039: AbstractActionExt extAction = (AbstractActionExt) action;
040: assertTrue(extAction.isStateAction());
041: assertEquals(0, extAction.getPropertyChangeListeners().length);
042: AbstractButton menuItem = new JCheckBoxMenuItem();
043: ActionContainerFactory factory = new ActionContainerFactory(
044: null);
045: factory.configureSelectableButton(menuItem, extAction, null);
046: // sanity: here the action is bound to a menu item in the columnControl
047: // should have one ad
048: int initialPCLCount = extAction.getPropertyChangeListeners().length;
049: // sanity: expect it to be 2 - one is the menuitem itself, another
050: // the TogglePCL registered by the ActionContainerFacory
051: assertEquals(2, initialPCLCount);
052: menuItem = new JToggleButton();
053: factory.configureSelectableButton(menuItem, extAction, null);
054: System.gc();
055: PropertyChangeListener[] listeners = extAction
056: .getPropertyChangeListeners();
057: // testing this is not quite okay: probably the old buttons are not yet
058: // gc'ed
059: assertEquals(initialPCLCount, extAction
060: .getPropertyChangeListeners().length);
061:
062: }
063:
064: /**
065: * Issue #229-swingx: increasing listener list in column actions.
066: *
067: */
068: public void testColumnActionListenerCount() {
069: JXTable table = new JXTable(10, 1);
070: Action action = table.getActionMap().get(
071: JXTable.HORIZONTALSCROLL_ACTION_COMMAND);
072: if (!(action instanceof AbstractActionExt)) {
073: LOG
074: .info("cannot run testColumnActionListenerCount - action not of type AbstractAction");
075: return;
076: }
077: AbstractActionExt extAction = (AbstractActionExt) action;
078: assertTrue(extAction.isStateAction());
079: assertEquals(0, extAction.getPropertyChangeListeners().length);
080: table.setColumnControlVisible(true);
081: // make sure the control is initialized (usually done lazyly on showing)
082: table.getColumnControl();
083: // sanity: here the action is bound to a menu item in the columnControl
084: // should have one ad
085: int initialPCLCount = extAction.getPropertyChangeListeners().length;
086: // sanity: expect it to be 2 - one is the menuitem itself, another
087: // the TogglePCL registered by the ActionContainerFacory
088: assertEquals(2, initialPCLCount);
089: table.setModel(new DefaultTableModel(10, 1));
090: System.gc();
091: PropertyChangeListener[] listeners = extAction
092: .getPropertyChangeListeners();
093: // testing this is not quite okay: probably the old buttons are not yet
094: // gc'ed
095: assertEquals(initialPCLCount, extAction
096: .getPropertyChangeListeners().length);
097:
098: }
099:
100: }
|