Java 类org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable 实例源码

项目:eclemma    文件:CoverageViewTest.java   
@Test
public void testImportSession() {
  // given
  UIThreadRunnable.syncExec(new VoidResult() {
    public void run() {
      try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.eclemma.ui.CoverageView");
      } catch (PartInitException e) {
        e.printStackTrace();
      }
    }
  });

  // when
  SWTBotView view = bot.viewByTitle("Coverage");
  view.bot().tree().contextMenu("Import Session...").click();

  // then
  bot.shell("Import").activate();
  bot.text(" Please select an existing execution data file.");
}
项目:mesfavoris    文件:ShowInBookmarksViewOperationTest.java   
@Test
public void testShowInBookmarksView() throws TimeoutException {
    // Given
    IWorkbenchPage activePage = UIThreadRunnable
            .syncExec(() -> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
    assertNotNull(activePage);

    // When
    bookmarksService.showInBookmarksView(activePage, new BookmarkId("bookmark21"), true);

    // Then
    SWTBotTree botTree = bookmarksViewDriver.tree();
    Waiter.waitUntil("bookmark not selected", () -> {
        assertThat(botTree.selection().get(0).get(0)).isEqualTo("bookmark21");
        return true;
    });
}
项目:mesfavoris    文件:JavaEditorBookmarkPropertiesProviderTest.java   
private SWTBotEclipseEditor textEditor(String fullyQualifiedType) throws JavaModelException, PartInitException {
    IType type = javaProject.findType(fullyQualifiedType);

    IEditorPart editorPart = UIThreadRunnable.syncExec(new Result<IEditorPart>() {

        public IEditorPart run() {
            try {
                return JavaUI.openInEditor(type, true, true);
            } catch (PartInitException | JavaModelException e) {
                throw new RuntimeException(e);
            }
        }

    });

    // IEditorPart editorPart = JavaUI.openInEditor(type, true, true);
    SWTBotEditor editor = bot.editorById(editorPart.getEditorSite().getId());
    return editor.toTextEditor();
}
项目:dsl-devkit    文件:TestRunRecording.java   
/** {@inheritDoc} */
@Override
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public void testStarted(final Description description) {
  if (!screenshotsCleared) {
    deleteDirectoryContents(new File(screenshotFolder));
    screenshotsCleared = true;
  }
  testFailed = false;
  testStepStarted = false;
  if (description.getTestClass() != null) {
    testClassName = description.getTestClass().getName();
  } else {
    testClassName = testClass.getSimpleName();
  }
  testMethodName = description.getMethodName();
  AbstractTestStep.registerTestStepListener(this);
  UIThreadRunnable.syncExec(new VoidResult() {
    @Override
    public void run() {
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addMouseListener(TestRunRecording.this);
    }
  });
  start();
}
项目:dsl-devkit    文件:TestRunRecording.java   
/** {@inheritDoc} */
@Override
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public void testFinished(final Description description) {
  stop();
  AbstractTestStep.removeTestStepListener(this);
  UIThreadRunnable.syncExec(new VoidResult() {
    @Override
    public void run() {
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().removeMouseListener(TestRunRecording.this);
    }
  });
  if (!testFailed) {
    deleteScreenshots();
  }
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Clicks on the {@link MenuItem}.
 *
 * @param menuItem
 *          the {@link MenuItem} to click on
 */
private static void click(final MenuItem menuItem) {
  final Event event = new Event();
  event.time = (int) System.currentTimeMillis();
  event.widget = menuItem;
  event.display = menuItem.getDisplay();
  event.type = SWT.Selection;

  UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
    @Override
    public void run() {
      if (SWTUtils.hasStyle(menuItem, SWT.CHECK) || SWTUtils.hasStyle(menuItem, SWT.RADIO)) {
        menuItem.setSelection(!menuItem.getSelection());
      }
      menuItem.notifyListeners(SWT.Selection, event);
    }
  });
}
项目:dsl-devkit    文件:ShellUiTestUtil.java   
/**
 * Tests if a shell with a specific type of data contained (e.g. Window).
 * 
 * @param bot
 *          to use
 * @param clazz
 *          class of data contained to check for
 */
