Java Code Examples for org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable#syncExec()

The following examples show how to use org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable#syncExec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRefactoringSwtBotTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@BeforeClass
public static void initialize() {
  try {
    TargetPlatformUtil.setTargetPlatform(AbstractRefactoringSwtBotTest.class);
    IResourcesSetupUtil.cleanWorkspace();
    SWTWorkbenchBot _sWTWorkbenchBot = new SWTWorkbenchBot();
    AbstractRefactoringSwtBotTest.bot = _sWTWorkbenchBot;
    UIThreadRunnable.syncExec(new VoidResult() {
      @Override
      public void run() {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
      }
    });
    SwtBotProjectHelper.newXtendProject(AbstractRefactoringSwtBotTest.bot, "test");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source File: ImportAndReadPcapTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static IViewReference getViewPartRef(final String viewTile) {
    final IViewReference[] vrs = new IViewReference[1];
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
            for (IViewReference viewRef : viewRefs) {
                IViewPart vp = viewRef.getView(true);
                if (vp.getTitle().equals(viewTile)) {
                    vrs[0] = viewRef;
                    return;
                }
            }
        }
    });

    return vrs[0];
}
 
Example 3
Source File: ContextMenuHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Clicks the context menu item matching the text nodes with regular expression.
 *
 * @param bot a SWTBot class that wraps a {@link Widget} which extends {@link Control}. E.g.
 *     {@link SWTBotTree}.
 * @param nodes the nodes of the context menu e.g New, Class
 * @throws WidgetNotFoundException if the widget is not found.
 */
public static void clickContextMenuWithRegEx(
    final AbstractSWTBot<? extends Control> bot, final String... nodes) {

  final MenuItem menuItem = getMenuItemWithRegEx(bot, nodes);
  // show
  if (menuItem == null) {
    throw new WidgetNotFoundException("Could not find menu with regex: " + Arrays.asList(nodes));
  }

  // click
  click(menuItem);

  // hide
  UIThreadRunnable.syncExec(
      new VoidResult() {
        @Override
        public void run() {
          hide(menuItem.getParent());
        }
      });
}
 
Example 4
Source File: SystemCallLatencyTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractSegmentStoreTableView openTable() {
    /*
     * Open latency view
     */
    SWTBotUtils.openView(PRIMARY_VIEW_ID, SECONDARY_VIEW_ID);
    SWTBotView viewBot = fBot.viewById(PRIMARY_VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertTrue("Could not instanciate view", viewPart instanceof SegmentStoreTableView);
    return (SegmentStoreTableView) viewPart;
}
 
Example 5
Source File: PatternLatencyTableViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get the table associated to the view
 */
private void getTable() {
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertNotNull(viewPart);
    if (!(viewPart instanceof PatternLatencyTableView)) {
        fail("Could not instanciate view");
    }
    fLatencyView = (PatternLatencyTableView) viewPart;
    fTable = fLatencyView.getSegmentStoreViewer();
    assertNotNull(fTable);
}
 
Example 6
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the context menu item identified by the given labels.
 * When a context menu 'Compile' exists with the sub context menu 'All Invalids',
 * then the context menu 'All Invalids' is returned when giving the labels 'Compile' and 'All Invalids'.
 *
 * @param bot
 *          the {@link AbstractSWTBot} on which to infer the context menu
 * @param labels
 *          the labels on the context menus
 * @return the context menu item, {@code null} if the context menu item could not be found
 */
private static MenuItem getContextMenuItem(final AbstractSWTBot<? extends Control> bot, final String... labels) {
  return UIThreadRunnable.syncExec(new WidgetResult<MenuItem>() {
    @Override
    public MenuItem run() {
      MenuItem menuItem = null;
      Control control = bot.widget;

      // MenuDetectEvent
      Event event = new Event();
      control.notifyListeners(SWT.MenuDetect, event);
      if (event.doit) {
        Menu menu = control.getMenu();
        for (String text : labels) {
          Matcher<?> matcher = allOf(instanceOf(MenuItem.class), withMnemonic(text));
          menuItem = show(menu, matcher);
          if (menuItem != null) {
            menu = menuItem.getMenu();
          } else {
            hide(menu);
            break;
          }
        }
        return menuItem;
      } else {
        return null;
      }
    }
  });
}
 
Example 7
Source File: TimeGraphViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private Rectangle getBounds() {
    return UIThreadRunnable.syncExec((Result<Rectangle>) () -> {
        Control control = fTimeGraph.widget;
        Rectangle ctrlRelativeBounds = control.getBounds();
        Point res = control.toDisplay(new Point(fTimeGraph.getNameSpace(), 0));
        ctrlRelativeBounds.width -= fTimeGraph.getNameSpace();
        ctrlRelativeBounds.x = res.x;
        ctrlRelativeBounds.y = res.y;
        return ctrlRelativeBounds;
    });
}
 
Example 8
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get text content from the clipboard.
 *
 * @param bot
 *          to work with, must not be {@code null}
 * @return clipboard text content, or {@code null} if no text data is available
 */
public static String getClipboardContent(final SWTWorkbenchBot bot) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  return UIThreadRunnable.syncExec(new Result<String>() {
    @Override
    public String run() {
      final Clipboard clipboard = new Clipboard(bot.getDisplay());
      return (String) clipboard.getContents(TextTransfer.getInstance());
    }
  });
}
 
