1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assert
.fail
;
19 import java
.util
.List
;
20 import java
.util
.TimeZone
;
22 import org
.eclipse
.core
.resources
.IFolder
;
23 import org
.eclipse
.core
.resources
.IProject
;
24 import org
.eclipse
.core
.resources
.IResource
;
25 import org
.eclipse
.core
.resources
.IResourceVisitor
;
26 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
27 import org
.eclipse
.core
.runtime
.CoreException
;
28 import org
.eclipse
.core
.runtime
.IPath
;
29 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
30 import org
.eclipse
.core
.runtime
.jobs
.Job
;
31 import org
.eclipse
.jdt
.annotation
.NonNull
;
32 import org
.eclipse
.jface
.bindings
.keys
.IKeyLookup
;
33 import org
.eclipse
.jface
.bindings
.keys
.KeyStroke
;
34 import org
.eclipse
.jface
.bindings
.keys
.ParseException
;
35 import org
.eclipse
.swt
.graphics
.Point
;
36 import org
.eclipse
.swt
.graphics
.Rectangle
;
37 import org
.eclipse
.swt
.widgets
.Display
;
38 import org
.eclipse
.swt
.widgets
.Shell
;
39 import org
.eclipse
.swt
.widgets
.Table
;
40 import org
.eclipse
.swt
.widgets
.TableItem
;
41 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
42 import org
.eclipse
.swtbot
.eclipse
.finder
.matchers
.WidgetMatcherFactory
;
43 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
44 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
45 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
46 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
47 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
48 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
49 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTUtils
;
50 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
51 import org
.eclipse
.swtbot
.swt
.finder
.waits
.DefaultCondition
;
52 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
53 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCheckBox
;
54 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotMenu
;
55 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
56 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
57 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
58 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
59 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.TimeoutException
;
60 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.operations
.NewExperimentOperation
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentElement
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTracesFolder
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
.ProjectElementHasChild
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TracingPerspectiveFactory
;
72 import org
.eclipse
.ui
.IEditorPart
;
73 import org
.eclipse
.ui
.IEditorReference
;
74 import org
.eclipse
.ui
.IPageLayout
;
75 import org
.eclipse
.ui
.PartInitException
;
76 import org
.eclipse
.ui
.PlatformUI
;
77 import org
.eclipse
.ui
.WorkbenchException
;
78 import org
.hamcrest
.Matcher
;
81 * SWTBot Helper functions
83 * @author Matthew Khouzam
85 @SuppressWarnings("restriction")
86 public final class SWTBotUtils
{
88 private static final String WINDOW_MENU
= "Window";
89 private static final String PREFERENCES_MENU_ITEM
= "Preferences";
90 private static boolean fPrintedEnvironment
= false;
92 private SWTBotUtils() {
95 private static final String TRACING_PERSPECTIVE_ID
= TracingPerspectiveFactory
.ID
;
98 * Waits for all Eclipse jobs to finish
100 public static void waitForJobs() {
101 while (!Job
.getJobManager().isIdle()) {
107 * Sleeps current thread for a given time.
109 * @param waitTimeMillis
110 * time in milliseconds to wait
112 public static void delay(final long waitTimeMillis
) {
114 Thread
.sleep(waitTimeMillis
);
115 } catch (final InterruptedException e
) {
121 * Create a tracing project
124 * the name of the tracing project
126 public static void createProject(final String projectName
) {
130 UIThreadRunnable
.syncExec(new VoidResult() {
133 IProject project
= TmfProjectRegistry
.createProject(projectName
, null, new NullProgressMonitor());
134 assertNotNull(project
);
138 SWTBotUtils
.waitForJobs();
145 * the name of the tracing project
146 * @param deleteResources
147 * whether or not to deleted resources under the project
151 public static void deleteProject(final String projectName
, boolean deleteResources
, SWTWorkbenchBot bot
) {
152 // Wait for any analysis to complete because it might create
153 // supplementary files
154 SWTBotUtils
.waitForJobs();
156 ResourcesPlugin
.getWorkspace().getRoot().getProject(projectName
).refreshLocal(IResource
.DEPTH_INFINITE
, null);
157 } catch (CoreException e
) {
160 SWTBotUtils
.waitForJobs();
162 final SWTBotView projectViewBot
= bot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
163 projectViewBot
.setFocus();
165 SWTBotTree treeBot
= projectViewBot
.bot().tree();
166 SWTBotTreeItem treeItem
= treeBot
.getTreeItem(projectName
);
167 SWTBotMenu contextMenu
= treeItem
.contextMenu("Delete");
170 if (deleteResources
) {
171 bot
.shell("Delete Resources").setFocus();
172 final SWTBotCheckBox checkBox
= bot
.checkBox();
173 bot
.waitUntil(Conditions
.widgetIsEnabled(checkBox
));
177 final SWTBotButton okButton
= bot
.button("OK");
178 bot
.waitUntil(Conditions
.widgetIsEnabled(okButton
));
181 SWTBotUtils
.waitForJobs();
185 * Deletes a project and its resources
188 * the name of the tracing project
192 public static void deleteProject(String projectName
, SWTWorkbenchBot bot
) {
193 deleteProject(projectName
, true, bot
);
197 * Creates an experiment
200 * a given workbench bot
202 * the name of the project, creates the project if needed
204 * the experiment name
206 public static void createExperiment(SWTWorkbenchBot bot
, String projectName
, final @NonNull String expName
) {
207 IProject project
= ResourcesPlugin
.getWorkspace().getRoot().getProject(projectName
);
208 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(project
, true);
209 TmfExperimentFolder expFolder
= tmfProject
.getExperimentsFolder();
210 assertNotNull(expFolder
);
211 NewExperimentOperation operation
= new NewExperimentOperation(expFolder
, expName
);
212 operation
.run(new NullProgressMonitor());
214 bot
.waitUntil(new DefaultCondition() {
216 public boolean test() throws Exception
{
217 TmfExperimentElement experiment
= expFolder
.getExperiment(expName
);
218 return experiment
!= null;
222 public String
getFailureMessage() {
223 return "Experiment (" + expName
+ ") couldn't be created";
230 * Focus on the main window
233 * swtbotshells for all the shells
235 public static void focusMainWindow(SWTBotShell
[] shellBots
) {
236 for (SWTBotShell shellBot
: shellBots
) {
237 if (shellBot
.getText().toLowerCase().contains("eclipse")) {
244 * Close a view with a title
247 * the title, like "welcome"
251 public static void closeView(String title
, SWTWorkbenchBot bot
) {
252 final List
<SWTBotView
> openViews
= bot
.views();
253 for (SWTBotView view
: openViews
) {
254 if (view
.getTitle().equalsIgnoreCase(title
)) {
256 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
262 * Close a view with an id
265 * the view id, like "org.eclipse.linuxtools.tmf.ui.views.histogram"
269 public static void closeViewById(String viewId
, SWTWorkbenchBot bot
) {
270 final SWTBotView view
= bot
.viewById(viewId
);
272 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
276 * Switch to the tracing perspective
278 public static void switchToTracingPerspective() {
279 switchToPerspective(TRACING_PERSPECTIVE_ID
);
283 * Switch to a given perspective
286 * the perspective id (like
287 * "org.eclipse.linuxtools.tmf.ui.perspective"
289 public static void switchToPerspective(final String id
) {
290 UIThreadRunnable
.syncExec(new VoidResult() {
294 PlatformUI
.getWorkbench().showPerspective(id
, PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
295 } catch (WorkbenchException e
) {
296 fail(e
.getMessage());
303 * Initialize the environment for SWTBot
305 public static void initialize() {
308 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
309 UIThreadRunnable
.syncExec(() -> {
312 // There seems to be problems on some system where the main shell is
313 // not in focus initially. This was seen using Xvfb and Xephyr on some occasions.
314 focusMainWindow(bot
.shells());
316 Shell shell
= bot
.activeShell().widget
;
318 // Only adjust shell if it appears to be the top-most
319 if (shell
.getParent() == null) {
320 makeShellFullyVisible(shell
);
325 private static void printEnvironment() {
326 if (fPrintedEnvironment
) {
330 // Print some information about the environment that could affect test outcome
331 Rectangle bounds
= Display
.getDefault().getBounds();
332 System
.out
.println("Display size: " + bounds
.width
+ "x" + bounds
.height
);
334 String osVersion
= System
.getProperty("os.version");
335 if (osVersion
!= null) {
336 System
.out
.println("OS version=" + osVersion
);
338 String gtkVersion
= System
.getProperty("org.eclipse.swt.internal.gtk.version");
339 if (gtkVersion
!= null) {
340 System
.out
.println("GTK version=" + gtkVersion
);
341 String overlayScrollbar
= System
.getenv("LIBOVERLAY_SCROLLBAR");
342 if (overlayScrollbar
!= null) {
343 System
.out
.println("LIBOVERLAY_SCROLLBAR=" + overlayScrollbar
);
345 String ubuntuMenuProxy
= System
.getenv("UBUNTU_MENUPROXY");
346 if (ubuntuMenuProxy
!= null) {
347 System
.out
.println("UBUNTU_MENUPROXY=" + ubuntuMenuProxy
);
351 System
.out
.println("Time zone: " + TimeZone
.getDefault().getDisplayName());
353 fPrintedEnvironment
= true;
357 * If the test is running in the UI thread then fail
359 private static void failIfUIThread() {
360 if (Display
.getCurrent() != null && Display
.getCurrent().getThread() == Thread
.currentThread()) {
361 fail("SWTBot test needs to run in a non-UI thread. Make sure that \"Run in UI thread\" is unchecked in your launch configuration or"
362 + " that useUIThread is set to false in the pom.xml");
367 * Try to make the shell fully visible in the display. If the shell cannot
368 * fit the display, it will be positioned so that top-left corner is at
369 * <code>(0, 0)</code> in display-relative coordinates.
372 * the shell to make fully visible
374 private static void makeShellFullyVisible(Shell shell
) {
375 Rectangle displayBounds
= shell
.getDisplay().getBounds();
376 Point absCoord
= shell
.toDisplay(0, 0);
377 Point shellSize
= shell
.getSize();
379 Point newLocation
= new Point(absCoord
.x
, absCoord
.y
);
380 newLocation
.x
= Math
.max(0, Math
.min(absCoord
.x
, displayBounds
.width
- shellSize
.x
));
381 newLocation
.y
= Math
.max(0, Math
.min(absCoord
.y
, displayBounds
.height
- shellSize
.y
));
382 if (!newLocation
.equals(absCoord
)) {
383 shell
.setLocation(newLocation
);
388 * Open a trace, this does not perform any validation though
393 * the path of the trace file (absolute or relative)
395 * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
397 public static void openTrace(final String projectName
, final String tracePath
, final String traceType
) {
398 openTrace(projectName
, tracePath
, traceType
, true);
402 * Open a trace, this does not perform any validation though
407 * the path of the trace file (absolute or relative)
409 * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
411 * delay and wait for jobs
413 public static void openTrace(final String projectName
, final String tracePath
, final String traceType
, boolean delay
) {
414 final Exception exception
[] = new Exception
[1];
416 UIThreadRunnable
.syncExec(new VoidResult() {
420 IProject project
= ResourcesPlugin
.getWorkspace().getRoot().getProject(projectName
);
421 TmfTraceFolder destinationFolder
= TmfProjectRegistry
.getProject(project
, true).getTracesFolder();
422 TmfOpenTraceHelper
.openTraceFromPath(destinationFolder
, tracePath
, PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), traceType
);
423 } catch (CoreException e
) {
428 if (exception
[0] != null) {
429 fail(exception
[0].getMessage());
439 * Finds an editor and sets focus to the editor
445 * @return the corresponding SWTBotEditor
447 public static SWTBotEditor
activateEditor(SWTWorkbenchBot bot
, String editorName
) {
448 Matcher
<IEditorReference
> matcher
= WidgetMatcherFactory
.withPartName(editorName
);
449 final SWTBotEditor editorBot
= bot
.editor(matcher
);
450 IEditorPart iep
= editorBot
.getReference().getEditor(true);
451 final TmfEventsEditor tmfEd
= (TmfEventsEditor
) iep
;
453 UIThreadRunnable
.syncExec(new VoidResult() {
460 SWTBotUtils
.waitForJobs();
461 SWTBotUtils
.delay(1000);
462 assertNotNull(tmfEd
);
467 * Opens a trace in an editor and get the TmfEventsEditor
472 * the name of the project that contains the trace
474 * the trace element path (relative to Traces folder)
475 * @return TmfEventsEditor the opened editor
477 public static TmfEventsEditor
openEditor(SWTWorkbenchBot bot
, String projectName
, IPath elementPath
) {
478 final SWTBotView projectExplorerView
= bot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
479 projectExplorerView
.setFocus();
480 SWTBot projectExplorerBot
= projectExplorerView
.bot();
482 final SWTBotTree tree
= projectExplorerBot
.tree();
483 projectExplorerBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(projectName
, tree
));
484 final SWTBotTreeItem treeItem
= tree
.getTreeItem(projectName
);
487 SWTBotTreeItem tracesNode
= getTraceProjectItem(projectExplorerBot
, treeItem
, TmfTracesFolder
.TRACES_FOLDER_NAME
);
490 SWTBotTreeItem currentItem
= tracesNode
;
491 for (String segment
: elementPath
.segments()) {
492 currentItem
= getTraceProjectItem(projectExplorerBot
, currentItem
, segment
);
493 currentItem
.select();
494 currentItem
.doubleClick();
497 SWTBotEditor editor
= bot
.editorByTitle(elementPath
.toString());
498 IEditorPart editorPart
= editor
.getReference().getEditor(false);
499 assertTrue(editorPart
instanceof TmfEventsEditor
);
500 return (TmfEventsEditor
) editorPart
;
504 * Returns the child tree item of the specified item with the given name.
505 * The project element label may have a count suffix in the format ' [n]'.
508 * a given workbench bot
510 * the parent tree item
512 * the desired child element name (without suffix)
513 * @return the a {@link SWTBotTreeItem} with the specified name
515 public static SWTBotTreeItem
getTraceProjectItem(SWTBot bot
, final SWTBotTreeItem parentItem
, final String name
) {
516 ProjectElementHasChild condition
= new ProjectElementHasChild(parentItem
, name
);
517 bot
.waitUntil(condition
);
518 return condition
.getItem();
522 * Select the traces folder
525 * a given workbench bot
527 * the name of the project (it needs to exist or else it would
529 * @return a {@link SWTBotTreeItem} of the "Traces" folder
531 public static SWTBotTreeItem
selectTracesFolder(SWTWorkbenchBot bot
, String projectName
) {
532 SWTBotTreeItem projectTreeItem
= selectProject(bot
, projectName
);
533 projectTreeItem
.select();
534 SWTBotTreeItem tracesFolderItem
= getTraceProjectItem(bot
, projectTreeItem
, TmfTracesFolder
.TRACES_FOLDER_NAME
);
535 tracesFolderItem
.select();
536 return tracesFolderItem
;
540 * Clear the traces folder
543 * a given workbench bot
545 * the name of the project (needs to exist)
547 public static void clearTracesFolder(SWTWorkbenchBot bot
, String projectName
) {
548 IProject project
= ResourcesPlugin
.getWorkspace().getRoot().getProject(projectName
);
549 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(project
, false);
550 TmfTraceFolder tracesFolder
= tmfProject
.getTracesFolder();
552 for (TmfTraceElement traceElement
: tracesFolder
.getTraces()) {
553 traceElement
.delete(null);
556 final IFolder resource
= tracesFolder
.getResource();
557 resource
.accept(new IResourceVisitor() {
559 public boolean visit(IResource visitedResource
) throws CoreException
{
560 if (visitedResource
!= resource
) {
561 visitedResource
.delete(true, null);
565 }, IResource
.DEPTH_ONE
, 0);
566 } catch (CoreException e
) {
567 fail(e
.getMessage());
570 bot
.waitUntil(new DefaultCondition() {
571 private int fTraceNb
= 0;
574 public boolean test() throws Exception
{
575 List
<TmfTraceElement
> traces
= tracesFolder
.getTraces();
576 fTraceNb
= traces
.size();
577 return fTraceNb
== 0;
581 public String
getFailureMessage() {
582 return "Traces Folder not empty (" + fTraceNb
+ ")";
588 * Clear the experiment folder
591 * a given workbench bot
593 * the name of the project (needs to exist)
595 public static void clearExperimentFolder(SWTWorkbenchBot bot
, String projectName
) {
596 IProject project
= ResourcesPlugin
.getWorkspace().getRoot().getProject(projectName
);
597 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(project
, false);
598 TmfExperimentFolder expFolder
= tmfProject
.getExperimentsFolder();
599 expFolder
.getExperiments().forEach(experiment
-> {
600 IResource resource
= experiment
.getResource();
602 // Close the experiment if open
603 experiment
.closeEditors();
605 IPath path
= resource
.getLocation();
607 // Delete supplementary files
608 experiment
.deleteSupplementaryFolder();
610 // Finally, delete the experiment
611 resource
.delete(true, null);
612 } catch (CoreException e
) {
613 fail(e
.getMessage());
617 bot
.waitUntil(new DefaultCondition() {
618 private int fExperimentNb
= 0;
621 public boolean test() throws Exception
{
622 List
<TmfExperimentElement
> experiments
= expFolder
.getExperiments();
623 fExperimentNb
= experiments
.size();
624 return fExperimentNb
== 0;
628 public String
getFailureMessage() {
629 return "Experiment Folder not empty (" + fExperimentNb
+ ")";
635 * Select the project in Project Explorer
638 * a given workbench bot
640 * the name of the project (it needs to exist or else it would time out)
641 * @return a {@link SWTBotTreeItem} of the project
643 public static SWTBotTreeItem
selectProject(SWTWorkbenchBot bot
, String projectName
) {
644 SWTBotView projectExplorerBot
= bot
.viewByTitle("Project Explorer");
645 projectExplorerBot
.show();
646 SWTBotTreeItem treeItem
= projectExplorerBot
.bot().tree().getTreeItem(projectName
);
657 public static void openView(final String id
) {
658 final PartInitException res
[] = new PartInitException
[1];
659 UIThreadRunnable
.syncExec(new VoidResult() {
663 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id
);
664 } catch (PartInitException e
) {
669 if (res
[0] != null) {
670 fail(res
[0].getMessage());
679 * the {@link SWTBotTable} table
681 public static void maximizeTable(SWTBotTable tableBot
) {
683 tableBot
.pressShortcut(KeyStroke
.getInstance(IKeyLookup
.CTRL_NAME
+ "+"), KeyStroke
.getInstance("M"));
684 } catch (ParseException e
) {
690 * Get the bounds of a cell (SWT.Rectangle) for the specified row and column
696 * the row of the table to look up
698 * the column of the table to look up
699 * @return the bounds in display relative coordinates
701 public static Rectangle
getCellBounds(final Table table
, final int row
, final int col
) {
702 return UIThreadRunnable
.syncExec(new Result
<Rectangle
>() {
704 public Rectangle
run() {
705 TableItem item
= table
.getItem(row
);
706 Rectangle bounds
= item
.getBounds(col
);
707 Point p
= table
.toDisplay(bounds
.x
, bounds
.y
);
708 Rectangle rect
= new Rectangle(p
.x
, p
.y
, bounds
.width
, bounds
.height
);
715 * Get the tree item from a tree at the specified location
720 * the tree to find the tree item in
722 * the path to the tree item, in the form of node names (from
724 * @return the tree item
726 public static SWTBotTreeItem
getTreeItem(SWTBot bot
, SWTBotTree tree
, String
... nodeNames
) {
727 if (nodeNames
.length
== 0) {
731 bot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(nodeNames
[0], tree
));
732 SWTBotTreeItem currentNode
= tree
.getTreeItem(nodeNames
[0]);
733 for (int i
= 1; i
< nodeNames
.length
; i
++) {
734 currentNode
.expand();
736 String nodeName
= nodeNames
[i
];
738 bot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(nodeName
, currentNode
));
739 } catch (TimeoutException e
) {
740 //FIXME: Sometimes in a JFace TreeViewer, it expands to nothing. Need to find out why.
741 currentNode
.collapse();
742 currentNode
.expand();
743 bot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(nodeName
, currentNode
));
746 SWTBotTreeItem newNode
= currentNode
.getNode(nodeName
);
747 currentNode
= newNode
;
754 * Get the active events editor. Note that this will wait until such editor
757 * @param workbenchBot
758 * a given workbench bot
759 * @return the active events editor
761 public static SWTBotEditor
activeEventsEditor(final SWTWorkbenchBot workbenchBot
) {
762 final SWTBotEditor editor
[] = new SWTBotEditor
[1];
763 workbenchBot
.waitUntil(new DefaultCondition() {
765 public boolean test() throws Exception
{
766 List
<SWTBotEditor
> editors
= workbenchBot
.editors(WidgetMatcherFactory
.withPartId(TmfEventsEditor
.ID
));
767 for (SWTBotEditor e
: editors
) {
768 if (e
.isActive() && !e
.getWidget().isDisposed()) {
777 public String
getFailureMessage() {
778 return "Active events editor not found";
785 * Open the preferences dialog and return the corresponding shell.
788 * a given workbench bot
789 * @return the preferences shell
791 public static SWTBotShell
openPreferences(SWTBot bot
) {
792 if (SWTUtils
.isMac()) {
793 // On Mac, the Preferences menu item is under the application name.
794 // For some reason, we can't access the application menu anymore so
795 // we use the keyboard shortcut.
797 bot
.activeShell().pressShortcut(KeyStroke
.getInstance(IKeyLookup
.COMMAND_NAME
+ "+"), KeyStroke
.getInstance(","));
798 } catch (ParseException e
) {
802 bot
.menu(WINDOW_MENU
).menu(PREFERENCES_MENU_ITEM
).click();
805 bot
.waitUntil(Conditions
.shellIsActive(PREFERENCES_MENU_ITEM
));
806 return bot
.activeShell();