@SuppressWarnings("rawtypes")
public static void assertShellWithDataTypeVisible(final SWTWorkbenchBot bot, final Class clazz) {
  bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
    @SuppressWarnings("unchecked")
    public boolean matches(final Object item) {
      return UIThreadRunnable.syncExec(new Result<Boolean>() {
        public Boolean run() {
          if (item instanceof Shell) {
            Object shellData = ((Shell) item).getData();
            if (shellData != null) {
              return clazz.isAssignableFrom(shellData.getClass());
            }
          }
          return false;
        }
      });
    }

    public void describeTo(final Description description) {
      description.appendText("Shell for " + clazz.getName());
    }
  }));
}
项目:tlaplus    文件:RCPTestSetupHelper.java   
public static void beforeClass() {
    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            resetWorkbench();
            resetToolbox();

            // close browser-based welcome screen (if open)
            SWTWorkbenchBot bot = new SWTWorkbenchBot();
            try {
                SWTBotView welcomeView = bot.viewByTitle("Welcome");
                welcomeView.close();
            } catch (WidgetNotFoundException e) {
                return;
            }
        }
    });
}
项目:emfstore-rest    文件:UIShowHistoryControllerForElementTest.java   
@Override
@Test
public void testController() throws ESException {

    final Player player = createPlayerAndCommit();

    UIThreadRunnable.asyncExec(new VoidResult() {
        public void run() {
            final UIShowHistoryController showHistoryController =
                new UIShowHistoryController(bot.getDisplay().getActiveShell(), player);
            showHistoryController.execute();
        }
    });

    final SWTBotView historyView = bot.viewById(
        "org.eclipse.emf.emfstore.client.ui.views.historybrowserview.HistoryBrowserView");

    assertNotNull(historyView);
}
项目:emfstore-rest    文件:UIShowHistoryControllerTest.java   
@Override
@Test
public void testController() throws ESException {

    createPlayerAndCommit();
    UIThreadRunnable.asyncExec(new VoidResult() {
        public void run() {
            final UIShowHistoryController showHistoryController =
                new UIShowHistoryController(bot.getDisplay().getActiveShell(), localProject);
            showHistoryController.execute();
        }
    });

    final SWTBotView historyView = bot.viewById(
        "org.eclipse.emf.emfstore.client.ui.views.historybrowserview.HistoryBrowserView");

    assertNotNull(historyView);
}
项目:emfstore-rest    文件:UIAddTagControllerTest.java   
private ESPathQuery createTag() throws ESException {
    ESPrimaryVersionSpec baseVersion = localProject.getBaseVersion();
    createPlayerAndCommit();
    ESPathQuery pathQuery = ESHistoryQuery.FACTORY
        .pathQuery(baseVersion, localProject.getBaseVersion(), true, true);
    List<ESHistoryInfo> historyInfos = localProject.getHistoryInfos(pathQuery, new NullProgressMonitor());
    assertEquals(2, historyInfos.size());
    final ESHistoryInfo historyInfo = historyInfos.get(1);
    assertEquals(2, historyInfo.getTagSpecs().size());
    UIThreadRunnable.asyncExec(
        new VoidResult() {
            public void run() {
                UIAddTagController addTagController = new UIAddTagController(bot.getDisplay().getActiveShell(),
                    localProject, historyInfo);
                addTagController.execute();
            }
        });

    bot.table(0).select(0);
    SWTBotButton button = bot.button("OK");
    button.click();
    return pathQuery;
}
项目:emfstore-rest    文件:UIServerControllerTest.java   
private void addServer() {
    final int howManyServers = ESWorkspaceProvider.INSTANCE.getWorkspace().getServers().size();
    UIThreadRunnable.asyncExec(new VoidResult() {
        public void run() {
            final UIAddServerController addServerController = new UIAddServerController(
                bot.getDisplay().getActiveShell());
            addServerController.execute();
        }
    });
    bot.button("Finish").click();
    bot.waitUntil(new DefaultCondition() {
        // BEGIN SUPRESS CATCH EXCEPTION

        public boolean test() throws Exception {
            return howManyServers + 1 == ESWorkspaceProvider.INSTANCE.getWorkspace().getServers().size();
        }

        public String getFailureMessage() {
            return "Add server did not succeed.";
        }
        // END SUPRESS CATCH EXCEPTION

    });
    assertEquals(howManyServers + 1, ESWorkspaceProvider.INSTANCE.getWorkspace().getServers().size());
}
项目:eclipse-plugin    文件:SWTBotBaseTest.java   
@Before
public void baseBeforeTest() {
    // Sets codenvy fake API
    CodenvyAPI.setClient(new FakeCodenvyClient());

    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            final Shell eclipseShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            eclipseShell.forceFocus();
        }
    });

    try {

        final SWTBotView welcomeView = bot.viewByTitle("Welcome");
        welcomeView.close();

    } catch (WidgetNotFoundException e) {
        // ignore the exception
    }
}
项目:gw4e.project    文件:GraphElementProperties.java   
protected void selectTab(SWTBotGefEditPart part, String label) {
    selectPart(part);
    Matcher<TabbedPropertyList> matcher = new BaseMatcher<TabbedPropertyList>() {
        @Override
        public boolean matches(Object item) {
            if (item instanceof TabbedPropertyList) {
                return true;
            }
            return false;
        }
        @Override
        public void describeTo(Description description) {
        }
    };
    List<TabbedPropertyList> allWidgets = widget(matcher);
    UIThreadRunnable.syncExec(Display.getDefault(), new VoidResult() {
        @Override
        public void run() {
            for (final TabbedPropertyList tabbedProperty : allWidgets) {
                final ListElement tabItem = getTabItem(label, tabbedProperty);
                if (tabItem != null) {
                    final Event mouseEvent = createEvent(tabItem);
                    tabItem.notifyListeners(SWT.MouseUp, mouseEvent);
                    tabItem.setFocus();
                    return;
                }
            }
            throw new IllegalStateException("Unable to select the tab " + label);
        }
    });
}
项目:gw4e.project    文件:VertexProperties.java   
public void setInit(SWTBotGefEditPart part, String script) {
    selectPart(part);
    selectTab(part, INIT);
    SWTBotStyledText st = bot.styledTextWithId( WIDGET_ID,  WIDGET_SCRIPT);
    st.setText(script);
    UIThreadRunnable.syncExec(Display.getDefault(), new VoidResult() {
        @Override
        public void run() {
            st.widget.notifyListeners(SWT.FocusOut, null);
            editor.setFocus();
        }
    });
}
项目:gw4e.project    文件:GraphHelper.java   
protected void syncWithUIThread() {
    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) {
            }
        }
    });
}
项目:gw4e.project    文件:EdgeProperties.java   
public void setGuard(SWTBotGefEditPart part, String script) {
    selectPart(part);
    selectTab(part, GUARD);
    SWTBotStyledText st = bot.styledTextWithId(WIDGET_ID, WIDGET_GUARD_SCRIPT);
    st.setText(script);
    UIThreadRunnable.syncExec(Display.getDefault(), new VoidResult() {
        @Override
        public void run() {
            st.widget.notifyListeners(SWT.FocusOut, null);
            editor.setFocus();
        }
    });
}
项目:gw4e.project    文件:EdgeProperties.java   
public void setAction(SWTBotGefEditPart part, String script) {
    selectPart(part);
    selectTab(part, ACTION);
    SWTBotStyledText st = bot.styledTextWithId(WIDGET_ID, WIDGET_ACTION_SCRIPT);
    st.setText(script);
    UIThreadRunnable.syncExec(Display.getDefault(), new VoidResult() {
        @Override
        public void run() {
            st.widget.notifyListeners(SWT.FocusOut, null);
            editor.setFocus();
        }
    });
}
项目:gw4e.project    文件:GW4EProject.java   
public   void asyncPrint(final List<MenuItem> list) {
    UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() {
        public void run() {
            for (MenuItem menuItem : list) {
                System.out.println(menuItem.getText());
            }
        }
    });

}
项目:eclemma    文件:DumpExecutionDataTest.java   
private static void openCoverageView() {
    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            try {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                        .showView("org.eclipse.eclemma.ui.CoverageView");
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
private static boolean treeItemHasText(final TreeItem widget) {
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      TreeItem[] items = widget.getItems();
      for (TreeItem item : items) {
        if (item.getText() == null || item.getText().isEmpty()) {
          return false;
        }
      }
      return true;
    }
  });
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * Helper method to check whether a given tree is expanded which can be called from any thread.
 */
