Skip to main content
summaryrefslogtreecommitdiffstats
blob: acf84bde8d4e42be1da0a9aa32a7275db16d1e9c (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
/*******************************************************************************
 * Copyright (c) 2010 SAP AG, Walldorf.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     SAP AG - initial API and implementation
 *******************************************************************************/
package org.eclipse.platform.discovery.testutils.utils.abbot.matchers;

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Widget;

import abbot.swt.finder.generic.Matcher;

public class ToolItemMatcher implements Matcher<Widget>
{
	private final Widget parent;
	private Display display;

	public ToolItemMatcher(final Widget parent, final Display testDisplay)
	{
		this.parent = parent;
		this.display = testDisplay;
	}

	private boolean belongsToParent(final ToolItem toolItem, final Widget parent)
	{
		final boolean result[] = new boolean[] { false };
		display.syncExec(new Runnable()
		{
			public void run()
			{
				Control parentControl = toolItem.getParent();
				while (parentControl != null)
				{
					if (parentControl == parent)
					{
						result[0] = true;
					}
					parentControl = parentControl.getParent();
				}
			}
		});

		return result[0];
	}

	public boolean matches(Widget w)
	{
		if(w instanceof ToolItem)
		{
			return belongsToParent((ToolItem) w, this.parent);
		}
		return false;
	}
}

Back to the top