org.eclipse.swtbot.swt.finder.utils.SWTUtils Java Examples

The following examples show how to use org.eclipse.swtbot.swt.finder.utils.SWTUtils. 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: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
    }
  });
}
 
Example #2
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open the preferences dialog and return the corresponding shell. See also
 * {@link #pressOKishButtonInPreferences(SWTBot)} to close the dialog.
 *
 * @param bot
 *            a given workbench bot
 * @param text
 *            an alternative text for the preferences dialog, useful when a
 *            specific preference page was previously selected
 * @return the preferences shell
 */
public static SWTBotShell openPreferences(SWTBot bot, String text) {
    SWTBotShell mainShell = focusMainWindow(bot.shells());
    if (SWTUtils.isMac()) {
        // On Mac, the Preferences menu item is under the application name.
        // For some reason, we can't access the application menu anymore so
        // we use the keyboard shortcut.
        try {
            mainShell.pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
        } catch (ParseException e) {
            fail();
        }
    } else {
        mainShell.bot().menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
    }

    if (text != null) {
        return anyShellOf(bot, PREFERENCES_SHELL, text).activate();
    }
    return bot.shell(PREFERENCES_SHELL).activate();
}
 
Example #3
Source File: TestTraceOffsetting.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static MacOsVersion getMacOsVersion() {
    if (fRunningMacOsVersion != null) {
        return fRunningMacOsVersion;
    }

    if (!SWTUtils.isMac()) {
        return null;
    }

    String osVersion = System.getProperty("os.version");
    if (osVersion == null) {
        return null;
    }
    Matcher matcher = MAC_OS_VERSION_PATTERN.matcher(osVersion);
    if (matcher.matches()) {
        try {
            fRunningMacOsVersion = new MacOsVersion(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)));
            return fRunningMacOsVersion;
        } catch (NumberFormatException e) {
            // ignore
        }
    }
    return null;
}
 
Example #4
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: SwtBotButton.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc} A customized version with less notifications, since the button could be disabled after the {@link SWT.Selection} event.
 */
@Override
public SwtBotButton click() {
  log.debug(MessageFormat.format("Clicking on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
  waitForEnabled();
  notify(SWT.MouseEnter);
  notify(SWT.MouseMove);
  notify(SWT.Activate);
  notify(SWT.FocusIn);
  notify(SWT.MouseDown);
  notify(SWT.MouseUp);
  notify(SWT.Selection);
  log.debug(MessageFormat.format("Clicked on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
  return this;
}
 
Example #6
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Press the keyboard shortcut that goes to the top of a tree widget. The
 * key combination can differ on different platforms.
 *
 * @param keyboard
 *            the keyboard to use
 */
public static void pressShortcutGoToTreeTop(Keyboard keyboard) {
    if (SWTUtils.isMac()) {
        pressShortcut(keyboard, Keystrokes.ALT, Keystrokes.UP);
    } else {
        pressShortcut(keyboard, Keystrokes.HOME);
    }
}
 
Example #7
Source File: FindDialogTestBase.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void openDialog(SWTBotView view) {
    SWTBotCanvas canvas = view.bot().canvas(1);
    view.setFocus();
    canvas.pressShortcut(Keystrokes.HOME);
    if (SWTUtils.isMac()) {
        canvas.pressShortcut(Keystrokes.COMMAND, KeyStroke.getInstance('F'));
    } else {
        canvas.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance('F'));
    }
    fBot.shell(DIALOG_TITLE).activate();
}
 
Example #8
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void selectCurrentLine() throws RemoteException {
  widget.selectCurrentLine();
  // It's is necessary to sleep a litte time so that the following
  // operation like quickfix will be successfully performed.
  SWTUtils.sleep(500);
}
 
Example #9
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void selectLine(int line) throws RemoteException {
  widget.selectLine(line);
  // It's is necessary to sleep a litte time so that the following
  // operation like quickfix will be successfully performed.
  SWTUtils.sleep(1000);
}
 
Example #10
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void selectRange(int line, int column, int length) throws RemoteException {
  widget.selectRange(line, column, length);
  // It's is necessary to sleep a litte time so that the following
  // operation like quickfix will be successfully performed.
  SWTUtils.sleep(800);
}
 
Example #11
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void pressShortRunAsJavaApplication() throws RemoteException {
  if (WidgetUtil.getOperatingSystem() == WidgetUtil.OperatingSystem.MAC)
    widget.pressShortcut(SWT.ALT | SWT.COMMAND, 'x');
  else widget.pressShortcut(SWT.ALT | SWT.SHIFT, 'x');

  SWTUtils.sleep(1000);

  widget.pressShortcut(SWT.NONE, 'j');
}
 
Example #12
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void pressShortCutNextAnnotation() throws RemoteException {
  if (WidgetUtil.getOperatingSystem() == WidgetUtil.OperatingSystem.MAC)
    widget.pressShortcut(SWT.COMMAND, '.');
  else widget.pressShortcut(SWT.CTRL, '.');

  SWTUtils.sleep(100);
}
 
Example #13
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void pressShortCutQuickAssignToLocalVariable() throws RemoteException {
  if (WidgetUtil.getOperatingSystem() == WidgetUtil.OperatingSystem.MAC)
    widget.pressShortcut(SWT.COMMAND, '2');
  else widget.pressShortcut(SWT.CTRL, '2');

  SWTUtils.sleep(1000);

  widget.pressShortcut(SWT.NONE, 'l');
}
 
Example #14
Source File: DragAndDropUtil.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Performs the drag and drop from source {@link Point} to destination {@link Point}.
 *
 * @param source
 *          the source {@link Point} to start dragging
 * @param dest
 *          the destination {@link Point} for dropping
 */
private void doDragAndDrop(final Point source, final Point dest) {
  // log.debug(MessageFormat.format("Drag-and-dropping from ({0},{1}) to ({2},{3})",
  // source.x, source.y, dest.x, dest.y));
  try {
    final Robot awtRobot = new Robot();
    // the x+10 motion is needed to let native functions register a drag
    // detect. It did not work under Windows
    // otherwise and has been reported to be required for linux, too.
    // But I could not test that.
    syncExec(new VoidResult() {
      @Override
      public void run() {
        awtRobot.mouseMove(source.x, source.y);
        awtRobot.mousePress(InputEvent.BUTTON1_MASK);
        awtRobot.mouseMove(source.x + DRAG_THRESHOLD, source.y);
      }
    });

    /* drag delay */
    SWTUtils.sleep(DRAG_DELAY);

    syncExec(new VoidResult() {
      @Override
      public void run() {
        awtRobot.mouseMove(dest.x + DRAG_THRESHOLD, dest.y);
        awtRobot.mouseMove(dest.x, dest.y);
      }
    });

    /* drop delay */
    SWTUtils.sleep(DRAG_DELAY);

    syncExec(new VoidResult() {
      @Override
      public void run() {
        awtRobot.mouseRelease(InputEvent.BUTTON1_MASK);
      }
    });
  } catch (final AWTException e) {
    // log.error(e.getMessage(), e);
    throw new IllegalStateException(e);
  }
}