Java 类org.eclipse.swtbot.swt.finder.results.Result 实例源码

项目: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    文件: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());
    }
  }));
}
项目: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();
    }
  });
}
项目: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    文件: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;
    }
  });
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Whether the context menu with the given labels is enabled.
 *
 * @param widgetBot
 *          the bot representing the widget on which it should be checked, whether the context menu
 *          with the given labels is enabled
 * @param labels
 *          the labels on the context menus
 * @return {@code true} if the context menu is enabled, else {@code false}
 * @throw {@link WidgetNotFoundException} if the context menu could not be found
 */
public static boolean isEnabled(final AbstractSWTBot<? extends Control> widgetBot, final String... labels) {
  final MenuItem menuItem = getContextMenuItem(widgetBot, labels);
  if (menuItem == null) {
    throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(labels));
  }
  return UIThreadRunnable.syncExec(new Result<Boolean>() {
    @Override
    public Boolean run() {
      return menuItem.isEnabled();
    }
  });
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
@Override
protected Rectangle absoluteLocation() {
  return UIThreadRunnable.syncExec(new Result<Rectangle>() {
    @Override
    public Rectangle run() {
      return display.map(widget.getParent(), null, widget.getBounds());
    }
  });
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
@Override
protected Rectangle absoluteLocation() {
  return UIThreadRunnable.syncExec(new Result<Rectangle>() {
    @Override
    public Rectangle run() {
      return display.map(widget.getParent(), null, widget.getBounds());
    }
  });
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
@Override
protected Rectangle absoluteLocation() {
  return UIThreadRunnable.syncExec(new Result<Rectangle>() {
    @Override
    public Rectangle run() {
      return display.map(widget.getParent(), null, widget.getBounds());
    }
  });
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
@Override
protected Rectangle absoluteLocation() {
  return UIThreadRunnable.syncExec(new Result<Rectangle>() {
    @Override
    public Rectangle run() {
      return display.map(widget.getParent(), null, widget.getBounds());
    }
  });
}
项目:dsl-devkit    文件:ClipboardUiTestUtil.java   
/**
 * 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());
    }
  });
}
项目:dsl-devkit    文件:CoreSwtbotTools.java   
/**
 * 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());
    }
  });
}
项目:dsl-devkit    文件:AbstractXtextUiTest.java   
/**
 * 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;
}
项目:dsl-devkit    文件:AbstractSyntaxColoringTest.java   
/**
 * Retrieves the {@link StyleRange} found at a given offset in the given {@link XtextEditor}.
 *
 * @param editor
 *          the {@link XtextEditor}
 * @param offset
 *          the position for which to retrieve the {@link StyleRange}
 * @return the {@link StyleRange} found at the given offset
 */
public static StyleRange getStyleRange(final XtextEditor editor, final int offset) {
  StyleRange styleRange = UIThreadRunnable.syncExec(new Result<StyleRange>() {
    @Override
    public StyleRange run() {
      StyledText styledText = editor.getInternalSourceViewer().getTextWidget();
      return styledText.getStyleRangeAtOffset(offset);
    }
  });
  if (styleRange == null) {
    // if no style range was found, then the default style is used
    return createStyleRange(offset, 1, createTextAttribute(TEXT_STYLE_DEFAULT));
  }
  return styleRange;
}
项目:dsl-devkit    文件:AbstractHyperlinkHelperTest.java   
/**
 * Retrieves the hyperlinks found in a given source at a given offset.
 *
 * @param resource
 *          the resource in which to look for hyperlinks, must not be {@code null}
 * @param offset
 *          the position at which to look for hyperlinks
 * @return a list of hyperlinks, never {@code null}
 */
protected List<IHyperlink> getOffsetHyperlinks(final XtextResource resource, final int offset) {
  IHyperlink[] hyperlinks = UIThreadRunnable.syncExec(new Result<IHyperlink[]>() {
    @Override
    public IHyperlink[] run() {
      return getTestUtil().get(IHyperlinkHelper.class).createHyperlinksByOffset(resource, offset, true);
    }
  });
  return hyperlinks != null ? Arrays.asList(hyperlinks) : new ArrayList<IHyperlink>();
}
项目:gwt-eclipse-plugin    文件:SwtBotTreeActions.java   
private static boolean doesTreeItemHaveText(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().length() == 0) {
          return false;
        }
      }
      return true;
    }
  });
}
项目:gwt-eclipse-plugin    文件:SwtBotTreeActions.java   
/**
 * 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();
    }
  });
}