Search in sources :

Example 56 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class CheckboxUnitTest method elementHasValue_wrapIntoField_propertyIsNotSetToInitialValue.

@Test
public void elementHasValue_wrapIntoField_propertyIsNotSetToInitialValue() {
    Element element = new Element("vaadin-checkbox");
    element.setProperty("checked", true);
    UI ui = new UI();
    UI.setCurrent(ui);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    ui.getInternals().setSession(session);
    VaadinService service = Mockito.mock(VaadinService.class);
    Mockito.when(session.getService()).thenReturn(service);
    Instantiator instantiator = Mockito.mock(Instantiator.class);
    Mockito.when(service.getInstantiator()).thenReturn(instantiator);
    Mockito.when(instantiator.createComponent(Checkbox.class)).thenAnswer(invocation -> new Checkbox());
    Checkbox field = Component.from(element, Checkbox.class);
    Assert.assertEquals(Boolean.TRUE, field.getElement().getPropertyRaw("checked"));
}
Also used : UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Element(com.vaadin.flow.dom.Element) VaadinService(com.vaadin.flow.server.VaadinService) Instantiator(com.vaadin.flow.di.Instantiator) Test(org.junit.Test)

Example 57 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class CheckboxUnitTest method testIndeterminate.

@Test
public void testIndeterminate() {
    Checkbox checkbox = new Checkbox();
    Assert.assertFalse(checkbox.isIndeterminate());
    checkbox = new Checkbox(true);
    Assert.assertFalse(checkbox.isIndeterminate());
    checkbox.setIndeterminate(true);
    Assert.assertTrue(checkbox.getValue());
    Assert.assertTrue(checkbox.isIndeterminate());
    checkbox.setValue(true);
    Assert.assertTrue(checkbox.getValue());
    Assert.assertTrue(checkbox.isIndeterminate());
    checkbox.setValue(false);
    Assert.assertFalse(checkbox.getValue());
    Assert.assertTrue(checkbox.isIndeterminate());
    checkbox.setIndeterminate(false);
    Assert.assertFalse(checkbox.getValue());
    Assert.assertFalse(checkbox.isIndeterminate());
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Test(org.junit.Test)

Example 58 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class CheckboxUnitTest method labelAndInitialValueCtor.

@Test
public void labelAndInitialValueCtor() {
    Checkbox checkbox = new Checkbox("foo", true);
    Assert.assertTrue(checkbox.getValue());
    Assert.assertEquals("foo", checkbox.getLabel());
    checkbox = new Checkbox("foo", false);
    Assert.assertFalse(checkbox.getValue());
    Assert.assertEquals("foo", checkbox.getLabel());
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Test(org.junit.Test)

Example 59 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithComponents.

private void addContextMenuWithComponents() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    // Components can be used also inside menu items
    contextMenu.addItem(new H5("First menu item"), e -> message.setText("Clicked on the first item"));
    Checkbox checkbox = new Checkbox("Checkbox");
    contextMenu.addItem(checkbox, e -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    // Components can also be added to the overlay
    // without creating menu items with add()
    Component separator = new Hr();
    contextMenu.add(separator, new Label("This is not a menu item"));
    addCard("ContextMenu With Components", target, message);
    target.setId("context-menu-with-components-target");
    contextMenu.setId("context-menu-with-components");
    message.setId("context-menu-with-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Example 60 with Checkbox

use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithComponentsInSubMenu.

private void addContextMenuWithComponentsInSubMenu() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    contextMenu.addItem(new H5("First menu item"), event -> message.setText("Clicked on the first item"));
    MenuItem subMenuItem = contextMenu.addItem("SubMenu Item");
    SubMenu subMenu = subMenuItem.getSubMenu();
    Checkbox checkbox = new Checkbox("Checkbox");
    subMenu.addItem(checkbox, event -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    subMenu.addItem("TextItem", event -> message.setText("Clicked on text item"));
    // Components can also be added to the submenu overlay
    // without creating menu items with add()
    subMenu.addComponentAtIndex(1, new Hr());
    subMenu.add(new Label("This is not a menu item"));
    addCard("ContextMenu With Components in Sub Menu", target, message);
    target.setId("context-menu-with-submenu-components-target");
    contextMenu.setId("context-menu-with-submenu-components");
    message.setId("context-menu-with-submenu-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Aggregations

Checkbox (com.vaadin.flow.component.checkbox.Checkbox)68 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)16 Div (com.vaadin.flow.component.html.Div)14 TextField (com.vaadin.flow.component.textfield.TextField)14 Route (com.vaadin.flow.router.Route)14 Button (com.vaadin.flow.component.button.Button)12 Grid (com.vaadin.flow.component.grid.Grid)12 Label (com.vaadin.flow.component.html.Label)12 Collectors (java.util.stream.Collectors)10 Component (com.vaadin.flow.component.Component)8 NativeButton (com.vaadin.flow.component.html.NativeButton)8 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)8 Optional (java.util.Optional)8 Binder (com.vaadin.flow.data.binder.Binder)7 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)7 Set (java.util.Set)7 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)6 PageTitle (io.imunity.furms.ui.components.PageTitle)6 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)6 DateTimeFormatter (java.time.format.DateTimeFormatter)6