Example 9
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to check whether a given tree is expanded which can be called from any thread.
 */
public static boolean isTreeExpanded(final TreeItem tree) {
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      return tree.getExpanded();
    }
  });
}
 
Example 10
Source File: FontEventEditorTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static FontData getFont(final SWTBotStyledText rawText) {
    return UIThreadRunnable.syncExec(new Result<FontData>() {
        @Override
        public FontData run() {
            return rawText.widget.getFont().getFontData()[0];
        }
    });
}
 
Example 11
Source File: XYChartViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clean up after a test, reset the views.
 */
@After
public void after() {
    TmfTraceStub trace = fTrace;
    assertNotNull(trace);
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace)));
    fViewBot.close();
    fBot.waitUntil(ConditionHelpers.viewIsClosed(fViewBot));
    fTrace.dispose();
}
 
Example 12
Source File: AbstractImportAndReadSmokeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Verifies the Histogram View
 *
 * @param vp
 *            the view part
 * @param tmfEd
 *            the events editor
 */
protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
    final CtfTmfEvent desiredEvent1 = getEvent(100);
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            tmfEd.setFocus();
            tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
        }
    });

    WaitUtils.waitForJobs();
    SWTBotUtils.delay(1000);

    final CtfTmfEvent desiredEvent2 = getEvent(10000);
    SWTBotView hvBot = fBot.viewById(HistogramView.ID);
    List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
    for (SWTBotToolbarButton hvTool : hvTools) {
        if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
            hvTool.click();
        }
    }
    HistogramView hv = (HistogramView) vp;
    final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent1.getTimestamp());
    final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent2.getTimestamp());
    hv.updateTimeRange(100000);
    WaitUtils.waitForJobs();
    hv.selectionRangeUpdated(signal);
    hv.broadcast(signal);
    WaitUtils.waitForJobs();
    SWTBotUtils.delay(1000);

    hv.updateTimeRange(1000000000);
    WaitUtils.waitForJobs();
    hv.selectionRangeUpdated(signal2);
    hv.broadcast(signal2);
    WaitUtils.waitForJobs();
    SWTBotUtils.delay(1000);
    assertNotNull(hv);
}
 
Example 13
Source File: SegmentTableTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Opens a latency table
 */
@Before
public void init() {
    setTableView(openTable());
    assertNotNull(getTableView());
    setTable(getTableView().getSegmentStoreViewer());
    assertNotNull(getTable());
    ISegmentStoreProvider segStoreProvider = getSegStoreProvider();
    assertNotNull(segStoreProvider);
    UIThreadRunnable.syncExec(() -> getTable().setSegmentProvider(segStoreProvider));
}
 
Example 14
Source File: AbstractXtextUiTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens an {@link IEditorPart} for a provided {@link org.eclipse.emf.common.util.URI}.
 *
 * @param uri
 *          {@link org.eclipse.emf.common.util.URI} to open editor for
 * @param activate
 *          true if focus is to be set to the opened editor
 * @return {@link IEditorPart} created
 */
