Java 类org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot 实例源码

项目:dsl-devkit    文件:SwtWorkbenchBot.java   
/**
 * Checks that the given function can supply a widget without throwing a {@link WidgetNotFoundException}.
 *
 * @param widgetNotFoundExceptionThrower
 *          the supplier function, must not be {@code null}
 * @return {code true} if the function executes without throwing a {@link WidgetNotFoundException}, {@code false} otherwise
 */
private boolean widgetNotFoundExceptionToBoolean(final Supplier<? extends AbstractSWTBot<? extends Widget>> widgetNotFoundExceptionThrower) {
  try {
    widgetNotFoundExceptionThrower.get();
  } catch (WidgetNotFoundException e) {
    return false;
  }
  return true;
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Clicks the context menu matching the given labels.
 * When a context menu 'Compile' exists with the sub context menu 'All Invalids',
 * then the context menu 'All Invalids' can be clicked by 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
 * @throw {@link WidgetNotFoundException} if the context menu could not be found
 */
public static void clickContextMenu(final AbstractSWTBot<? extends Control> bot, final String... labels) {
  MenuItem menuItem = getContextMenuItem(bot, labels);
  if (menuItem == null) {
    long endTime = System.currentTimeMillis() + SWTBotPreferences.TIMEOUT;
    while (menuItem == null && System.currentTimeMillis() < endTime) {
      SWTUtils.sleep(SWTBotPreferences.DEFAULT_POLL_DELAY);
      menuItem = getContextMenuItem(bot, labels);
    }
    if (menuItem == null) {
      throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(labels));
    }
  }
  click(menuItem);
}
项目: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;
    }
  });
}
项目: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();
    }
  });
}
项目:gwt-eclipse-plugin    文件:ActiveWidgetCondition.java   
public static ICondition widgetMakeActive(final AbstractSWTBot<? extends Widget> widget) {
  return new ActiveWidgetCondition(widget);
}
项目:gwt-eclipse-plugin    文件:ActiveWidgetCondition.java   
protected ActiveWidgetCondition(AbstractSWTBot<? extends Widget> widget) {
  this.widget = widget;
}
项目:dsl-devkit    文件:ContextActionUiTestUtil.java   
/**
 * Whether on the given {@link AbstractSWTBot} a context menu with the given labels is available.
 * When one wants to find out, whether a context menu 'Compile' with the sub context menu 'All Invalids' exists,
 * then one has to provide the labels 'Compile' and 'All Invalids'.
 *
 * @param widgetBot
 *          the bot representing the widget on which it should be checked, whether a the context menu
 *          with the given text is available
 * @param labels
 *          the labels on the context menus
 * @return {@code true} if on the given widget bot a context menu with the given text is available, else {@code false}
 */
public static boolean hasContextMenuItem(final AbstractSWTBot<? extends Control> widgetBot, final String... labels) {
  return getContextMenuItem(widgetBot, labels) != null;
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a drag and drop operation from this widget to the given target.
 * The drag start location will be chosen depending on this widget's default
 * implementation.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          To perform the drop on
 * @see #dragAndDrop(Point)
 */
// TODO add modifier key mask
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final AbstractSWTBot<? extends Widget> target) {
  dragAndDrop(source, on(target));
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a drag and drop operation from this widget to the target editor.
 * The drag start location will be chosen depending on this widget's default
 * implementation.
 * The exact drop position is calculated through the StyledText contained by the editor.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          Editor to perform the drop on
 * @see #dragAndDrop(Point)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final SWTBotEclipseEditor target) {
  if (target != null) {
    dragAndDrop(source, on(target.getStyledText()));
  }
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a drag and drop operation from this widget to the given target
 * at the given location from target origin. The drag start location will be
 * chosen depending on this widget's default implementation.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          To perform the drop on
 * @param locationOnTarget
 *          The target locations, from target origin, where the DND shall
 *          finish.
 * @see #dragAndDrop(Point)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final AbstractSWTBot<? extends Widget> target, final Point locationOnTarget) {
  Rectangle targetRectangle = absoluteLocation(target);
  Point dropTarget = new Point(targetRectangle.x + locationOnTarget.x, targetRectangle.y + locationOnTarget.y);
  dragAndDrop(source, dropTarget);
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a drag and drop operation from this widget to the given target
 * at the given location from target origin. The drag start location will be
 * chosen depending on this widget's default implementation.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          To perform the drop on
 * @param locationOnTarget
 *          The target locations, from target origin, where the DND shall
 *          finish.
 * @see #dragAndDrop(Point)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final AbstractSWTBot<? extends Widget> target, final org.eclipse.draw2d.geometry.Point locationOnTarget) {
  dragAndDrop(source, target, new Point(locationOnTarget.x, locationOnTarget.y));
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a DND operation to an arbitrary location. The drag start
 * location will be chosen depending on this widget's default
 * implementation.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          The target locations where the DND shall finish.
 * @see #before(AbstractSWTBot)
 * @see #on(AbstractSWTBot)
 * @see #after(AbstractSWTBot)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final Point target) {
  final Rectangle sourceLocation = absoluteLocation(source);
  final Point slightOffset = Geometry.add(Geometry.getLocation(sourceLocation), new Point(DRAG_THRESHOLD, DRAG_THRESHOLD));
  doDragAndDrop(Geometry.min(Geometry.centerPoint(sourceLocation), slightOffset), target);
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Performs a DND operation starting at an arbitrary location, targeting the
 * given widget.
 *
 * @param source
 *          From where to start dragging
 * @param target
 *          Where to drop onto
 * @see #dragAndDrop(AbstractSWTBot)
 * @see #dragAndDrop(Point)
 */
protected void dragAndDrop(final Point source, final AbstractSWTBot<? extends Widget> target) {
  doDragAndDrop(source, on(target));
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Calculates a position which can be used to insert an item <em>before</em> the given one by a DND operation.
 *
 * @param targetItem
 *          Before which the new item shall appear
 * @param <T>
 *          .
 * @return A point suitable to drop an item before {@code targetItem}
 * @see #dragAndDrop(Point)
 * @see org.eclipse.swt.dnd.DND#FEEDBACK_INSERT_BEFORE
 */
public static <T extends Widget> Point before(final AbstractSWTBot<T> targetItem) {
  return pointOnUpperBorder(absoluteLocation(targetItem));
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Calculates a position which can be used to drop something <em>onto</em> the given widget by a DND operation. For tree structures, this will most
 * likely result in another child node being added. But how this is handled
 * in detail ultimately depends on the "drop action"'s implementation.
 *
 * @param targetItem
 *          On which to drop
 * @param <T>
 *          .
 * @return The {@code targetItem}'s center
 * @see #dragAndDrop(Point)
 * @see org.eclipse.swt.dnd.DND#FEEDBACK_SELECT
 */
@SuppressWarnings("PMD.ShortMethodName")
public static <T extends Widget> Point on(final AbstractSWTBot<T> targetItem) {
  return Geometry.centerPoint(absoluteLocation(targetItem));
}
项目:dsl-devkit    文件:DragAndDropUtil.java   
/**
 * Calculates a position which can be used to insert an item after the given
 * one by a DND operation.
 *
 * @param targetItem
 *          After which the new item shall appear
 * @param <T>
 *          .
 * @return A point suitable to drop an item after {@code targetItem}
 * @see #dragAndDrop(Point)
 * @see org.eclipse.swt.dnd.DND#FEEDBACK_INSERT_AFTER
 */
public static <T extends Widget> Point after(final AbstractSWTBot<T> targetItem) {
  return pointOnLowerBorder(absoluteLocation(targetItem));
}