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

The following examples show how to use com.google.gwt.user.client.ui.ListBox#setSelectedIndex() . 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
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 2
Source File: SettingsPanel.java    From swcv with MIT License 6 votes vote down vote up
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 3
Source File: SettingsPanel.java    From swcv with MIT License 6 votes vote down vote up
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 4
Source File: SettingsPanel.java    From swcv with MIT License 6 votes vote down vote up
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 5
Source File: SettingsPanel.java    From swcv with MIT License 6 votes vote down vote up
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 6
Source File: SettingsPanel.java    From swcv with MIT License 6 votes vote down vote up
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 7
Source File: SingleListBox.java    From gwt-traction with Apache License 2.0 6 votes vote down vote up
/**
    * 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 8
Source File: TemplateUploadWizard.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: PageFilter.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 10
Source File: ReservationEdit.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 11
Source File: Toolbar.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: SettingsPanel.java    From swcv with MIT License 5 votes vote down vote up
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 13
Source File: DataTypeSelectPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
/**
 * UI initialization
 */
public void init()
{
	this.setSize("480px", "100px");

	//Dialog box title
	closeButton.setSize("10px", "10px");
	closeButton.setStyleName("closebtn");

	//Selection dialog
	HorizontalPanel typeListPanel = new HorizontalPanel();
	typeListPanel.setStyleName("popupDatatypeSelectPanel");
	typeListBox = new ListBox();
	typeListBox.setWidth("120px");
	typeListBox.addItem("----");
	typeListBox.addItem(DatasetType.GENERAL.getDesc());
	typeListBox.addItem(DatasetType.CSV.getDesc());
	typeListBox.addItem(DatasetType.TSV.getDesc());
	typeListBox.addItem(DatasetType.JSON.getDesc());
	if(dataset.getContenttype() == null || dataset.getContenttype() .equals(""))
		typeListBox.setSelectedIndex(0);
	else
	{
		for(int i = 0 ; i<typeListBox.getItemCount() ; i++)
		{
			if(typeListBox.getItemText(i).equals(dataset.getContenttype()))
			{
				typeListBox.setSelectedIndex(i);
				break;
			}
		}
	}
	Label selectLabel = new Label("Select data type: ");
	typeListPanel.add(selectLabel);
	typeListPanel.add(typeListBox);

	//Ok and cancel button
	HorizontalPanel buttonPanel = new HorizontalPanel();
	buttonPanel.setStyleName("popupDatatypeButtonPanel");
	okBtn = new Button("Ok");
	okBtn.setStyleName("button-style");
	cancelBtn = new Button("Cancel");
	cancelBtn.setStyleName("button-style");
	buttonPanel.add(okBtn);
	buttonPanel.add(cancelBtn);

	//Overall arrangement
	VerticalPanel topPanel = new VerticalPanel();
	topPanel.add(closeButton);
	topPanel.setCellHeight(closeButton, "13px");
	topPanel.setStyleName("vpanel");
	desc.setStyleName("popupDatatypeSelectTitle");
	topPanel.add(desc);
	topPanel.setCellHeight(desc, "30px");
	topPanel.add(typeListPanel);
	topPanel.add(buttonPanel);

	this.setGlassEnabled(true);
	this.setModal(true);
	this.add(topPanel);
	this.center();
	this.setStyleName("loading-panel");
}
 
Example 14
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 15
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 16
Source File: PointInTimeDataReportsPage.java    From unitime with Apache License 2.0 4 votes vote down vote up
public void reload(String history) {
	if (history == null) return;
	if (history.indexOf('&') >= 0)
		history = history.substring(0, history.indexOf('&')); 
	if (history.isEmpty()) return;
	String[] params = history.split(":");
	String id = params[0];
	PointInTimeDataReportsInterface.Report rpt = null;
	for (int i = 0; i < iReports.size(); i++) {
		PointInTimeDataReportsInterface.Report q = iReports.get(i);
		if (id.equals(q.getId())) {
			rpt = q;
			iReportSelector.getWidget().setSelectedIndex(1 + i);
			queryChanged();
			break;
		}
	}
	if (rpt == null) return;
	int idx = 1;
	for (int i = 0; i < iParameters.size(); i++) {
		PointInTimeDataReportsInterface.Parameter parameter = iParameters.get(i);
		if (rpt.parametersContain(parameter.getType())) {
			String param = params[idx++];
			if (param == null || param.isEmpty()) continue;
			if (parameter.isTextField()) {
				TextBox text = ((UniTimeWidget<TextBox>)iForm.getWidget(3 + i, 1)).getWidget();
				text.setText(param);
			} else {
				ListBox list = ((UniTimeWidget<ListBox>)iForm.getWidget(3 + i, 1)).getWidget();
				if (list.isMultipleSelect()) {
					for (int j = 0; j < list.getItemCount(); j++) {
						String value = list.getValue(j);
						boolean contains = false;
						for (String o: param.split(",")) if (o.equals(value)) { contains = true; break; }
						list.setItemSelected(j, contains);
					}
				} else {
					for (int j = 1; j < list.getItemCount(); j++) {
						if (list.getValue(j).equals(param)) {
							list.setSelectedIndex(j); break;
						}
					}
				}
			}
		}
	}
	iLastSort = Integer.parseInt(params[idx++]);
	execute();
}