org.eclipse.swtbot.swt.finder.results.VoidResult Java Examples

The following examples show how to use org.eclipse.swtbot.swt.finder.results.VoidResult. 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: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open a view by id and secondary id
 *
 * @param id
 *            view id.
 * @param secondaryId
 *            The secondary ID
 */
public static void openView(final String id, final @Nullable String secondaryId) {
    final PartInitException res[] = new PartInitException[1];
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            try {
                if (secondaryId == null) {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id);
                } else {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
                }
            } catch (PartInitException e) {
                res[0] = e;
            }
        }
    });
    if (res[0] != null) {
        fail(res[0].getMessage());
    }
    WaitUtils.waitForJobs();
}
 
Example #2
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the text of the combo box.
 * 
 * @param text the text to set.
 * @since 1.0
 */
public void setText(final String text) {
	log.debug(MessageFormat.format("Setting text on {0} to {1}", this, text)); //$NON-NLS-1$
	waitForEnabled();

	if (hasStyle(widget, SWT.READ_ONLY))
		throw new RuntimeException("This combo box is read-only."); //$NON-NLS-1$

	asyncExec(new VoidResult() {
		public void run() {
			widget.setText(text);
		}
	});
	notify(SWT.Modify);
	log.debug(MessageFormat.format("Set text on {0} to {1}", this, text)); //$NON-NLS-1$
}
 
Example #3
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the selection to the given text.
 * 
 * @param text The text to select.
 */
private void _setSelection(final String text) {
	final int indexOf = syncExec(new IntResult() {
		public Integer run() {
			String[] items = widget.getItems();
			return Arrays.asList(items).indexOf(text);
		}
	});
	if (indexOf == -1)
		throw new RuntimeException("Item `" + text + "' not found in combo box."); //$NON-NLS-1$ //$NON-NLS-2$
	asyncExec(new VoidResult() {
		public void run() {
			widget.select(indexOf);
		}
	});
}
 
Example #4
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Scroll to bottom.
 */
public void scrollToBottom() {
    UIThreadRunnable.syncExec(new VoidResult() {

        @Override
        public void run() {
            final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) gmfEditor.getReference().getEditor(false);
            final FigureCanvas canvas = (FigureCanvas) processEditor.getDiagramGraphicalViewer().getControl();
            Point current;
            Point next = canvas.getViewport().getViewLocation();
            do {
                current = next.getCopy();
                canvas.getViewport().setVerticalLocation(current.y + 10);
                next = canvas.getViewport().getViewLocation();
            } while (!current.equals(next));
        }
    });
}
 
Example #5
Source File: ContextMenuHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
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() {
          menuItem.notifyListeners(SWT.Selection, event);
        }
      });
}
 
Example #6
Source File: ContextMenuHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if the context menu item matching the text nodes exists.
 *
 * @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
 * @return <tt>true</tt> if the context menu item exists, <tt>false</tt> otherwise
 */
public static boolean existsContextMenu(
    final AbstractSWTBot<? extends Control> bot, final String... nodes) {

  final MenuItem menuItem = getMenuItemWithRegEx(bot, quote(nodes));

  // hide
  if (menuItem != null) {
    UIThreadRunnable.syncExec(
        new VoidResult() {
          @Override
          public void run() {
            hide(menuItem.getParent());
          }
        });
    return true;
  }
  return false;
}
 
Example #7
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 #8
Source File: SarosSWTBotChatInput.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public SarosSWTBotChatInput pressEnterKey() {
  // the ChatControl key listener ignores the mock keyboard event
  // styledText.pressShortcut(Keystrokes.CR);
  syncExec(
      new VoidResult() {
        @Override
        public void run() {
          try {
            String message = styledText.widget.getText().trim();

            ChatControl control = (ChatControl) widget.getParent().getParent();

            Method sendChatMessageMethod =
                ChatControl.class.getDeclaredMethod("sendMessage", new Class<?>[] {String.class});

            sendChatMessageMethod.setAccessible(true);

            sendChatMessageMethod.invoke(control, message);
          } catch (Exception e) {
            log.error("sending chat message failed", e);
          }
        }
      });
  return this;
}
 
Example #9
Source File: ImportAndReadKernelSmokeTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static IViewPart getViewPart(final String viewTile) {
    final IViewPart[] vps = new IViewPart[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)) {
                    vps[0] = vp;
                    return;
                }
            }
        }
    });

    return vps[0];
}
 
