0001: /*
0002: DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s): Alexandre Iline.
0025: *
0026: * The Original Software is the Jemmy library.
0027: * The Initial Developer of the Original Software is Alexandre Iline.
0028: * All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: *
0041: *
0042: *
0043: * $Id$ $Revision$ $Date$
0044: *
0045: */
0046: package org.netbeans.jemmy.operators;
0047:
0048: import org.netbeans.jemmy.ComponentChooser;
0049: import org.netbeans.jemmy.ComponentSearcher;
0050: import org.netbeans.jemmy.JemmyException;
0051: import org.netbeans.jemmy.JemmyInputException;
0052: import org.netbeans.jemmy.Outputable;
0053: import org.netbeans.jemmy.QueueTool;
0054: import org.netbeans.jemmy.TestOut;
0055: import org.netbeans.jemmy.Timeoutable;
0056: import org.netbeans.jemmy.Timeouts;
0057: import org.netbeans.jemmy.Waitable;
0058: import org.netbeans.jemmy.Waiter;
0059:
0060: import org.netbeans.jemmy.util.EmptyVisualizer;
0061:
0062: import org.netbeans.jemmy.drivers.DriverManager;
0063: import org.netbeans.jemmy.drivers.TreeDriver;
0064:
0065: import java.awt.Component;
0066: import java.awt.Container;
0067: import java.awt.Dimension;
0068: import java.awt.Point;
0069: import java.awt.Rectangle;
0070:
0071: import java.util.Enumeration;
0072: import java.util.Hashtable;
0073:
0074: import javax.swing.JPopupMenu;
0075: import javax.swing.JScrollPane;
0076: import javax.swing.JTree;
0077:
0078: import javax.swing.event.TreeExpansionListener;
0079: import javax.swing.event.TreeSelectionListener;
0080: import javax.swing.event.TreeWillExpandListener;
0081:
0082: import javax.swing.plaf.TreeUI;
0083:
0084: import javax.swing.tree.ExpandVetoException;
0085: import javax.swing.tree.TreeCellEditor;
0086: import javax.swing.tree.TreeCellRenderer;
0087: import javax.swing.tree.TreeModel;
0088: import javax.swing.tree.TreePath;
0089: import javax.swing.tree.TreeSelectionModel;
0090:
0091: /**
0092: * <BR><BR>Timeouts used: <BR>
0093: * JTreeOperator.WaitNodeExpandedTimeout - time to wait node expanded <BR>
0094: * JTreeOperator.WaitNodeCollapsedTimeout - time to wait node collapsed <BR>
0095: * JTreeOperator.WaitAfterNodeExpandedTimeout - time to to sleep after node expanded <BR>
0096: * JTreeOperator.WaitNextNodeTimeout - time to wait next node displayed <BR>
0097: * JTreeOperator.WaitNodeVisibleTimeout - time to wait node visible <BR>
0098: * JTreeOperator.BeforeEditTimeout - time to sleep before edit click <BR>
0099: * JTreeOperator.WaitEditingTimeout - time to wait node editing <BR>
0100: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
0101: * ComponentOperator.WaitStateTimeout - time to wait for path to be expanded, collapsed, selected,
0102: * time to wait for a text in a row <BR>
0103: * WindowWaiter.WaitWindowTimeout - time to wait popup window displayed <BR>
0104: * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>.
0105: *
0106: * @see org.netbeans.jemmy.Timeouts
0107: *
0108: * @author Alexandre Iline (alexandre.iline@sun.com)
0109: *
0110: */
0111:
0112: public class JTreeOperator extends JComponentOperator implements
0113: Timeoutable, Outputable {
0114:
0115: /**
0116: * Identifier for a "root" property.
0117: * @see #getDump
0118: */
0119: public static final String ROOT_DPROP = "Root";
0120:
0121: /**
0122: * Identifier for a "node" properties.
0123: * @see #getDump
0124: */
0125: public static final String NODE_PREFIX_DPROP = "Node";
0126:
0127: /**
0128: * Identifier for a "first selected" property.
0129: * @see #getDump
0130: */
0131: public static final String SELECTION_FIRST_DPROP = "First selected";
0132:
0133: /**
0134: * Identifier for a "last selected" property.
0135: * @see #getDump
0136: */
0137: public static final String SELECTION_LAST_DPROP = "Last selected";
0138:
0139: private final static long WAIT_NODE_EXPANDED_TIMEOUT = 60000;
0140: private final static long WAIT_NODE_COLLAPSED_TIMEOUT = 60000;
0141: private final static long WAIT_AFTER_NODE_EXPANDED_TIMEOUT = 0;
0142: private final static long WAIT_NEXT_NODE_TIMEOUT = 60000;
0143: private final static long WAIT_NODE_VISIBLE_TIMEOUT = 60000;
0144: private final static long BEFORE_EDIT_TIMEOUT = 1000;
0145: private final static long WAIT_EDITING_TIMEOUT = 60000;
0146:
0147: private TestOut output;
0148: private Timeouts timeouts;
0149: private TreeDriver driver;
0150:
0151: /**
0152: * Constructor.
0153: * @param b a component
0154: */
0155: public JTreeOperator(JTree b) {
0156: super (b);
0157: driver = DriverManager.getTreeDriver(getClass());
0158: }
0159:
0160: /**
0161: * Constructs a JTreeOperator object.
0162: * @param cont a container
0163: * @param chooser a component chooser specifying searching criteria.
0164: * @param index an index between appropriate ones.
0165: */
0166: public JTreeOperator(ContainerOperator cont,
0167: ComponentChooser chooser, int index) {
0168: this ((JTree) cont.waitSubComponent(new JTreeFinder(chooser),
0169: index));
0170: copyEnvironment(cont);
0171: }
0172:
0173: /**
0174: * Constructs a JTreeOperator object.
0175: * @param cont a container
0176: * @param chooser a component chooser specifying searching criteria.
0177: */
0178: public JTreeOperator(ContainerOperator cont,
0179: ComponentChooser chooser) {
0180: this (cont, chooser, 0);
0181: }
0182:
0183: /**
0184: * Constructor.
0185: * Waits component in container first.
0186: * Uses cont's timeout and output for waiting and to init operator.
0187: * @param cont a container
0188: * @param text Text of a row which is currently selected.
0189: * @param row a row index to check text in. If equals to -1, selected row is checked.
0190: * @param index Ordinal component index.
0191: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0192: * @throws TimeoutExpiredException
0193: */
0194: public JTreeOperator(ContainerOperator cont, String text, int row,
0195: int index) {
0196: this ((JTree) waitComponent(cont, new JTreeByItemFinder(text,
0197: row, cont.getComparator()), index));
0198: copyEnvironment(cont);
0199: }
0200:
0201: /**
0202: * Constructor.
0203: * Waits component in container first.
0204: * Uses cont's timeout and output for waiting and to init operator.
0205: * @param cont a container
0206: * @param text Text of a row which is currently selected.
0207: * @param index Ordinal component index.
0208: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0209: * @throws TimeoutExpiredException
0210: */
0211: public JTreeOperator(ContainerOperator cont, String text, int index) {
0212: this (cont, text, -1, index);
0213: }
0214:
0215: /**
0216: * Constructor.
0217: * Waits component in container first.
0218: * Uses cont's timeout and output for waiting and to init operator.
0219: * @param cont a container
0220: * @param text Text of a row which is currently selected.
0221: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0222: * @throws TimeoutExpiredException
0223: */
0224: public JTreeOperator(ContainerOperator cont, String text) {
0225: this (cont, text, 0);
0226: }
0227:
0228: /**
0229: * Constructor.
0230: * Waits component in container first.
0231: * Uses cont's timeout and output for waiting and to init operator.
0232: * @param cont a container
0233: * @param index Ordinal component index.
0234: * @throws TimeoutExpiredException
0235: */
0236: public JTreeOperator(ContainerOperator cont, int index) {
0237: this ((JTree) waitComponent(cont, new JTreeFinder(), index));
0238: copyEnvironment(cont);
0239: }
0240:
0241: /**
0242: * Constructor.
0243: * Waits component in container first.
0244: * Uses cont's timeout and output for waiting and to init operator.
0245: * @param cont a container
0246: * @throws TimeoutExpiredException
0247: */
0248: public JTreeOperator(ContainerOperator cont) {
0249: this (cont, 0);
0250: }
0251:
0252: /**
0253: * Searches JTree in container.
0254: * @param cont Container to search component in.
0255: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0256: * @param index Ordinal component index.
0257: * @return JTree instance or null if component was not found.
0258: */
0259: public static JTree findJTree(Container cont,
0260: ComponentChooser chooser, int index) {
0261: return ((JTree) findComponent(cont, new JTreeFinder(chooser),
0262: index));
0263: }
0264:
0265: /**
0266: * Searches 0'th JTree in container.
0267: * @param cont Container to search component in.
0268: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0269: * @return JTree instance or null if component was not found.
0270: */
0271: public static JTree findJTree(Container cont,
0272: ComponentChooser chooser) {
0273: return (findJTree(cont, chooser, 0));
0274: }
0275:
0276: /**
0277: * Searches JTree by item.
0278: * @param cont Container to search component in.
0279: * @param text Item text. If null, contents is not checked.
0280: * @param ce Compare text exactly.
0281: * @param ccs Compare text case sensitively.
0282: * @param rowIndex Index of row to compare text. If -1, selected row is checked.
0283: * @param index Ordinal component index.
0284: * @return JTree instance or null if component was not found.
0285: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0286: */
0287: public static JTree findJTree(Container cont, String text,
0288: boolean ce, boolean ccs, int rowIndex, int index) {
0289: return (findJTree(cont, new JTreeByItemFinder(text, rowIndex,
0290: new DefaultStringComparator(ce, ccs)), index));
0291: }
0292:
0293: /**
0294: * Searches JTree by item.
0295: * @param cont Container to search component in.
0296: * @param text Item text. If null, contents is not checked.
0297: * @param ce Compare text exactly.
0298: * @param ccs Compare text case sensitively.
0299: * @param rowIndex Index of row to compare text. If -1, selected row is checked.
0300: * @return JTree instance or null if component was not found.
0301: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0302: */
0303: public static JTree findJTree(Container cont, String text,
0304: boolean ce, boolean ccs, int rowIndex) {
0305: return (findJTree(cont, text, ce, ccs, rowIndex, 0));
0306: }
0307:
0308: /**
0309: * Waits JTree in container.
0310: * @param cont Container to search component in.
0311: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0312: * @param index Ordinal component index.
0313: * @return JTree instance or null if component was not found.
0314: * @throws TimeoutExpiredException
0315: */
0316: public static JTree waitJTree(Container cont,
0317: ComponentChooser chooser, int index) {
0318: return ((JTree) waitComponent(cont, new JTreeFinder(chooser),
0319: index));
0320: }
0321:
0322: /**
0323: * Waits 0'th JTree in container.
0324: * @param cont Container to search component in.
0325: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0326: * @return JTree instance or null if component was not found.
0327: * @throws TimeoutExpiredException
0328: */
0329: public static JTree waitJTree(Container cont,
0330: ComponentChooser chooser) {
0331: return (waitJTree(cont, chooser, 0));
0332: }
0333:
0334: /**
0335: * Waits JTree by item.
0336: * @param cont Container to search component in.
0337: * @param text Item text. If null, contents is not checked.
0338: * @param ce Compare text exactly.
0339: * @param ccs Compare text case sensitively.
0340: * @param rowIndex Index of row to compare text. If -1, selected row is checked.
0341: * @param index Ordinal component index.
0342: * @return JTree instance or null if component was not found.
0343: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0344: * @throws TimeoutExpiredException
0345: */
0346: public static JTree waitJTree(Container cont, String text,
0347: boolean ce, boolean ccs, int rowIndex, int index) {
0348: return (waitJTree(cont, new JTreeByItemFinder(text, rowIndex,
0349: new DefaultStringComparator(ce, ccs)), index));
0350: }
0351:
0352: /**
0353: * Waits JTree by item.
0354: * @param cont Container to search component in.
0355: * @param text Item text. If null, contents is not checked.
0356: * @param ce Compare text exactly.
0357: * @param ccs Compare text case sensitively.
0358: * @param rowIndex Index of row to compare text. If -1, selected row is checked.
0359: * @return JTree instance or null if component was not found.
0360: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0361: * @throws TimeoutExpiredException
0362: */
0363: public static JTree waitJTree(Container cont, String text,
0364: boolean ce, boolean ccs, int rowIndex) {
0365: return (waitJTree(cont, text, ce, ccs, rowIndex, 0));
0366: }
0367:
0368: static {
0369: Timeouts.initDefault("JTreeOperator.WaitNodeExpandedTimeout",
0370: WAIT_NODE_EXPANDED_TIMEOUT);
0371: Timeouts.initDefault("JTreeOperator.WaitNodeCollapsedTimeout",
0372: WAIT_NODE_COLLAPSED_TIMEOUT);
0373: Timeouts.initDefault(
0374: "JTreeOperator.WaitAfterNodeExpandedTimeout",
0375: WAIT_AFTER_NODE_EXPANDED_TIMEOUT);
0376: Timeouts.initDefault("JTreeOperator.WaitNextNodeTimeout",
0377: WAIT_NEXT_NODE_TIMEOUT);
0378: Timeouts.initDefault("JTreeOperator.WaitNodeVisibleTimeout",
0379: WAIT_NODE_VISIBLE_TIMEOUT);
0380: Timeouts.initDefault("JTreeOperator.BeforeEditTimeout",
0381: BEFORE_EDIT_TIMEOUT);
0382: Timeouts.initDefault("JTreeOperator.WaitEditingTimeout",
0383: WAIT_EDITING_TIMEOUT);
0384: }
0385:
0386: public void setTimeouts(Timeouts times) {
0387: this .timeouts = times;
0388: super .setTimeouts(timeouts);
0389: }
0390:
0391: public Timeouts getTimeouts() {
0392: return (timeouts);
0393: }
0394:
0395: public void setOutput(TestOut out) {
0396: output = out;
0397: super .setOutput(output.createErrorOutput());
0398: }
0399:
0400: public TestOut getOutput() {
0401: return (output);
0402: }
0403:
0404: public void copyEnvironment(Operator anotherOperator) {
0405: super .copyEnvironment(anotherOperator);
0406: driver = (TreeDriver) DriverManager.getDriver(
0407: DriverManager.TREE_DRIVER_ID, getClass(),
0408: anotherOperator.getProperties());
0409: }
0410:
0411: /**
0412: * Expands path.
0413: * @param path a path to be expanded.
0414: * @throws TimeoutExpiredException
0415: */
0416: public void doExpandPath(TreePath path) {
0417: if (path != null) {
0418: output.printLine("Expanding \""
0419: + path.getPathComponent(path.getPathCount() - 1)
0420: .toString() + "\" node");
0421: output.printGolden("Expanding \""
0422: + path.getPathComponent(path.getPathCount() - 1)
0423: .toString() + "\" node");
0424: driver.expandItem(this , getRowForPath(path));
0425: waitExpanded(path);
0426: } else {
0427: throw (new NoSuchPathException());
0428: }
0429: }
0430:
0431: /**
0432: * Expands path on row.
0433: * @param row a row index to be expanded.
0434: * @throws TimeoutExpiredException
0435: */
0436: public void doExpandRow(int row) {
0437: output.printLine("Expanding " + Integer.toString(row) + " row");
0438: output.printGolden("Expanding " + Integer.toString(row)
0439: + " row");
0440: driver.expandItem(this , row);
0441: waitExpanded(row);
0442: }
0443:
0444: /**
0445: * Ensures that the node identified by path is currently viewable.
0446: * @param path a path to be made visible.
0447: * @throws TimeoutExpiredException
0448: */
0449: public void doMakeVisible(TreePath path) {
0450: if (path != null) {
0451: output.printLine("Making \"" + path.toString()
0452: + "\" path visible");
0453: output.printGolden("Making path visible");
0454: makeVisible(path);
0455: waitVisible(path);
0456: } else {
0457: throw (new NoSuchPathException());
0458: }
0459: }
0460:
0461: /**
0462: * Returns number of child.
0463: * @param node a node to count children of.
0464: * @return a number of children.
0465: */
0466: public int getChildCount(final Object node) {
0467: return runMapping(new MapIntegerAction("getChildCount") {
0468: public int map() {
0469: return ((JTree) getSource()).getModel().getChildCount(
0470: node);
0471: }
0472: });
0473: }
0474:
0475: /**
0476: * Returns node children.
0477: * @param node a node to get children of.
0478: * @return an array of node children.
0479: */
0480: public Object[] getChildren(final Object node) {
0481: return (Object[]) runMapping(new MapAction("getChildren") {
0482: public Object map() {
0483: TreeModel md = ((JTree) getSource()).getModel();
0484: Object[] result = new Object[md.getChildCount(node)];
0485: for (int i = 0; i < md.getChildCount(node); i++) {
0486: result[i] = md.getChild(node, i);
0487: }
0488: return result;
0489: }
0490: });
0491: }
0492:
0493: /**
0494: * Returns node child.
0495: * @param node a node to get a child of.
0496: * @param index a child index.
0497: * @return a node child.
0498: */
0499: public Object getChild(final Object node, final int index) {
0500: return runMapping(new MapAction("getChild") {
0501: public Object map() {
0502: return ((JTree) getSource()).getModel().getChild(node,
0503: index);
0504: }
0505: });
0506: }
0507:
0508: /**
0509: * Returns number of child.
0510: * @param path a path indicating a node to count children of.
0511: * @return a number of children.
0512: */
0513: public int getChildCount(TreePath path) {
0514: if (path != null) {
0515: return (getChildCount(path.getLastPathComponent()));
0516: } else {
0517: throw (new NoSuchPathException());
0518: }
0519: }
0520:
0521: /**
0522: * Constructs new path from a path and index's subnode of it last node.
0523: * @param path a path indicating a node to get a child of.
0524: * @param index a child node index.
0525: * @return a number of children.
0526: */
0527: public TreePath getChildPath(TreePath path, int index) {
0528: if (path != null) {
0529: return (path.pathByAddingChild(getChild(path
0530: .getLastPathComponent(), index)));
0531: } else {
0532: throw (new NoSuchPathException());
0533: }
0534: }
0535:
0536: /**
0537: * Constructs new paths from a path and all subnodes of it last node.
0538: * @param path a path indicating a node to get children of.
0539: * @return a number of children.
0540: */
0541: public TreePath[] getChildPaths(TreePath path) {
0542: if (path != null) {
0543: Object[] children = getChildren(path.getLastPathComponent());
0544: TreePath[] result = new TreePath[children.length];
0545: for (int i = 0; i < children.length; i++) {
0546: result[i] = path.pathByAddingChild(children[i]);
0547: }
0548: return (result);
0549: } else {
0550: throw (new NoSuchPathException());
0551: }
0552: }
0553:
0554: /**
0555: * Returns the root of the tree.
0556: * @return tree root.
0557: * @throws TimeoutExpiredException
0558: */
0559: public Object getRoot() {
0560: Timeouts times = timeouts.cloneThis();
0561: times.setTimeout("Waiter.WaitingTime", timeouts
0562: .getTimeout("JTreeOperator.WaitNodeVisibleTimeout"));
0563: Waiter rootWaiter = new Waiter(new Waitable() {
0564: public Object actionProduced(Object obj) {
0565: Object root = ((TreeModel) getModel()).getRoot();
0566: if (root == null || root.toString() == null
0567: || root.toString().equals("null")) {
0568: return (null);
0569: } else {
0570: return (root);
0571: }
0572: }
0573:
0574: public String getDescription() {
0575: return ("Wait root node");
0576: }
0577: });
0578: rootWaiter.setTimeouts(times);
0579: rootWaiter.setOutput(output.createErrorOutput());
0580: try {
0581: return (rootWaiter.waitAction(null));
0582: } catch (InterruptedException e) {
0583: output.printStackTrace(e);
0584: return (null);
0585: }
0586: }
0587:
0588: /**
0589: * Searches path in tree.
0590: * @param chooser TreePathChooser implementation.
0591: * @return a path fitting the criteria.
0592: * @see TreePathChooser
0593: * @see #findPath
0594: * @throws TimeoutExpiredException
0595: */
0596: public TreePath findPath(TreePathChooser chooser) {
0597: output.printLine("Search for a tree path "
0598: + chooser.getDescription());
0599: output.printGolden("Search for a tree path");
0600: TreePath rootPath = new TreePath(getRoot());
0601: if (chooser.checkPath(rootPath, 0)) {
0602: return (rootPath);
0603: }
0604: Timeouts times = timeouts.cloneThis();
0605: times.setTimeout("Waiter.WaitingTime", timeouts
0606: .getTimeout("JTreeOperator.WaitNextNodeTimeout"));
0607: Waiter loadedWaiter = new Waiter(new Waitable() {
0608: // fields used in getDescription() method
0609: TreePath currentPath;
0610: String requestedPath;
0611:
0612: public Object actionProduced(Object obj) {
0613: TreePathChooser chsr = (TreePathChooser) ((Object[]) obj)[0];
0614: requestedPath = chsr.getDescription();
0615: TreePath path = (TreePath) ((Object[]) obj)[1];
0616: currentPath = path;
0617: Object[] result = new Object[2];
0618: Object[] children = getChildren(path
0619: .getLastPathComponent());
0620: for (int j = 0; j < children.length; j++) {
0621: result[0] = path.pathByAddingChild(children[j]);
0622: if (chsr.checkPath((TreePath) result[0], j)) {
0623: result[1] = Boolean.TRUE;
0624: return (result);
0625: }
0626: if (chsr.hasAsParent((TreePath) result[0], j)) {
0627: result[1] = Boolean.FALSE;
0628: return (result);
0629: }
0630: }
0631: return (null);
0632: }
0633:
0634: public String getDescription() {
0635: return "Wait next node loaded under parent "
0636: + currentPath + " when requested was "
0637: + requestedPath;
0638: }
0639: });
0640: loadedWaiter.setTimeouts(times);
0641: loadedWaiter.setOutput(output.createErrorOutput());
0642: return (findPathPrimitive(rootPath, chooser, loadedWaiter));
0643: }
0644:
0645: /**
0646: * Searches index'th row by row chooser.
0647: * @param chooser a path searching criteria.
0648: * @param index a child index.
0649: * @return Row index or -1 if search was insuccessful.
0650: * @see JTreeOperator.TreeRowChooser
0651: */
0652: public int findRow(TreeRowChooser chooser, int index) {
0653: TreeModel model = getModel();
0654: int count = 0;
0655: for (int i = 0; i < getRowCount(); i++) {
0656: if (chooser.checkRow(this , i)) {
0657: if (count == index) {
0658: return (i);
0659: } else {
0660: count++;
0661: }
0662: }
0663: }
0664: return (-1);
0665: }
0666:
0667: /**
0668: * Searches a row by row chooser.
0669: * @param chooser a path searching criteria.
0670: * @return Row index or -1 if search was insuccessful.
0671: * @see JTreeOperator.TreeRowChooser
0672: */
0673: public int findRow(TreeRowChooser chooser) {
0674: return (findRow(chooser, 0));
0675: }
0676:
0677: /**
0678: * Searches index'th row by substring.
0679: * @param item Substring.
0680: * @param comparator a string comparision algorithm
0681: * @param index an ordinal row index between ones matching the criteria
0682: * @return Row index or -1 if search was insuccessful.
0683: */
0684: public int findRow(String item, StringComparator comparator,
0685: int index) {
0686: return (findRow(
0687: new BySubStringTreeRowChooser(item, comparator), index));
0688: }
0689:
0690: /**
0691: * Searches index'th row by substring.
0692: * @param item Substring.
0693: * @param ce Compare exactly
0694: * @param cc Compare case sensitivelly.
0695: * @param index an ordinal row index between ones matching the criteria
0696: * @return Row index or -1 if search was insuccessful.
0697: * @deprecated Use findRow(String, int) or findRow(String, StringComparator, int)
0698: */
0699: public int findRow(String item, boolean ce, boolean cc, int index) {
0700: return (findRow(item, new DefaultStringComparator(ce, cc),
0701: index));
0702: }
0703:
0704: /**
0705: * Searches index'th row by substring.
0706: * Uses StringComparator assigned to this object.
0707: * @param item Substring.
0708: * @param index an ordinal row index between ones matching the criteria
0709: * @return Row index or -1 if search was insuccessful.
0710: */
0711: public int findRow(String item, int index) {
0712: return (findRow(item, getComparator(), index));
0713: }
0714:
0715: /**
0716: * Searches a row by substring.
0717: * @param item Substring.
0718: * @param comparator a string comparision algorithm
0719: * @return Row index or -1 if search was insuccessful.
0720: */
0721: public int findRow(String item, StringComparator comparator) {
0722: return (findRow(item, comparator, 0));
0723: }
0724:
0725: /**
0726: * Searches a row by substring.
0727: * @param item Substring.
0728: * @param ce Compare exactly
0729: * @param cc Compare case sensitivelly.
0730: * @return Row index or -1 if search was insuccessful.
0731: * @deprecated Use findRow(String) or findRow(String, StringComparator)
0732: */
0733: public int findRow(String item, boolean ce, boolean cc) {
0734: return (findRow(item, ce, cc, 0));
0735: }
0736:
0737: /**
0738: * Searches a row by substring.
0739: * Uses StringComparator assigned to this object.
0740: * @param item Substring.
0741: * @return Row index or -1 if search was insuccessful.
0742: */
0743: public int findRow(String item) {
0744: return (findRow(item, getComparator(), 0));
0745: }
0746:
0747: /**
0748: * Searches index'th row by rendered component.
0749: * @param chooser Component checking object.
0750: * @param index an ordinal row index between ones matching the criteria
0751: * @return Row index or -1 if search was insuccessful.
0752: */
0753: public int findRow(ComponentChooser chooser, int index) {
0754: return (findRow(new ByRenderedComponentTreeRowChooser(chooser),
0755: index));
0756: }
0757:
0758: /**
0759: * Searches a row by rendered component.
0760: * @param chooser Component checking object.
0761: * @return Row index or -1 if search was insuccessful.
0762: */
0763: public int findRow(ComponentChooser chooser) {
0764: return (findRow(chooser, 0));
0765: }
0766:
0767: /**
0768: * Searches path in tree.
0769: * Can be used to find one of the nodes with the same text.
0770: * Example:<BR>
0771: * <pre>
0772: * root
0773: * +-+node
0774: * | +--subnode
0775: * +-+node
0776: * | +--subnode
0777: * | +--subnode
0778: * ...
0779: * String[] names = {"node", "subnode"};<BR>
0780: * int[] indexes = {1, 0};<BR>
0781: * </pre>
0782: * TreePath path = findPath(names, indexes, true, true);<BR>
0783: * "path" will points to the second (from the top) "subnode" node.
0784: * @param names Node texts array.
0785: * @param indexes Nodes indexes.
0786: * @param comparator a string comparision algorithm
0787: * @return a tree path matching the criteria
0788: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0789: * @see #findPath
0790: * @throws TimeoutExpiredException
0791: */
0792: public TreePath findPath(String[] names, int[] indexes,
0793: StringComparator comparator) {
0794: return (findPath(new StringArrayPathChooser(names, indexes,
0795: comparator)));
0796: }
0797:
0798: /**
0799: * Searches path in tree.
0800: * Can be used to find one of the nodes with the same text.
0801: * Example:<BR>
0802: * <pre>
0803: * root
0804: * +-+node
0805: * | +--subnode
0806: * +-+node
0807: * | +--subnode
0808: * | +--subnode
0809: * ...
0810: * String[] names = {"node", "subnode"};<BR>
0811: * int[] indexes = {1, 0};<BR>
0812: * </pre>
0813: * TreePath path = findPath(names, indexes, true, true);<BR>
0814: * "path" will points to the second (from the top) "subnode" node.
0815: * @param names Node texts array.
0816: * @param indexes Nodes indexes.
0817: * @param ce Compare exactly.
0818: * @param ccs Compare case sensitively.
0819: * @return a tree path matching the criteria
0820: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0821: * @see #findPath
0822: * @throws TimeoutExpiredException
0823: * @deprecated Use findPath(String[], int[]) or findCellRow(String[], int[], StringComparator)
0824: */
0825: public TreePath findPath(String[] names, int[] indexes, boolean ce,
0826: boolean ccs) {
0827: return (findPath(names, indexes, new DefaultStringComparator(
0828: ce, ccs)));
0829: }
0830:
0831: /**
0832: * Searches path in tree.
0833: * Uses StringComparator assigned to this object.
0834: * @param names Node texts array.
0835: * @param indexes Nodes indexes.
0836: * @return a tree path matching the criteria
0837: * @see #findPath
0838: * @throws TimeoutExpiredException
0839: */
0840: public TreePath findPath(String[] names, int[] indexes) {
0841: return (findPath(names, indexes, getComparator()));
0842: }
0843:
0844: /**
0845: * Searches path in tree.
0846: * @param names Node texts array.
0847: * @param comparator a string comparision algorithm
0848: * @return a tree path matching the criteria
0849: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0850: * @see #findPath
0851: * @throws TimeoutExpiredException
0852: */
0853: public TreePath findPath(String[] names, StringComparator comparator) {
0854: int[] indexes = new int[0];
0855: return (findPath(names, indexes, comparator));
0856: }
0857:
0858: /**
0859: * Searches path in tree.
0860: * @param names Node texts array.
0861: * @param ce Compare exactly.
0862: * @param ccs Compare case sensitively.
0863: * @return a tree path matching the criteria
0864: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0865: * @see #findPath
0866: * @throws TimeoutExpiredException
0867: * @deprecated Use findPath(String[]) or findCellRow(String[], StringComparator)
0868: */
0869: public TreePath findPath(String[] names, boolean ce, boolean ccs) {
0870: int[] indexes = new int[0];
0871: return (findPath(names, indexes, ce, ccs));
0872: }
0873:
0874: /**
0875: * Searches path in tree.
0876: * Uses StringComparator assigned to this object.
0877: * @param names Node texts array.
0878: * @return a tree path matching the criteria
0879: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0880: * @see #findPath
0881: * @throws TimeoutExpiredException
0882: */
0883: public TreePath findPath(String[] names) {
0884: int[] indexes = new int[0];
0885: return (findPath(names, indexes, getComparator()));
0886: }
0887:
0888: /**
0889: * Searches path in tree.
0890: * @param path String representing tree path.
0891: * Path components should be devided by "delim" parameter.
0892: * @param indexes String representing indexes to search path components.
0893: * Indexes should be devided by "delim" parameter.
0894: * @param delim Path components delimiter.
0895: * @param comparator a string comparision algorithm
0896: * @return a tree path matching the criteria
0897: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0898: * @see #findPath
0899: * @throws TimeoutExpiredException
0900: */
0901: public TreePath findPath(String path, String indexes, String delim,
0902: StringComparator comparator) {
0903: String[] indexStrings = parseString(indexes, delim);
0904: int[] indInts = new int[indexStrings.length];
0905: for (int i = 0; i < indexStrings.length; i++) {
0906: indInts[i] = Integer.parseInt(indexStrings[i]);
0907: }
0908: return (findPath(parseString(path, delim), indInts, comparator));
0909: }
0910:
0911: /**
0912: * Searches path in tree.
0913: * @param path String representing tree path.
0914: * Path components should be devided by "delim" parameter.
0915: * @param indexes String representing indexes to search path components.
0916: * Indexes should be devided by "delim" parameter.
0917: * @param delim Path components delimiter.
0918: * @param ce Compare exactly.
0919: * @param ccs Compare case sensitively.
0920: * @return a tree path matching the criteria
0921: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0922: * @see #findPath
0923: * @throws TimeoutExpiredException
0924: * @deprecated Use findPath(String, String, String) or findCellRow(String, String, String, StringComparator)
0925: */
0926: public TreePath findPath(String path, String indexes, String delim,
0927: boolean ce, boolean ccs) {
0928: return (findPath(path, indexes, delim,
0929: new DefaultStringComparator(ce, ccs)));
0930: }
0931:
0932: /**
0933: * Searches path in tree.
0934: * Uses StringComparator assigned to this object.
0935: * @param path String representing tree path.
0936: * Path components should be devided by "delim" parameter.
0937: * @param indexes String representing indexes to search path components.
0938: * Indexes should be devided by "delim" parameter.
0939: * @param delim Path components delimiter.
0940: * @return a tree path matching the criteria
0941: * @see #findPath
0942: * @throws TimeoutExpiredException
0943: */
0944: public TreePath findPath(String path, String indexes, String delim) {
0945: return (findPath(path, indexes, delim, getComparator()));
0946: }
0947:
0948: /**
0949: * Searches path in tree.
0950: * @param path String representing tree path.
0951: * Path components should be devided by "delim" parameter.
0952: * @param delim Path components delimiter.
0953: * @param comparator a string comparision algorithm
0954: * @return a tree path matching the criteria
0955: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0956: * @see #findPath
0957: * @throws TimeoutExpiredException
0958: */
0959: public TreePath findPath(String path, String delim,
0960: StringComparator comparator) {
0961: return (findPath(parseString(path, delim), comparator));
0962: }
0963:
0964: /**
0965: * Searches path in tree.
0966: * @param path String representing tree path.
0967: * @param comparator a string comparision algorithm
0968: * @return a tree path matching the criteria
0969: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0970: * @see #findPath
0971: * @throws TimeoutExpiredException
0972: */
0973: public TreePath findPath(String path, StringComparator comparator) {
0974: return (findPath(parseString(path), comparator));
0975: }
0976:
0977: /**
0978: * Searches path in tree.
0979: * @param path String representing tree path.
0980: * Path components should be devided by "delim" parameter.
0981: * @param delim Path components delimiter.
0982: * @param ce Compare exactly.
0983: * @param ccs Compare case sensitively.
0984: * @return a tree path matching the criteria
0985: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0986: * @see #findPath
0987: * @throws TimeoutExpiredException
0988: * @deprecated Use findPath(String, String) or findCellRow(String, String, StringComparator)
0989: */
0990: public TreePath findPath(String path, String delim, boolean ce,
0991: boolean ccs) {
0992: return (findPath(parseString(path, delim), ce, ccs));
0993: }
0994:
0995: /**
0996: * Searches path in tree.
0997: * Uses StringComparator assigned to this object.
0998: * @param path String representing tree path.
0999: * Path components should be devided by "delim" parameter.
1000: * @param delim Path components delimiter.
1001: * @return a tree path matching the criteria
1002: * @see #findPath
1003: * @throws TimeoutExpiredException
1004: */
1005: public TreePath findPath(String path, String delim) {
1006: return (findPath(parseString(path, delim)));
1007: }
1008:
1009: /**
1010: * Searches path in tree.
1011: * Uses StringComparator assigned to this object.
1012: * Uses PathParser assigned to this object.
1013: * @param path String representing tree path.
1014: * @return a tree path matching the criteria
1015: * @see #findPath
1016: * @throws TimeoutExpiredException
1017: */
1018: public TreePath findPath(String path) {
1019: return (findPath(parseString(path)));
1020: }
1021:
1022: /**
1023: * Ensures that the node identified by the specified path is collapsed and viewable.
1024: * @param path a path to collapse.
1025: * @throws TimeoutExpiredException
1026: */
1027: public void doCollapsePath(TreePath path) {
1028: if (path != null) {
1029: output.printLine("Collapsing \"" + path.toString()
1030: + "\" path");
1031: output.printGolden("Collapsing path");
1032: driver.collapseItem(this , getRowForPath(path));
1033: if (getVerification()) {
1034: waitCollapsed(path);
1035: }
1036: } else {
1037: throw (new NoSuchPathException());
1038: }
1039: }
1040:
1041: /**
1042: * Ensures that the node in the specified row is collapsed.
1043: * @param row a row index to collapse.
1044: * @throws TimeoutExpiredException
1045: */
1046: public void doCollapseRow(int row) {
1047: output.printLine("Collapsing \"" + Integer.toString(row)
1048: + "\" row");
1049: output.printGolden("Collapsing path");
1050: driver.collapseItem(this , row);
1051: if (getVerification()) {
1052: waitCollapsed(row);
1053: }
1054: }
1055:
1056: /**
1057: * Selects the path.
1058: * @param path a path to select.
1059: */
1060: public void selectPath(final TreePath path) {
1061: if (path != null) {
1062: output.printLine("Selecting \"" + path.toString()
1063: + "\" path");
1064: output.printGolden("Selecting path");
1065: scrollToPath(path);
1066: getQueueTool().invokeSmoothly(
1067: new QueueTool.QueueAction("Path selecting") {
1068: public Object launch() {
1069: driver.selectItem(JTreeOperator.this ,
1070: getRowForPath(path));
1071: return (null);
1072: }
1073: });
1074: if (getVerification()) {
1075: waitSelected(path);
1076: }
1077: } else {
1078: throw (new NoSuchPathException());
1079: }
1080: }
1081:
1082: /**
1083: * Selects the node in the specified row.
1084: * @param row an index of row to select.
1085: */
1086: public void selectRow(int row) {
1087: output.printLine("Collapsing \"" + Integer.toString(row)
1088: + "\" row");
1089: output.printGolden("Collapsing path");
1090: driver.selectItem(this , row);
1091: if (getVerification()) {
1092: waitSelected(row);
1093: }
1094: }
1095:
1096: /**
1097: * Selects some pathes.
1098: * If verification mode is on, checks that right paths have been selected.
1099: * @param paths a paths to select.
1100: */
1101: public void selectPaths(TreePath[] paths) {
1102: output.printLine("Selecting paths:");
1103: int[] rows = new int[paths.length];
1104: for (int i = 0; i < paths.length; i++) {
1105: output.printLine(" " + paths[i].toString());
1106: rows[i] = getRowForPath(paths[i]);
1107: }
1108: output.printGolden("Selecting paths");
1109: driver.selectItems(this , rows);
1110: if (getVerification()) {
1111: waitSelected(paths);
1112: }
1113: }
1114:
1115: /**
1116: * Retuns points which can be used to click on path.
1117: * @param path a tree path to click on.
1118: * @return a Point in component's coordinate system.
1119: */
1120: public Point getPointToClick(TreePath path) {
1121: if (path != null) {
1122: Rectangle rect = getPathBounds(path);
1123: if (rect != null) {
1124: return (new Point(
1125: (int) (rect.getX() + rect.getWidth() / 2),
1126: (int) (rect.getY() + rect.getHeight() / 2)));
1127: } else {
1128: throw (new NoSuchPathException(path));
1129: }
1130: } else {
1131: throw (new NoSuchPathException());
1132: }
1133: }
1134:
1135: /**
1136: * Retuns points which can be used to click on path.
1137: * @param row a row index to click on.
1138: * @return a Point in component's coordinate system.
1139: */
1140: public Point getPointToClick(int row) {
1141: Rectangle rect = getRowBounds(row);
1142: if (rect != null) {
1143: return (new Point(
1144: (int) (rect.getX() + rect.getWidth() / 2),
1145: (int) (rect.getY() + rect.getHeight() / 2)));
1146: } else {
1147: throw (new NoSuchPathException(row));
1148: }
1149: }
1150:
1151: /**
1152: * Clicks on the node.
1153: * @param path a path to click on.
1154: * @param clickCount a number of clicks
1155: * @param mouseButton InputEvent.BUTTON1/2/3_MASK value
1156: * @param modifiers Combination of InputEvent.*_MASK values
1157: * @throws TimeoutExpiredException
1158: */
1159: public void clickOnPath(TreePath path, int clickCount,
1160: int mouseButton, int modifiers) {
1161: if (path != null) {
1162: output.printLine("Click on \"" + path.toString()
1163: + "\" path");
1164: output.printGolden("Click on path");
1165: makeComponentVisible();
1166: if (path.getParentPath() != null) {
1167: expandPath(path.getParentPath());
1168: }
1169: makeVisible(path);
1170: scrollToPath(path);
1171: Point point = getPointToClick(path);
1172: clickMouse((int) point.getX(), (int) point.getY(),
1173: clickCount, mouseButton, modifiers);
1174: } else {
1175: throw (new NoSuchPathException());
1176: }
1177: }
1178:
1179: /**
1180: * Clicks on the node.
1181: * @param path a path to click on.
1182: * @param clickCount a number of clicks
1183: * @param mouseButton InputEvent.BUTTON1/2/3_MASK value
1184: * @throws TimeoutExpiredException
1185: */
1186: public void clickOnPath(TreePath path, int clickCount,
1187: int mouseButton) {
1188: clickOnPath(path, clickCount, mouseButton, 0);
1189: }
1190:
1191: /**
1192: * Clicks on the node.
1193: * @param path a path to click on.
1194: * @param clickCount a number of clicks
1195: * @throws TimeoutExpiredException
1196: */
1197: public void clickOnPath(TreePath path, int clickCount) {
1198: clickOnPath(path, clickCount, getDefaultMouseButton());
1199: }
1200:
1201: /**
1202: * Clicks on the node.
1203: * @param path a path to click on.
1204: * @throws TimeoutExpiredException
1205: */
1206: public void clickOnPath(TreePath path) {
1207: clickOnPath(path, 1);
1208: }
1209:
1210: /**
1211: * Calls popup on the specified pathes.
1212: * @param paths an array of paths to select before invoking popup on one of them
1213: * @param mouseButton a mouse button tused to call popup.
1214: * @return an opened popup menu.
1215: * @throws TimeoutExpiredException
1216: */
1217: public JPopupMenu callPopupOnPaths(TreePath[] paths, int mouseButton) {
1218: if (paths.length == 1) {
1219: output.printLine("Call popup on \"" + paths[0].toString()
1220: + "\" path");
1221: output.printGolden("Call popup on path");
1222: } else {
1223: output.printLine("Call popup on some pathes:");
1224: for (int i = 0; i < paths.length; i++) {
1225: output.printLine(" " + paths[i].toString());
1226: }
1227: output.printGolden("Call popup on paths");
1228: }
1229: makeComponentVisible();
1230: for (int i = 0; i < paths.length; i++) {
1231: if (paths[i].getParentPath() != null) {
1232: expandPath(paths[i].getParentPath());
1233: }
1234: }
1235: selectPaths(paths);
1236: scrollToPath(paths[paths.length - 1]);
1237: Point point = getPointToClick(paths[paths.length - 1]);
1238: return (JPopupMenuOperator.callPopup(this , (int) point.getX(),
1239: (int) point.getY(), mouseButton));
1240: }
1241:
1242: /**
1243: * Calls popup on the specified pathes.
1244: * @param paths an array of paths to select before invoking popup on one of them
1245: * @return an opened popup menu.
1246: * @throws TimeoutExpiredException
1247: */
1248: public JPopupMenu callPopupOnPaths(TreePath[] paths) {
1249: return (callPopupOnPaths(paths, getPopupMouseButton()));
1250: }
1251:
1252: /**
1253: * Calls popup on the specified path.
1254: * @param path a path to invoking popup on.
1255: * @param mouseButton a mouse button tused to call popup.
1256: * @return an opened popup menu.
1257: * @throws TimeoutExpiredException
1258: */
1259: public JPopupMenu callPopupOnPath(TreePath path, int mouseButton) {
1260: if (path != null) {
1261: TreePath[] paths = { path };
1262: return (callPopupOnPaths(paths, mouseButton));
1263: } else {
1264: throw (new NoSuchPathException());
1265: }
1266: }
1267:
1268: /**
1269: * Calls popup on the specified path.
1270: * @param path a path to invoking popup on.
1271: * @return an opened popup menu.
1272: * @throws TimeoutExpiredException
1273: */
1274: public JPopupMenu callPopupOnPath(TreePath path) {
1275: return (callPopupOnPath(path, getPopupMouseButton()));
1276: }
1277:
1278: /**
1279: * Scrolls to a path if the tree is on a JScrollPane component.
1280: * @param path a tree path to scroll to.
1281: */
1282: public void scrollToPath(TreePath path) {
1283: if (path != null) {
1284: output
1285: .printTrace("Scroll JTree to path \""
1286: + path.toString() + "\"\n : "
1287: + toStringSource());
1288: output.printGolden("Scroll JTree to path \""
1289: + path.toString() + "\"");
1290: makeComponentVisible();
1291: //try to find JScrollPane under.
1292: JScrollPane scroll = (JScrollPane) getContainer(new JScrollPaneOperator.JScrollPaneFinder(
1293: ComponentSearcher.getTrueChooser("JScrollPane")));
1294: if (scroll == null) {
1295: return;
1296: }
1297: JScrollPaneOperator scroller = new JScrollPaneOperator(
1298: scroll);
1299: scroller.copyEnvironment(this );
1300: scroller.setVisualizer(new EmptyVisualizer());
1301: Rectangle rect = getPathBounds(path);
1302: if (rect != null) {
1303: scroller.scrollToComponentRectangle(getSource(),
1304: (int) rect.getX(), (int) rect.getY(),
1305: (int) rect.getWidth(), (int) rect.getHeight());
1306: } else {
1307: throw (new NoSuchPathException(path));
1308: }
1309: } else {
1310: throw (new NoSuchPathException());
1311: }
1312: }
1313:
1314: /**
1315: * Scrolls to a row if the tree is on a JScrollPane component.
1316: * @param row a row index to scroll to.
1317: */
1318: public void scrollToRow(int row) {
1319: scrollToPath(getPathForRow(row));
1320: }
1321:
1322: /**
1323: * Turns path to the editing mode.
1324: * @param path a tree path to click on.
1325: * @throws TimeoutExpiredException
1326: */
1327: public void clickForEdit(TreePath path) {
1328: driver.startEditing(this , getRowForPath(path), timeouts
1329: .create("JTreeOperator.WaitEditingTimeout"));
1330: }
1331:
1332: /**
1333: * Ask renderer for component to be displayed.
1334: * @param path a path indicating the rendered node.
1335: * @param isSelected True if the specified cell is selected.
1336: * @param isExpanded True if the specified cell is expanded.
1337: * @param cellHasFocus True if the specified cell has the focus.
1338: * @return Component to be displayed.
1339: */
1340: public Component getRenderedComponent(TreePath path,
1341: boolean isSelected, boolean isExpanded, boolean cellHasFocus) {
1342: if (path != null) {
1343: return (getCellRenderer().getTreeCellRendererComponent(
1344: (JTree) getSource(), path.getLastPathComponent(),
1345: isSelected, isExpanded, getModel().isLeaf(
1346: path.getLastPathComponent()),
1347: getRowForPath(path), cellHasFocus));
1348: } else {
1349: throw (new NoSuchPathException());
1350: }
1351: }
1352:
1353: /**
1354: * Ask renderer for component to be displayed.
1355: * Uses isPathSelected(TreePath) to determine whether path is selected.
1356: * Uses isExpanded(TreePath) to determine whether path is expanded.
1357: * @param path a path indicating the rendered node.
1358: * @return Component to be displayed.
1359: */
1360: public Component getRenderedComponent(TreePath path) {
1361: return (getRenderedComponent(path, isPathSelected(path),
1362: isExpanded(path), false));
1363: }
1364:
1365: /**
1366: * Changes text of last path component.
1367: * @param path a path indicating the node to change value for.
1368: * @param newNodeText a new node value
1369: * @deprecated Use changePathObject(TreePath, Object) instead.
1370: * @see #changePathObject(TreePath, Object)
1371: * @throws TimeoutExpiredException
1372: */
1373: public void changePathText(TreePath path, String newNodeText) {
1374: changePathObject(path, newNodeText);
1375: }
1376:
1377: /**
1378: * Changes last path component using getCellEditor() editor.
1379: * @param path a path indicating the node to change value for.
1380: * @param newValue a new node value
1381: * @throws TimeoutExpiredException
1382: */
1383: public void changePathObject(TreePath path, Object newValue) {
1384: scrollToPath(path);
1385: driver.editItem(this , getRowForPath(path), newValue, timeouts
1386: .create("JTreeOperator.WaitEditingTimeout"));
1387: }
1388:
1389: /**
1390: * Waits path to be expanded.
1391: * @param path a path to wait expanded.
1392: */
1393: public void waitExpanded(final TreePath path) {
1394: if (path != null) {
1395: getOutput()
1396: .printLine(
1397: "Wait \""
1398: + path.toString()
1399: + "\" path to be expanded in component \n : "
1400: + toStringSource());
1401: getOutput().printGolden(
1402: "Wait \"" + path.toString()
1403: + "\" path to be expanded");
1404: waitState(new ComponentChooser() {
1405: public boolean checkComponent(Component comp) {
1406: return (isExpanded(path));
1407: }
1408:
1409: public String getDescription() {
1410: return ("Has \"" + path.toString() + "\" path expanded");
1411: }
1412: });
1413: } else {
1414: throw (new NoSuchPathException());
1415: }
1416: }
1417:
1418: /**
1419: * Waits row to be expanded.
1420: * @param row a row index to wait expanded.
1421: */
1422: public void waitExpanded(final int row) {
1423: getOutput()
1424: .printLine(
1425: "Wait "
1426: + Integer.toString(row)
1427: + "'th row to be expanded in component \n : "
1428: + toStringSource());
1429: getOutput().printGolden(
1430: "Wait " + Integer.toString(row)
1431: + "'th row to be expanded");
1432: waitState(new ComponentChooser() {
1433: public boolean checkComponent(Component comp) {
1434: return (isExpanded(row));
1435: }
1436:
1437: public String getDescription() {
1438: return ("Has " + Integer.toString(row) + "'th row expanded");
1439: }
1440: });
1441: }
1442:
1443: /**
1444: * Waits path to be collapsed.
1445: * @param path a path to wait collapsed.
1446: */
1447: public void waitCollapsed(final TreePath path) {
1448: if (path != null) {
1449: getOutput()
1450: .printLine(
1451: "Wait \""
1452: + path.toString()
1453: + "\" path to be collapsed in component \n : "
1454: + toStringSource());
1455: getOutput().printGolden(
1456: "Wait \"" + path.toString()
1457: + "\" path to be collapsed");
1458: waitState(new ComponentChooser() {
1459: public boolean checkComponent(Component comp) {
1460: return (isCollapsed(path));
1461: }
1462:
1463: public String getDescription() {
1464: return ("Has \"" + path.toString() + "\" path collapsed");
1465: }
1466: });
1467: } else {
1468: throw (new NoSuchPathException());
1469: }
1470: }
1471:
1472: /**
1473: * Waits row to be collapsed.
1474: * @param row a row index to wait collapsed.
1475: */
1476: public void waitCollapsed(final int row) {
1477: getOutput()
1478: .printLine(
1479: "Wait "
1480: + Integer.toString(row)
1481: + "'th row to be collapsed in component \n : "
1482: + toStringSource());
1483: getOutput().printGolden(
1484: "Wait " + Integer.toString(row)
1485: + "'th row to be collapsed");
1486: waitState(new ComponentChooser() {
1487: public boolean checkComponent(Component comp) {
1488: return (isCollapsed(row));
1489: }
1490:
1491: public String getDescription() {
1492: return ("Has " + Integer.toString(row) + "'th row collapsed");
1493: }
1494: });
1495: }
1496:
1497: /**
1498: * Waits path to be visible.
1499: * @param path a path to wait visible.
1500: */
1501: public void waitVisible(final TreePath path) {
1502: if (path != null) {
1503: getOutput()
1504: .printLine(
1505: "Wait \""
1506: + path.toString()
1507: + "\" path to be visible in component \n : "
1508: + toStringSource());
1509: getOutput().printGolden(
1510: "Wait \"" + path.toString()
1511: + "\" path to be visible");
1512: waitState(new ComponentChooser() {
1513: public boolean checkComponent(Component comp) {
1514: return (isVisible(path));
1515: }
1516:
1517: public String getDescription() {
1518: return ("Has \"" + path.toString() + "\" path visible");
1519: }
1520: });
1521: } else {
1522: throw (new NoSuchPathException());
1523: }
1524: }
1525:
1526: /**
1527: * Waits some paths to be selected.
1528: * @param paths an array of paths to be selected.
1529: */
1530: public void waitSelected(final TreePath[] paths) {
1531: getOutput().printLine(
1532: "Wait right selection in component \n : "
1533: + toStringSource());
1534: getOutput().printGolden("Wait right selection");
1535: waitState(new ComponentChooser() {
1536: public boolean checkComponent(Component comp) {
1537: TreePath[] rpaths = getSelectionModel()
1538: .getSelectionPaths();
1539: if (rpaths != null) {
1540: for (int i = 0; i < rpaths.length; i++) {
1541: if (!rpaths[i].equals(paths[i])) {
1542: return (false);
1543: }
1544: }
1545: return (true);
1546: } else {
1547: return (false);
1548: }
1549: }
1550:
1551: public String getDescription() {
1552: return ("Has right selection");
1553: }
1554: });
1555: }
1556:
1557: /**
1558: * Waits path to be selected.
1559: * @param path a tree path to be selected.
1560: */
1561: public void waitSelected(final TreePath path) {
1562: waitSelected(new TreePath[] { path });
1563: }
1564:
1565: /**
1566: * Waits rows to be selected.
1567: * @param rows an indices of rows to be selected.
1568: */
1569: public void waitSelected(int[] rows) {
1570: TreePath[] paths = new TreePath[rows.length];
1571: for (int i = 0; i < rows.length; i++) {
1572: paths[i] = getPathForRow(rows[i]);
1573: }
1574: waitSelected(paths);
1575: }
1576:
1577: /**
1578: * Waits row to be selected.
1579: * @param row an index of a row to be selected.
1580: */
1581: public void waitSelected(int row) {
1582: waitSelected(new int[] { row });
1583: }
1584:
1585: /**
1586: * Wat for text in certain row.
1587: * @param rowText Text to be compared with row text be <code>getComparator()</code> comparator.
1588: * @param row Row index. If -1, selected one is checked.
1589: */
1590: public void waitRow(String rowText, int row) {
1591: getOutput().printLine(
1592: "Wait \"" + rowText + "\" text in "
1593: + Integer.toString(row)
1594: + "'th line in component \n : "
1595: + toStringSource());
1596: getOutput().printGolden(
1597: "Wait \"" + rowText + " \" text in "
1598: + Integer.toString(row) + "'th line");
1599: waitState(new JTreeByItemFinder(rowText, row, getComparator()));
1600: }
1601:
1602: public Object chooseSubnode(Object parent, String text, int index,
1603: StringComparator comparator) {
1604: int count = -1;
1605: Object node;
1606: for (int i = 0; i < getChildCount(parent); i++) {
1607: try {
1608: node = getChild(parent, i);
1609: } catch (JemmyException e) {
1610: if (e.getInnerThrowable() instanceof IndexOutOfBoundsException) {
1611: // tree probably re-generated because we haven't found child with specified index
1612: return null;
1613: } else {
1614: throw e;
1615: }
1616: }
1617: if (comparator.equals(node.toString(), text)) {
1618: count++;
1619: if (count == index) {
1620: return (node);
1621: }
1622: }
1623: }
1624: return (null);
1625: }
1626:
1627: public Object chooseSubnode(Object parent, String text,
1628: StringComparator comparator) {
1629: return (chooseSubnode(parent, text, 0, comparator));
1630: }
1631:
1632: public Object chooseSubnode(Object parent, String text, int index) {
1633: return (chooseSubnode(parent, text, index, getComparator()));
1634: }
1635:
1636: public Object chooseSubnode(Object parent, String text) {
1637: return (chooseSubnode(parent, text, 0, getComparator()));
1638: }
1639:
1640: /**
1641: * Returns information about component.
1642: */
1643: public Hashtable getDump() {
1644: Hashtable result = super .getDump();
1645: Object root = ((JTree) getSource()).getModel().getRoot();
1646: if (root.toString() != null) {
1647: // only if root is not hidden
1648: result.put(ROOT_DPROP, root.toString());
1649: }
1650: addChildrenToDump(result, NODE_PREFIX_DPROP, root,
1651: new TreePath(root));
1652: int minSelection = ((JTree) getSource()).getMinSelectionRow();
1653: if (minSelection >= 0) {
1654: Object minObject = ((JTree) getSource()).getPathForRow(
1655: minSelection).getLastPathComponent();
1656: result.put(SELECTION_FIRST_DPROP, minObject.toString());
1657: int maxSelection = ((JTree) getSource())
1658: .getMaxSelectionRow();
1659: if (maxSelection > minSelection) {
1660: Object maxObject = ((JTree) getSource()).getPathForRow(
1661: maxSelection).getLastPathComponent();
1662: result.put(SELECTION_LAST_DPROP, maxObject.toString());
1663: }
1664: }
1665: return (result);
1666: }
1667:
1668: ////////////////////////////////////////////////////////
1669: //Mapping //
1670:
1671: /**Maps <code>JTree.addSelectionInterval(int, int)</code> through queue*/
1672: public void addSelectionInterval(final int i, final int i1) {
1673: runMapping(new MapVoidAction("addSelectionInterval") {
1674: public void map() {
1675: ((JTree) getSource()).addSelectionInterval(i, i1);
1676: }
1677: });
1678: }
1679:
1680: /**Maps <code>JTree.addSelectionPath(TreePath)</code> through queue*/
1681: public void addSelectionPath(final TreePath treePath) {
1682: runMapping(new MapVoidAction("addSelectionPath") {
1683: public void map() {
1684: ((JTree) getSource()).addSelectionPath(treePath);
1685: }
1686: });
1687: }
1688:
1689: /**Maps <code>JTree.addSelectionPaths(TreePath[])</code> through queue*/
1690: public void addSelectionPaths(final TreePath[] treePath) {
1691: runMapping(new MapVoidAction("addSelectionPaths") {
1692: public void map() {
1693: ((JTree) getSource()).addSelectionPaths(treePath);
1694: }
1695: });
1696: }
1697:
1698: /**Maps <code>JTree.addSelectionRow(int)</code> through queue*/
1699: public void addSelectionRow(final int i) {
1700: runMapping(new MapVoidAction("addSelectionRow") {
1701: public void map() {
1702: ((JTree) getSource()).addSelectionRow(i);
1703: }
1704: });
1705: }
1706:
1707: /**Maps <code>JTree.addSelectionRows(int[])</code> through queue*/
1708: public void addSelectionRows(final int[] i) {
1709: runMapping(new MapVoidAction("addSelectionRows") {
1710: public void map() {
1711: ((JTree) getSource()).addSelectionRows(i);
1712: }
1713: });
1714: }
1715:
1716: /**Maps <code>JTree.addTreeExpansionListener(TreeExpansionListener)</code> through queue*/
1717: public void addTreeExpansionListener(
1718: final TreeExpansionListener treeExpansionListener) {
1719: runMapping(new MapVoidAction("addTreeExpansionListener") {
1720: public void map() {
1721: ((JTree) getSource())
1722: .addTreeExpansionListener(treeExpansionListener);
1723: }
1724: });
1725: }
1726:
1727: /**Maps <code>JTree.addTreeSelectionListener(TreeSelectionListener)</code> through queue*/
1728: public void addTreeSelectionListener(
1729: final TreeSelectionListener treeSelectionListener) {
1730: runMapping(new MapVoidAction("addTreeSelectionListener") {
1731: public void map() {
1732: ((JTree) getSource())
1733: .addTreeSelectionListener(treeSelectionListener);
1734: }
1735: });
1736: }
1737:
1738: /**Maps <code>JTree.addTreeWillExpandListener(TreeWillExpandListener)</code> through queue*/
1739: public void addTreeWillExpandListener(
1740: final TreeWillExpandListener treeWillExpandListener) {
1741: runMapping(new MapVoidAction("addTreeWillExpandListener") {
1742: public void map() {
1743: ((JTree) getSource())
1744: .addTreeWillExpandListener(treeWillExpandListener);
1745: }
1746: });
1747: }
1748:
1749: /**Maps <code>JTree.cancelEditing()</code> through queue*/
1750: public void cancelEditing() {
1751: runMapping(new MapVoidAction("cancelEditing") {
1752: public void map() {
1753: ((JTree) getSource()).cancelEditing();
1754: }
1755: });
1756: }
1757:
1758: /**Maps <code>JTree.clearSelection()</code> through queue*/
1759: public void clearSelection() {
1760: runMapping(new MapVoidAction("clearSelection") {
1761: public void map() {
1762: ((JTree) getSource()).clearSelection();
1763: }
1764: });
1765: }
1766:
1767: /**Maps <code>JTree.collapsePath(TreePath)</code> through queue*/
1768: public void collapsePath(final TreePath treePath) {
1769: runMapping(new MapVoidAction("collapsePath") {
1770: public void map() {
1771: ((JTree) getSource()).collapsePath(treePath);
1772: }
1773: });
1774: }
1775:
1776: /**Maps <code>JTree.collapseRow(int)</code> through queue*/
1777: public void collapseRow(final int i) {
1778: runMapping(new MapVoidAction("collapseRow") {
1779: public void map() {
1780: ((JTree) getSource()).collapseRow(i);
1781: }
1782: });
1783: }
1784:
1785: /**Maps <code>JTree.convertValueToText(Object, boolean, boolean, boolean, int, boolean)</code> through queue*/
1786: public String convertValueToText(final Object object,
1787: final boolean b, final boolean b1, final boolean b2,
1788: final int i, final boolean b3) {
1789: return ((String) runMapping(new MapAction("convertValueToText") {
1790: public Object map() {
1791: return (((JTree) getSource()).convertValueToText(
1792: object, b, b1, b2, i, b3));
1793: }
1794: }));
1795: }
1796:
1797: /**Maps <code>JTree.expandPath(TreePath)</code> through queue*/
1798: public void expandPath(final TreePath treePath) {
1799: runMapping(new MapVoidAction("expandPath") {
1800: public void map() {
1801: ((JTree) getSource()).expandPath(treePath);
1802: }
1803: });
1804: }
1805:
1806: /**Maps <code>JTree.expandRow(int)</code> through queue*/
1807: public void expandRow(final int i) {
1808: runMapping(new MapVoidAction("expandRow") {
1809: public void map() {
1810: ((JTree) getSource()).expandRow(i);
1811: }
1812: });
1813: }
1814:
1815: /**Maps <code>JTree.fireTreeCollapsed(TreePath)</code> through queue*/
1816: public void fireTreeCollapsed(final TreePath treePath) {
1817: runMapping(new MapVoidAction("fireTreeCollapsed") {
1818: public void map() {
1819: ((JTree) getSource()).fireTreeCollapsed(treePath);
1820: }
1821: });
1822: }
1823:
1824: /**Maps <code>JTree.fireTreeExpanded(TreePath)</code> through queue*/
1825: public void fireTreeExpanded(final TreePath treePath) {
1826: runMapping(new MapVoidAction("fireTreeExpanded") {
1827: public void map() {
1828: ((JTree) getSource()).fireTreeExpanded(treePath);
1829: }
1830: });
1831: }
1832:
1833: /**Maps <code>JTree.fireTreeWillCollapse(TreePath)</code> through queue*/
1834: public void fireTreeWillCollapse(final TreePath treePath) {
1835: runMapping(new MapVoidAction("fireTreeWillCollapse") {
1836: public void map() throws ExpandVetoException {
1837: ((JTree) getSource()).fireTreeWillCollapse(treePath);
1838: }
1839: });
1840: }
1841:
1842: /**Maps <code>JTree.fireTreeWillExpand(TreePath)</code> through queue*/
1843: public void fireTreeWillExpand(final TreePath treePath) {
1844: runMapping(new MapVoidAction("fireTreeWillExpand") {
1845: public void map() throws ExpandVetoException {
1846: ((JTree) getSource()).fireTreeWillExpand(treePath);
1847: }
1848: });
1849: }
1850:
1851: /**Maps <code>JTree.getCellEditor()</code> through queue*/
1852: public TreeCellEditor getCellEditor() {
1853: return ((TreeCellEditor) runMapping(new MapAction(
1854: "getCellEditor") {
1855: public Object map() {
1856: return (((JTree) getSource()).getCellEditor());
1857: }
1858: }));
1859: }
1860:
1861: /**Maps <code>JTree.getCellRenderer()</code> through queue*/
1862: public TreeCellRenderer getCellRenderer() {
1863: return ((TreeCellRenderer) runMapping(new MapAction(
1864: "getCellRenderer") {
1865: public Object map() {
1866: return (((JTree) getSource()).getCellRenderer());
1867: }
1868: }));
1869: }
1870:
1871: /**Maps <code>JTree.getClosestPathForLocation(int, int)</code> through queue*/
1872: public TreePath getClosestPathForLocation(final int i, final int i1) {
1873: return ((TreePath) runMapping(new MapAction(
1874: "getClosestPathForLocation") {
1875: public Object map() {
1876: return (((JTree) getSource())
1877: .getClosestPathForLocation(i, i1));
1878: }
1879: }));
1880: }
1881:
1882: /**Maps <code>JTree.getClosestRowForLocation(int, int)</code> through queue*/
1883: public int getClosestRowForLocation(final int i, final int i1) {
1884: return (runMapping(new MapIntegerAction(
1885: "getClosestRowForLocation") {
1886: public int map() {
1887: return (((JTree) getSource()).getClosestRowForLocation(
1888: i, i1));
1889: }
1890: }));
1891: }
1892:
1893: /**Maps <code>JTree.getEditingPath()</code> through queue*/
1894: public TreePath getEditingPath() {
1895: return ((TreePath) runMapping(new MapAction("getEditingPath") {
1896: public Object map() {
1897: return (((JTree) getSource()).getEditingPath());
1898: }
1899: }));
1900: }
1901:
1902: /**Maps <code>JTree.getExpandedDescendants(TreePath)</code> through queue*/
1903: public Enumeration getExpandedDescendants(final TreePath treePath) {
1904: return ((Enumeration) runMapping(new MapAction(
1905: "getExpandedDescendants") {
1906: public Object map() {
1907: return (((JTree) getSource())
1908: .getExpandedDescendants(treePath));
1909: }
1910: }));
1911: }
1912:
1913: /**Maps <code>JTree.getInvokesStopCellEditing()</code> through queue*/
1914: public boolean getInvokesStopCellEditing() {
1915: return (runMapping(new MapBooleanAction(
1916: "getInvokesStopCellEditing") {
1917: public boolean map() {
1918: return (((JTree) getSource())
1919: .getInvokesStopCellEditing());
1920: }
1921: }));
1922: }
1923:
1924: /**Maps <code>JTree.getLastSelectedPathComponent()</code> through queue*/
1925: public Object getLastSelectedPathComponent() {
1926: return ((Object) runMapping(new MapAction(
1927: "getLastSelectedPathComponent") {
1928: public Object map() {
1929: return (((JTree) getSource())
1930: .getLastSelectedPathComponent());
1931: }
1932: }));
1933: }
1934:
1935: /**Maps <code>JTree.getLeadSelectionPath()</code> through queue*/
1936: public TreePath getLeadSelectionPath() {
1937: return ((TreePath) runMapping(new MapAction(
1938: "getLeadSelectionPath") {
1939: public Object map() {
1940: return (((JTree) getSource()).getLeadSelectionPath());
1941: }
1942: }));
1943: }
1944:
1945: /**Maps <code>JTree.getLeadSelectionRow()</code> through queue*/
1946: public int getLeadSelectionRow() {
1947: return (runMapping(new MapIntegerAction("getLeadSelectionRow") {
1948: public int map() {
1949: return (((JTree) getSource()).getLeadSelectionRow());
1950: }
1951: }));
1952: }
1953:
1954: /**Maps <code>JTree.getMaxSelectionRow()</code> through queue*/
1955: public int getMaxSelectionRow() {
1956: return (runMapping(new MapIntegerAction("getMaxSelectionRow") {
1957: public int map() {
1958: return (((JTree) getSource()).getMaxSelectionRow());
1959: }
1960: }));
1961: }
1962:
1963: /**Maps <code>JTree.getMinSelectionRow()</code> through queue*/
1964: public int getMinSelectionRow() {
1965: return (runMapping(new MapIntegerAction("getMinSelectionRow") {
1966: public int map() {
1967: return (((JTree) getSource()).getMinSelectionRow());
1968: }
1969: }));
1970: }
1971:
1972: /**Maps <code>JTree.getModel()</code> through queue*/
1973: public TreeModel getModel() {
1974: return ((TreeModel) runMapping(new MapAction("getModel") {
1975: public Object map() {
1976: return (((JTree) getSource()).getModel());
1977: }
1978: }));
1979: }
1980:
1981: /**Maps <code>JTree.getPathBounds(TreePath)</code> through queue*/
1982: public Rectangle getPathBounds(final TreePath treePath) {
1983: return ((Rectangle) runMapping(new MapAction("getPathBounds") {
1984: public Object map() {
1985: return (((JTree) getSource()).getPathBounds(treePath));
1986: }
1987: }));
1988: }
1989:
1990: /**Maps <code>JTree.getPathForLocation(int, int)</code> through queue*/
1991: public TreePath getPathForLocation(final int i, final int i1) {
1992: return ((TreePath) runMapping(new MapAction(
1993: "getPathForLocation") {
1994: public Object map() {
1995: return (((JTree) getSource()).getPathForLocation(i, i1));
1996: }
1997: }));
1998: }
1999:
2000: /**Maps <code>JTree.getPathForRow(int)</code> through queue*/
2001: public TreePath getPathForRow(final int i) {
2002: return ((TreePath) runMapping(new MapAction("getPathForRow") {
2003: public Object map() {
2004: return (((JTree) getSource()).getPathForRow(i));
2005: }
2006: }));
2007: }
2008:
2009: /**Maps <code>JTree.getPreferredScrollableViewportSize()</code> through queue*/
2010: public Dimension getPreferredScrollableViewportSize() {
2011: return ((Dimension) runMapping(new MapAction(
2012: "getPreferredScrollableViewportSize") {
2013: public Object map() {
2014: return (((JTree) getSource())
2015: .getPreferredScrollableViewportSize());
2016: }
2017: }));
2018: }
2019:
2020: /**Maps <code>JTree.getRowBounds(int)</code> through queue*/
2021: public Rectangle getRowBounds(final int i) {
2022: return ((Rectangle) runMapping(new MapAction("getRowBounds") {
2023: public Object map() {
2024: return (((JTree) getSource()).getRowBounds(i));
2025: }
2026: }));
2027: }
2028:
2029: /**Maps <code>JTree.getRowCount()</code> through queue*/
2030: public int getRowCount() {
2031: return (runMapping(new MapIntegerAction("getRowCount") {
2032: public int map() {
2033: return (((JTree) getSource()).getRowCount());
2034: }
2035: }));
2036: }
2037:
2038: /**Maps <code>JTree.getRowForLocation(int, int)</code> through queue*/
2039: public int getRowForLocation(final int i, final int i1) {
2040: return (runMapping(new MapIntegerAction("getRowForLocation") {
2041: public int map() {
2042: return (((JTree) getSource()).getRowForLocation(i, i1));
2043: }
2044: }));
2045: }
2046:
2047: /**Maps <code>JTree.getRowForPath(TreePath)</code> through queue*/
2048: public int getRowForPath(final TreePath treePath) {
2049: return (runMapping(new MapIntegerAction("getRowForPath") {
2050: public int map() {
2051: return (((JTree) getSource()).getRowForPath(treePath));
2052: }
2053: }));
2054: }
2055:
2056: /**Maps <code>JTree.getRowHeight()</code> through queue*/
2057: public int getRowHeight() {
2058: return (runMapping(new MapIntegerAction("getRowHeight") {
2059: public int map() {
2060: return (((JTree) getSource()).getRowHeight());
2061: }
2062: }));
2063: }
2064:
2065: /**Maps <code>JTree.getScrollableBlockIncrement(Rectangle, int, int)</code> through queue*/
2066: public int getScrollableBlockIncrement(final Rectangle rectangle,
2067: final int i, final int i1) {
2068: return (runMapping(new MapIntegerAction(
2069: "getScrollableBlockIncrement") {
2070: public int map() {
2071: return (((JTree) getSource())
2072: .getScrollableBlockIncrement(rectangle, i, i1));
2073: }
2074: }));
2075: }
2076:
2077: /**Maps <code>JTree.getScrollableTracksViewportHeight()</code> through queue*/
2078: public boolean getScrollableTracksViewportHeight() {
2079: return (runMapping(new MapBooleanAction(
2080: "getScrollableTracksViewportHeight") {
2081: public boolean map() {
2082: return (((JTree) getSource())
2083: .getScrollableTracksViewportHeight());
2084: }
2085: }));
2086: }
2087:
2088: /**Maps <code>JTree.getScrollableTracksViewportWidth()</code> through queue*/
2089: public boolean getScrollableTracksViewportWidth() {
2090: return (runMapping(new MapBooleanAction(
2091: "getScrollableTracksViewportWidth") {
2092: public boolean map() {
2093: return (((JTree) getSource())
2094: .getScrollableTracksViewportWidth());
2095: }
2096: }));
2097: }
2098:
2099: /**Maps <code>JTree.getScrollableUnitIncrement(Rectangle, int, int)</code> through queue*/
2100: public int getScrollableUnitIncrement(final Rectangle rectangle,
2101: final int i, final int i1) {
2102: return (runMapping(new MapIntegerAction(
2103: "getScrollableUnitIncrement") {
2104: public int map() {
2105: return (((JTree) getSource())
2106: .getScrollableUnitIncrement(rectangle, i, i1));
2107: }
2108: }));
2109: }
2110:
2111: /**Maps <code>JTree.getScrollsOnExpand()</code> through queue*/
2112: public boolean getScrollsOnExpand() {
2113: return (runMapping(new MapBooleanAction("getScrollsOnExpand") {
2114: public boolean map() {
2115: return (((JTree) getSource()).getScrollsOnExpand());
2116: }
2117: }));
2118: }
2119:
2120: /**Maps <code>JTree.getSelectionCount()</code> through queue*/
2121: public int getSelectionCount() {
2122: return (runMapping(new MapIntegerAction("getSelectionCount") {
2123: public int map() {
2124: return (((JTree) getSource()).getSelectionCount());
2125: }
2126: }));
2127: }
2128:
2129: /**Maps <code>JTree.getSelectionModel()</code> through queue*/
2130: public TreeSelectionModel getSelectionModel() {
2131: return ((TreeSelectionModel) runMapping(new MapAction(
2132: "getSelectionModel") {
2133: public Object map() {
2134: return (((JTree) getSource()).getSelectionModel());
2135: }
2136: }));
2137: }
2138:
2139: /**Maps <code>JTree.getSelectionPath()</code> through queue*/
2140: public TreePath getSelectionPath() {
2141: return ((TreePath) runMapping(new MapAction("getSelectionPath") {
2142: public Object map() {
2143: return (((JTree) getSource()).getSelectionPath());
2144: }
2145: }));
2146: }
2147:
2148: /**Maps <code>JTree.getSelectionPaths()</code> through queue*/
2149: public TreePath[] getSelectionPaths() {
2150: return ((TreePath[]) runMapping(new MapAction(
2151: "getSelectionPaths") {
2152: public Object map() {
2153: return (((JTree) getSource()).getSelectionPaths());
2154: }
2155: }));
2156: }
2157:
2158: /**Maps <code>JTree.getSelectionRows()</code> through queue*/
2159: public int[] getSelectionRows() {
2160: return ((int[]) runMapping(new MapAction("getSelectionRows") {
2161: public Object map() {
2162: return (((JTree) getSource()).getSelectionRows());
2163: }
2164: }));
2165: }
2166:
2167: /**Maps <code>JTree.getShowsRootHandles()</code> through queue*/
2168: public boolean getShowsRootHandles() {
2169: return (runMapping(new MapBooleanAction("getShowsRootHandles") {
2170: public boolean map() {
2171: return (((JTree) getSource()).getShowsRootHandles());
2172: }
2173: }));
2174: }
2175:
2176: /**Maps <code>JTree.getUI()</code> through queue*/
2177: public TreeUI getUI() {
2178: return ((TreeUI) runMapping(new MapAction("getUI") {
2179: public Object map() {
2180: return (((JTree) getSource()).getUI());
2181: }
2182: }));
2183: }
2184:
2185: /**Maps <code>JTree.getVisibleRowCount()</code> through queue*/
2186: public int getVisibleRowCount() {
2187: return (runMapping(new MapIntegerAction("getVisibleRowCount") {
2188: public int map() {
2189: return (((JTree) getSource()).getVisibleRowCount());
2190: }
2191: }));
2192: }
2193:
2194: /**Maps <code>JTree.hasBeenExpanded(TreePath)</code> through queue*/
2195: public boolean hasBeenExpanded(final TreePath treePath) {
2196: return (runMapping(new MapBooleanAction("hasBeenExpanded") {
2197: public boolean map() {
2198: return (((JTree) getSource()).hasBeenExpanded(treePath));
2199: }
2200: }));
2201: }
2202:
2203: /**Maps <code>JTree.isCollapsed(int)</code> through queue*/
2204: public boolean isCollapsed(final int i) {
2205: return (runMapping(new MapBooleanAction("isCollapsed") {
2206: public boolean map() {
2207: return (((JTree) getSource()).isCollapsed(i));
2208: }
2209: }));
2210: }
2211:
2212: /**Maps <code>JTree.isCollapsed(TreePath)</code> through queue*/
2213: public boolean isCollapsed(final TreePath treePath) {
2214: return (runMapping(new MapBooleanAction("isCollapsed") {
2215: public boolean map() {
2216: return (((JTree) getSource()).isCollapsed(treePath));
2217: }
2218: }));
2219: }
2220:
2221: /**Maps <code>JTree.isEditable()</code> through queue*/
2222: public boolean isEditable() {
2223: return (runMapping(new MapBooleanAction("isEditable") {
2224: public boolean map() {
2225: return (((JTree) getSource()).isEditable());
2226: }
2227: }));
2228: }
2229:
2230: /**Maps <code>JTree.isEditing()</code> through queue*/
2231: public boolean isEditing() {
2232: return (runMapping(new MapBooleanAction("isEditing") {
2233: public boolean map() {
2234: return (((JTree) getSource()).isEditing());
2235: }
2236: }));
2237: }
2238:
2239: /**Maps <code>JTree.isExpanded(int)</code> through queue*/
2240: public boolean isExpanded(final int i) {
2241: return (runMapping(new MapBooleanAction("isExpanded") {
2242: public boolean map() {
2243: return (((JTree) getSource()).isExpanded(i));
2244: }
2245: }));
2246: }
2247:
2248: /**Maps <code>JTree.isExpanded(TreePath)</code> through queue*/
2249: public boolean isExpanded(final TreePath treePath) {
2250: return (runMapping(new MapBooleanAction("isExpanded") {
2251: public boolean map() {
2252: return (((JTree) getSource()).isExpanded(treePath));
2253: }
2254: }));
2255: }
2256:
2257: /**Maps <code>JTree.isFixedRowHeight()</code> through queue*/
2258: public boolean isFixedRowHeight() {
2259: return (runMapping(new MapBooleanAction("isFixedRowHeight") {
2260: public boolean map() {
2261: return (((JTree) getSource()).isFixedRowHeight());
2262: }
2263: }));
2264: }
2265:
2266: /**Maps <code>JTree.isLargeModel()</code> through queue*/
2267: public boolean isLargeModel() {
2268: return (runMapping(new MapBooleanAction("isLargeModel") {
2269: public boolean map() {
2270: return (((JTree) getSource()).isLargeModel());
2271: }
2272: }));
2273: }
2274:
2275: /**Maps <code>JTree.isPathEditable(TreePath)</code> through queue*/
2276: public boolean isPathEditable(final TreePath treePath) {
2277: return (runMapping(new MapBooleanAction("isPathEditable") {
2278: public boolean map() {
2279: return (((JTree) getSource()).isPathEditable(treePath));
2280: }
2281: }));
2282: }
2283:
2284: /**Maps <code>JTree.isPathSelected(TreePath)</code> through queue*/
2285: public boolean isPathSelected(final TreePath treePath) {
2286: return (runMapping(new MapBooleanAction("isPathSelected") {
2287: public boolean map() {
2288: return (((JTree) getSource()).isPathSelected(treePath));
2289: }
2290: }));
2291: }
2292:
2293: /**Maps <code>JTree.isRootVisible()</code> through queue*/
2294: public boolean isRootVisible() {
2295: return (runMapping(new MapBooleanAction("isRootVisible") {
2296: public boolean map() {
2297: return (((JTree) getSource()).isRootVisible());
2298: }
2299: }));
2300: }
2301:
2302: /**Maps <code>JTree.isRowSelected(int)</code> through queue*/
2303: public boolean isRowSelected(final int i) {
2304: return (runMapping(new MapBooleanAction("isRowSelected") {
2305: public boolean map() {
2306: return (((JTree) getSource()).isRowSelected(i));
2307: }
2308: }));
2309: }
2310:
2311: /**Maps <code>JTree.isSelectionEmpty()</code> through queue*/
2312: public boolean isSelectionEmpty() {
2313: return (runMapping(new MapBooleanAction("isSelectionEmpty") {
2314: public boolean map() {
2315: return (((JTree) getSource()).isSelectionEmpty());
2316: }
2317: }));
2318: }
2319:
2320: /**Maps <code>JTree.isVisible(TreePath)</code> through queue*/
2321: public boolean isVisible(final TreePath treePath) {
2322: return (runMapping(new MapBooleanAction("isVisible") {
2323: public boolean map() {
2324: return (((JTree) getSource()).isVisible(treePath));
2325: }
2326: }));
2327: }
2328:
2329: /**Maps <code>JTree.makeVisible(TreePath)</code> through queue*/
2330: public void makeVisible(final TreePath treePath) {
2331: runMapping(new MapVoidAction("makeVisible") {
2332: public void map() {
2333: ((JTree) getSource()).makeVisible(treePath);
2334: }
2335: });
2336: }
2337:
2338: /**Maps <code>JTree.removeSelectionInterval(int, int)</code> through queue*/
2339: public void removeSelectionInterval(final int i, final int i1) {
2340: runMapping(new MapVoidAction("removeSelectionInterval") {
2341: public void map() {
2342: ((JTree) getSource()).removeSelectionInterval(i, i1);
2343: }
2344: });
2345: }
2346:
2347: /**Maps <code>JTree.removeSelectionPath(TreePath)</code> through queue*/
2348: public void removeSelectionPath(final TreePath treePath) {
2349: runMapping(new MapVoidAction("removeSelectionPath") {
2350: public void map() {
2351: ((JTree) getSource()).removeSelectionPath(treePath);
2352: }
2353: });
2354: }
2355:
2356: /**Maps <code>JTree.removeSelectionPaths(TreePath[])</code> through queue*/
2357: public void removeSelectionPaths(final TreePath[] treePath) {
2358: runMapping(new MapVoidAction("removeSelectionPaths") {
2359: public void map() {
2360: ((JTree) getSource()).removeSelectionPaths(treePath);
2361: }
2362: });
2363: }
2364:
2365: /**Maps <code>JTree.removeSelectionRow(int)</code> through queue*/
2366: public void removeSelectionRow(final int i) {
2367: runMapping(new MapVoidAction("removeSelectionRow") {
2368: public void map() {
2369: ((JTree) getSource()).removeSelectionRow(i);
2370: }
2371: });
2372: }
2373:
2374: /**Maps <code>JTree.removeSelectionRows(int[])</code> through queue*/
2375: public void removeSelectionRows(final int[] i) {
2376: runMapping(new MapVoidAction("removeSelectionRows") {
2377: public void map() {
2378: ((JTree) getSource()).removeSelectionRows(i);
2379: }
2380: });
2381: }
2382:
2383: /**Maps <code>JTree.removeTreeExpansionListener(TreeExpansionListener)</code> through queue*/
2384: public void removeTreeExpansionListener(
2385: final TreeExpansionListener treeExpansionListener) {
2386: runMapping(new MapVoidAction("removeTreeExpansionListener") {
2387: public void map() {
2388: ((JTree) getSource())
2389: .removeTreeExpansionListener(treeExpansionListener);
2390: }
2391: });
2392: }
2393:
2394: /**Maps <code>JTree.removeTreeSelectionListener(TreeSelectionListener)</code> through queue*/
2395: public void removeTreeSelectionListener(
2396: final TreeSelectionListener treeSelectionListener) {
2397: runMapping(new MapVoidAction("removeTreeSelectionListener") {
2398: public void map() {
2399: ((JTree) getSource())
2400: .removeTreeSelectionListener(treeSelectionListener);
2401: }
2402: });
2403: }
2404:
2405: /**Maps <code>JTree.removeTreeWillExpandListener(TreeWillExpandListener)</code> through queue*/
2406: public void removeTreeWillExpandListener(
2407: final TreeWillExpandListener treeWillExpandListener) {
2408: runMapping(new MapVoidAction("removeTreeWillExpandListener") {
2409: public void map() {
2410: ((JTree) getSource())
2411: .removeTreeWillExpandListener(treeWillExpandListener);
2412: }
2413: });
2414: }
2415:
2416: /**Maps <code>JTree.scrollPathToVisible(TreePath)</code> through queue*/
2417: public void scrollPathToVisible(final TreePath treePath) {
2418: runMapping(new MapVoidAction("scrollPathToVisible") {
2419: public void map() {
2420: ((JTree) getSource()).scrollPathToVisible(treePath);
2421: }
2422: });
2423: }
2424:
2425: /**Maps <code>JTree.scrollRowToVisible(int)</code> through queue*/
2426: public void scrollRowToVisible(final int i) {
2427: runMapping(new MapVoidAction("scrollRowToVisible") {
2428: public void map() {
2429: ((JTree) getSource()).scrollRowToVisible(i);
2430: }
2431: });
2432: }
2433:
2434: /**Maps <code>JTree.setCellEditor(TreeCellEditor)</code> through queue*/
2435: public void setCellEditor(final TreeCellEditor treeCellEditor) {
2436: runMapping(new MapVoidAction("setCellEditor") {
2437: public void map() {
2438: ((JTree) getSource()).setCellEditor(treeCellEditor);
2439: }
2440: });
2441: }
2442:
2443: /**Maps <code>JTree.setCellRenderer(TreeCellRenderer)</code> through queue*/
2444: public void setCellRenderer(final TreeCellRenderer treeCellRenderer) {
2445: runMapping(new MapVoidAction("setCellRenderer") {
2446: public void map() {
2447: ((JTree) getSource()).setCellRenderer(treeCellRenderer);
2448: }
2449: });
2450: }
2451:
2452: /**Maps <code>JTree.setEditable(boolean)</code> through queue*/
2453: public void setEditable(final boolean b) {
2454: runMapping(new MapVoidAction("setEditable") {
2455: public void map() {
2456: ((JTree) getSource()).setEditable(b);
2457: }
2458: });
2459: }
2460:
2461: /**Maps <code>JTree.setInvokesStopCellEditing(boolean)</code> through queue*/
2462: public void setInvokesStopCellEditing(final boolean b) {
2463: runMapping(new MapVoidAction("setInvokesStopCellEditing") {
2464: public void map() {
2465: ((JTree) getSource()).setInvokesStopCellEditing(b);
2466: }
2467: });
2468: }
2469:
2470: /**Maps <code>JTree.setLargeModel(boolean)</code> through queue*/
2471: public void setLargeModel(final boolean b) {
2472: runMapping(new MapVoidAction("setLargeModel") {
2473: public void map() {
2474: ((JTree) getSource()).setLargeModel(b);
2475: }
2476: });
2477: }
2478:
2479: /**Maps <code>JTree.setModel(TreeModel)</code> through queue*/
2480: public void setModel(final TreeModel treeModel) {
2481: runMapping(new MapVoidAction("setModel") {
2482: public void map() {
2483: ((JTree) getSource()).setModel(treeModel);
2484: }
2485: });
2486: }
2487:
2488: /**Maps <code>JTree.setRootVisible(boolean)</code> through queue*/
2489: public void setRootVisible(final boolean b) {
2490: runMapping(new MapVoidAction("setRootVisible") {
2491: public void map() {
2492: ((JTree) getSource()).setRootVisible(b);
2493: }
2494: });
2495: }
2496:
2497: /**Maps <code>JTree.setRowHeight(int)</code> through queue*/
2498: public void setRowHeight(final int i) {
2499: runMapping(new MapVoidAction("setRowHeight") {
2500: public void map() {
2501: ((JTree) getSource()).setRowHeight(i);
2502: }
2503: });
2504: }
2505:
2506: /**Maps <code>JTree.setScrollsOnExpand(boolean)</code> through queue*/
2507: public void setScrollsOnExpand(final boolean b) {
2508: runMapping(new MapVoidAction("setScrollsOnExpand") {
2509: public void map() {
2510: ((JTree) getSource()).setScrollsOnExpand(b);
2511: }
2512: });
2513: }
2514:
2515: /**Maps <code>JTree.setSelectionInterval(int, int)</code> through queue*/
2516: public void setSelectionInterval(final int i, final int i1) {
2517: runMapping(new MapVoidAction("setSelectionInterval") {
2518: public void map() {
2519: ((JTree) getSource()).setSelectionInterval(i, i1);
2520: }
2521: });
2522: }
2523:
2524: /**Maps <code>JTree.setSelectionModel(TreeSelectionModel)</code> through queue*/
2525: public void setSelectionModel(
2526: final TreeSelectionModel treeSelectionModel) {
2527: runMapping(new MapVoidAction("setSelectionModel") {
2528: public void map() {
2529: ((JTree) getSource())
2530: .setSelectionModel(treeSelectionModel);
2531: }
2532: });
2533: }
2534:
2535: /**Maps <code>JTree.setSelectionPath(TreePath)</code> through queue*/
2536: public void setSelectionPath(final TreePath treePath) {
2537: runMapping(new MapVoidAction("setSelectionPath") {
2538: public void map() {
2539: ((JTree) getSource()).setSelectionPath(treePath);
2540: }
2541: });
2542: }
2543:
2544: /**Maps <code>JTree.setSelectionPaths(TreePath[])</code> through queue*/
2545: public void setSelectionPaths(final TreePath[] treePath) {
2546: runMapping(new MapVoidAction("setSelectionPaths") {
2547: public void map() {
2548: ((JTree) getSource()).setSelectionPaths(treePath);
2549: }
2550: });
2551: }
2552:
2553: /**Maps <code>JTree.setSelectionRow(int)</code> through queue*/
2554: public void setSelectionRow(final int i) {
2555: runMapping(new MapVoidAction("setSelectionRow") {
2556: public void map() {
2557: ((JTree) getSource()).setSelectionRow(i);
2558: }
2559: });
2560: }
2561:
2562: /**Maps <code>JTree.setSelectionRows(int[])</code> through queue*/
2563: public void setSelectionRows(final int[] i) {
2564: runMapping(new MapVoidAction("setSelectionRows") {
2565: public void map() {
2566: ((JTree) getSource()).setSelectionRows(i);
2567: }
2568: });
2569: }
2570:
2571: /**Maps <code>JTree.setShowsRootHandles(boolean)</code> through queue*/
2572: public void setShowsRootHandles(final boolean b) {
2573: runMapping(new MapVoidAction("setShowsRootHandles") {
2574: public void map() {
2575: ((JTree) getSource()).setShowsRootHandles(b);
2576: }
2577: });
2578: }
2579:
2580: /**Maps <code>JTree.setUI(TreeUI)</code> through queue*/
2581: public void setUI(final TreeUI treeUI) {
2582: runMapping(new MapVoidAction("setUI") {
2583: public void map() {
2584: ((JTree) getSource()).setUI(treeUI);
2585: }
2586: });
2587: }
2588:
2589: /**Maps <code>JTree.setVisibleRowCount(int)</code> through queue*/
2590: public void setVisibleRowCount(final int i) {
2591: runMapping(new MapVoidAction("setVisibleRowCount") {
2592: public void map() {
2593: ((JTree) getSource()).setVisibleRowCount(i);
2594: }
2595: });
2596: }
2597:
2598: /**Maps <code>JTree.startEditingAtPath(TreePath)</code> through queue*/
2599: public void startEditingAtPath(final TreePath treePath) {
2600: runMapping(new MapVoidAction("startEditingAtPath") {
2601: public void map() {
2602: ((JTree) getSource()).startEditingAtPath(treePath);
2603: }
2604: });
2605: }
2606:
2607: /**Maps <code>JTree.stopEditing()</code> through queue*/
2608: public boolean stopEditing() {
2609: return (runMapping(new MapBooleanAction("stopEditing") {
2610: public boolean map() {
2611: return (((JTree) getSource()).stopEditing());
2612: }
2613: }));
2614: }
2615:
2616: /**Maps <code>JTree.treeDidChange()</code> through queue*/
2617: public void treeDidChange() {
2618: runMapping(new MapVoidAction("treeDidChange") {
2619: public void map() {
2620: ((JTree) getSource()).treeDidChange();
2621: }
2622: });
2623: }
2624:
2625: //End of mapping //
2626: ////////////////////////////////////////////////////////
2627:
2628: /**
2629: * Iterface to choose tree row. Defines criteria to distinguish row.
2630: */
2631: public interface TreeRowChooser {
2632: /**
2633: * Should be true if row is good.
2634: * @param oper Operator used to search item.
2635: * @param row Row be checked.
2636: * @return true if the row fits the criteria
2637: */
2638: public boolean checkRow(JTreeOperator oper, int row);
2639:
2640: /**
2641: * Row description.
2642: * @return a criteria description.
2643: */
2644: public String getDescription();
2645: }
2646:
2647: private TreePath findPathPrimitive(TreePath path,
2648: TreePathChooser chooser, Waiter loadedWaiter) {
2649: if (!isExpanded(path)) {
2650: if (!isPathSelected(path)) {
2651: clickOnPath(path);
2652: }
2653: expandPath(path);
2654: }
2655: Object[] waitParam = { chooser, path };
2656: Object[] waitResult = null;
2657: try {
2658: waitResult = (Object[]) loadedWaiter.waitAction(waitParam);
2659: } catch (InterruptedException e) {
2660: output.printStackTrace(e);
2661: return (null);
2662: }
2663: TreePath nextPath = (TreePath) waitResult[0];
2664: boolean found = ((Boolean) waitResult[1]).booleanValue();
2665: if (found) {
2666: return (nextPath);
2667: } else {
2668: return (findPathPrimitive(nextPath, chooser, loadedWaiter));
2669: }
2670: }
2671:
2672: private String[] addChildrenToDump(Hashtable table, String title,
2673: Object node, TreePath path) {
2674: if (((JTree) getSource()).isExpanded(path)) {
2675: Object[] subNodes = getChildren(node);
2676: String[] names = addToDump(table, title, subNodes);
2677: for (int i = 0; i < subNodes.length; i++) {
2678: addChildrenToDump(table, names[i], subNodes[i], path
2679: .pathByAddingChild(subNodes[i]));
2680: }
2681: return (names);
2682: } else {
2683: return (new String[0]);
2684: }
2685: }
2686:
2687: private static String pathToString(String[] path) {
2688: String desc = "";
2689: for (int i = 0; i < path.length; i++) {
2690: desc = desc + path[i] + ", ";
2691: }
2692: if (desc.length() > 0) {
2693: desc = desc.substring(0, desc.length() - 2);
2694: }
2695: return ("[ " + desc + " ]");
2696: }
2697:
2698: /**
2699: * Can be throught during item selecting if list does not have
2700: * item requested.
2701: */
2702: public class NoSuchPathException extends JemmyInputException {
2703: /**
2704: * Constructor.
2705: */
2706: public NoSuchPathException() {
2707: super ("Unknown/null/invalid tree path.", null);
2708: }
2709:
2710: /**
2711: * Constructor.
2712: * @param path a nonexistent path.
2713: */
2714: public NoSuchPathException(String[] path) {
2715: super ("No such path as \"" + pathToString(path) + "\"",
2716: getSource());
2717: }
2718:
2719: /**
2720: * Constructor.
2721: * @param index a nonexistent line index.
2722: */
2723: public NoSuchPathException(int index) {
2724: super ("Tree does not contain " + index + "'th line",
2725: getSource());
2726: }
2727:
2728: /**
2729: * Constructor.
2730: * @param path a nonexistent path.
2731: */
2732: public NoSuchPathException(TreePath path) {
2733: super ("No such path as \"" + path.toString() + "\"",
2734: getSource());
2735: }
2736: }
2737:
2738: /**
2739: * Specifies criteria for path searching.
2740: */
2741: public interface TreePathChooser {
2742: /**
2743: * Checks if the path fits the criteria.
2744: * @param path TreePath to check.
2745: * @param indexInParent Index of the "path" in path's parent.
2746: * @return true if the path fits the criteria
2747: */
2748: public boolean checkPath(TreePath path, int indexInParent);
2749:
2750: /**
2751: * Checks if the path has another path as a parent.
2752: * @param path TreePath to check.
2753: * @param indexInParent Index of the "path" in path's parent.
2754: * @return true if path looked for is a child/grandchild of a path passed as a parameter.
2755: */
2756: public boolean hasAsParent(TreePath path, int indexInParent);
2757:
2758: /**
2759: * Returns the description.
2760: * @return a description.
2761: */
2762: public String getDescription();
2763: }
2764:
2765: /**
2766: * Specifies searching criteria basing on nodes' text.
2767: */
2768: class StringArrayPathChooser implements TreePathChooser {
2769: String[] arr;
2770: int[] indices;
2771: StringComparator comparator;
2772:
2773: /**
2774: * Constructs StringArrayPathChooser.
2775: * @param arr a node text array. First element defines a text of a first node
2776: * under a tree root, second element - a children of the first node, ...
2777: * @param indices indexes of nodes in nodes' parents.
2778: * @param comparator String comparision criteria.
2779: */
2780: StringArrayPathChooser(String[] arr, int[] indices,
2781: StringComparator comparator) {
2782: this .arr = arr;
2783: this .comparator = comparator;
2784: this .indices = indices;
2785: }
2786:
2787: public boolean checkPath(TreePath path, int indexInParent) {
2788: return (path.getPathCount() - 1 == arr.length && hasAsParent(
2789: path, indexInParent));
2790: }
2791:
2792: public boolean hasAsParent(TreePath path, int indexInParent) {
2793: Object[] comps = path.getPath();
2794: Object node;
2795: for (int i = 1; i < comps.length; i++) {
2796: if (arr.length < path.getPathCount() - 1) {
2797: return (false);
2798: }
2799: /*
2800: if(!comparator.equals(comps[i].toString(), arr[i - 1])) {
2801: return(false);
2802: }
2803: */
2804: if (indices.length >= path.getPathCount() - 1) {
2805: node = chooseSubnode(comps[i - 1], arr[i - 1],
2806: indices[i - 1], comparator);
2807: } else {
2808: node = chooseSubnode(comps[i - 1], arr[i - 1],
2809: comparator);
2810: }
2811: if (node != comps[i]) {
2812: return (false);
2813: }
2814: }
2815: return (true);
2816: }
2817:
2818: public String getDescription() {
2819: return (pathToString(arr));
2820: }
2821: }
2822:
2823: private class BySubStringTreeRowChooser implements TreeRowChooser {
2824: String subString;
2825: StringComparator comparator;
2826:
2827: public BySubStringTreeRowChooser(String subString,
2828: StringComparator comparator) {
2829: this .subString = subString;
2830: this .comparator = comparator;
2831: }
2832:
2833: public boolean checkRow(JTreeOperator oper, int row) {
2834: return (comparator.equals(oper.getPathForRow(row)
2835: .getLastPathComponent().toString(), subString));
2836: }
2837:
2838: public String getDescription() {
2839: return ("Row containing \"" + subString + "\" string");
2840: }
2841: }
2842:
2843: private class ByRenderedComponentTreeRowChooser implements
2844: TreeRowChooser {
2845: ComponentChooser chooser;
2846:
2847: public ByRenderedComponentTreeRowChooser(
2848: ComponentChooser chooser) {
2849: this .chooser = chooser;
2850: }
2851:
2852: public boolean checkRow(JTreeOperator oper, int row) {
2853: return (chooser.checkComponent(oper
2854: .getRenderedComponent(oper.getPathForRow(row))));
2855: }
2856:
2857: public String getDescription() {
2858: return (chooser.getDescription());
2859: }
2860: }
2861:
2862: /**
2863: * Checks component type.
2864: */
2865: public static class JTreeFinder extends Finder {
2866: /**
2867: * Constructs JTreeFinder.
2868: * @param sf other searching criteria.
2869: */
2870: public JTreeFinder(ComponentChooser sf) {
2871: super (JTree.class, sf);
2872: }
2873:
2874: /**
2875: * Constructs JTreeFinder.
2876: */
2877: public JTreeFinder() {
2878: super (JTree.class);
2879: }
2880: }
2881:
2882: /**
2883: * Allows to find component by node text.
2884: */
2885: public static class JTreeByItemFinder implements ComponentChooser {
2886: String label;
2887: int rowIndex;
2888: StringComparator comparator;
2889:
2890: /**
2891: * Constructs JTreeByItemFinder.
2892: * @param lb a text pattern
2893: * @param ii row index to check. If equal to -1, selected row is checked.
2894: * @param comparator specifies string comparision algorithm.
2895: */
2896: public JTreeByItemFinder(String lb, int ii,
2897: StringComparator comparator) {
2898: label = lb;
2899: rowIndex = ii;
2900: this .comparator = comparator;
2901: }
2902:
2903: /**
2904: * Constructs JTreeByItemFinder.
2905: * @param lb a text pattern
2906: * @param ii row index to check. If equal to -1, selected row is checked.
2907: */
2908: public JTreeByItemFinder(String lb, int ii) {
2909: this (lb, ii, Operator.getDefaultStringComparator());
2910: }
2911:
2912: public boolean checkComponent(Component comp) {
2913: if (comp instanceof JTree) {
2914: if (label == null) {
2915: return (true);
2916: }
2917: if (((JTree) comp).getRowCount() > rowIndex) {
2918: int ii = rowIndex;
2919: if (ii == -1) {
2920: int[] rows = ((JTree) comp).getSelectionRows();
2921: if (rows != null && rows.length > 0) {
2922: ii = rows[0];
2923: } else {
2924: return (false);
2925: }
2926: }
2927: TreePath path = ((JTree) comp).getPathForRow(ii);
2928: if (path != null) {
2929: return (comparator.equals(path
2930: .getPathComponent(
2931: path.getPathCount() - 1)
2932: .toString(), label));
2933: }
2934: }
2935: }
2936: return (false);
2937: }
2938:
2939: public String getDescription() {
2940: return ("JTree with text \"" + label + "\" in "
2941: + (new Integer(rowIndex)).toString() + "'th row");
2942: }
2943: }
2944: }
|