001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.test.xslt.lib;
021:
022: import java.awt.Point;
023: import java.awt.Rectangle;
024: import java.awt.event.InputEvent;
025: import java.awt.event.KeyEvent;
026: import org.netbeans.jellytools.MainWindowOperator;
027: import org.netbeans.jemmy.Timeout;
028: import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
029: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
030: import org.netbeans.jemmy.operators.JComponentOperator;
031: import org.netbeans.jemmy.operators.JToggleButtonOperator;
032:
033: /**
034: *
035: * @author ca@netbeans.org
036: */
037:
038: public class XSLTEditorOperator {
039: private SourceTreeOperator m_opSourceTree;
040: private TargetTreeOperator m_opTargetTree;
041: private CanvasOperator m_opCanvas;
042: private PaletteOperator m_opPalette;
043:
044: private JToggleButtonOperator m_opDesignButton;
045: private JToggleButtonOperator m_opSourceButton;
046:
047: private JComponentOperator m_opEditor;
048: private MouseRobotDriver m_mouseDriver;
049: private KeyRobotDriver m_keyDriver;
050:
051: /**
052: * Creates a new instance of XSLTEditorOperator
053: */
054: public XSLTEditorOperator(String strEditorName) {
055: JComponentOperator opComponent = Helpers
056: .getComponentOperator(
057: MainWindowOperator.getDefault(),
058: "org.netbeans.core.multiview.MultiViewCloneableTopComponent",
059: strEditorName);
060:
061: m_opEditor = Helpers.getComponentOperator(opComponent,
062: "org.netbeans.modules.xslt.mapper.view.XsltMapper");
063:
064: m_opCanvas = new CanvasOperator(m_opEditor);
065: m_opSourceTree = new SourceTreeOperator(m_opEditor);
066: m_opTargetTree = new TargetTreeOperator(m_opEditor);
067: m_opPalette = new PaletteOperator();
068:
069: JComponentOperator opToolbar = Helpers.getComponentOperator(
070: opComponent, "javax.swing.JToolBar");
071:
072: m_opDesignButton = new JToggleButtonOperator(opToolbar,
073: "Design");
074: m_opSourceButton = new JToggleButtonOperator(opToolbar,
075: "Source");
076:
077: m_mouseDriver = new MouseRobotDriver(new Timeout("", 500));
078: m_keyDriver = new KeyRobotDriver(new Timeout("", 50));
079: }
080:
081: public CanvasOperator getCanvasOperator() {
082: return m_opCanvas;
083: }
084:
085: public void bindSourceToTarget(String sourceTreePath,
086: String targetTreePath) {
087: Point startPoint = m_opSourceTree
088: .prepareNodeForClick(sourceTreePath);
089: Point endPoint = m_opTargetTree
090: .prepareNodeForClick(targetTreePath);
091:
092: performDragAndDrop(m_opSourceTree, startPoint, m_opTargetTree,
093: endPoint);
094: }
095:
096: public void bindSourceToMethoid(String sourceTreePath,
097: String strMethoidTitle, int methoidIndex,
098: int methiodPortIndex) {
099: Point startPoint = m_opSourceTree
100: .prepareNodeForClick(sourceTreePath);
101:
102: MethoidOperator opMethoid = m_opCanvas.findMethoid(
103: strMethoidTitle, methoidIndex);
104: Point endPoint = opMethoid.getPortPoint(methiodPortIndex);
105:
106: performDragAndDrop(m_opSourceTree, startPoint, m_opCanvas,
107: endPoint);
108: }
109:
110: public void bindMethoidToTarget(String strMethoidTitle,
111: int methoidIndex, String targetTreePath) {
112: MethoidOperator opMethoid = m_opCanvas.findMethoid(
113: strMethoidTitle, methoidIndex);
114: Point startPoint = opMethoid.getPortPoint(opMethoid
115: .getPortCount() - 1);
116:
117: Point endPoint = m_opTargetTree
118: .prepareNodeForClick(targetTreePath);
119:
120: performDragAndDrop(m_opCanvas, startPoint, m_opTargetTree,
121: endPoint);
122: }
123:
124: public void bindMethoidToMethiod(String strSrcMethoidTitle,
125: int srcMethoidIndex, int srcMethiodPortIndex,
126: String strDstMethoidTitle, int dstMethoidIndex,
127: int dstMethiodPortIndex) {
128: MethoidOperator opSrcMethoid = m_opCanvas.findMethoid(
129: strSrcMethoidTitle, srcMethoidIndex);
130: Point startPoint = opSrcMethoid
131: .getPortPoint(srcMethiodPortIndex);
132:
133: MethoidOperator opDstMethoid = m_opCanvas.findMethoid(
134: strDstMethoidTitle, dstMethoidIndex);
135: Point endPoint = opDstMethoid.getPortPoint(dstMethiodPortIndex);
136:
137: performDragAndDrop(m_opCanvas, startPoint, m_opCanvas, endPoint);
138: }
139:
140: public void dropPaletteItemOnCanvas(PaletteOperator.Groups group,
141: String strItem, Point canvasPoint) {
142: Point palettePoint = m_opPalette.prepareNodeForClick(group,
143: strItem);
144:
145: performDragAndDrop(m_opPalette, palettePoint, m_opCanvas,
146: canvasPoint);
147: Helpers.waitNoEvent();
148: }
149:
150: public void removeMethoid(String strTitle, int index) {
151: MethoidOperator opMethoid = m_opCanvas.findMethoid(strTitle,
152: index);
153: Rectangle rect = opMethoid.getBoundings();
154: Point clickPoint = new Point(rect.x + 1, rect.y + 1);
155: m_mouseDriver.clickMouse(m_opCanvas, clickPoint.x,
156: clickPoint.y, 1, InputEvent.BUTTON1_MASK, 0,
157: new Timeout("t1", 50));
158:
159: m_keyDriver.pushKey(m_opCanvas, KeyEvent.VK_DELETE, 0,
160: new Timeout("t1", 50));
161: Helpers.waitNoEvent();
162: }
163:
164: private void performDragAndDrop(JComponentOperator opFrom,
165: Point pointFrom, JComponentOperator opTo, Point pointTo) {
166:
167: // Doesn't work on Solaris
168: // Point p1 = Helpers.getContainerPoint(opFrom, pointFrom, m_opEditor);
169: // Point p2 = Helpers.getContainerPoint(opTo, pointTo, m_opEditor);
170: // m_mouseDriver.dragNDrop(m_opEditor, p1.x, p1.y, p2.x, p2.y, InputEvent.BUTTON1_MASK, 0, new Timeout("t1", 50), new Timeout("t2", 50));
171:
172: m_mouseDriver.moveMouse(opFrom, pointFrom.x, pointFrom.y);
173: m_mouseDriver.pressMouse(InputEvent.BUTTON1_MASK, 0);
174: m_mouseDriver.enterMouse(opTo);
175: m_mouseDriver.dragMouse(opTo, pointTo.x, pointTo.y,
176: InputEvent.BUTTON1_MASK, 0);
177: m_mouseDriver.releaseMouse(InputEvent.BUTTON1_MASK, 0);
178: }
179:
180: public void switchToDesign() {
181: m_opDesignButton.push();
182: Helpers.waitNoEvent();
183: }
184:
185: public void switchToSource() {
186: m_opSourceButton.push();
187: Helpers.waitNoEvent();
188: }
189:
190: public void removeAllTargetNodes(String strRoot) {
191: m_opTargetTree.ivokeDeleteOnPath(strRoot);
192: }
193: }
|