da11de540d20706ee8707609268b8724d2e7a238
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / shared / org / eclipse / tracecompass / tmf / ui / swtbot / tests / shared / SWTBotUtils.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
18
19 import java.util.List;
20
21 import org.eclipse.core.resources.IFolder;
22 import org.eclipse.core.resources.IProject;
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.core.resources.IResourceVisitor;
25 import org.eclipse.core.resources.ResourcesPlugin;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IPath;
28 import org.eclipse.core.runtime.NullProgressMonitor;
29 import org.eclipse.core.runtime.jobs.Job;
30 import org.eclipse.jface.bindings.keys.IKeyLookup;
31 import org.eclipse.jface.bindings.keys.KeyStroke;
32 import org.eclipse.jface.bindings.keys.ParseException;
33 import org.eclipse.swt.graphics.Point;
34 import org.eclipse.swt.graphics.Rectangle;
35 import org.eclipse.swt.widgets.Display;
36 import org.eclipse.swt.widgets.Shell;
37 import org.eclipse.swt.widgets.Table;
38 import org.eclipse.swt.widgets.TableItem;
39 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
40 import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
41 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
42 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
43 import org.eclipse.swtbot.swt.finder.SWTBot;
44 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
45 import org.eclipse.swtbot.swt.finder.results.Result;
46 import org.eclipse.swtbot.swt.finder.results.VoidResult;
47 import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
48 import org.eclipse.swtbot.swt.finder.waits.Conditions;
49 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
50 import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
51 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
52 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
53 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
54 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
55 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
56 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
57 import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
58 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
59 import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
60 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
61 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
62 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
63 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
64 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
65 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.ProjectElementHasChild;
66 import org.eclipse.tracecompass.tmf.ui.views.TracingPerspectiveFactory;
67 import org.eclipse.ui.IEditorPart;
68 import org.eclipse.ui.IEditorReference;
69 import org.eclipse.ui.IPageLayout;
70 import org.eclipse.ui.PartInitException;
71 import org.eclipse.ui.PlatformUI;
72 import org.eclipse.ui.WorkbenchException;
73 import org.hamcrest.Matcher;
74
75 /**
76 * SWTBot Helper functions
77 *
78 * @author Matthew Khouzam
79 */
80 public final class SWTBotUtils {
81
82 private static final String WINDOW_MENU = "Window";
83 private static final String PREFERENCES_MENU_ITEM = "Preferences";
84 private static boolean fPrintedEnvironment = false;
85
86 private SWTBotUtils() {
87 }
88
89 private static final String TRACING_PERSPECTIVE_ID = TracingPerspectiveFactory.ID;
90
91 /**
92 * Waits for all Eclipse jobs to finish
93 */
94 public static void waitForJobs() {
95 while (!Job.getJobManager().isIdle()) {
96 delay(100);
97 }
98 }
99
100 /**
101 * Sleeps current thread for a given time.
102 *
103 * @param waitTimeMillis
104 * time in milliseconds to wait
105 */
106 public static void delay(final long waitTimeMillis) {
107 try {
108 Thread.sleep(waitTimeMillis);
109 } catch (final InterruptedException e) {
110 // Ignored
111 }
112 }
113
114 /**
115 * Create a tracing project
116 *
117 * @param projectName
118 * the name of the tracing project
119 */
120 public static void createProject(final String projectName) {
121 /*
122 * Make a new test
123 */
124 UIThreadRunnable.syncExec(new VoidResult() {
125 @Override
126 public void run() {
127 IProject project = TmfProjectRegistry.createProject(projectName, null, new NullProgressMonitor());
128 assertNotNull(project);
129 }
130 });
131
132 SWTBotUtils.waitForJobs();
133 }
134
135 /**
136 * Deletes a project
137 *
138 * @param projectName
139 * the name of the tracing project
140 * @param deleteResources
141 * whether or not to deleted resources under the project
142 * @param bot
143 * the workbench bot
144 */
145 public static void deleteProject(final String projectName, boolean deleteResources, SWTWorkbenchBot bot) {
146 // Wait for any analysis to complete because it might create
147 // supplementary files
148 SWTBotUtils.waitForJobs();
149 try {
150 ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).refreshLocal(IResource.DEPTH_INFINITE, null);
151 } catch (CoreException e) {
152 }
153
154 SWTBotUtils.waitForJobs();
155
156 final SWTBotView projectViewBot = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
157 projectViewBot.setFocus();
158
159 SWTBotTree treeBot = projectViewBot.bot().tree();
160 SWTBotTreeItem treeItem = treeBot.getTreeItem(projectName);
161 SWTBotMenu contextMenu = treeItem.contextMenu("Delete");
162 contextMenu.click();
163
164 if (deleteResources) {
165 bot.shell("Delete Resources").setFocus();
166 final SWTBotCheckBox checkBox = bot.checkBox();
167 bot.waitUntil(Conditions.widgetIsEnabled(checkBox));
168 checkBox.click();
169 }
170
171 final SWTBotButton okButton = bot.button("OK");
172 bot.waitUntil(Conditions.widgetIsEnabled(okButton));
173 okButton.click();
174
175 SWTBotUtils.waitForJobs();
176 }
177
178 /**
179 * Deletes a project and its resources
180 *
181 * @param projectName
182 * the name of the tracing project
183 * @param bot
184 * the workbench bot
185 */
186 public static void deleteProject(String projectName, SWTWorkbenchBot bot) {
187 deleteProject(projectName, true, bot);
188 }
189
190 /**
191 * Focus on the main window
192 *
193 * @param shellBots
194 * swtbotshells for all the shells
195 */
196 public static void focusMainWindow(SWTBotShell[] shellBots) {
197 for (SWTBotShell shellBot : shellBots) {
198 if (shellBot.getText().toLowerCase().contains("eclipse")) {
199 shellBot.activate();
200 }
201 }
202 }
203
204 /**
205 * Close a view with a title
206 *
207 * @param title
208 * the title, like "welcome"
209 * @param bot
210 * the workbench bot
211 */
212 public static void closeView(String title, SWTWorkbenchBot bot) {
213 final List<SWTBotView> openViews = bot.views();
214 for (SWTBotView view : openViews) {
215 if (view.getTitle().equalsIgnoreCase(title)) {
216 view.close();
217 bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
218 }
219 }
220 }
221
222 /**
223 * Close a view with an id
224 *
225 * @param viewId
226 * the view id, like "org.eclipse.linuxtools.tmf.ui.views.histogram"
227 * @param bot
228 * the workbench bot
229 */
230 public static void closeViewById(String viewId, SWTWorkbenchBot bot) {
231 final SWTBotView view = bot.viewById(viewId);
232 view.close();
233 bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
234 }
235
236 /**
237 * Switch to the tracing perspective
238 */
239 public static void switchToTracingPerspective() {
240 switchToPerspective(TRACING_PERSPECTIVE_ID);
241 }
242
243 /**
244 * Switch to a given perspective
245 *
246 * @param id
247 * the perspective id (like
248 * "org.eclipse.linuxtools.tmf.ui.perspective"
249 */
250 public static void switchToPerspective(final String id) {
251 UIThreadRunnable.syncExec(new VoidResult() {
252 @Override
253 public void run() {
254 try {
255 PlatformUI.getWorkbench().showPerspective(id, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
256 } catch (WorkbenchException e) {
257 fail(e.getMessage());
258 }
259 }
260 });
261 }
262
263 /**
264 * Initialize the environment for SWTBot
265 */
266 public static void initialize() {
267 failIfUIThread();
268
269 SWTWorkbenchBot bot = new SWTWorkbenchBot();
270 UIThreadRunnable.syncExec(() -> {
271 printEnvironment();
272
273 // There seems to be problems on some system where the main shell is
274 // not in focus initially. This was seen using Xvfb and Xephyr on some occasions.
275 focusMainWindow(bot.shells());
276
277 Shell shell = bot.activeShell().widget;
278
279 // Only adjust shell if it appears to be the top-most
280 if (shell.getParent() == null) {
281 makeShellFullyVisible(shell);
282 }
283 });
284 }
285
286 private static void printEnvironment() {
287 if (fPrintedEnvironment) {
288 return;
289 }
290
291 // Print some information about the environment that could affect test outcome
292 Rectangle bounds = Display.getDefault().getBounds();
293 System.out.println("Display size: " + bounds.width + "x" + bounds.height);
294
295 String osVersion = System.getProperty("os.version");
296 if (osVersion != null) {
297 System.out.println("OS version=" + osVersion);
298 }
299 String gtkVersion = System.getProperty("org.eclipse.swt.internal.gtk.version");
300 if (gtkVersion != null) {
301 System.out.println("GTK version=" + gtkVersion);
302 String overlayScrollbar = System.getenv("LIBOVERLAY_SCROLLBAR");
303 if (overlayScrollbar != null) {
304 System.out.println("LIBOVERLAY_SCROLLBAR=" + overlayScrollbar);
305 }
306 String ubuntuMenuProxy = System.getenv("UBUNTU_MENUPROXY");
307 if (ubuntuMenuProxy != null) {
308 System.out.println("UBUNTU_MENUPROXY=" + ubuntuMenuProxy);
309 }
310 }
311
312 fPrintedEnvironment = true;
313 }
314
315 /**
316 * If the test is running in the UI thread then fail
317 */
318 private static void failIfUIThread() {
319 if (Display.getCurrent() != null && Display.getCurrent().getThread() == Thread.currentThread()) {
320 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"
321 + " that useUIThread is set to false in the pom.xml");
322 }
323 }
324
325 /**
326 * Try to make the shell fully visible in the display. If the shell cannot
327 * fit the display, it will be positioned so that top-left corner is at
328 * <code>(0, 0)</code> in display-relative coordinates.
329 *
330 * @param shell
331 * the shell to make fully visible
332 */
333 private static void makeShellFullyVisible(Shell shell) {
334 Rectangle displayBounds = shell.getDisplay().getBounds();
335 Point absCoord = shell.toDisplay(0, 0);
336 Point shellSize = shell.getSize();
337
338 Point newLocation = new Point(absCoord.x, absCoord.y);
339 newLocation.x = Math.max(0, Math.min(absCoord.x, displayBounds.width - shellSize.x));
340 newLocation.y = Math.max(0, Math.min(absCoord.y, displayBounds.height - shellSize.y));
341 if (!newLocation.equals(absCoord)) {
342 shell.setLocation(newLocation);
343 }
344 }
345
346 /**
347 * Open a trace, this does not perform any validation though
348 *
349 * @param projectName
350 * The project name
351 * @param tracePath
352 * the path of the trace file (absolute or relative)
353 * @param traceType
354 * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
355 */
356 public static void openTrace(final String projectName, final String tracePath, final String traceType) {
357 openTrace(projectName, tracePath, traceType, true);
358 }
359
360 /**
361 * Open a trace, this does not perform any validation though
362 *
363 * @param projectName
364 * The project name
365 * @param tracePath
366 * the path of the trace file (absolute or relative)
367 * @param traceType
368 * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
369 * @param delay
370 * delay and wait for jobs
371 */
372 public static void openTrace(final String projectName, final String tracePath, final String traceType, boolean delay) {
373 final Exception exception[] = new Exception[1];
374 exception[0] = null;
375 UIThreadRunnable.syncExec(new VoidResult() {
376 @Override
377 public void run() {
378 try {
379 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
380 TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
381 TmfOpenTraceHelper.openTraceFromPath(destinationFolder, tracePath, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), traceType);
382 } catch (CoreException e) {
383 exception[0] = e;
384 }
385 }
386 });
387 if (exception[0] != null) {
388 fail(exception[0].getMessage());
389 }
390
391 if (delay) {
392 delay(1000);
393 waitForJobs();
394 }
395 }
396
397 /**
398 * Finds an editor and sets focus to the editor
399 *
400 * @param bot
401 * the workbench bot
402 * @param editorName
403 * the editor name
404 * @return the corresponding SWTBotEditor
405 */
406 public static SWTBotEditor activateEditor(SWTWorkbenchBot bot, String editorName) {
407 Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(editorName);
408 final SWTBotEditor editorBot = bot.editor(matcher);
409 IEditorPart iep = editorBot.getReference().getEditor(true);
410 final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
411 editorBot.show();
412 UIThreadRunnable.syncExec(new VoidResult() {
413 @Override
414 public void run() {
415 tmfEd.setFocus();
416 }
417 });
418
419 SWTBotUtils.waitForJobs();
420 SWTBotUtils.delay(1000);
421 assertNotNull(tmfEd);
422 return editorBot;
423 }
424
425 /**
426 * Opens a trace in an editor and get the TmfEventsEditor
427 *
428 * @param bot
429 * the workbench bot
430 * @param projectName
431 * the name of the project that contains the trace
432 * @param elementPath
433 * the trace element path (relative to Traces folder)
434 * @return TmfEventsEditor the opened editor
435 */
436 public static TmfEventsEditor openEditor(SWTWorkbenchBot bot, String projectName, IPath elementPath) {
437 final SWTBotView projectExplorerView = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
438 projectExplorerView.setFocus();
439 SWTBot projectExplorerBot = projectExplorerView.bot();
440
441 final SWTBotTree tree = projectExplorerBot.tree();
442 projectExplorerBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(projectName, tree));
443 final SWTBotTreeItem treeItem = tree.getTreeItem(projectName);
444 treeItem.expand();
445
446 SWTBotTreeItem tracesNode = getTraceProjectItem(projectExplorerBot, treeItem, TmfTracesFolder.TRACES_FOLDER_NAME);
447 tracesNode.expand();
448
449 SWTBotTreeItem currentItem = tracesNode;
450 for (String segment : elementPath.segments()) {
451 currentItem = getTraceProjectItem(projectExplorerBot, currentItem, segment);
452 currentItem.select();
453 currentItem.doubleClick();
454 }
455
456 SWTBotEditor editor = bot.editorByTitle(elementPath.toString());
457 IEditorPart editorPart = editor.getReference().getEditor(false);
458 assertTrue(editorPart instanceof TmfEventsEditor);
459 return (TmfEventsEditor) editorPart;
460 }
461
462 /**
463 * Returns the child tree item of the specified item with the given name.
464 * The project element label may have a count suffix in the format ' [n]'.
465 *
466 * @param bot
467 * a given workbench bot
468 * @param parentItem
469 * the parent tree item
470 * @param name
471 * the desired child element name (without suffix)
472 * @return the a {@link SWTBotTreeItem} with the specified name
473 */
474 public static SWTBotTreeItem getTraceProjectItem(SWTBot bot, final SWTBotTreeItem parentItem, final String name) {
475 ProjectElementHasChild condition = new ProjectElementHasChild(parentItem, name);
476 bot.waitUntil(condition);
477 return condition.getItem();
478 }
479
480 /**
481 * Select the traces folder
482 *
483 * @param bot
484 * a given workbench bot
485 * @param projectName
486 * the name of the project (it needs to exist or else it would
487 * time out)
488 * @return a {@link SWTBotTreeItem} of the "Traces" folder
489 */
490 public static SWTBotTreeItem selectTracesFolder(SWTWorkbenchBot bot, String projectName) {
491 SWTBotTreeItem projectTreeItem = selectProject(bot, projectName);
492 projectTreeItem.select();
493 SWTBotTreeItem tracesFolderItem = getTraceProjectItem(bot, projectTreeItem, TmfTracesFolder.TRACES_FOLDER_NAME);
494 tracesFolderItem.select();
495 return tracesFolderItem;
496 }
497
498 /**
499 * Clear the traces folder
500 *
501 * @param bot
502 * a given workbench bot
503 * @param projectName
504 * the name of the project (needs to exist)
505 */
506 public static void clearTracesFolder(SWTWorkbenchBot bot, String projectName) {
507 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
508 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
509 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
510 try {
511 for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
512 traceElement.delete(null);
513 }
514
515 final IFolder resource = tracesFolder.getResource();
516 resource.accept(new IResourceVisitor() {
517 @Override
518 public boolean visit(IResource visitedResource) throws CoreException {
519 if (visitedResource != resource) {
520 visitedResource.delete(true, null);
521 }
522 return true;
523 }
524 }, IResource.DEPTH_ONE, 0);
525 } catch (CoreException e) {
526 fail(e.getMessage());
527 }
528
529 bot.waitUntil(new DefaultCondition() {
530 private int fTraceNb = 0;
531
532 @Override
533 public boolean test() throws Exception {
534 List<TmfTraceElement> traces = tracesFolder.getTraces();
535 fTraceNb = traces.size();
536 return fTraceNb == 0;
537 }
538
539 @Override
540 public String getFailureMessage() {
541 return "Traces Folder not empty (" + fTraceNb + ")";
542 }
543 });
544
545 }
546
547 /**
548 * Select the project in Project Explorer
549 *
550 * @param bot
551 * a given workbench bot
552 * @param projectName
553 * the name of the project (it needs to exist or else it would time out)
554 * @return a {@link SWTBotTreeItem} of the project
555 */
556 public static SWTBotTreeItem selectProject(SWTWorkbenchBot bot, String projectName) {
557 SWTBotView projectExplorerBot = bot.viewByTitle("Project Explorer");
558 projectExplorerBot.show();
559 SWTBotTreeItem treeItem = projectExplorerBot.bot().tree().getTreeItem(projectName);
560 treeItem.select();
561 return treeItem;
562 }
563
564 /**
565 * Open a view by id.
566 *
567 * @param id
568 * view id.
569 */
570 public static void openView(final String id) {
571 final PartInitException res[] = new PartInitException[1];
572 UIThreadRunnable.syncExec(new VoidResult() {
573 @Override
574 public void run() {
575 try {
576 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id);
577 } catch (PartInitException e) {
578 res[0] = e;
579 }
580 }
581 });
582 if (res[0] != null) {
583 fail(res[0].getMessage());
584 }
585 waitForJobs();
586 }
587
588 /**
589 * Maximize a table
590 *
591 * @param tableBot
592 * the {@link SWTBotTable} table
593 */
594 public static void maximizeTable(SWTBotTable tableBot) {
595 try {
596 tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
597 } catch (ParseException e) {
598 fail();
599 }
600 }
601
602 /**
603 * Get the bounds of a cell (SWT.Rectangle) for the specified row and column
604 * index in a table
605 *
606 * @param table
607 * the table
608 * @param row
609 * the row of the table to look up
610 * @param col
611 * the column of the table to look up
612 * @return the bounds in display relative coordinates
613 */
614 public static Rectangle getCellBounds(final Table table, final int row, final int col) {
615 return UIThreadRunnable.syncExec(new Result<Rectangle>() {
616 @Override
617 public Rectangle run() {
618 TableItem item = table.getItem(row);
619 Rectangle bounds = item.getBounds(col);
620 Point p = table.toDisplay(bounds.x, bounds.y);
621 Rectangle rect = new Rectangle(p.x, p.y, bounds.width, bounds.height);
622 return rect;
623 }
624 });
625 }
626
627 /**
628 * Get the tree item from a tree at the specified location
629 *
630 * @param bot
631 * the SWTBot
632 * @param tree
633 * the tree to find the tree item in
634 * @param nodeNames
635 * the path to the tree item, in the form of node names (from
636 * parent to child).
637 * @return the tree item
638 */
639 public static SWTBotTreeItem getTreeItem(SWTBot bot, SWTBotTree tree, String... nodeNames) {
640 if (nodeNames.length == 0) {
641 return null;
642 }
643
644 bot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(nodeNames[0], tree));
645 SWTBotTreeItem currentNode = tree.getTreeItem(nodeNames[0]);
646 for (int i = 1; i < nodeNames.length; i++) {
647 currentNode.expand();
648
649 String nodeName = nodeNames[i];
650 try {
651 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, currentNode));
652 } catch (TimeoutException e) {
653 //FIXME: Sometimes in a JFace TreeViewer, it expands to nothing. Need to find out why.
654 currentNode.collapse();
655 currentNode.expand();
656 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, currentNode));
657 }
658
659 SWTBotTreeItem newNode = currentNode.getNode(nodeName);
660 currentNode = newNode;
661 }
662
663 return currentNode;
664 }
665
666 /**
667 * Get the active events editor. Note that this will wait until such editor
668 * is available.
669 *
670 * @param workbenchBot
671 * a given workbench bot
672 * @return the active events editor
673 */
674 public static SWTBotEditor activeEventsEditor(final SWTWorkbenchBot workbenchBot) {
675 final SWTBotEditor editor[] = new SWTBotEditor[1];
676 workbenchBot.waitUntil(new DefaultCondition() {
677 @Override
678 public boolean test() throws Exception {
679 List<SWTBotEditor> editors = workbenchBot.editors(WidgetMatcherFactory.withPartId(TmfEventsEditor.ID));
680 for (SWTBotEditor e : editors) {
681 if (e.isActive() && !e.getWidget().isDisposed()) {
682 editor[0] = e;
683 return true;
684 }
685 }
686 return false;
687 }
688
689 @Override
690 public String getFailureMessage() {
691 return "Active events editor not found";
692 }
693 });
694 return editor[0];
695 }
696
697 /**
698 * Open the preferences dialog and return the corresponding shell.
699 *
700 * @param bot
701 * a given workbench bot
702 * @return the preferences shell
703 */
704 public static SWTBotShell openPreferences(SWTBot bot) {
705 if (SWTUtils.isMac()) {
706 // On Mac, the Preferences menu item is under the application name.
707 // For some reason, we can't access the application menu anymore so
708 // we use the keyboard shortcut.
709 try {
710 bot.activeShell().pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
711 } catch (ParseException e) {
712 fail();
713 }
714 } else {
715 bot.menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
716 }
717
718 bot.waitUntil(Conditions.shellIsActive(PREFERENCES_MENU_ITEM));
719 return bot.activeShell();
720 }
721 }
This page took 0.049844 seconds and 4 git commands to generate.