swtbot: Add SWTBotTimeGraph and update SWTBotSash
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / shared / org / eclipse / tracecompass / tmf / ui / swtbot / tests / shared / SWTBotSash.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.swt.graphics.Rectangle;
18 import org.eclipse.swt.widgets.Event;
19 import org.eclipse.swt.widgets.Sash;
20 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
21 import org.eclipse.swtbot.swt.finder.results.Result;
22 import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
23
24 /**
25 * SWTBot class representing a Sash
26 */
27 public class SWTBotSash extends AbstractSWTBotControl<Sash> {
28
29 /**
30 * The widget wrapper
31 *
32 * @param w
33 * the sash
34 * @throws WidgetNotFoundException
35 * if there is no widget
36 */
37 public SWTBotSash(Sash w) throws WidgetNotFoundException {
38 super(w);
39 }
40
41 /**
42 * Get the bounds of the sash
43 *
44 * @return the bounds relative to the parent
45 */
46 public Rectangle getBounds() {
47 return syncExec(new Result<Rectangle>() {
48 @Override
49 public Rectangle run() {
50 return widget.getBounds();
51 }
52 });
53 }
54
55 /**
56 * Drag the sash from its middle point to the destination point
57 *
58 * @param dst
59 * the destination point relative to the parent
60 */
61 public void drag(final Point dst) {
62 Rectangle bounds = getBounds();
63 int x = bounds.width / 2;
64 int y = bounds.height / 2;
65 notify(SWT.MouseEnter);
66 notify(SWT.Activate);
67 notify(SWT.Selection, createSelectionEvent(bounds.x + x, bounds.y + y, SWT.NONE));
68 notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
69 notify(SWT.DragDetect, createMouseEvent(x, y, 0, SWT.NONE, 0));
70 notify(SWT.Move);
71 notify(SWT.Selection, createSelectionEvent(dst.x, dst.y, SWT.NONE));
72 notify(SWT.MouseMove, createMouseEvent(x, y, 0, SWT.BUTTON1, 0));
73 notify(SWT.Selection, createSelectionEvent(dst.x, dst.y, SWT.BUTTON1));
74 notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.NONE, 1));
75 notify(SWT.MouseExit);
76 }
77
78 private Event createSelectionEvent(int x, int y, int stateMask) {
79 return syncExec(new Result<Event>() {
80 @Override
81 public Event run() {
82 boolean vertical = (widget.getStyle() | SWT.VERTICAL) != 0;
83 Point size = widget.getSize();
84 Event event = createSelectionEvent(stateMask);
85 event.x = vertical ? x : 0;
86 event.y = vertical ? 0 : y;
87 event.width = size.x;
88 event.height = size.y;
89 return event;
90 }
91 });
92 }
93 }
This page took 0.040051 seconds and 6 git commands to generate.