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;
}
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;
}
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);
}
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);
}
}
}
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());
}
Aggregations