com.vaadin.flow.router.Route类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中com.vaadin.flow.router.Route类的一些代码示例,展示了Route类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Route类的具体详情如下:
包路径:com.vaadin.flow.router.Route
类名称:Route

Route介绍

暂无

代码示例

代码示例来源:origin: com.holon-platform.vaadin/documentation-vaadin-flow

@Route("some/path")
public class View extends Div {
  @OnShow // <1>
  public void afterNavigation1() {
    /* ... */
  }
  @OnShow // <2>
  public void afterNavigation2(AfterNavigationEvent event) {
    /* ... */
  }
}
// end::route1[]

代码示例来源:origin: appreciated/vaadin-app-layout

public DefaultNavigationElementInfoProducer() {
    super(info -> info.getAnnotation(Route.class).value());
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Get the actual route path including all parent layout
 * {@link RoutePrefix}.
 *
 * @param component
 *            navigation target component to get route path for
 * @param route
 *            route annotation to check
 * @return actual path for given route target
 */
public static String getRoutePath(Class<?> component, Route route) {
  if (route.absolute()) {
    return resolve(component, route);
  }
  List<String> parentRoutePrefixes = getRoutePrefixes(component,
      route.layout(), resolve(component, route));
  return parentRoutePrefixes.stream().collect(Collectors.joining("/"));
}

代码示例来源:origin: com.vaadin/flow-server

private List<String> validateAnnotatedClasses(
    Collection<Class<?>> classSet) {
  List<String> offendingAnnotations = new ArrayList<>();
  for (Class<?> clazz : classSet) {
    Route route = clazz.getAnnotation(Route.class);
    if (route != null) {
      if (!UI.class.equals(route.layout())) {
        offendingAnnotations.add(String.format(NON_PARENT,
            clazz.getName(), getClassAnnotations(clazz)));
      }
      RouteAlias routeAlias = clazz.getAnnotation(RouteAlias.class);
      if (routeAlias != null
          && !UI.class.equals(routeAlias.layout())) {
        offendingAnnotations.add(String.format(NON_PARENT_ALIAS,
            clazz.getName(), getClassAnnotations(clazz)));
      }
    } else if (!RouterLayout.class.isAssignableFrom(clazz)) {
      if (!Modifier.isAbstract(clazz.getModifiers())) {
        offendingAnnotations.add(String.format(NON_ROUTER_LAYOUT,
            clazz.getName(), getClassAnnotations(clazz)));
      }
    } else if (RouterLayout.class.isAssignableFrom(clazz)
        && clazz.getAnnotation(ParentLayout.class) != null) {
      offendingAnnotations.add(String.format(MIDDLE_ROUTER_LAYOUT,
          clazz.getName(), getClassAnnotations(clazz)));
    }
  }
  return offendingAnnotations;
}

代码示例来源:origin: com.vaadin/flow-component-demo-helpers

private String getTabUrl(String relativeHref) {
  String href = relativeHref == null || relativeHref.isEmpty() ? ""
      : "/" + relativeHref;
  return getClass().getAnnotation(Route.class).value() + href;
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Get parent layouts for navigation target according to the {@link Route}
 * or {@link RouteAlias} annotation.
 *
 * @param component navigation target to get parents for
 * @param path      path used to get navigation target so we know which annotation
 *                  to handle
 * @return parent layouts for target
 */
public static List<Class<? extends RouterLayout>> getParentLayouts(
    Class<?> component, String path) {
  final List<Class<? extends RouterLayout>> list = new ArrayList<>();
  Optional<Route> route = AnnotationReader.getAnnotationFor(component,
      Route.class);
  List<RouteAlias> routeAliases = AnnotationReader
      .getAnnotationsFor(component, RouteAlias.class);
  if (route.isPresent()
      && path.equals(getRoutePath(component, route.get()))
      && !route.get().layout().equals(UI.class)) {
    list.addAll(collectRouteParentLayouts(route.get().layout()));
  } else {
    Optional<RouteAlias> matchingRoute = getMatchingRouteAlias(
        component, path, routeAliases);
    if (matchingRoute.isPresent()) {
      list.addAll(collectRouteParentLayouts(
          matchingRoute.get().layout()));
    }
  }
  return list;
}

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view2", layout = LeftHybridBehaviourView.class) // an empty view name will also be the default view
public class View2 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: appreciated/vaadin-app-layout

default int computeClosenessScore(Class<? extends HasElement> compare, Class<? extends HasElement> compare2) {
  String[] desiredRoute = getRoute(compare).get().value().split("/");
  String[] elementRoute = getRoute(compare2).map(route -> route.value().split("/")).orElse(null);
  int score = 0;
  for (; score < elementRoute.length; score++)
    if (desiredRoute.length >= score && !elementRoute[score].equals(desiredRoute[score])) {
      return score;
    }
  return score;
}

代码示例来源:origin: com.vaadin/flow-server

if (route.isPresent()
    && path.equals(getRoutePath(component, route.get()))
    && !route.get().layout().equals(UI.class)) {
  list.addAll(collectRouteParentLayouts(route.get().layout()));
} else {

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view5", layout = LeftResponsiveHybridNoAppBarBehaviourView.class)
// an empty view name will also be the default view
public class View5 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
   * Gets the effective route path value of the annotated class.
   *
   * @param component
   *            the component where the route points to
   * @param route
   *            the annotation
   * @return The value of the annotation or naming convention based value if
   *         no explicit value is given.
   */
  public static String resolve(Class<?> component, Route route) {
    if (route.value().equals(Route.NAMING_CONVENTION)) {
      String simpleName = component.getSimpleName();
      if ("MainView".equals(simpleName) || "Main".equals(simpleName)) {
        return "";
      }
      if (simpleName.endsWith("View")) {
        return simpleName
            .substring(0, simpleName.length() - "View".length())
            .toLowerCase();
      }
      return simpleName.toLowerCase();
    }
    return route.value();
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Validate PWA annotations of the potential route classes stream, search
 * for properly annotated PWA class and return it, or null if none existing.
 *
 * @param routeClasses
 *         potential route classes
 * @return a PWA -annotated class, or null if none exist.
 */
@SuppressWarnings("unchecked")
protected Class<?> validatePwaClass(Stream<Class<?>> routeClasses) {
  pwaClass = null;
  routeClasses.forEach(route -> {
    // check and validate route pwa annotation
    validatePwa(route);
    Route routeAnnotation = route.getAnnotation(Route.class);
    if (!UI.class.equals(routeAnnotation.layout())) {
      Class<? extends RouterLayout> topParentLayout = RouteUtil
          .getTopParentLayout(route,
              RouteUtil.resolve(route, routeAnnotation));
      // check and validate top parent layout pwa annotation
      validatePwa(topParentLayout);
    }
  });
  return pwaClass;
}

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view5", layout = TopLargeBehaviourView.class)
// an empty view name will also be the default view
public class View5 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: com.vaadin/flow-server

private void validateRouteImplementation(Class<?> route,
    Class<?> implementation) {
  Route annotation = route.getAnnotation(Route.class);
  if (!UI.class.equals(annotation.layout())) {
    if (implementation.isAssignableFrom(route)) {
      throw new InvalidRouteLayoutConfigurationException(
          String.format(
              "%s needs to be the top parent layout '%s' not '%s'",
              implementation.getSimpleName(), RouteUtil
                  .getTopParentLayout(route, RouteUtil
                      .resolve(route, annotation))
                  .getName(), route.getName()));
    }
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
        .getParentLayouts(route,
            RouteUtil.resolve(route, annotation));
    Class<? extends RouterLayout> topParentLayout = RouteUtil
        .getTopParentLayout(route,
            RouteUtil.resolve(route, annotation));
    validateParentImplementation(parentLayouts, topParentLayout,
        implementation);
  }
}

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view5", layout = LeftHybridSmallBehaviourView.class) // an empty view name will also be the default view
public class View5 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: com.vaadin/flow-server

private void validateRouteAnnotation(Class<?> route,
    Class<? extends Annotation> annotation) {
  Route routeAnnotation = route.getAnnotation(Route.class);
  if (!UI.class.equals(routeAnnotation.layout())) {
    if (route.isAnnotationPresent(annotation)) {
      throw new InvalidRouteLayoutConfigurationException(
          String.format(
              "%s annotation needs to be on the top parent layout '%s' not on '%s'",
              annotation.getSimpleName(), RouteUtil
                  .getTopParentLayout(route, RouteUtil
                      .resolve(route,
                          routeAnnotation))
                  .getName(), route.getName()));
    }
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
        .getParentLayouts(route,
            RouteUtil.resolve(route, routeAnnotation));
    Class<? extends RouterLayout> topParentLayout = RouteUtil
        .getTopParentLayout(route,
            RouteUtil.resolve(route, routeAnnotation));
    validateParentAnnotation(parentLayouts, topParentLayout,
        annotation);
  }
}

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view3", layout = LeftResponsiveSmallNoAppBarBehaviourView.class)
// an empty view name will also be the default view
public class View3 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: com.vaadin/flow-server

if (route.isPresent()
    && path.equals(getRoutePath(component, route.get()))
    && !route.get().layout().equals(UI.class)) {
  return recurseToTopLayout(route.get().layout());
} else {
  Optional<RouteAlias> matchingRoute = getMatchingRouteAlias(

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view7", layout = LeftResponsiveSmallBehaviourView.class)
// an empty view name will also be the default view
public class View7 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

代码示例来源:origin: appreciated/vaadin-app-layout

@Route(value = "view7", layout = TopLargeBehaviourView.class)
// an empty view name will also be the default view
public class View7 extends ExampleView {
  @Override
  protected String getViewName() {
    return getClass().getName();
  }
}

相关文章

微信公众号

最新文章

更多