Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8433dc2bc52f94849e947c6ad2b6e6180dbe290e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
 * Copyright (c) 2016, 2018 Red Hat.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/

package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.junit.Assert;
import org.junit.rules.ExternalResource;

/**
 *
 */
public class SWTBotViewRule extends ExternalResource {

	private final SWTWorkbenchBot bot = new SWTWorkbenchBot();

	private final String viewId;

	private SWTBotView botView = null;

	private IViewPart view = null;

	public SWTBotViewRule(final String viewId) {
		this.viewId = viewId;
	}

	@Override
	protected void before() {
		SWTUtils.asyncExec(() -> {
			try {
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(this.viewId);
			} catch (Exception e) {
				e.printStackTrace();
				Assert.fail("Failed to open view with id '" + this.viewId + "': " + e.getMessage());
			}
		});
		this.botView = this.bot.viewById(this.viewId);
		this.botView.show();
		this.view = this.botView.getViewReference().getView(true);
	}

	public SWTBotView bot() {
		return this.botView;
	}

	@SuppressWarnings("unchecked")
	public <T> T view() {
		return (T) view;
	}

	public void close() {
		this.botView.close();
	}
}

Back to the top