use of com.vaadin.flow.component.Component in project flow by vaadin.
the class RouterTest method getErrorText.
private String getErrorText(Component routeNotFoundError) {
if (routeNotFoundError.getClass() == RouteNotFoundError.class) {
Component errorContent = routeNotFoundError.getChildren().findFirst().get();
Assert.assertEquals(Html.class, errorContent.getClass());
return ((Html) errorContent).getInnerHtml().toString();
} else {
return routeNotFoundError.getElement().getText();
}
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class ToStringTest method testViewsElementsStringable.
@Test
public void testViewsElementsStringable() throws Exception {
Collection<Class<? extends Component>> viewClasses = new ViewClassLocator(getClass().getClassLoader()).getAllViewClasses();
for (Class<? extends Component> viewClass : viewClasses) {
Component view = viewClass.newInstance();
String string = view.getElement().toString();
Assert.assertNotNull(string);
Assert.assertNotEquals("", string);
}
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class PublishedServerEventHandlerRpcHandler method handleNode.
@Override
public Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_TEMPLATE_EVENT_METHOD_NAME);
String methodName = invocationJson.getString(JsonConstants.RPC_TEMPLATE_EVENT_METHOD_NAME);
if (methodName == null) {
throw new IllegalArgumentException("Event handler method name may not be null");
}
JsonValue args = invocationJson.get(JsonConstants.RPC_TEMPLATE_EVENT_ARGS);
if (args == null) {
args = Json.createArray();
}
if (args.getType() != JsonType.ARRAY) {
throw new IllegalArgumentException("Incorrect type for method arguments: " + args.getClass());
}
assert node.hasFeature(ComponentMapping.class);
Optional<Component> component = node.getFeature(ComponentMapping.class).getComponent();
if (!component.isPresent()) {
throw new IllegalStateException("Unable to handle RPC template event JSON message: " + "there is no component available for the target node");
}
invokeMethod(component.get(), component.get().getClass(), methodName, (JsonArray) args);
return Optional.empty();
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class RouteRegistryInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException {
try {
if (classSet == null) {
RouteRegistry.getInstance(servletContext).setNavigationTargets(Collections.emptySet());
return;
}
Set<Class<? extends Component>> routes = validateRouteClasses(classSet.stream());
RouteRegistry.getInstance(servletContext).setNavigationTargets(routes);
} catch (InvalidRouteConfigurationException irce) {
throw new ServletException("Exception while registering Routes on servlet startup", irce);
}
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class AngularTemplate method tryMapComponentOrElement.
@SuppressWarnings("unchecked")
private void tryMapComponentOrElement(Field field) {
Optional<Id> idAnnotation = AnnotationReader.getAnnotationFor(field, Id.class);
if (!idAnnotation.isPresent()) {
return;
}
String id = idAnnotation.get().value();
Class<?> fieldType = field.getType();
String fieldName = field.getName();
Element element = getElementById(id).orElseThrow(() -> new IllegalArgumentException(String.format("No element with id '%s' found while binding field '%s' in '%s'", id, fieldName, getClass().getName())));
if (element.equals(getElement())) {
throw new IllegalArgumentException("Cannot map the root element of the template. " + "This is always mapped to the template instance itself (" + getClass().getName() + ")");
}
if (Component.class.isAssignableFrom(fieldType)) {
Class<? extends Component> componentType = (Class<? extends Component>) fieldType;
Component c = Component.from(element, componentType);
ReflectTools.setJavaFieldValue(this, field, c);
} else if (Element.class.isAssignableFrom(fieldType)) {
ReflectTools.setJavaFieldValue(this, field, element);
} else {
throw new IllegalArgumentException(String.format("The field '%s' in '%s' has an @'%s' " + "annotation but the field type '%s' " + "does not extend neither '%s' nor '%s'", fieldName, getClass().getName(), Id.class.getSimpleName(), fieldType.getName(), Component.class.getSimpleName(), Element.class.getSimpleName()));
}
}
Aggregations