gwt.material.design.client.ui.html.Option Java Examples

The following examples show how to use gwt.material.design.client.ui.html.Option. 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: MaterialListBoxTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void testAllowBlanks() {
    // given
    MaterialListBox listBox = (MaterialListBox)getWidget();
    assertFalse(listBox.isAllowBlank());
    assertEquals(0, listBox.getItemCount());

    // when / then
    listBox.setValue(null);
    assertEquals("", listBox.getValue());

    listBox.setAllowBlank(true);
    listBox.addItem("user1");
    listBox.addItem("user2");
    Option option = new Option("user3");
    listBox.add(option);
    assertEquals(4, listBox.getItemCount());

    listBox.setValue("");
    assertEquals("", listBox.getValue());
    assertEquals(0, listBox.getSelectedIndex());

    listBox.setValue("user3");
    assertEquals("user3", listBox.getValue());
    assertEquals(3, listBox.getSelectedIndex());

    listBox.setValue(null);
    assertEquals("", listBox.getValue());
    assertEquals(0, listBox.getSelectedIndex());

    listBox.setValue("user4");
    assertEquals("", listBox.getValue());
    assertEquals(0, listBox.getSelectedIndex());

    listBox.setAllowBlank(false);
    assertEquals(3, listBox.getItemCount());
    assertEquals("user1", listBox.getValue());
    assertEquals(0, listBox.getSelectedIndex());
}
 
Example #2
Source File: MaterialComboBox.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
@Override
public void add(Widget child) {
    if (child instanceof OptGroup) {
        for (Widget w : ((OptGroup) child).getChildren()) {
            if (w instanceof Option) {
                values.add((T) ((Option) w).getValue());
            }
        }
    } else if (child instanceof Option) {
        values.add((T) ((Option) child).getValue());
    }
    listbox.add(child);
}
 
Example #3
Source File: MaterialComboBox.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Add Value directly to combobox component
 *
 * @param text  - The text you want to labeled on the option item
 * @param value - The value you want to pass through in this option
 */
public Option addItem(String text, T value) {
    if (!values.contains(value)) {
        Option option = buildOption(text, value);
        values.add(value);
        listbox.add(option);
        return option;
    }
    return null;
}
 
Example #4
Source File: MaterialComboBox.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Build the Option Element with provided params
 */
protected Option buildOption(String text, T value) {
    Option option = new Option();
    option.setText(text);
    option.setValue(keyFactory.generateKey(value));
    return option;
}
 
Example #5
Source File: MaterialComboBoxTest.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
@Override
protected MaterialComboBox createWidget() {
    MaterialComboBox<String> comboBox = new MaterialComboBox<>();
    for (int i = 1; i <= 5; i++) {
        Option option = comboBox.addItem(String.valueOf(i), String.valueOf(i));
        assertNotNull(option);
    }
    return comboBox;
}
 
Example #6
Source File: MaterialComboBoxTest.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public void testAddItemOption() {
    // given
    MaterialComboBox<String> comboBox = new MaterialComboBox<>();
    RootPanel.get().add(comboBox);

    // when / then
    // Check Initial children
    assertEquals(0, comboBox.getValues().size());
    assertEquals(3, comboBox.getChildren().size());
    // Check simple String object
    for (int i = 1; i <= 5; i++) {
        comboBox.addItem("item" + i);
    }
    assertEquals(5, comboBox.getValues().size());
    final String VALUE = comboBox.getValues().get(0);
    final String SECOND_VALUE = comboBox.getValues().get(1);
    checkValueChangeEvent(comboBox, Collections.singletonList(VALUE), Collections.singletonList(SECOND_VALUE));

    // Check ListBox
    assertNotNull(comboBox.getWidget(0));
    assertTrue(comboBox.getWidget(0) instanceof MaterialWidget);
    assertEquals(comboBox.getListbox(), comboBox.getWidget(0));
    MaterialWidget listBox = comboBox.getListbox();
    assertEquals(5, listBox.getWidgetCount());
    for (Widget w : listBox) {
        assertNotNull(w);
        assertTrue(w instanceof Option);
    }
    // Check Label
    assertNotNull(comboBox.getWidget(1));
    assertTrue(comboBox.getWidget(1) instanceof Label);
    Label lblTitle = (Label) comboBox.getWidget(1);
    assertTrue(lblTitle.getElement().hasClassName(AddinsCssName.SELECT2LABEL));
    // Check error label
    assertNotNull(comboBox.getWidget(2));
    assertTrue(comboBox.getWidget(2) instanceof MaterialLabel);
    assertEquals(comboBox.getErrorLabel(), comboBox.getWidget(2));

}
 