Example #10
Source File: AbstractStandardImportWizardTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open the import wizard
 */
public void openImportWizard() {
    fWizard = new ImportTraceWizard();

    UIThreadRunnable.asyncExec(new VoidResult() {
        @Override
        public void run() {
            final IWorkbench workbench = PlatformUI.getWorkbench();
            // Fire the Import Trace Wizard
            if (workbench != null) {
                final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                Shell shell = activeWorkbenchWindow.getShell();
                assertNotNull(shell);
                ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
                WizardDialog dialog = new WizardDialog(shell, fWizard);
                dialog.open();
            }
        }
    });

    fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
}
 
Example #11
Source File: SWTBotTimeGraphEntry.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected SWTBotRootMenu contextMenu(final Control control) throws WidgetNotFoundException {
    Rectangle bounds = absoluteLocation();
    if (bounds == null) {
        return null;
    }
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            final Event event = new Event();
            event.time = (int) System.currentTimeMillis();
            event.display = control.getDisplay();
            event.widget = control;
            event.x = bounds.x + widget.getTimeDataProvider().getNameSpace() / 2;
            event.y = bounds.y + bounds.height / 2;
            control.notifyListeners(SWT.MenuDetect, event);
        }
    });
    select();

    WaitForObjectCondition<Menu> waitForMenu = Conditions.waitForPopupMenu(control);
    new SWTBot().waitUntilWidgetAppears(waitForMenu);
    return new SWTBotRootMenu(waitForMenu.get(0));
}
 
Example #12
Source File: GuiUtils.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Changes to CDT project.
 * 
 * @param perspective
 *            The perspective to be changed to.
 * @param bot
 *            the workbench bot to be used.
 */
public static void changePerspectiveTo(String perspective, SWTWorkbenchBot bot) {
    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
        }
    });

    // Change the perspective via the Open Perspective dialog
    bot.menu(WINDOW_MENU).menu(PERSP_MENU).menu(OPEN_PERSP).menu(OTHER_MENU).click();
    SWTBotShell openPerspectiveShell = bot.shell(OPEN_PERSP);
    openPerspectiveShell.activate();

    // select the dialog
    bot.table().select(perspective);
    bot.button("Open").click();

}
 
Example #13
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Finds an editor and sets focus to the editor
 *
 * @param bot
 *            the workbench bot
 * @param editorName
 *            the editor name
 * @return the corresponding SWTBotEditor
 */
public static SWTBotEditor activateEditor(SWTWorkbenchBot bot, String editorName) {
    Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(editorName);
    final SWTBotEditor editorBot = bot.editor(matcher);
    IEditorPart iep = editorBot.getReference().getEditor(true);
    final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
    editorBot.show();
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            tmfEd.setFocus();
        }
    });

    WaitUtils.waitForJobs();
    activeEventsEditor(bot);
    assertNotNull(tmfEd);
    return editorBot;
}
 
Example #14
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 #15
Source File: ImportAndReadPcapTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static IViewPart getViewPart(final String viewTile) {
    final IViewPart[] vps = new IViewPart[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)) {
                    vps[0] = vp;
                    return;
                }
            }
        }
    });

    return vps[0];
}
 
Example #16
Source File: ImportAndReadPcapTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void openTrace() {
    final Exception exception[] = new Exception[1];
    exception[0] = null;
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            try {
                IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
                TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
                String absolutePath = (new File(pttt.getTrace().getPath())).getAbsolutePath();
                TmfOpenTraceHelper.openTraceFromPath(destinationFolder, absolutePath, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.eclipse.linuxtools.tmf.pcap.core.pcaptrace");
            } catch (CoreException e) {
                exception[0] = e;
            }
        }
    });
    if (exception[0] != null) {
        fail(exception[0].getMessage());
    }

    SWTBotUtils.delay(1000);
    WaitUtils.waitForJobs();
}
 
Example #17
Source File: RCPTestSetupHelper.java    From tlaplus with MIT License 6 votes vote down vote up
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;
			}
		}
	});
}
 
Example #18
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 #19
Source File: TestRunRecording.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@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();
  }
}
 
Example #20
Source File: TestRunRecording.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@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();
}
 
