001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.trees;
048:
049: import java.awt.event.KeyEvent;
050:
051: import javax.swing.text.JTextComponent;
052:
053: import javax.swing.tree.TreePath;
054:
055: import org.netbeans.jemmy.Timeout;
056:
057: import org.netbeans.jemmy.drivers.DriverManager;
058: import org.netbeans.jemmy.drivers.LightSupportiveDriver;
059: import org.netbeans.jemmy.drivers.TextDriver;
060: import org.netbeans.jemmy.drivers.TreeDriver;
061:
062: import org.netbeans.jemmy.operators.ComponentOperator;
063: import org.netbeans.jemmy.operators.JTextComponentOperator;
064: import org.netbeans.jemmy.operators.JTreeOperator;
065:
066: /**
067: * TreeDriver for javax.swing.JTree component type.
068: * Uses API calls.
069: *
070: * @author Alexandre Iline(alexandre.iline@sun.com)
071: */
072: public class JTreeAPIDriver extends LightSupportiveDriver implements
073: TreeDriver {
074: /**
075: * Constructs a JTreeAPIDriver.
076: */
077: public JTreeAPIDriver() {
078: super (
079: new String[] { "org.netbeans.jemmy.operators.JTreeOperator" });
080: }
081:
082: public void selectItem(ComponentOperator oper, int index) {
083: selectItems(oper, new int[] { index });
084: }
085:
086: public void selectItems(ComponentOperator oper, int[] indices) {
087: checkSupported(oper);
088: ((JTreeOperator) oper).clearSelection();
089: ((JTreeOperator) oper).addSelectionRows(indices);
090: }
091:
092: public void expandItem(ComponentOperator oper, int index) {
093: checkSupported(oper);
094: ((JTreeOperator) oper).expandRow(index);
095: }
096:
097: public void collapseItem(ComponentOperator oper, int index) {
098: checkSupported(oper);
099: ((JTreeOperator) oper).collapseRow(index);
100: }
101:
102: public void editItem(ComponentOperator oper, int index,
103: Object newValue, Timeout waitEditorTime) {
104: JTextComponentOperator textoper = startEditingAndReturnEditor(
105: oper, index, waitEditorTime);
106: TextDriver text = DriverManager
107: .getTextDriver(JTextComponentOperator.class);
108: text.clearText(textoper);
109: text.typeText(textoper, newValue.toString(), 0);
110: ((JTreeOperator) oper).stopEditing();
111: }
112:
113: public void startEditing(ComponentOperator oper, int index,
114: Timeout waitEditorTime) {
115: startEditing(oper, index, waitEditorTime);
116: }
117:
118: private JTextComponentOperator startEditingAndReturnEditor(
119: ComponentOperator oper, int index, Timeout waitEditorTime) {
120: checkSupported(oper);
121: JTreeOperator toper = (JTreeOperator) oper;
122: toper.startEditingAtPath(toper.getPathForRow(index));
123: toper.getTimeouts().setTimeout(
124: "ComponentOperator.WaitComponentTimeout",
125: waitEditorTime.getValue());
126: return (new JTextComponentOperator(
127: (JTextComponent) toper
128: .waitSubComponent(new JTextComponentOperator.JTextComponentFinder())));
129: }
130: }
|