Java Code Examples for com.google.gwt.user.client.ui.ListBox
The following examples show how to use
com.google.gwt.user.client.ui.ListBox. These examples are extracted from open source projects.
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 Project: cuba Source File: CubaTwinColSelectWidget.java License: Apache License 2.0 | 6 votes |
protected void updateListBox(List<JsonObject> items, ListBox listBox, BiConsumer<ListBox, List<JsonObject>> updateTask) { List<String> selectedItems = null; int selectedIdx = listBox.getSelectedIndex(); int itemsCount = listBox.getItemCount(); if (selectedIdx >= 0) { selectedItems = new ArrayList<>(); for (int i = selectedIdx; i < itemsCount; i++) { selectedItems.add(listBox.getItemText(i)); } } updateTask.accept(listBox, items); if (selectedItems != null) { // re-set selection for (int i = 0; i < itemsCount; i++) { String item = listBox.getItemText(i); listBox.setItemSelected(i, selectedItems.contains(item)); } } }
Example 2
Source Project: cuba Source File: CubaTwinColSelectWidget.java License: Apache License 2.0 | 6 votes |
protected void updateListBoxItems(ListBox listBox, List<JsonObject> options) { List<String> listBoxItems = ((CubaDoubleClickListBox) listBox).getItems(); for (int i = 0; i < options.size(); i++) { final JsonObject item = options.get(i); String value = MultiSelectWidget.getKey(item); String caption = MultiSelectWidget.getCaption(item); int index = i; // reuse existing option if possible if (index < listBox.getItemCount()) { if (!reorderable) { int listBoxItemIndex = listBoxItems.indexOf(caption); if (listBoxItemIndex >= 0) { index = listBoxItemIndex; } } listBox.setItemText(index, caption); listBox.setValue(index, value); } else { listBox.addItem(caption, value); } } }
Example 3
Source Project: cuba Source File: CubaTwinColSelectWidget.java License: Apache License 2.0 | 6 votes |
protected static Set<String> moveSelectedItems(ListBox source, ListBox target) { final boolean[] sel = getSelectionBitmap(source); final Set<String> movedItems = new HashSet<>(); for (int i = 0; i < sel.length; i++) { if (sel[i]) { final int optionIndex = i - (sel.length - source.getItemCount()); movedItems.add(source.getValue(optionIndex)); // Move selection to another column final String text = source.getItemText(optionIndex); final String value = source.getValue(optionIndex); target.addItem(text, value); target.setItemSelected(target.getItemCount() - 1, true); source.removeItem(optionIndex); } } target.setFocus(true); return movedItems; }
Example 4
Source Project: cuba Source File: CubaTwinColSelectWidget.java License: Apache License 2.0 | 6 votes |
private Set<String> moveAllItems(ListBox source, ListBox target) { final Set<String> movedItems = new HashSet<String>(); int size = source.getItemCount(); for (int i = 0; i < size; i++) { movedItems.add(source.getValue(i)); final String text = source.getItemText(i); final String value = source.getValue(i); target.addItem(text, value); target.setItemSelected(target.getItemCount() - 1, true); } target.setFocus(true); if (source.getItemCount() > 0) { target.setSelectedIndex(0); } source.clear(); return movedItems; }
Example 5
Source Project: jolie Source File: Echoes.java License: GNU Lesser General Public License v2.1 | 6 votes |
private void addVolumeMenuItems( ListBox volumeMenu ) { volumeMenu.addItem( "0%", "0" ); volumeMenu.addItem( "5%", "5" ); volumeMenu.addItem( "10%", "10" ); volumeMenu.addItem( "15%", "15" ); volumeMenu.addItem( "20%", "20" ); volumeMenu.addItem( "25%", "25" ); volumeMenu.addItem( "30%", "30" ); volumeMenu.addItem( "35%", "35" ); volumeMenu.addItem( "40%", "40" ); volumeMenu.addItem( "45%", "45" ); volumeMenu.addItem( "50%", "50" ); volumeMenu.addItem( "55%", "55" ); volumeMenu.addItem( "60%", "60" ); volumeMenu.addItem( "65%", "65" ); volumeMenu.addItem( "70%", "70" ); volumeMenu.addItem( "75%", "75" ); volumeMenu.addItem( "80%", "80" ); volumeMenu.addItem( "85%", "85" ); volumeMenu.addItem( "90%", "90" ); volumeMenu.addItem( "95%", "95" ); volumeMenu.addItem( "100%", "100" ); }
Example 6
Source Project: unitime Source File: CourseNumbersSuggestBox.java License: Apache License 2.0 | 6 votes |
private String getConfiguration() { String conf = iConfiguration; for (MatchResult matcher = iRegExp.exec(conf); matcher != null; matcher = iRegExp.exec(conf)) { Element element = DOM.getElementById(matcher.getGroup(1)); String value = ""; if ("select".equalsIgnoreCase(element.getTagName())) { ListBox list = ListBox.wrap(element); for (int i = 0; i < list.getItemCount(); i++) { if (list.isItemSelected(i)) value += (value.isEmpty() ? "" : ",") + list.getValue(i); } } else if ("input".equalsIgnoreCase(element.getTagName())) { TextBox text = TextBox.wrap(element); value = text.getText(); } else { Hidden hidden = Hidden.wrap(element); value = hidden.getValue(); } conf = conf.replace("${" + matcher.getGroup(1) + "}", value); } return conf; }
Example 7
Source Project: unitime Source File: ChangeGradeModesDialog.java License: Apache License 2.0 | 6 votes |
public GradeModeChange(ClassAssignmentInterface.ClassAssignment ca, SpecialRegistrationGradeModeChanges gradeMode) { super(null); iList = new ListBox(); iList.addStyleName("grade-mode-list"); iClasses = new ArrayList<ClassAssignmentInterface.ClassAssignment>(); iClasses.add(ca); iGradeMode = new ArrayList<SpecialRegistrationGradeModeChanges>(); iGradeMode.add(gradeMode); iList.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { formChanged(); } }); setup(); }
Example 8
Source Project: unitime Source File: ChangeGradeModesDialog.java License: Apache License 2.0 | 6 votes |
public GradeModeLabel(GradeModeChange change, SpecialRegistrationGradeModeChanges gradeMode) { super(null); iGradeMode = gradeMode; iLabel = new Label(); iLabel.addStyleName("grade-mode-label"); iLabel.setText(iGradeMode.getCurrentGradeMode() == null ? "" : iGradeMode.getCurrentGradeMode().getLabel()); final ListBox box = (ListBox)change.getWidget(); box.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { if (box.getSelectedIndex() <= 0) { iLabel.setText(iGradeMode.getCurrentGradeMode() == null ? "" : iGradeMode.getCurrentGradeMode().getLabel()); } else { SpecialRegistrationGradeMode m = iGradeMode.getAvailableChange(box.getValue(box.getSelectedIndex())); if (m == null) { iLabel.setText(iGradeMode.getCurrentGradeMode() == null ? "" : iGradeMode.getCurrentGradeMode().getLabel()); } else { iLabel.setText(m.getLabel()); } } } }); }
Example 9
Source Project: djvu-html5 Source File: Toolbar.java License: GNU General Public License v2.0 | 6 votes |
protected void zoomSelectionChanged() { if (pageLayout == null) return; ListBox zoomSelection = zoomPanel.selection; int index = zoomSelection.getSelectedIndex(); if (index < zoomOptions.size()) { pageLayout.setZoom(zoomOptions.get(index)); } else { switch (index - zoomOptions.size()) { case 0: pageLayout.zoomToFitWidth(); break; case 1: pageLayout.zoomToFitPage(); break; default: throw new RuntimeException(); } } zoomPanel.textBox.setText(zoomSelection.getSelectedItemText()); zoomSelection.setFocus(false); }
Example 10
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 6 votes |
private Widget createAspectRatioListBox() { final ListBox box = new ListBox(); for (WCAspectRatio algo : WCAspectRatioRegistry.list()) box.addItem(algo.getDescription(), algo.getId()); box.setSelectedIndex(findIndex(box, setting.getAspectRatio().getId())); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { WCAspectRatio value = WCAspectRatioRegistry.getById(box.getValue(box.getSelectedIndex())); setting.setAspectRatio(value); } }); box.setTitle("Desired aspect ratio of the drawing"); return box; }
Example 11
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 6 votes |
private ListBox createNumberListBox() { final ListBox box = new ListBox(); List<String> values = Arrays.asList("10", "20", "30", "40", "50", "75", "100", "125", "150", "200", "250", "300"); for (int i = 0; i < values.size(); i++) box.addItem(values.get(i)); box.setSelectedIndex(findIndex(box, String.valueOf(setting.getWordCount()))); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { int value = Integer.parseInt(box.getValue(box.getSelectedIndex())); setting.setWordCount(value); } }); box.setTitle("Number of words to include in the word cloud"); return box; }
Example 12
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 6 votes |
private ListBox createFontListBox() { final ListBox box = new ListBox(); for (WCFont font : WCFontRegistry.list()) box.addItem(font.getDescription(), font.getName()); box.setSelectedIndex(findIndex(box, setting.getFont().getName())); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { WCFont value = WCFontRegistry.getByName(box.getValue(box.getSelectedIndex())); setting.setFont(value); } }); box.setTitle("Font family of the words"); return box; }
Example 13
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 6 votes |
private ListBox createRankingListBox() { final ListBox box = new ListBox(); for (WCRankingAlgo algo : WCRankingAlgoRegistry.list()) box.addItem(algo.getDescription(), algo.getId()); box.setSelectedIndex(findIndex(box, setting.getRankingAlgorithm().getId())); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { WCRankingAlgo value = WCRankingAlgoRegistry.getById(box.getValue(box.getSelectedIndex())); setting.setRankingAlgorithm(value); } }); box.setTitle("Ranking method for computing word importance, which determines font size of each word"); return box; }
Example 14
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 6 votes |
private Widget createSimilarityListBox() { final ListBox box = new ListBox(); for (WCSimilarityAlgo font : WCSimilarityAlgoRegistry.list()) box.addItem(font.getDescription(), font.getId()); box.setSelectedIndex(findIndex(box, setting.getSimilarityAlgorithm().getId())); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { WCSimilarityAlgo value = WCSimilarityAlgoRegistry.getById(box.getValue(box.getSelectedIndex())); setting.setSimilarityAlgorithm(value); } }); box.setTitle("Similarity method for computing relatedness between words; similar words tend to be placed together"); return box; }
Example 15
Source Project: gwt-traction Source File: SingleListBox.java License: Apache License 2.0 | 6 votes |
/** * Utility function to set the current value in a ListBox. * * @return returns true if the option corresponding to the value * was successfully selected in the ListBox */ public static final boolean setSelectedValue(ListBox list, String value, boolean addMissingValues) { if (value == null) { list.setSelectedIndex(0); return false; } else { int index = findValueInListBox(list, value); if (index >= 0) { list.setSelectedIndex(index); return true; } if (addMissingValues) { list.addItem(value, value); // now that it's there, search again index = findValueInListBox(list, value); list.setSelectedIndex(index); return true; } return false; } }
Example 16
Source Project: appinventor-extensions Source File: TemplateUploadWizard.java License: Apache License 2.0 | 5 votes |
/** * Creates a drop down menu for selecting Template repositories. * @return the drop down menu of repository Urls. */ private ListBox makeTemplatesMenu() { final ListBox templatesMenu = new ListBox(); templatesMenu.addItem(MESSAGES.templateUploadNewUrlCaption()); templatesMenu.addItem(MIT_TEMPLATES); for (int k = 0; k < dynamicTemplateUrls.size(); k++) { // Dynamically added Urls templatesMenu.addItem(dynamicTemplateUrls.get(k)); } templatesMenu.setSelectedIndex(MIT_TEMPLATES_INDEX); templatesMenu.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { int selectedIndex = templatesMenu.getSelectedIndex(); if (selectedIndex == 0) { templatesMenu.setSelectedIndex(lastSelectedIndex); usingExternalTemplate = true; // MIT templates at index 1 removeButton.setVisible(false); new InputTemplateUrlWizard(instance).center(); // This will do a callback } else if (selectedIndex == 1) { removeButton.setVisible(false); lastSelectedIndex = selectedIndex; usingExternalTemplate = false; // MIT templates at index 1 templateHostUrl = ""; retrieveSelectedTemplates(templatesMenu.getValue(selectedIndex)); // may do callback } else { removeButton.setVisible(true); lastSelectedIndex = selectedIndex; usingExternalTemplate = true; // MIT templates at index 1 templateHostUrl = templatesMenu.getValue(selectedIndex); retrieveSelectedTemplates(templatesMenu.getValue(selectedIndex)); // may do callback } } }); templatesMenu.setVisibleItemCount(1); // Turns menu into a drop-down list). return templatesMenu; }
Example 17
Source Project: appinventor-extensions Source File: MockSpinner.java License: Apache License 2.0 | 5 votes |
/** * Creates a new MockSpinner component. * * @param editor editor of source file the component belongs to */ public MockSpinner(SimpleEditor editor) { super(editor, TYPE, images.spinner()); // Initialize mock label UI spinnerWidget = new ListBox(); spinnerWidget.addItem(MESSAGES.MockSpinnerAddItems()); spinnerWidget.setStylePrimaryName("ode-SimpleMockComponent"); spinnerWidget.addStyleName("spinnerComponentStyle"); initComponent(spinnerWidget); refreshForm(); }
Example 18
Source Project: cuba Source File: SuggestPopup.java License: Apache License 2.0 | 5 votes |
protected void createChoiceList() { choiceList = new ListBox(); choiceList.setStyleName("list"); choiceList.addKeyDownHandler(this); choiceList.addDoubleClickHandler(this); choiceList.addChangeHandler(this); choiceList.setStylePrimaryName("aceeditor-suggestpopup-list"); setWidget(choiceList); }
Example 19
Source Project: gwt-material Source File: MaterialListBoxTest.java License: Apache License 2.0 | 5 votes |
public void testChildren() { // UiBinder // given MaterialListBox listBox = (MaterialListBox)getWidget(); // when / then assertEquals(3, listBox.getChildren().size()); assertTrue(listBox.getWidget(0) instanceof ListBox); assertTrue(listBox.getWidget(1) instanceof Label); assertTrue(listBox.getWidget(2) instanceof MaterialLabel); }
Example 20
Source Project: unitime Source File: PageFilter.java License: Apache License 2.0 | 5 votes |
public void setValue(String name, String value) { Widget w = iWidgets.get(name); FilterParameterInterface param = iFilter.getParameter(name); if (param != null) param.setValue(value); if (w == null) return; if (w instanceof CheckBox) { ((CheckBox)w).setValue("1".equals(value)); } else if (w instanceof ListBox) { ListBox list = (ListBox)w; if (param != null && param.isMultiSelect()) { for (int i = 0; i < list.getItemCount(); i++) { boolean selected = false; for (String val: value.split(",")) if (val.equalsIgnoreCase(list.getValue(i))) selected = true; list.setItemSelected(i, selected); } } else { for (int i = 0; i < list.getItemCount(); i++) { if (value.equalsIgnoreCase(list.getValue(i))) { list.setSelectedIndex(i); break; } } } } else if (w instanceof HasText) { ((HasText)w).setText(value); } }
Example 21
Source Project: unitime Source File: UniTimeWidget.java License: Apache License 2.0 | 5 votes |
@Deprecated public void clear() { if (getWidget() instanceof ListBox) ((ListBox)getWidget()).clear(); if (getWidget() instanceof Panel) ((Panel)getWidget()).clear(); }
Example 22
Source Project: unitime Source File: EventAdd.java License: Apache License 2.0 | 5 votes |
@Override public List<RelatedObjectInterface> getValue() { List<RelatedObjectInterface> objects = new ArrayList<RelatedObjectInterface>(); for (int row = 1; row < getRowCount(); row ++) { CourseRelatedObjectLine line = getData(row); ListBox subject = (ListBox)getWidget(row, 0); RelatedObjectLookupRpcResponse rSubject = (subject.getSelectedIndex() < 0 ? null : line.getSubject(subject.getValue(subject.getSelectedIndex()))); ListBox course = (ListBox)getWidget(row, 1); RelatedObjectLookupRpcResponse rCourse = (course.getSelectedIndex() < 0 ? null : line.getCourse(course.getValue(course.getSelectedIndex()))); ListBox subpart = (ListBox)getWidget(row, 2); RelatedObjectLookupRpcResponse rSubpart = (subpart.getSelectedIndex() < 0 ? null : line.getSubpart(subpart.getValue(subpart.getSelectedIndex()))); ListBox clazz = (ListBox)getWidget(row, 3); RelatedObjectLookupRpcResponse rClazz = (clazz.getSelectedIndex() < 0 ? null : line.getClass(clazz.getValue(clazz.getSelectedIndex()))); if (rClazz != null && rClazz.getRelatedObject() != null) { objects.add(rClazz.getRelatedObject()); continue; } if (rSubpart != null && rSubpart.getRelatedObject() != null) { objects.add(rSubpart.getRelatedObject()); continue; } if (rCourse != null && rCourse.getRelatedObject() != null) { objects.add(rCourse.getRelatedObject()); continue; } if (rSubject != null && rSubject.getRelatedObject() != null) { objects.add(rSubject.getRelatedObject()); continue; } } return objects; }
Example 23
Source Project: unitime Source File: ChangeGradeModesDialog.java License: Apache License 2.0 | 5 votes |
public VariableCreditChange(ClassAssignmentInterface.ClassAssignment ca, SpecialRegistrationVariableCreditChange vcc) { super(null); iList = new ListBox(); iList.addStyleName("variable-credit-list"); iClass = ca; iVarCredit = vcc; iList.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { formChanged(); } }); setup(); }
Example 24
Source Project: unitime Source File: ReservationEdit.java License: Apache License 2.0 | 5 votes |
private void select(ListBox l, String value) { for (int i = 0; i < l.getItemCount(); i++) { if (l.getValue(i).equals(value)) { l.setSelectedIndex(i); return; } } }
Example 25
Source Project: djvu-html5 Source File: Toolbar.java License: GNU General Public License v2.0 | 5 votes |
public void setZoomOptions(List<Integer> newZoomOptions) { ListBox zoomSelection = zoomPanel.selection; int previousIndex = zoomSelection.getSelectedIndex(); zoomSelection.clear(); for (int i : newZoomOptions) { zoomSelection.addItem(i + "%"); } zoomSelection.addItem(DjvuContext.getString("label_fitWidth", "Fit width")); zoomSelection.addItem(DjvuContext.getString("label_fitPage", "Fit page")); if (previousIndex >= zoomOptions.size()) { // either "fit with" or "fit page" was selected zoomSelection.setSelectedIndex(newZoomOptions.size() + (zoomOptions.size() - previousIndex)); } else { int zoom = pageLayout != null ? pageLayout.getZoom() : 100; int newSelected = Arrays.binarySearch(newZoomOptions.toArray(), zoom, Collections.reverseOrder()); if (newSelected >= 0) { zoomSelection.setSelectedIndex(Math.min(newSelected, newZoomOptions.size() - 1)); zoomOptions = newZoomOptions; zoomSelectionChanged(); } else { zoomSelection.setSelectedIndex(-1); zoomOptions = newZoomOptions; } } zoomPanel.updateButtons(); }
Example 26
Source Project: djvu-html5 Source File: Toolbar.java License: GNU General Public License v2.0 | 5 votes |
public void setPageCount(int pagesCount) { this.pagesCount = pagesCount; ListBox pageSelection = pagePanel.selection; pageSelection.clear(); for (int i = 1; i <= pagesCount; i++) { pageSelection.addItem(i + ""); } pagePanel.updateButtons(); }
Example 27
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 5 votes |
private void setItemEnabled(ListBox b, int index, boolean enabled) { if (enabled) b.getElement().getElementsByTagName("option").getItem(index).removeAttribute("disabled"); else b.getElement().getElementsByTagName("option").getItem(index).setAttribute("disabled", "disabled"); }
Example 28
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 5 votes |
private int findIndex(ListBox box, String value) { for (int i = 0; i < box.getItemCount(); i++) if (box.getValue(i).equals(value)) return i; return -1; }
Example 29
Source Project: swcv Source File: SettingsPanel.java License: MIT License | 5 votes |
private ListBox createLanguageListBox() { final ListBox box = new ListBox(); box.addItem("Arabic", "ar"); box.addItem("Czech", "cs"); box.addItem("Danish", "da"); box.addItem("Dutch", "nl"); box.addItem("English", "en"); box.addItem("Finnish", "fi"); box.addItem("French", "fr"); box.addItem("German", "de"); box.addItem("Greek", "el"); box.addItem("Hungarian", "hu"); box.addItem("Italian", "it"); box.addItem("Japanese", "ja"); box.addItem("Norwegian", "no"); box.addItem("Polish", "pl"); box.addItem("Portuguese", "pt"); box.addItem("Russian", "ru"); box.addItem("Spanish", "es"); box.addItem("Swedish", "sv"); box.addItem("Turkish", "tr"); box.setSelectedIndex(findIndex(box, setting.getLanguage())); setNonEnglishText("en".equals(setting.getLanguage())); box.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { String value = box.getValue(box.getSelectedIndex()); setting.setLanguage(value); setNonEnglishText("en".equals(value)); } }); box.setTitle("Language of text"); return box; }
Example 30
Source Project: gwt-traction Source File: SingleListBoxDemo.java License: Apache License 2.0 | 5 votes |
@Override public void onModuleLoad() { eventListBox = new ListBox(true); eventListBox.setVisibleItemCount(20); RootPanel.get("eventlog").add(eventListBox); singleListBox = new SingleListBox(); singleListBox.addItem("Apples"); singleListBox.addItem("Bananas"); singleListBox.addItem("Oranges"); singleListBox.addItem("Pears"); singleListBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { addEvent("ValueChangeEvent: " + event.getValue()); } }); Panel select = RootPanel.get("select"); select.add(singleListBox); Panel toggle = RootPanel.get("toggle"); toggle.add(createSetAddMissingValue(true)); toggle.add(createSetAddMissingValue(false)); Panel controls1 = RootPanel.get("controls1"); controls1.add(createSelectButton("Bananas")); controls1.add(createSelectButton("Pears")); Panel controls2 = RootPanel.get("controls2"); controls2.add(createSelectButton("Kiwis")); controls2.add(createSelectButton("Watermelons")); }