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

The following examples show how to use com.google.gwt.user.client.ui.ListBox#getItemCount() . 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 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 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 4
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 5
Source File: CourseNumbersSuggestBox.java    From unitime with Apache License 2.0 6 votes vote down vote up
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 6
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 7
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 8
Source File: SettingsPanel.java    From swcv with MIT License 5 votes vote down vote up
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 9
Source File: SingleListBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
    * Utility function to find the first index of a value in a
    * ListBox.
    */
   public static final int findValueInListBox(ListBox list, String value) {
for (int i=0; i<list.getItemCount(); i++) {
    if (value.equals(list.getValue(i))) {
	return i;
    }
}
return -1;
   }
 
Example 10
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 11
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();
}