From: <gda...@us...> - 2012-06-21 16:03:07
|
Revision: 2837 http://abbot.svn.sourceforge.net/abbot/?rev=2837&view=rev Author: gdavison Date: 2012-06-21 16:02:58 +0000 (Thu, 21 Jun 2012) Log Message: ----------- Try to improve reliability of toggleRow in a JTree in the case where the node has a double click listener. Temporarily change the threshold of click to trigger a toggle to 5. Modified Paths: -------------- abbot/trunk/ChangeLog abbot/trunk/src/abbot/tester/JTreeTester.java Modified: abbot/trunk/ChangeLog =================================================================== --- abbot/trunk/ChangeLog 2012-06-11 09:05:56 UTC (rev 2836) +++ abbot/trunk/ChangeLog 2012-06-21 16:02:58 UTC (rev 2837) @@ -1,3 +1,7 @@ +2012-06-21 Gerard Davison + * Modify the toggleRow funcition in JTreeTester to temporaily up the number of clicks for a toggle to + 5 so that we don't acidently trigger a double click listener. + 2012-06-11 Gerard Davison * Provide better information for the user when we match multiple components to a single ComponentReference Modified: abbot/trunk/src/abbot/tester/JTreeTester.java =================================================================== --- abbot/trunk/src/abbot/tester/JTreeTester.java 2012-06-11 09:05:56 UTC (rev 2836) +++ abbot/trunk/src/abbot/tester/JTreeTester.java 2012-06-21 16:02:58 UTC (rev 2837) @@ -507,38 +507,71 @@ // row height. clicking in the center of that square should work. public void actionToggleRow(Component c, ComponentLocation loc) { final JTree tree = (JTree)c; - // Alternatively, we can reflect into the UI and do a single click - // on the appropriate expand location, but this is safer. - if (tree.getToggleClickCount() != 0) { + + // Accessing the toggle click count is thread safe; but updating + // it can fire a properly listener which is going to be an issue in some cases + // hence this little class to update the value as required + class SetToggleClickCount implements Runnable { + + int clickCount; + + public SetToggleClickCount(int clickCount) { + this.clickCount = clickCount; + } + + @Override + public void run() { + tree.setToggleClickCount(clickCount); + } + } + + // It turns out that some trees have double click actions on them + // so this doesn't work too well. So we are going to increase the click + // count to 5 just for the toggle operation, this should make things more + // reliable + int originalToggleRowCount = tree.getToggleClickCount(); + invokeAndWait(new SetToggleClickCount(5)); + try { actionClick(tree, loc, InputEvent.BUTTON1_MASK, tree.getToggleClickCount()); + } - else { - // BasicTreeUI provides this method; punt if we can't find it - if (!(tree.getUI() instanceof BasicTreeUI)) - throw new ActionFailedException("Can't toggle row for " - + tree.getUI()); - try { - final java.lang.reflect.Method method = - BasicTreeUI.class. - getDeclaredMethod("toggleExpandState", - new Class[] { - TreePath.class - }); - method.setAccessible(true); - final Point where = loc.getPoint(tree); - Robot.callAndWait(tree, new Callable<Object>() { - public Object call() throws Exception { - return method.invoke(tree.getUI(), new Object[] { - tree.getPathForLocation(where.x, where.y)}); - } - }); - } - catch(Exception e) { - throw new ActionFailedException(e.toString()); - } + finally { + invokeAndWait(new SetToggleClickCount(originalToggleRowCount)); } +// // Alternatively, we can reflect into the UI and do a single click +// // on the appropriate expand location, but this is safer. +// if (tree.getToggleClickCount() != 0) { +// actionClick(tree, loc, InputEvent.BUTTON1_MASK, +// tree.getToggleClickCount()); +// } +// else { +// // BasicTreeUI provides this method; punt if we can't find it +// if (!(tree.getUI() instanceof BasicTreeUI)) +// throw new ActionFailedException("Can't toggle row for " +// + tree.getUI()); +// try { +// final java.lang.reflect.Method method = +// BasicTreeUI.class. +// getDeclaredMethod("toggleExpandState", +// new Class[] { +// TreePath.class +// }); +// method.setAccessible(true); +// final Point where = loc.getPoint(tree); +// Robot.callAndWait(tree, new Callable<Object>() { +// public Object call() throws Exception { +// return method.invoke(tree.getUI(), new Object[] { +// tree.getPathForLocation(where.x, where.y)}); +// } +// }); +// } +// catch(Exception e) { +// throw new ActionFailedException(e.toString()); +// } +// } + // Make sure all operations have finsished waitForIdle(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |