1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.graphics
.Rectangle
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Event
;
23 import org
.eclipse
.swt
.widgets
.Menu
;
24 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
25 import org
.eclipse
.swtbot
.swt
.finder
.exceptions
.WidgetNotFoundException
;
26 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
27 import org
.eclipse
.swtbot
.swt
.finder
.results
.ArrayResult
;
28 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
29 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
30 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
31 import org
.eclipse
.swtbot
.swt
.finder
.waits
.WaitForObjectCondition
;
32 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.AbstractSWTBotControl
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRootMenu
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
35 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
38 * SWTBot class representing a time graph entry
40 public class SWTBotTimeGraphEntry
extends AbstractSWTBotControl
<TimeGraphControl
> {
42 private final ITimeGraphEntry fEntry
;
48 * @param entry the time graph entry
50 * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
52 public SWTBotTimeGraphEntry(TimeGraphControl w
, ITimeGraphEntry entry
) throws WidgetNotFoundException
{
59 protected SWTBotRootMenu
contextMenu(final Control control
) throws WidgetNotFoundException
{
60 UIThreadRunnable
.syncExec(new VoidResult() {
63 Rectangle bounds
= widget
.getItemBounds(fEntry
);
67 final Event event
= new Event();
68 event
.time
= (int) System
.currentTimeMillis();
69 event
.display
= control
.getDisplay();
70 event
.widget
= control
;
71 event
.x
= bounds
.x
+ widget
.getTimeDataProvider().getNameSpace() / 2;
72 event
.y
= bounds
.y
+ bounds
.height
/ 2;
73 control
.notifyListeners(SWT
.MenuDetect
, event
);
77 WaitForObjectCondition
<Menu
> waitForMenu
= Conditions
.waitForPopupMenu(control
);
78 new SWTBot().waitUntilWidgetAppears(waitForMenu
);
79 return new SWTBotRootMenu(waitForMenu
.get(0));
83 * Get the child entries of this entry
85 * @return the array of child entries
87 public SWTBotTimeGraphEntry
[] getEntries() {
88 return syncExec(new ArrayResult
<SWTBotTimeGraphEntry
>() {
90 public SWTBotTimeGraphEntry
[] run() {
91 List
<SWTBotTimeGraphEntry
> entries
= new ArrayList
<>();
92 for (ITimeGraphEntry entry
: widget
.getExpandedElements()) {
93 if (fEntry
.equals(entry
.getParent())) {
94 entries
.add(new SWTBotTimeGraphEntry(widget
, entry
));
97 return entries
.toArray(new SWTBotTimeGraphEntry
[0]);
103 * Get the child entry of this entry with the given name
106 * the name of the entry
108 * @return the child entry
110 public SWTBotTimeGraphEntry
getEntry(String name
) {
111 return syncExec(new Result
<SWTBotTimeGraphEntry
>() {
113 public SWTBotTimeGraphEntry
run() {
114 ITableLabelProvider labelProvider
= widget
.getLabelProvider();
115 for (ITimeGraphEntry entry
: widget
.getExpandedElements()) {
116 if (fEntry
.equals(entry
.getParent())) {
117 String label
= labelProvider
== null ? entry
.getName() : labelProvider
.getColumnText(entry
, 0);
118 if (name
.equals(label
)) {
119 return new SWTBotTimeGraphEntry(widget
, entry
);
123 throw new WidgetNotFoundException("Timed out waiting for time graph entry " + name
); //$NON-NLS-1$
129 * Get the text of this entry
134 public String
getText() {
139 * Get the text of this entry for the given column index
143 * @return the column text
145 public String
getText(int column
) {
146 ITableLabelProvider labelProvider
= widget
.getLabelProvider();
147 return labelProvider
!= null ? labelProvider
.getColumnText(fEntry
, column
) : column
== 0 ? fEntry
.getName() : "";
151 * Select this time graph entry
155 public SWTBotTimeGraphEntry
select() {
156 syncExec(new VoidResult() {
160 widget
.selectItem(fEntry
, true);