private static boolean isTreeExpanded(final TreeItem tree) {
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      return tree.getExpanded();
    }
  });
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
private static void printTree(final TreeItem tree) {
  UIThreadRunnable.syncExec(new VoidResult() {
    @Override
    public void run() {
      System.err.println(String.format("%s has %d items:", tree.getText(), tree.getItemCount()));
      for (TreeItem item : tree.getItems()) {
        System.err.println(String.format("  - %s", item.getText()));
      }
    }
  });
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * Gets the item matching the given name from a tree item.
 * 
 * @param widget the tree item to search
 * @param nodeText the text on the node
 * @return the child tree item with the specified text
 */
public static TreeItem getTreeItem(final TreeItem widget, final String nodeText) {
  return UIThreadRunnable.syncExec(new WidgetResult<TreeItem>() {
    @Override
    public TreeItem run() {
      TreeItem[] items = widget.getItems();
      for (TreeItem item : items) {
        if (item.getText().equals(nodeText)) {
          return item;
        }
      }
      return null;
    }
  });
}
项目:mesfavoris    文件:GetLinkedBookmarksOperationTest.java   
private IEditorPart openEditor(IPath path) throws PartInitException {
    return UIThreadRunnable.syncExec(() -> {
        try {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
            return IDE.openEditor(window.getActivePage(), workspaceRoot.getFile(path));
        } catch (PartInitException e) {
            throw new RuntimeException(e);
        }
    });
}
项目:mesfavoris    文件:CopyBookmarkOperationTest.java   
private String getClipboardContents() {
    return UIThreadRunnable.syncExec(() -> {
        Clipboard clipboard = new Clipboard(null);
        String textData;
        try {
            TextTransfer textTransfer = TextTransfer.getInstance();
            textData = (String) clipboard.getContents(textTransfer);
            return textData;
        } finally {
            clipboard.dispose();
        }
    });
}
项目:mesfavoris    文件:PasteBookmarkOperationTest.java   
public void copyToClipboard(Object data, Transfer transfer) {
    UIThreadRunnable.syncExec(() -> {
        Clipboard clipboard = new Clipboard(null);
        try {
            Transfer[] transfers = new Transfer[] { transfer };
            Object[] contents = new Object[] { data };
            clipboard.setContents(contents, transfers);
        } finally {
            clipboard.dispose();
        }
    });
}
项目:mesfavoris    文件:SWTBotViewHelper.java   
public static IViewPart showView(final String viewId) {
    return UIThreadRunnable.syncExec(() -> {
        try {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewPart viewPart = activePage.showView(viewId);
            return viewPart;
        } catch (PartInitException e) {
            throw new RuntimeException(e);
        }
    });
}
项目:mesfavoris    文件:AbstractDialogTest.java   
protected void openDialog(Function<Shell, Dialog> dialogCreator) {
    UIThreadRunnable.syncExec(() -> {
        Shell parentShell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
        Dialog dialog = dialogCreator.apply(parentShell);
        dialog.setBlockOnOpen(false);
        dialog.open();
        shellText = dialog.getShell().getText();
    });
    bot.shell(shellText).activate();
}
项目:mesfavoris    文件:SWTBotEditorHelper.java   
public static void closeEditor(IEditorPart editor) {
    IWorkbenchPartSite site;
    IWorkbenchPage page;
    if (editor != null && (site= editor.getSite()) != null && (page= site.getPage()) != null) {
        UIThreadRunnable.syncExec(()->page.closeEditor(editor, false));
    }
}
项目:mesfavoris    文件:CopyBookmarkUrlHandlerTest.java   
private void executeHandler(IHandler handler, ExecutionEvent event) {
    UIThreadRunnable.syncExec(()->{
        try {
            return handler.execute(event);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    });
}
项目:mesfavoris    文件:CopyBookmarkUrlHandlerTest.java   
private String getClipboardContents() {
    return UIThreadRunnable.syncExec(() -> {
        Clipboard clipboard = new Clipboard(null);
        String textData;
        try {
            TextTransfer textTransfer = TextTransfer.getInstance();
            textData = (String) clipboard.getContents(textTransfer);
            return textData;
        } finally {
            clipboard.dispose();
        }
    });
}
项目:mesfavoris    文件:CommitEditorBookmarkPropertiesProviderTest.java   
private IEditorPart openCommitEditor(RepositoryCommit repositoryCommit) {
    return UIThreadRunnable.syncExec(() -> {
        try {
            return CommitEditor.open(repositoryCommit);
        } catch (PartInitException e) {
            throw new RuntimeException(e);
        }
    });
}
项目:dsl-devkit    文件:FixedDefaultWorkbench.java   
/**
 * Reset active perspective.
 *
 * @return the fixed default workbench
 */
FixedDefaultWorkbench resetActivePerspective() {
  UIThreadRunnable.syncExec(new VoidResult() {
    @Override
    public void run() {
      activePage().resetPerspective();
    }
  });
  return this;
}
项目:dsl-devkit    文件:FixedDefaultWorkbench.java   
private IWorkbenchWindow getActiveWorkbenchWindow() {
  return UIThreadRunnable.syncExec(bot.getDisplay(), new Result<IWorkbenchWindow>() {
    @Override
    public IWorkbenchWindow run() {
      return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    }
  });
}
项目:dsl-devkit    文件:WaitForTable.java   
/** {@inheritDoc} */
@Override
protected java.util.List<TableItem> findMatches() {
  return UIThreadRunnable.syncExec(new ListResult<TableItem>() {
    @Override
    public java.util.List<TableItem> run() {
      return new ArrayList<TableItem>(Arrays.asList(parent.getItems()));
    }
  });
}
项目:dsl-devkit    文件:WaitForTree.java   
/** {@inheritDoc} */
@Override
protected java.util.List<TreeItem> findMatches() {
  return UIThreadRunnable.syncExec(new ListResult<TreeItem>() {
    @Override
    public java.util.List<TreeItem> run() {
      return new ArrayList<TreeItem>(Arrays.asList(parent.getItems()));
    }
  });
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * 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;
      }
    }
  });
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Returns the {@link SWTBotMenu}s available on the given widget bot.
 *
 * @param widgetBot
 *          the bot representing the widget, whose {@link SWTBotMenu}s should be returned
 * @return the {@link SWTBotMenu}s on the given widget bot
 */