private IEditorPart openEditor(final org.eclipse.emf.common.util.URI uri, final boolean activate) {
  UiAssert.isNotUiThread();
  final IEditorPart editorPart = UIThreadRunnable.syncExec(getBot().getDisplay(), new Result<IEditorPart>() {
    @Override
    public IEditorPart run() {
      IEditorPart editor = getXtextTestUtil().get(GlobalURIEditorOpener.class).open(uri, activate);
      editor.setFocus();
      return editor;
    }
  });

  waitForEditorJobs(editorPart);

  getBot().waitUntil(new DefaultCondition() {
    @Override
    public boolean test() {
      if (editorPart.getEditorSite() != null && editorPart.getEditorInput() != null) {
        IEditorInput input = editorPart.getEditorInput();
        if (input instanceof IFileEditorInput) {
          return !((IFileEditorInput) input).getFile().isReadOnly();
        }
      }
      return false;
    }

    @Override
    public String getFailureMessage() {
      return "Editor must be initialized.";
    }
  }, EDITOR_ENABLED_TIMEOUT);

  return editorPart;
}
 
Example 15
Source File: TimeGraphViewTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void setWindowRange(long start, long end) {
    ITmfTimestamp startTime = TmfTimestamp.fromNanos(start);
    ITmfTimestamp endTime = TmfTimestamp.fromNanos(end);
    TmfTimeRange range = new TmfTimeRange(startTime, endTime);
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range)));
    fViewBot.bot().waitUntil(ConditionHelpers.timeGraphRangeCondition(getView(), Objects.requireNonNull(fTrace), range));
}
 
Example 16
Source File: LamiChartViewerTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Execute the LAMI analyses and return the viewBot corresponding to the
 * newly opened view. To avoid tests interracting with each other, it is
 * preferable to use the returned view bot in a try finally statement and
 * make sure the view is closed at the end of the test.
 *
 * @param analysis
 *            The analysis to execute
 * @return The view bot
 */
private SWTBotView executeAnalysis(LamiAnalyses analysis) {
    // Open the LAMI analysis
    SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
    SWTBotTreeItem externalAnalyses = SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, TRACE.getPath(), "External Analyses", analysis.getAnalysis().getName());
    assertNotNull(externalAnalyses);
    fBot.waitUntil(isLamiAnalysisEnabled(externalAnalyses));
    externalAnalyses.doubleClick();

    fBot.shell("External Analysis Parameters").activate();
    fBot.button("OK").click();
    WaitUtils.waitForJobs();

    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    viewBot.setFocus();
    final @Nullable LamiReportView lamiView = UIThreadRunnable.syncExec((Result<@Nullable LamiReportView>) () -> {
        IViewPart viewRef = viewBot.getViewReference().getView(true);
        return (viewRef instanceof LamiReportView) ? (LamiReportView) viewRef : null;
    });
    assertNotNull(lamiView);
    SWTBotUtils.maximize(lamiView);
    fViewBot = viewBot;

    fCurrentTab = lamiView.getCurrentSelectedPage();

    return viewBot;
}
 
Example 17
Source File: ClipboardUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Content from the clipboard.
 * 
 * @param bot
 *          to work with
 * @return clipboard content
 */
public static String clipboardContent(final SWTWorkbenchBot bot) {
  return UIThreadRunnable.syncExec(new Result<String>() {
    public String run() {
      Clipboard clipboard = new Clipboard(bot.getDisplay());
      return (String) clipboard.getContents(TextTransfer.getInstance());
    }
  });
}
 
Example 18
Source File: ImportAndReadKernelSmokeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Main test case
 */
@Test
public void test() {
    CtfTmfTrace trace = CtfTmfTestTraceUtils.getSyntheticTrace();
    try {
        Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(trace.getName());
        IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true);
        final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;

        fDesired1 = getEvent(trace, 100);
        fDesired2 = getEvent(trace, 10000);

        UIThreadRunnable.syncExec(new VoidResult() {
            @Override
            public void run() {
                tmfEd.setFocus();
                tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
            }
        });
        testHV(getViewPart("Histogram"));
        testCFV((ControlFlowView) getViewPart("Control Flow"));
        testRV((ResourcesView) getViewPart("Resources"));
        testStateSystemExplorer(trace.getPath());
    } finally {
        trace.dispose();
    }
}
 
Example 19
Source File: BookmarksViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static Image getBookmarkImage(SWTBotTableItem tableItem) {
    return UIThreadRunnable.syncExec((Result<Image>) () -> tableItem.widget.getImage(0));
}
 