Example #7
Source File: MaterialListBox.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public void add(Option option) {
    getSelectElement().add(OptionElement.as(option.getElement()), null);
    values.add(option.getValue());
}
 
Example #8
Source File: PickersView.java    From gwt-material-demo with Apache License 2.0 4 votes vote down vote up
private void initLanguage() {
    for(DatePickerLanguage lang : DataHelper.getAllDateLanguage()) {
        languages.add(lang);
        lstLanguage.add(new Option(lang.getName()));
    }
}
 
Example #9
Source File: MaterialComboBox.java    From gwt-material-addins with Apache License 2.0 4 votes vote down vote up
public Option addItem(T value) {
    return addItem(keyFactory.generateKey(value), value);
}
 
Example #10
Source File: QueryOptionsView.java    From lumongo with Apache License 2.0 4 votes vote down vote up
public QueryOptionsView(UIQueryResults uiQueryResults) {
	setMargin(15);
	setPadding(10);

	uiQueryObject = uiQueryResults.getUiQueryObject();
	if (uiQueryObject == null) {
		uiQueryObject = new UIQueryObject();
	}

	if (!uiQueryResults.getJsonDocs().isEmpty()) {
		MaterialBadge resultsBadge = new MaterialBadge("Total Results: " + NumberFormat.getFormat("#,##0").format(uiQueryResults.getTotalResults()));
		add(resultsBadge);
		add(new Br());
	}

	MaterialButton executeButton = new MaterialButton("Execute", IconType.SEARCH);
	executeButton.addClickHandler(clickEvent -> runSearch());
	executeButton.setMarginRight(2);
	add(executeButton);

	MaterialButton resetButton = new MaterialButton("Reset", IconType.REFRESH);
	resetButton.addClickHandler(clickEvent -> MainController.get().goTo(new QueryPlace(null)));
	add(resetButton);

	MaterialListBox indexesListBox = new MaterialListBox();
	indexesListBox.setMultipleSelect(true);
	Option selectOneIndexOption = new Option("Select Indexes");
	selectOneIndexOption.setDisabled(true);
	indexesListBox.add(selectOneIndexOption);

	fieldNameCollapsible = new MaterialCollapsible();
	fieldNameCollapsible.setAccordion(false);
	for (IndexInfo indexInfo : uiQueryResults.getIndexes()) {
		createFieldNameCollapsible(indexInfo);

		Option option = new Option(indexInfo.getName());
		if (uiQueryObject.getIndexNames().contains(indexInfo.getName())) {
			option.setSelected(true);
			fieldItems.get(indexInfo.getName()).setVisible(true);
		}
		indexesListBox.add(option);
	}
	indexesListBox.addValueChangeHandler(valueChangeEvent -> {
		for (String indexName : fieldItems.keySet()) {
			fieldItems.get(indexName).setVisible(false);
		}
		for (String itemsSelected : indexesListBox.getItemsSelected()) {
			uiQueryObject.getIndexNames().add(itemsSelected);
			fieldItems.get(itemsSelected).setVisible(true);
		}
	});

	add(indexesListBox);
	add(fieldNameCollapsible);

	CustomTextBox searchBox = new CustomTextBox(true);
	searchBox.setPlaceHolder("q=*:*");
	searchBox.setValue(uiQueryObject.getQuery());
	searchBox.addKeyUpHandler(clickEvent -> {
		if (clickEvent.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
			uiQueryObject.setQuery(searchBox.getValue());
			runSearch();
		}
	});

	searchBox.getButton().setTitle("Execute Query");
	searchBox.getButton().addClickHandler(clickEvent -> {
		uiQueryObject.setQuery(searchBox.getValue());
		runSearch();
	});

	add(searchBox);

	CustomTextBox rowsIntegerBox = new CustomTextBox();
	rowsIntegerBox.setPlaceHolder("rows (defaults to 10)");
	if (uiQueryObject != null && uiQueryObject.getRows() != 10) {
		rowsIntegerBox.setValue(uiQueryObject.getRows() + "");
	}
	rowsIntegerBox.getTextBox().addChangeHandler(changeEvent -> uiQueryObject.setRows(Integer.valueOf(rowsIntegerBox.getValue())));
	rowsIntegerBox.addKeyUpHandler(clickEvent -> {
		if (clickEvent.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
			runSearch();
		}
	});

	add(rowsIntegerBox);

	filterQueryDiv = new Div();
	if (!uiQueryObject.getFilterQueries().isEmpty()) {
		for (String fq : uiQueryObject.getFilterQueries()) {
			createFilterQueryWidget(fq);
		}
	}
	else {
		createFilterQueryWidget(null);
	}

	add(filterQueryDiv);

}