List of usage examples for com.google.gwt.user.client.ui SuggestBox setLimit
public void setLimit(int limit)
From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.AbstractSearchWidget.java
License:Open Source License
private SuggestBox getNewSuggestBox(PopSortedMultiWordSuggestOracle oracle) { final SuggestBox box = new SuggestBox(oracle); box.setLimit(15); box.setAutoSelectEnabled(false);//from w ww .j a va 2s . co m box.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { // If enter key pressed, submit the form if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { DeferredCommand.addCommand(new Command() { @Override public void execute() { search(); } }); // If escape key pressed, hide the suggestbox } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) { box.hideSuggestionList(); } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) { if (!box.isSuggestionListShowing()) { box.showSuggestionList(); } } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_LEFT || event.getNativeEvent().getKeyCode() == KeyCodes.KEY_RIGHT) { box.hideSuggestionList(); } } }); if (searchBoxStyleName != null && searchBoxStyleName.length() > 0) { box.addStyleName(searchBoxStyleName); } box.addFocusListener(focusListener); box.setText(DEFAULT_TXT); return box; }
From source file:net.opentsdb.tsd.client.MetricForm.java
License:Open Source License
private void assembleUi() { setWidth("100%"); { // Left hand-side panel. final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel(); l.setText("Metric:"); hbox.add(l);/* ww w. j a va 2s .c o m*/ final SuggestBox suggest = RemoteOracle.newSuggestBox("metrics", metric); suggest.setLimit(40); hbox.add(suggest); hbox.setWidth("100%"); metric.setWidth("100%"); tagtable.setWidget(0, 0, hbox); tagtable.getFlexCellFormatter().setColSpan(0, 0, 3); addTag(null); tagtable.setText(1, 0, "Tags"); add(tagtable); } { // Right hand-side panel. final VerticalPanel vbox = new VerticalPanel(); { final HorizontalPanel hbox = new HorizontalPanel(); hbox.add(rate); hbox.add(x1y2); vbox.add(hbox); } { final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel(); l.setText("Aggregator:"); hbox.add(l); hbox.add(aggregators); vbox.add(hbox); } vbox.add(downsample); { final HorizontalPanel hbox = new HorizontalPanel(); hbox.add(downsampler); hbox.add(interval); vbox.add(hbox); } add(vbox); } }
From source file:org.bonitasoft.forms.client.view.widget.FormFieldWidget.java
License:Open Source License
/** * Create a {@link SuggestBox} widget//from ww w .jav a 2s . c om * * @param widgetData * the widget data object * @param fieldValue * the widget value * @return a {@link SuggestBox} */ @SuppressWarnings("unchecked") protected SuggestBox createSuggestBox(final ReducedFormWidget widgetData, final FormFieldValue fieldValue) { final TextBox textBox = new TextBox(); textBox.setEnabled(!widgetData.isReadOnly()); final DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay(); final String popupStyle = widgetData.getItemsStyle(); if (popupStyle != null && popupStyle.length() > 0) { suggestionDisplay.setPopupStyleName(popupStyle); } suggestionsMap = new TreeMap<String, String>(); final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); // this fix the reordering of numbers final Comparator<String> numberComparator = new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (stringIsDouble(o1) && stringIsDouble(o2)) { return Double.valueOf(o1).compareTo(Double.valueOf(o2)); } return o1.compareTo(o2); } private boolean stringIsDouble(final String str) { return str.matches("^(([0-9]*)|(([0-9]*)[\\.,\\,]([0-9]*)))$"); } }; oracle.setComparator(numberComparator); String labelValue = null; final String fieldValueStr = getStringValue(fieldValue); widgetData.getAvailableValues(); for (final ReducedFormFieldAvailableValue availableValue : widgetData.getAvailableValues()) { final String label = availableValue.getLabel(); final String value = availableValue.getValue(); suggestionsMap.put(label, value); oracle.add(label); if (value != null && value.equals(fieldValueStr)) { labelValue = label; } } final SuggestBox suggestBox = new SuggestBox(oracle, textBox, suggestionDisplay); suggestBox.addValueChangeHandler(this); suggestBox.addSelectionHandler(this); if (labelValue != null) { suggestBox.setValue(labelValue); } else { suggestBox.setValue(fieldValueStr); } if (widgetData.getMaxItems() > 0) { suggestBox.setLimit(widgetData.getMaxItems() - 1); } return suggestBox; }
From source file:org.iplantc.phyloviewer.viewer.client.Phyloviewer.java
License:Creative Commons License
/** * This is the entry point method./*from www . j a va2 s. c o m*/ */ public void onModuleLoad() { widget = new TreeWidget(searchService, eventBus); Style highlight = new Style("highlight"); highlight.setNodeStyle(new NodeStyle("#C2C2F5", Double.NaN, null)); highlight.setLabelStyle(new LabelStyle(null)); highlight.setGlyphStyle(new GlyphStyle(null, "#C2C2F5", Double.NaN)); highlight.setBranchStyle(new BranchStyle("#C2C2F5", Double.NaN)); RenderPreferences rp = new RenderPreferences(); rp.setHighlightStyle(highlight); widget.setRenderPreferences(rp); MenuBar fileMenu = new MenuBar(true); fileMenu.addItem("Open...", new Command() { @Override public void execute() { Phyloviewer.this.displayTrees(); } }); Command openURL = new Command() { @Override public void execute() { Window.open(widget.exportImageURL(), "_blank", ""); } }; fileMenu.addItem("Get image (opens in a popup window)", openURL); Command showSVG = new Command() { @Override public void execute() { String svg = getSVG(); String url = "data:image/svg+xml;charset=utf-8," + svg; Window.open(url, "_blank", ""); } }; fileMenu.addItem("Export to SVG", showSVG); MenuBar layoutMenu = new MenuBar(true); layoutMenu.addItem("Rectangular Cladogram", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_CLADOGRAM); layoutType = "LAYOUT_TYPE_CLADOGRAM"; loadTree(null, treeID, layoutType); } }); layoutMenu.addItem("Rectangular Phylogram", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_CLADOGRAM); layoutType = "LAYOUT_TYPE_PHYLOGRAM"; loadTree(null, treeID, layoutType); } }); layoutMenu.addItem("Circular", new Command() { @Override public void execute() { ITree tree = widget.getDocument().getTree(); byte[] treeID = ((RemoteTree) tree).getHash(); widget.setDocument(null); widget.setViewType(TreeWidget.ViewType.VIEW_TYPE_RADIAL); layoutType = "LAYOUT_TYPE_CLADOGRAM"; loadTree(null, treeID, layoutType); } }); MenuBar styleMenu = new MenuBar(true); final TextInputPopup styleTextPopup = new TextInputPopup(); styleTextPopup.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String style = event.getValue(); try { IStyleMap styleMap = StyleServiceClient.parseJSON(style); widget.getDocument().setStyleMap(styleMap); widget.render(); } catch (StyleServiceException e) { Window.alert( "Unable to parse style document. See https://pods.iplantcollaborative.org/wiki/display/iptol/Using+Phyloviewer+GWT+client+library#UsingPhyloviewerGWTclientlibrary-Addingstylingmarkuptoviewer for help."); } } }); styleTextPopup.setModal(true); styleMenu.addItem("Import Tree Styling", new Command() { @Override public void execute() { styleTextPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { int left = (Window.getClientWidth() - offsetWidth) / 3; int top = (Window.getClientHeight() - offsetHeight) / 3; styleTextPopup.setPopupPosition(left, top); } }); } }); // Make a search box final SuggestBox searchBox = new SuggestBox(searchService); searchBox.setLimit(10); // TODO make scrollable? searchBox.addSelectionHandler(new SelectionHandler<Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { Box2D box = ((RemoteNodeSuggestion) event.getSelectedItem()).getResult().layout.boundingBox; widget.show(box); } }); // create some styling widgets for the context menu NodeStyleWidget nodeStyleWidget = new NodeStyleWidget(widget.getDocument()); BranchStyleWidget branchStyleWidget = new BranchStyleWidget(widget.getDocument()); GlyphStyleWidget glyphStyleWidget = new GlyphStyleWidget(widget.getDocument()); LabelStyleWidget labelStyleWidget = new LabelStyleWidget(widget.getDocument()); // replace their default TextBoxes with ColorBoxes, which jscolor.js will add a color picker to nodeStyleWidget.setColorWidget(createColorBox()); branchStyleWidget.setStrokeColorWidget(createColorBox()); glyphStyleWidget.setStrokeColorWidget(createColorBox()); glyphStyleWidget.setFillColorWidget(createColorBox()); labelStyleWidget.setColorWidget(createColorBox()); // add the widgets to separate panels on the context menu final ContextMenu contextMenuPanel = new ContextMenu(widget); contextMenuPanel.add(new NodeTable(), "Node details", 3); contextMenuPanel.add(nodeStyleWidget, "Node", 3); contextMenuPanel.add(branchStyleWidget, "Branch", 3); contextMenuPanel.add(glyphStyleWidget, "Glyph", 3); contextMenuPanel.add(labelStyleWidget, "Label", 3); HorizontalPanel searchPanel = new HorizontalPanel(); searchPanel.add(new Label("Search:")); searchPanel.add(searchBox); // Make the UI. MenuBar menu = new MenuBar(); final DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.EM); mainPanel.addNorth(menu, 2); mainPanel.addSouth(searchPanel, 2); mainPanel.addWest(contextMenuPanel, 0); mainPanel.add(widget); RootLayoutPanel.get().add(mainPanel); MenuBar viewMenu = new MenuBar(true); viewMenu.addItem("Layout", layoutMenu); viewMenu.addItem("Style", styleMenu); contextMenuPanel.setVisible(false); viewMenu.addItem("Toggle Context Panel", new Command() { @Override public void execute() { if (contextMenuPanel.isVisible()) { contextMenuPanel.setVisible(false); mainPanel.setWidgetSize(contextMenuPanel, 0); mainPanel.forceLayout(); } else { contextMenuPanel.setVisible(true); mainPanel.setWidgetSize(contextMenuPanel, 20); mainPanel.forceLayout(); } } }); menu.addItem("File", fileMenu); menu.addItem("View", viewMenu); // Draw for the first time. RootLayoutPanel.get().forceLayout(); mainPanel.forceLayout(); widget.setViewType(ViewType.VIEW_TYPE_CLADOGRAM); widget.render(); initColorPicker(); String[] splitPath = Window.Location.getPath().split("/"); String treeIdString = null; for (int i = 0; i < splitPath.length; i++) { if (splitPath[i].equalsIgnoreCase("tree")) { treeIdString = splitPath[i + 1]; } } if (treeIdString != null && !treeIdString.equals("")) { try { final byte[] treeId = Hex.decodeHex(treeIdString.toCharArray()); this.loadTree(null, treeId, layoutType); } catch (Exception e) { Window.alert("Unable to parse tree ID string from URL"); } } else { // Present the user the dialog to load a tree. this.displayTrees(); } updateStyle(); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { updateStyle(); } }); }
From source file:tsd.client.MetricForm.java
License:Open Source License
private void assembleUi() { setWidth("100%"); { // Left hand-side panel. final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel(); l.setText("Metric:"); hbox.add(l);/* w ww . jav a 2 s . co m*/ final SuggestBox suggest = RemoteOracle.newSuggestBox("metrics", metric); suggest.setLimit(40); hbox.add(suggest); hbox.setWidth("100%"); metric.setWidth("100%"); tagtable.setWidget(0, 0, hbox); tagtable.getFlexCellFormatter().setColSpan(0, 0, 3); addTag(); tagtable.setText(1, 0, "Tags"); add(tagtable); } { // Right hand-side panel. final VerticalPanel vbox = new VerticalPanel(); { final HorizontalPanel hbox = new HorizontalPanel(); hbox.add(rate); hbox.add(rate_counter); hbox.add(x1y2); vbox.add(hbox); } { final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel("Rate Ctr Max:"); hbox.add(l); hbox.add(counter_max); vbox.add(hbox); } { final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel("Rate Ctr Reset:"); hbox.add(l); hbox.add(counter_reset_value); vbox.add(hbox); } { final HorizontalPanel hbox = new HorizontalPanel(); final InlineLabel l = new InlineLabel(); l.setText("Aggregator:"); hbox.add(l); hbox.add(aggregators); vbox.add(hbox); } vbox.add(downsample); { final HorizontalPanel hbox = new HorizontalPanel(); hbox.add(downsampler); hbox.add(interval); vbox.add(hbox); } add(vbox); } }