Example 20
Source File: BookmarksViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static void bookmarkTest(String editorName) throws IOException {
    SWTBotView fViewBot = fBot.viewByPartName("Bookmarks");
    fViewBot.setFocus();
    WaitUtils.waitForJobs();
    assertEquals("Failed to show the Bookmarks View", "Bookmarks", fViewBot.getTitle());
    /**
     * Add a bookmark: a) Double click to select an event in the event
     * editor b) Go to the Edit > Add Bookmark... menu c) Enter the bookmark
     * description in dialog box
     */
    SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, editorName);
    SWTBotTable tableBot = editorBot.bot().table();
    SWTBotTableItem tableItem = tableBot.getTableItem(7);
    String expectedTimeStamp = tableItem.getText(1);
    assertNull("The image should not be bookmarked yet", getBookmarkImage(tableItem));

    tableItem.select();
    tableItem.doubleClick();
    fBot.menu("Edit").menu("Add Bookmark...").click();
    WaitUtils.waitForJobs();
    SWTBotShell addBookmarkShell = fBot.shell("Add Bookmark");
    addBookmarkShell.bot().text().setText(BOOKMARK_NAME);
    addBookmarkShell.bot().button("OK").click();
    assertNotNull("Failed to add bookmark in event editor", getBookmarkImage(tableItem));

    fViewBot.setFocus();
    WaitUtils.waitForJobs();
    SWTBotTree bookmarkTree = fViewBot.bot().tree();
    WaitUtils.waitForJobs();
    /**
     * throws WidgetNotFoundException - if the node was not found, nothing
     * to assert
     */
    SWTBotTreeItem bookmark = bookmarkTree.getTreeItem(BOOKMARK_NAME);
    assertEquals(BOOKMARK_NAME, bookmark.cell(0));

    /**
     * Scroll within event table so that bookmark is not visible anymore and
     * then double-click on bookmark in Bookmarks View
     */
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(null, TmfTimestamp.fromMicros(22))));
    bookmark.doubleClick();
    WaitUtils.waitUntil(TABLE_NOT_EMPTY, tableBot, "Table is still empty");
    TableCollection selection = tableBot.selection();
    TableRow row = selection.get(0);
    assertNotNull(selection.toString(), row);
    assertEquals("Wrong event was selected " + selection, expectedTimeStamp, row.get(1));

    /**
     * Open another trace #2 and then double-click on bookmark in Bookmarks
     * view
     */
    SWTBotUtils.openTrace(PROJECT_NAME, FileLocator.toFileURL(TmfTraceStub.class.getResource("/testfiles/E-Test-10K")).getPath(), TRACE_TYPE);
    WaitUtils.waitForJobs();
    bookmark.doubleClick();
    editorBot = SWTBotUtils.activeEventsEditor(fBot, editorName);
    WaitUtils.waitUntil(TABLE_NOT_EMPTY, tableBot, "Table is still empty");
    selection = tableBot.selection();
    row = selection.get(0);
    assertNotNull(selection.toString(), row);
    assertEquals("Wrong event was selected " + selection, expectedTimeStamp, row.get(1));

    /**
     * Close the trace #1 and then double-click on bookmark in Bookmarks
     * view
     */
    editorBot.close();
    WaitUtils.waitUntil(eb -> !eb.isActive(), editorBot, "Waiting for the editor to close");
    bookmark.doubleClick();
    editorBot = SWTBotUtils.activeEventsEditor(fBot, editorName);
    WaitUtils.waitUntil(eb -> eb.bot().table().selection().rowCount() > 0, editorBot, "Selection is still empty");
    tableBot = editorBot.bot().table();
    WaitUtils.waitUntil(tb -> !Objects.equal(tb.selection().get(0).get(1), "<srch>"), tableBot, "Header is still selected");
    selection = tableBot.selection();
    row = selection.get(0);
    assertNotNull(selection.toString(), row);
    assertEquals("Wrong event was selected " + selection, expectedTimeStamp, row.get(1));

    /**
     * Select bookmarks icon in bookmark view right-click on icon and select
     * "Remove Bookmark"
     */
    bookmark.select();
    bookmark.contextMenu("Delete").click();
    SWTBotShell deleteBookmarkShell = fBot.shell("Delete Selected Entries");
    SWTBotUtils.anyButtonOf(deleteBookmarkShell.bot(), "Delete", "Yes").click();
    fBot.waitUntil(Conditions.treeHasRows(bookmarkTree, 0));
    tableItem = editorBot.bot().table().getTableItem(7);
    assertNull("Bookmark not deleted from event table", getBookmarkImage(tableItem));
}