/** * Selects specified text in specified opened editor, shows open on options via selecting Navigate * -> Open Hyperlink and select one of them specified by openOnOption * * @param bot * @param editorTitle * @param textToSelect * @param selectionOffset * @param selectionLength * @param textToSelectIndex * @param openOnOption */ public static SWTBotEditor selectOpenOnOption( SWTBotExt bot, String editorTitle, String textToSelect, int selectionOffset, int selectionLength, int textToSelectIndex, String openOnOption) { showOpenOnOptions( bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex); SWTBotTable table = bot.activeShell().bot().table(0); boolean optionFound = false; String foundOptions = ""; for (int i = 0; i < table.rowCount(); i++) { String foundOption = table.getTableItem(i).getText(); foundOptions = foundOptions + foundOption + ", "; if (foundOption.contains(openOnOption)) { optionFound = true; table.click(i, 0); break; } } foundOptions = foundOptions.substring(0, foundOptions.length() - 3); assertTrue( openOnOption + " was not found in open on options of " + textToSelect + " Found: " + foundOptions, optionFound); return bot.activeEditor(); }
/** * Returns true if runtimeName Server Runtime is defined * * @param bot * @param runtimeName * @return */ public static boolean isServerRuntimeDefined(SWTWorkbenchBot bot, String runtimeName) { boolean serverRuntimeNotDefined = true; bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click(); bot.shell(IDELabel.Shell.PREFERENCES).activate(); bot.tree() .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP) .select(PreferencesDialog.RUNTIME_ENVIRONMENTS); SWTBotTable tbRuntimeEnvironments = bot.table(); int numRows = tbRuntimeEnvironments.rowCount(); if (numRows > 0) { int currentRow = 0; while (serverRuntimeNotDefined && currentRow < numRows) { if (tbRuntimeEnvironments.cell(currentRow, 0).equalsIgnoreCase(runtimeName)) { serverRuntimeNotDefined = false; } else { currentRow++; } } } bot.button(IDELabel.Button.OK).click(); return !serverRuntimeNotDefined; }
/** * Returns string representing version of defined Server Runtime on rowIndex position in Defined * Server Runtime table * * @param bot * @param rowIndex * @return null when no server runtime is specified, "unknown when not possible to determine * server runtime version" or server runtime version */ public static String getDefinedServerRuntimeVersion(SWTWorkbenchBot bot, int rowIndex) { String result = null; bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click(); bot.shell(IDELabel.Shell.PREFERENCES).activate(); bot.tree() .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP) .select(PreferencesDialog.RUNTIME_ENVIRONMENTS); SWTBotTable serverRuntimesTable = bot.table(); if (serverRuntimesTable.rowCount() > rowIndex) { String[] splitServerRuntimeType = serverRuntimesTable.cell(rowIndex, 1).split(" "); int index = 0; while (index < splitServerRuntimeType.length && result == null) { if (splitServerRuntimeType[index].length() > 0 && splitServerRuntimeType[index].charAt(0) >= '0' && splitServerRuntimeType[index].charAt(0) <= '9') { result = splitServerRuntimeType[index].trim(); } else { index++; } } } bot.button(IDELabel.Button.OK).click(); return result; }
public boolean selectSDK(File home) throws IOException { String path = home.getPath(); int count = sdks.rowCount(); for (int row = 0; row < count; ++row) { SWTBotTableItem item = sdks.getTableItem(row); if (path.equals(item.getText(2))) { item.check(); return true; } } return false; }
/** * @param table * @param object * @return the table item corresponding to the object */ private SWTBotTableItem getTableItem(SWTBotTable table, EObject object) { for (int i = 0; i < table.rowCount(); i++) { final SWTBotTableItem tableItem = table.getTableItem(i); final Object data = syncExec( new Result<Object>() { public Object run() { return tableItem.widget.getData(); } }); if (data.equals(object)) { return table.getTableItem(i); } } return null; }