Commit | Line | Data |
---|---|---|
ff93f0e2 | 1 | /******************************************************************************* |
2d594808 | 2 | * Copyright (c) 2015, 2016 Ericsson |
ff93f0e2 MK |
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 | ||
2d594808 | 15 | import org.eclipse.swt.SWT; |
ff93f0e2 | 16 | import org.eclipse.swt.graphics.Point; |
2d594808 PT |
17 | import org.eclipse.swt.graphics.Rectangle; |
18 | import org.eclipse.swt.widgets.Event; | |
ff93f0e2 MK |
19 | import org.eclipse.swt.widgets.Sash; |
20 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | |
ff93f0e2 | 21 | import org.eclipse.swtbot.swt.finder.results.Result; |
ff93f0e2 | 22 | import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl; |
ff93f0e2 MK |
23 | |
24 | /** | |
2d594808 | 25 | * SWTBot class representing a Sash |
ff93f0e2 MK |
26 | */ |
27 | public class SWTBotSash extends AbstractSWTBotControl<Sash> { | |
28 | ||
29 | /** | |
30 | * The widget wrapper | |
31 | * | |
32 | * @param w | |
33 | * the sash | |
ff93f0e2 MK |
34 | * @throws WidgetNotFoundException |
35 | * if there is no widget | |
36 | */ | |
2d594808 PT |
37 | public SWTBotSash(Sash w) throws WidgetNotFoundException { |
38 | super(w); | |
ff93f0e2 MK |
39 | } |
40 | ||
41 | /** | |
2d594808 | 42 | * Get the bounds of the sash |
ff93f0e2 | 43 | * |
2d594808 | 44 | * @return the bounds relative to the parent |
ff93f0e2 | 45 | */ |
2d594808 PT |
46 | public Rectangle getBounds() { |
47 | return syncExec(new Result<Rectangle>() { | |
ff93f0e2 | 48 | @Override |
2d594808 PT |
49 | public Rectangle run() { |
50 | return widget.getBounds(); | |
ff93f0e2 | 51 | } |
ff93f0e2 MK |
52 | }); |
53 | } | |
54 | ||
55 | /** | |
2d594808 | 56 | * Drag the sash from its middle point to the destination point |
ff93f0e2 MK |
57 | * |
58 | * @param dst | |
2d594808 | 59 | * the destination point relative to the parent |
ff93f0e2 MK |
60 | */ |
61 | public void drag(final Point dst) { | |
2d594808 PT |
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 | } | |
ff93f0e2 | 77 | |
2d594808 PT |
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; | |
ff93f0e2 | 90 | } |
2d594808 | 91 | }); |
ff93f0e2 | 92 | } |
ff93f0e2 | 93 | } |