@Test public void testGetSelectedOption() throws WidgetException { wd.open(url); Select s = new Select(selectLocator); String selectedOption = s.getSelectedOption(); Assert.assertEquals("Car", selectedOption); }
@Test public void testGetSelectedOptions() throws WidgetException { wd.open(url); Select s = new Select(selectLocator); List<String> options = s.getSelectedOptions(); Assert.assertEquals("Car", options.get(0)); }
/** * Executes a SELECT statement. It is assumed that the argument is of the correct type. * * @param cs a CompiledStatement of type CompiledStatement.SELECT * @throws HsqlException if a database access error occurs * @return the result of executing the statement */ private Result executeSelectStatement(CompiledStatement cs) throws HsqlException { Select select = cs.select; Result result; if (select.sIntoTable != null) { // session level user rights session.checkDDLWrite(); if (session.getDatabase().findUserTable(session, select.sIntoTable.name) != null || session.getDatabase().dInfo.getSystemTable(session, select.sIntoTable.name) != null) { throw Trace.error(Trace.TABLE_ALREADY_EXISTS, select.sIntoTable.name); } result = select.getResult(session.getMaxRows(), session); result = session.dbCommandInterpreter.processSelectInto( result, select.sIntoTable, select.intoType); session.getDatabase().setMetaDirty(false); } else { result = select.getResult(session.getMaxRows(), session); } return result; }
@Test(expected = WidgetException.class) public void testSelectMultipleOptionsException() throws WidgetException { wd.open(url); Select s = new Select(brokeLocator); List<String> options = new ArrayList<String>(); s.selectMultipleOptions(options); }
@Override public Collection<? extends ComplexTypeMetadata> visit(Select select) { closure.addAll(select.getTypes()); if (select.getCondition() != null) { select.getCondition().accept(this); } return closure; }
private static void getSelectColumn(final Field field, final StringBuilder builder) throws Exception { final Select select = field.getAnnotation(Select.class); if (select != null) { final String columnName = (String) field.get(null); builder.append(String.format("%s as %s,", select.value(), columnName)); } }
private Select buildPairSelect() { IndexedContainer pairsCon = new IndexedContainer(); for (Pair pair : Pair.values()) { pairsCon.addItem(pair); } Select pairSelect = new Select("Select Pair"); pairSelect.setContainerDataSource(pairsCon); return pairSelect; }
@Test public void testDeselectAllOptions() throws WidgetException { wd.open(url); Select s = new Select(selectMultipleLocator); s.selectOption("Car"); s.selectOption("Truck"); s.deselectAllOptions(); Assert.assertEquals(null, s.getSelectedOption()); }
@Test public void testGetOptions() throws WidgetException { wd.open(url); Select s = new Select(selectLocator); List<String> options = s.getOptions(); Assert.assertEquals("Car", options.get(0)); Assert.assertEquals("Bike", options.get(1)); Assert.assertEquals("Truck", options.get(2)); Assert.assertEquals("Feet", options.get(3)); }
@Test public void testSelectMultipleOptions() throws WidgetException { wd.open(url); Select s = new Select(selectMultipleLocator); List<String> options = new ArrayList<String>(); options.add("Car"); options.add("Truck"); s.selectMultipleOptions(options); Assert.assertEquals(options, s.getSelectedOptions()); }
@SuppressWarnings("deprecation") private Form getRemoveForm(final String admin) { removeExperimentForm = new Form(); removeExperimentForm.setCaption("Remove Existing Experiment"); removeExperimentForm.setWidth("50%"); expList = eh.getExperiments(null); List<String> strExpList = new ArrayList<String>(); for (ExperimentBean exp : expList.values()) { if (user.getEmail().equalsIgnoreCase("*****@*****.**") || exp.getEmail().equalsIgnoreCase(user.getEmail())) { String str = exp.getExpId() + " " + exp.getName() + " ( " + exp.getUploadedByName() + " )"; strExpList.add(str); } } final Select selectExp = new Select("Experiment ID", strExpList); selectExp.setWidth("100%"); removeExperimentForm.addField(Integer.valueOf(1), selectExp); Button removeExpButton = new Button("Remove Experiment"); removeExpButton.setStyle(Reindeer.BUTTON_SMALL); removeExperimentForm.addField(Integer.valueOf(2), removeExpButton); removeExpButton.addListener( new ClickListener() { /** */ private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { String str = selectExp.getValue().toString(); String[] strArr = str.split("\t"); Integer expId = (Integer.valueOf(strArr[0])); if (expId != null) { boolean test = auth.removeExp(expId); if (test) { updateComponents(user); } else { getWindow().showNotification("Failed to Remove The Experiment! "); } } else { } } }); return removeExperimentForm; }
@Override public void visit(Select obj) { visitNodes(obj.getFrom()); visitNodes(obj.getDerivedColumns()); visitNode(obj.getWhere()); visitNode(obj.getGroupBy()); visitNode(obj.getHaving()); visitNode(obj.getOrderBy()); visitNode(obj.getLimit()); if (this.doScanEvaluation) { HashMap<String, String> options = buildTableMetadata( this.scanTable.getName(), this.scanTable.getColumns(), this.ef.getEncoding()); options.put(EvaluatorIterator.QUERYSTRING, SQLStringVisitor.getSQLString(obj.getWhere())); IteratorSetting it = new IteratorSetting(1, EvaluatorIterator.class, options); this.scanIterators.add(it); } if (this.selectColumns.size() < this.scanTable.getColumns().size()) { HashMap<String, String> options = buildTableMetadata(this.scanTable.getName(), this.selectColumns, this.ef.getEncoding()); IteratorSetting it = new IteratorSetting(iteratorPriority++, LimitProjectionIterator.class, options); this.scanIterators.add(it); } }
public static List<Object> performSearch( Select command, Class<?> type, String cacheName, CacheContainerWrapper cache) throws TranslatorException { LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Using Lucene Searching."); // $NON-NLS-1$ // Map<?, ?> cache, SearchManager searchManager = Search.getSearchManager((Cache<?, ?>) cache.getCache(cacheName)); QueryBuilder queryBuilder = searchManager.buildQueryBuilderForClass(type).get(); BooleanJunction<BooleanJunction> junction = queryBuilder.bool(); boolean createdQueries = buildQueryFromWhereClause(command.getWhere(), junction, queryBuilder); Query query = null; if (createdQueries) { query = junction.createQuery(); } else { query = queryBuilder.all().createQuery(); } CacheQuery cacheQuery = searchManager.getQuery(query, type); // rootNodeType List<Object> results = cacheQuery.list(); if (results == null || results.isEmpty()) { return Collections.emptyList(); } return results; }
/** * @brief Visit the statement. This is the function that should be called in the first place. * @param statement A SQL statement. */ public void visit(Statement statement) throws Exception { if (statement instanceof Select) { Select select = (Select) statement; if (select.getWithItemsList() != null) { for (WithItem withItem : ((Select) statement).getWithItemsList()) { withItem.accept(this); } } if (select.getSelectBody() != null) { select.getSelectBody().accept(this); } } else if (statement instanceof DescribeTable) { ((DescribeTable) statement).accept(this); } // TODO: Add more type support here. }
/** * Fills the form with current field component. Adds additional widgets if needed (i.e. "select * all" box) * * @param form The form to place the field in * @param layout The layout that displays the field */ public void placeYourselfInForm(Form form, FormLayout layout) { if (fieldComponent == null) { return; } if (fieldComponent instanceof Field) { form.addField(name, (Field) fieldComponent); } else if (fieldComponent instanceof FilterContainer) { for (Select select : ((FilterContainer) fieldComponent).getLevels()) { form.addField(select.getCaption(), select); } } else { layout.addComponent(fieldComponent); } if (selectAll) { final CheckBox saCheckbox = UiFactory.createCheckBox(UiIds.AR_MSG_SELECT_ALL, null); saCheckbox.addListener( new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean selected = (Boolean) saCheckbox.getValue(); if (fieldComponent instanceof Select) { for (Object itemId : ((Select) fieldComponent).getItemIds()) { if (selected) { ((Select) fieldComponent).select(itemId); } else { ((Select) fieldComponent).unselect(itemId); } } } if (fieldComponent instanceof FilterContainer) { List<Select> selectList = ((FilterContainer) fieldComponent).getLevels(); Select select = selectList.get(selectList.size() - 1); for (Object itemId : select.getItemIds()) { if (selected) { select.select(itemId); } else { select.unselect(itemId); } } } } }); form.addField(name + "_all", saCheckbox); } }
@Override public void buttonClick(Button.ClickEvent clickEvent) { if (clickEvent.getSource() == myOkButton) { onOk((T) mySelect.getValue()); } else { onCancel(); } }
private void buildFeedSelect() { IndexedContainer feedsCon = new IndexedContainer(); File feedFolder = new File(feedsPath); for (String feed : feedFolder.list()) { feedsCon.addItem(feed); } feedSelect.setContainerDataSource(feedsCon); }
public SelectWindow( float width, int units, Collection<T> items, T selectedItem, Resource icon, String caption, String message, String okButtonText, String cancelButtonText) { super(); if (caption != null) { setCaption(caption); } if (icon != null) { setIcon(icon); } setWidth(width, units); setModal(true); setClosable(false); setResizable(false); setDraggable(false); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); setContent(verticalLayout); Label label = new Label(message); addComponent(label); mySelect = new Select(null, items); mySelect.setNullSelectionAllowed(false); mySelect.setValue(selectedItem != null ? selectedItem : items.iterator().next()); mySelect.setWidth(100, Sizeable.UNITS_PERCENTAGE); addComponent(mySelect); Panel panel = new Panel(); addComponent(panel); verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT); panel.addStyleName("light"); HorizontalLayout horizontalLayout = new HorizontalLayout(); panel.setContent(horizontalLayout); horizontalLayout.setSpacing(true); verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT); myCancelButton = new Button(cancelButtonText, this); panel.addComponent(myCancelButton); myOkButton = new Button(okButtonText, this); panel.addComponent(myOkButton); }
@Override public Matcher visit(Select select) { Condition condition = select.getCondition(); if (condition != null) { return condition.accept(this); } else { return new MatchAll(); } }
@SuppressWarnings("unchecked") @Override public <T> ResultIterator<T> iterator(Select<T> query) { final ResultIterator<DataRow> rows = performIteratedQuery(query); QueryMetadata md = query.getMetaData(getEntityResolver()); if (md.isFetchingDataRows()) { return (ResultIterator<T>) rows; } else { // this is a bit optimized version of 'objectFromDataRow' with // resolver cached for reuse... still the rest is pretty suboptimal ClassDescriptor descriptor = md.getClassDescriptor(); final ObjectResolver resolver = new ObjectResolver(this, descriptor, true); return new ResultIterator<T>() { @Override public Iterator<T> iterator() { return new ResultIteratorIterator<T>(this); } @Override public List<T> allRows() { List<T> list = new ArrayList<>(); while (hasNextRow()) { list.add(nextRow()); } return list; } @Override public boolean hasNextRow() { return rows.hasNextRow(); } @Override public T nextRow() { DataRow row = rows.nextRow(); List<T> objects = (List<T>) resolver.synchronizedObjectsFromDataRows(Collections.singletonList(row)); return (T) objects.get(0); } @Override public void skipRow() { rows.skipRow(); } @Override public void close() { rows.close(); } }; } }
public boolean generatePuzzle() { // index of the next word indexOfNextWord = newPuzzle.getIndexOfNextWord(); if (indexOfNextWord == -1) { return false; } // get the word length of the word at the next index wordLength = newPuzzle.getWordLength(indexOfNextWord); // get number of blanks numBlanks = newPuzzle.howManyBlanks(wordLength); // get the word name at the index of the next word wordName = newPuzzle.getWordName(indexOfNextWord); // blanks out letters and returns the word with '_' (blanks) withBlanks = (newPuzzle.whichLettersBlank(indexOfNextWord, numBlanks)); addSpaces(); return true; }
/** * Executes an INSERT_SELECT statement. It is assumed that the argument is of the correct type. * * @param cs a CompiledStatement of type CompiledStatement.INSERT_SELECT * @throws HsqlException if a database access error occurs * @return the result of executing the statement */ private Result executeInsertSelectStatement(CompiledStatement cs) throws HsqlException { Table t = cs.targetTable; Select s = cs.select; int[] ct = t.getColumnTypes(); // column types Result r = s.getResult(session.getMaxRows(), session); Record rc = r.rRoot; int[] cm = cs.columnMap; // column map boolean[] ccl = cs.checkColumns; // column check list int len = cm.length; Object[] row; int count; boolean success = false; session.beginNestedTransaction(); try { while (rc != null) { row = t.getNewRowData(session, ccl); for (int i = 0; i < len; i++) { int j = cm[i]; if (ct[j] != r.metaData.colType[i]) { row[j] = Column.convertObject(rc.data[i], ct[j]); } else { row[j] = rc.data[i]; } } rc.data = row; rc = rc.next; } count = t.insert(session, r); success = true; } finally { session.endNestedTransaction(!success); } updateResult.iUpdateCount = count; return updateResult; }
public void evaluateParams() { super.evaluateParams(); // override Select's default if (StringUtils.isBlank(size)) { addParameter("size", "5"); } if (StringUtils.isBlank(multiple)) { addParameter("multiple", Boolean.TRUE); } if (allowMoveUp != null) { addParameter("allowMoveUp", findValue(allowMoveUp, Boolean.class)); } if (allowMoveDown != null) { addParameter("allowMoveDown", findValue(allowMoveDown, Boolean.class)); } if (allowSelectAll != null) { addParameter("allowSelectAll", findValue(allowSelectAll, Boolean.class)); } if (moveUpLabel != null) { addParameter("moveUpLabel", findString(moveUpLabel)); } if (moveDownLabel != null) { addParameter("moveDownLabel", findString(moveDownLabel)); } if (selectAllLabel != null) { addParameter("selectAllLabel", findString(selectAllLabel)); } // inform our form ancestor about this UpDownSelect so the form knows how to // auto select all options upon it submission Form ancestorForm = (Form) findAncestor(Form.class); if (ancestorForm != null) { // inform form ancestor that we are using a custom onSubmit enableAncestorFormCustomOnsubmit(); Map m = (Map) ancestorForm.getParameters().get("updownselectIds"); if (m == null) { // map with key -> id , value -> headerKey m = new LinkedHashMap(); } m.put(getParameters().get("id"), getParameters().get("headerKey")); ancestorForm.getParameters().put("updownselectIds", m); } else { if (LOG.isWarnEnabled()) { LOG.warn( "no ancestor form found for updownselect " + this + ", therefore autoselect of all elements upon form submission will not work "); } } }
public void visit(Select entity) { wGetVisitor1().visit(entity.getSelectType()); wGetVisitor1().visit(entity.getColumnExprs()); wGetVisitor1().visit(entity.getFromClauses()); wGetVisitor1().visit(entity.getWhereExpr()); wGetVisitor1().visit(entity.getGroupByExprs()); wGetVisitor1().visit(entity.getHavingExpr()); wGetVisitor1().visit(entity.getOrderByColumnExprs()); }
/** * convert to order by sql * * @param sql * @param orderBy * @return */ public static String converToOrderBySql(String sql, String orderBy) { // 解析SQL Statement stmt = null; try { stmt = CCJSqlParserUtil.parse(sql); Select select = (Select) stmt; SelectBody selectBody = select.getSelectBody(); // 处理body-去最外层order by List<OrderByElement> orderByElements = extraOrderBy(selectBody); String defaultOrderBy = PlainSelect.orderByToString(orderByElements); if (defaultOrderBy.indexOf('?') != -1) { throw new RuntimeException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!"); } // 新的sql sql = select.toString(); } catch (Throwable e) { e.printStackTrace(); } return sql + " order by " + orderBy; }
public void addListGroups(String groupID, List form, int errorFlag, Collection owningCollection) throws WingException, SQLException { if (isAdvancedFormEnabled) { // currently set group form.addLabel(T_groups); Select groupSelect = form.addItem().addSelect("group_id"); groupSelect.setMultiple(false); java.util.List<Group> loadedGroups = null; // retrieve groups String name = ConfigurationManager.getProperty("webui.submission.restrictstep.groups"); if (name != null) { Group uiGroup = groupService.findByName(context, name); if (uiGroup != null) loadedGroups = uiGroup.getMemberGroups(); } if (loadedGroups == null || loadedGroups.size() == 0) { loadedGroups = groupService.findAll(context, GroupService.NAME); } // if no group selected for default set anonymous if (groupID == null || groupID.equals("")) groupID = "0"; // when we're just loading the main step, also default to anonymous if (errorFlag == AccessStep.STATUS_COMPLETE) { groupID = "0"; } for (Group group : loadedGroups) { boolean selectGroup = group.getID().toString().equals(groupID); groupSelect.addOption(selectGroup, group.getID().toString(), group.getName()); } if (errorFlag == AccessStep.STATUS_DUPLICATED_POLICY || errorFlag == AccessStep.EDIT_POLICY_STATUS_DUPLICATED_POLICY || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICIES_DUPLICATED_POLICY || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICY_DUPLICATED_POLICY) { groupSelect.addError(T_error_duplicated_policy); } } }
@Override public List<DataRecord> visit(Select select) { if (!select.isProjection()) { return records; } else { List<DataRecord> filteredRecords = new LinkedList<DataRecord>(); for (TypedExpression expression : select.getSelectedFields()) { expression.accept(this); } if (!aggregateProjection.isEmpty()) { for (FieldMetadata fieldMetadata : aggregateProjection.keySet()) { explicitProjection.addField(fieldMetadata); } for (Map.Entry<FieldMetadata, AggregateValueBuilder> entry : aggregateProjection.entrySet()) { Collection<Object> aggregateValues = entry.getValue().getValues(records); for (Object aggregateValue : aggregateValues) { DataRecord newRecord = new DataRecord(explicitProjection, UnsupportedDataRecordMetadata.INSTANCE); newRecord.set(entry.getKey(), aggregateValue); filteredRecords.add(newRecord); } } } else if (!recordProjection.isEmpty()) { ComplexTypeMetadata explicitProjection = new ComplexTypeMetadataImpl("", "ExplicitProjectionType", true); for (FieldMetadata fieldMetadata : recordProjection.keySet()) { explicitProjection.addField(fieldMetadata); } for (DataRecord inputReport : records) { DataRecord newRecord = new DataRecord(explicitProjection, UnsupportedDataRecordMetadata.INSTANCE); for (Map.Entry<FieldMetadata, ValueBuilder> entry : recordProjection.entrySet()) { newRecord.set(entry.getKey(), entry.getValue().getValue(inputReport)); } } } return filteredRecords; } }
/** * Sets the value of the current field component. * * @param value The value to set */ public void setValue(Object value) { if (fieldComponent != null) { if (fieldComponent instanceof Field) { Field field = ((Field) fieldComponent); field.setValue(value); if (field instanceof Select) { ((Select) fieldComponent).select(value); } } else if (fieldComponent instanceof FilterContainer) { ((FilterContainer) fieldComponent).setValue(value); } } }
@Override protected void writeToConfig() { MyTunesRss.CONFIG.setWebLoginMessage(myWebLoginMessage.getStringValue(null)); MyTunesRss.CONFIG.setWebWelcomeMessage(myWebWelcomeMessage.getStringValue(null)); MyTunesRss.CONFIG.setServerBrowserActive(myServerBrowserActive.booleanValue()); MyTunesRss.CONFIG.setOpenIdActive(myOpenIdActive.booleanValue()); MyTunesRss.CONFIG.setProxyHost(myProxyHost.getStringValue(null)); MyTunesRss.CONFIG.setProxyPort(myProxyPort.getIntegerValue(-1)); MyTunesRss.CONFIG.setMailHost(myMailHost.getStringValue(null)); MyTunesRss.CONFIG.setMailPort(myMailPort.getIntegerValue(-1)); MyTunesRss.CONFIG.setSmtpProtocol((SmtpProtocol) mySmtpProtocol.getValue()); MyTunesRss.CONFIG.setMailLogin(myMailLogin.getStringValue(null)); MyTunesRss.CONFIG.setMailPassword(myMailPassword.getStringValue(null)); MyTunesRss.CONFIG.setMailSender(myMailSender.getStringValue(null)); MyTunesRss.CONFIG.setHeadless(myHeadless.booleanValue()); String gmBinary = myGraphicsMagickBinary.getStringValue(null); MyTunesRss.CONFIG.setGmExecutable(gmBinary != null ? new File(gmBinary) : null); MyTunesRss.CONFIG.setGmEnabled(myGraphicsMagickEnabled.booleanValue()); MyTunesRss.CONFIG.save(); }
/** * Redirect all references from old_target to new_target, i.e., update targets of branch * instructions. * * @param old_target the old target instruction handle * @param new_target the new target instruction handle */ public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target) { for (InstructionHandle ih = start; ih != null; ih = ih.next) { Instruction i = ih.getInstruction(); if (i instanceof BranchInstruction) { BranchInstruction b = (BranchInstruction) i; InstructionHandle target = b.getTarget(); if (target == old_target) { b.setTarget(new_target); } if (b instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH InstructionHandle[] targets = ((Select) b).getTargets(); for (int j = 0; j < targets.length; j++) { if (targets[j] == old_target) { ((Select) b).setTarget(j, new_target); } } } } } }