Example #21
Source File: AbstractUiTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens the editor asynchronously.
 *
 * @param file
 *          the file
 * @param editorId
 *          the editor id
 * @param activate
 *          true to activate, false otherwise
 */
protected void openEditorAsync(final IFile file, final String editorId, final boolean activate) {
  asyncExec(new VoidResult() {
    @Override
    public void run() {
      try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
        final int matchFlags = IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT;
        final IEditorInput input = new FileEditorInput(file);
        IEditorPart editor = activePage.openEditor(input, editorId, activate, matchFlags);
        editor.setFocus();
        waitForEditorJobs(editor);
      } catch (PartInitException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e.getMessage(), e);
        }
      }
    }
  });
}
 
Example #22
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 #23
Source File: StandardImportAndReadSmokeTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void openImportWizard() {
    fWizard = new ImportTraceWizard();

    UIThreadRunnable.asyncExec(new VoidResult() {
        @Override
        public void run() {
            final IWorkbench workbench = PlatformUI.getWorkbench();
            // Fire the Import Trace Wizard
            if (workbench != null) {
                final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                Shell shell = activeWorkbenchWindow.getShell();
                assertNotNull(shell);
                ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
                WizardDialog dialog = new WizardDialog(shell, fWizard);
                dialog.open();
            }
        }
    });

    fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
}
 
Example #24
Source File: AbstractImportAndReadSmokeTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets a view part based on view title
 *
 * @param viewTile
 *            a view title
 * @return the view part
 */
protected IViewPart getViewPart(final String viewTile) {
    final IViewPart[] vps = new IViewPart[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)) {
                    vps[0] = vp;
                    return;
                }
            }
        }
    });

    return vps[0];
}
 
Example #25
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Click on the table on given cell. This can be used to activate a cellEditor on a cell.
 *
 * @param row the row in the table.
 * @param column the column in the table.
 * @since 1.2
 */
public void doubleClick(final int row, final int column) {
	assertIsLegalCell(row, column);
	setFocus();
	asyncExec(new VoidResult() {
		public void run() {
			TableItem item = widget.getTable().getItem(row);
			Rectangle cellBounds = item.getBounds(column);
			// for some reason, it does not work without setting selection first
			widget.getTable().setSelection(row);
			doubleClickXY(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2));
		}
	});
}
 
Example #26
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Click on the table on given cell. This can be used to activate a cellEditor on a cell.
 *
 * @param row the row in the table.
 * @param column the column in the table.
 * @since 1.2
 */
public void click(final int row, final int column) {
	assertIsLegalCell(row, column);
	// for some reason, it does not work without setting selection first
	setFocus();
	select(row);
	asyncExec(new VoidResult() {
		public void run() {
			TableItem item = widget.getTable().getItem(row);
			Rectangle cellBounds = item.getBounds(column);
			clickXY(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2));
		}
	});
}
 
Example #27
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Does not clear previous selections.
 */
private void additionalSelectAndNotify(final int j) {
	assertIsLegalRowIndex(j);
	asyncExec(new VoidResult() {
		public void run() {
			lastSelectionItem = widget.getTable().getItem(j);
			widget.select(j);
		}
	});
	notifySelect();
}
 
Example #28
Source File: AbstractSwtBotTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeClass
public static void initialize() throws Exception {
	TargetPlatformUtil.setTargetPlatform(AbstractSwtBotTest.class);
	IResourcesSetupUtil.cleanWorkspace();
	UIThreadRunnable.syncExec(new VoidResult() {
		@Override
		public void run() {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
		}
	});
}
 
Example #29
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unselect all selections.
 */
public void unselect() {
	waitForEnabled();
	setFocus();
	asyncExec(new VoidResult() {
		public void run() {
			log.debug(MessageFormat.format("Unselecting all in {0}", widget)); //$NON-NLS-1$
			widget.getTable().deselectAll();
		}
	});
	notifySelect();
}
 
Example #30
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Scroll to top.
 */
public void scrollToTop() {
    UIThreadRunnable.syncExec(new VoidResult() {

        @Override
        public void run() {
            final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) gmfEditor.getReference().getEditor(false);
            final FigureCanvas canvas = (FigureCanvas) processEditor.getDiagramGraphicalViewer().getControl();
            canvas.getViewport().setVerticalLocation(0);
        }
    });
}