Java Code Examples for com.google.gwt.user.client.ui.ListBox#getItemText()

The following examples show how to use com.google.gwt.user.client.ui.ListBox#getItemText() . 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: CubaTwinColSelectWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
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 File: CubaTwinColSelectWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
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 3
Source File: CubaTwinColSelectWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
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 4
Source File: YoungAndroidAssetSelectorPropertyEditor.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new property editor for selecting a Young Android asset.
 *
 * @param editor the editor that this property editor belongs to
 */
public YoungAndroidAssetSelectorPropertyEditor(final YaFormEditor editor) {
  Project project = Ode.getInstance().getProjectManager().getProject(editor.getProjectId());
  assetsFolder = ((YoungAndroidProjectNode) project.getRootNode()).getAssetsFolder();
  project.addProjectChangeListener(this);

  VerticalPanel selectorPanel = new VerticalPanel();
  assetsList = new ListBox();
  assetsList.setVisibleItemCount(10);
  assetsList.setWidth("100%");
  selectorPanel.add(assetsList);

  choices = new ListWithNone(MESSAGES.noneCaption(), new ListWithNone.ListBoxWrapper() {
    @Override
    public void addItem(String item) {
      assetsList.addItem(item);
    }

    @Override
    public String getItem(int index) {
      return assetsList.getItemText(index);
    }

    @Override
    public void removeItem(int index) {
      assetsList.removeItem(index);
    }

    @Override
    public void setSelectedIndex(int index) {
      assetsList.setSelectedIndex(index);
    }
  });

  // Fill choices with the assets.
  if (assetsFolder != null) {
    for (ProjectNode node : assetsFolder.getChildren()) {
      choices.addItem(node.getName());
    }
  }

  Button addButton = new Button(MESSAGES.addButton());
  addButton.setWidth("100%");
  addButton.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
      FileUploadedCallback callback = new FileUploadedCallback() {
        @Override
        public void onFileUploaded(FolderNode folderNode, FileNode fileNode) {
          // At this point, the asset has been uploaded to the server, and
          // has even been added to the assetsFolder. We are all set!
          choices.selectValue(fileNode.getName());
          closeAdditionalChoiceDialog(true);
        }
      };
      FileUploadWizard uploader = new FileUploadWizard(assetsFolder, callback);
      uploader.show();
    }
  });
  selectorPanel.add(addButton);
  selectorPanel.setWidth("100%");

  // At this point, the editor hasn't finished loading.
  // Use a DeferredCommand to finish the initialization after the editor has finished loading.
  DeferredCommand.addCommand(new Command() {
    @Override
    public void execute() {
      if (editor.isLoadComplete()) {
        finishInitialization();
      } else {
        // Editor still hasn't finished loading.
        DeferredCommand.addCommand(this);
      }
    }
  });

  initAdditionalChoicePanel(selectorPanel);
}
 
Example 5
Source File: YoungAndroidComponentSelectorPropertyEditor.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new property editor for selecting a component, where the
 * user chooses among components of one or more component types.
 *
 * @param editor the editor that this property editor belongs to
 * @param componentTypes types of component that can be selected, or null if
 *        all types of components can be selected.
 */
public YoungAndroidComponentSelectorPropertyEditor(final YaFormEditor editor,
    Set<String> componentTypes) {
  this.editor = editor;
  this.componentTypes = componentTypes;

  VerticalPanel selectorPanel = new VerticalPanel();
  componentsList = new ListBox();
  componentsList.setVisibleItemCount(10);
  componentsList.setWidth("100%");
  selectorPanel.add(componentsList);
  selectorPanel.setWidth("100%");

  choices = new ListWithNone(MESSAGES.noneCaption(), new ListWithNone.ListBoxWrapper() {
    @Override
    public void addItem(String item) {
      componentsList.addItem(item);
    }

    @Override
    public String getItem(int index) {
      return componentsList.getItemText(index);
    }

    @Override
    public void removeItem(int index) {
      componentsList.removeItem(index);
    }

    @Override
    public void setSelectedIndex(int index) {
      componentsList.setSelectedIndex(index);
    }
  });

  // At this point, the editor hasn't finished loading.
  // Use a DeferredCommand to finish the initialization after the editor has finished loading.
  DeferredCommand.addCommand(new Command() {
    @Override
    public void execute() {
      if (editor.isLoadComplete()) {
        finishInitialization();
      } else {
        // Editor still hasn't finished loading.
        DeferredCommand.addCommand(this);
      }
    }
  });

  initAdditionalChoicePanel(selectorPanel);
}
 
Example 6
Source File: SingleListBox.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
/**
    * Utility function to get the current text.
    */
   public static final String getSelectedText(ListBox list) {
int index = list.getSelectedIndex();
return (index >= 0) ? list.getItemText(index) : null;
   }