public static List<SWTBotMenu> getContextMenuItems(final AbstractSWTBot<? extends Control> widgetBot) {
  return UIThreadRunnable.syncExec(new Result<List<SWTBotMenu>>() {
    @Override
    public List<SWTBotMenu> run() {
      List<SWTBotMenu> menuItems = Lists.newArrayList();
      for (MenuItem menuItem : new ContextMenuFinder(widgetBot.widget).findMenus(widgetBot.widget.getShell(), WidgetMatcherFactory.widgetOfType(MenuItem.class), true)) {
        menuItems.add(new SWTBotMenu(menuItem));
      }
      return menuItems;
    }
  });
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Returns the disabled {@link SWTBotMenu}s on the given widget bot.
 *
 * @param widgetBot
 *          the bot representing the widget, whose disabled {@link SWTBotMenu}s should be returned
 * @return the disabled {@link SWTBotMenu}s on the given widget bot
 */
public static List<SWTBotMenu> getDisabledContextMenuItems(final AbstractSWTBot<? extends Control> widgetBot) {
  return UIThreadRunnable.syncExec(new Result<List<SWTBotMenu>>() {
    @Override
    public List<SWTBotMenu> run() {
      List<SWTBotMenu> disabledMenuItems = Lists.newArrayList();
      for (MenuItem menuItem : new ContextMenuFinder(widgetBot.widget).findMenus(widgetBot.widget.getShell(), WidgetMatcherFactory.widgetOfType(MenuItem.class), true)) {
        if (!menuItem.isEnabled()) {
          disabledMenuItems.add(new SWTBotMenu(menuItem));
        }
      }
      return disabledMenuItems;
    }
  });
}