Class CustomComponentHelper

java.lang.Object
com.vaadin.copilot.customcomponent.CustomComponentHelper

public class CustomComponentHelper extends Object
Helper class for custom components
  • Method Details

    • generateResponse

      public static CustomComponentResponseData generateResponse(com.vaadin.flow.server.VaadinSession vaadinSession, Map<com.vaadin.flow.component.Component,ComponentTypeAndSourceLocation> allComponents, List<com.vaadin.flow.component.Component> componentsInProject)
      Generates the response that is used in the UI
      Parameters:
      allComponents - Component and source location of all components that are found in the UI
      componentsInProject - Components that have source in the project.
      Returns:
      response that contains required metadata for the custom component feature
    • isDrilledDownComponent

      public static boolean isDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, com.fasterxml.jackson.databind.JsonNode data, com.fasterxml.jackson.databind.JsonNode component)
      Checks if the given component is drilled down
      Parameters:
      vaadinSession - Vaadin session to access component
      data - Sent data from client. It requires ACTIVE_CLASS_JSON_KEY and ACTIVE_NODE_ID_JSON_KEY
      component - JSON data that contains uiId and nodeId
      Returns:
      true if drilled down component, false otherwise
    • isDrilledDownComponent

      public static boolean isDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, com.fasterxml.jackson.databind.JsonNode data, int uiId, int nodeId)
      Checks if the given component is drilled down.
      Parameters:
      vaadinSession - Vaadin session to access component
      data - Sent data from client. It requires ACTIVE_CLASS_JSON_KEY and ACTIVE_NODE_ID_JSON_KEY
      uiId - uiId
      nodeId - nodeId of the given component
      Returns:
      true if drilled down component, false otherwise
    • getClassHierarchyOfJavaClassNameOrReactTagFromRequest

      public static List<String> getClassHierarchyOfJavaClassNameOrReactTagFromRequest(com.fasterxml.jackson.databind.JsonNode data)
      Returns the hierarchy of dropped element onto a custom component. Extracts the relevant parts from the data object.
      Parameters:
      data - should contain either javaClassName or reactTag to find relevant Java Class
      Returns:
      list of
      Throws:
      CopilotException - when something goes wrong with looking for class hierarchy
    • filterMethodBasedOnDraggedComponentHierarchy

      public static List<JavaReflectionUtil.ComponentAddableMethod> filterMethodBasedOnDraggedComponentHierarchy(List<JavaReflectionUtil.ComponentAddableMethod> methods, List<String> draggedElementClassHierarchy)
      Filters the method in the custom component based on the dragged element hierarchy. e.g. when you drop an Image onto Custom Component, the listed methods should be in the hierarchy of Image. Methods that gets Button or any other component as parameter should be filtered out.
      Parameters:
      methods - List of methods that accept Component as parameter.
      draggedElementClassHierarchy - Hierarchy of dragged component. Strongly related to getClassHierarchyOfJavaClassNameOrReactTagFromRequest(JsonNode)
      Returns:
      List of filtered components
    • addInfoFromComponentSource

      public static void addInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods) throws IOException
      Updates add/replace flags based on its usage
      Parameters:
      componentTypeAndSourceLocation - Component type and source location
      methods - Methods belonging to the given component
      Throws:
      IOException
    • extractFromRequest

      public static CustomComponentApiSelection extractFromRequest(com.fasterxml.jackson.databind.JsonNode data)
      Calls extractFromRequest(JsonNode, String) with customComponentApiSelection key
      Parameters:
      data - sent from the Client
      Returns:
      Null if customComponentApiSelection is not present in the JSON or not an object or unable to parse
    • extractFromRequest

      public static CustomComponentApiSelection extractFromRequest(com.fasterxml.jackson.databind.JsonNode data, String key)
      Extract CustomComponentApiSelection from the data witht the given key if present.
      Parameters:
      data - sent from the client
      key - JSON key to get the value
      Returns:
      CustomComponentApiSelection if present, or null if customComponentApiSelection is not present in the JSON or not an object or unable to parse