Search in sources :

Example 21 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class IconRenderer method createComponent.

@Override
public Component createComponent(ITEM item) {
    Component icon = iconGenerator.apply(item);
    if (icon == null) {
        throw new IllegalStateException(String.format("Got 'null' as an icon for the item '%s'. " + "Icon generator instance may not return 'null' values", item));
    }
    String text = itemLabelGenerator.apply(item);
    if (text == null) {
        throw new IllegalStateException(String.format("Got 'null' as a label value for the item '%s'. " + "'%s' instance may not return 'null' values", item, ItemLabelGenerator.class.getSimpleName()));
    }
    IconComponent component = new IconComponent();
    component.add(icon);
    component.add(new IconComponent(text));
    return component;
}
Also used : Component(com.vaadin.flow.component.Component)

Example 22 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class NativeButtonRenderer method createComponent.

@Override
public Component createComponent(SOURCE item) {
    NativeButton button = new NativeButton(getValueProvider().apply(item));
    button.addClickListener(event -> getItemClickListeners().forEach(listener -> listener.onItemClicked(item)));
    return button;
}
Also used : List(java.util.List) Component(com.vaadin.flow.component.Component) ValueProvider(com.vaadin.flow.function.ValueProvider) Registration(com.vaadin.flow.shared.Registration) NativeButton(com.vaadin.flow.component.html.NativeButton) Collections(java.util.Collections) ArrayList(java.util.ArrayList) NativeButton(com.vaadin.flow.component.html.NativeButton)

Example 23 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class ValidationTestView method initView.

private void initView() {
    HasValidation field = getValidationComponent();
    ((Component) field).setId("field");
    add(((Component) field));
    NativeButton button = new NativeButton("Make the input invalid");
    button.setId("invalidate");
    button.addClickListener(event -> {
        field.setErrorMessage("Invalidated from server");
        field.setInvalid(true);
    });
    add(button);
    button = new NativeButton("Make the input valid");
    button.setId("validate");
    button.addClickListener(event -> {
        field.setErrorMessage(null);
        field.setInvalid(false);
    });
    add(button);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Component(com.vaadin.flow.component.Component) HasValidation(com.vaadin.flow.component.HasValidation)

Example 24 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class ViewClassLocator method tryLoadClass.

@SuppressWarnings("unchecked")
private void tryLoadClass(Path root, Path path) {
    File file = path.toFile();
    if (file.getName().endsWith(".class") && !file.getName().contains("$")) {
        Path relative = root.relativize(path);
        String className = relative.toString().replace(File.separatorChar, '.').replace(".class", "");
        try {
            Class<?> cls = classLoader.loadClass(className);
            if (Component.class.isAssignableFrom(cls) && !Modifier.isAbstract(cls.getModifiers())) {
                try {
                    // Only include views which have a no-arg
                    // constructor
                    Constructor<?> constructor = cls.getConstructor();
                    assert constructor != null;
                    views.put(cls.getSimpleName(), (Class<? extends Component>) cls);
                } catch (Exception e) {
                // InlineTemplate or similar
                }
            }
        } catch (Exception e) {
            getLogger().warn("Unable to load class {}", className);
        }
    }
}
Also used : Path(java.nio.file.Path) Component(com.vaadin.flow.component.Component) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 25 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class RouterTest method error_target_has_parent_layout.

@Test
public void error_target_has_parent_layout() {
    router.getRegistry().setErrorNavigationTargets(Stream.of(ErrorTargetWithParent.class, RouteNotFoundError.class).collect(Collectors.toSet()));
    int result = router.navigate(ui, new Location("exception"), NavigationTrigger.PROGRAMMATIC);
    Assert.assertEquals("Non existent route should have returned.", HttpServletResponse.SC_NOT_FOUND, result);
    Component parenComponent = ComponentUtil.findParentComponent(ui.getElement().getChild(0)).get();
    Assert.assertEquals(RouteParent.class, parenComponent.getClass());
    Assert.assertEquals("Expected only one child component", 1, parenComponent.getChildren().count());
    Assert.assertEquals("Error target should have been the only child.", ErrorTargetWithParent.class, parenComponent.getChildren().findFirst().get().getClass());
}
Also used : Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Aggregations

Component (com.vaadin.flow.component.Component)66 Test (org.junit.Test)9 Element (com.vaadin.flow.dom.Element)7 UI (com.vaadin.flow.component.UI)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 HasElement (com.vaadin.flow.component.HasElement)2 NativeButton (com.vaadin.flow.component.html.NativeButton)2 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)2 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)2 BeforeEnterEvent (com.vaadin.flow.router.BeforeEnterEvent)2 BeforeLeaveEvent (com.vaadin.flow.router.BeforeLeaveEvent)2 ContinueNavigationAction (com.vaadin.flow.router.BeforeLeaveEvent.ContinueNavigationAction)2 Location (com.vaadin.flow.router.Location)2 LocationChangeEvent (com.vaadin.flow.router.LocationChangeEvent)2 NavigationEvent (com.vaadin.flow.router.NavigationEvent)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 ErrorStateRenderer (com.vaadin.flow.router.internal.ErrorStateRenderer)2 ViewClassLocator (com.vaadin.flow.uitest.servlet.ViewClassLocator)2 Optional (java.util.Optional)2