Class CustomComponentHelper
java.lang.Object
com.vaadin.copilot.customcomponent.CustomComponentHelper
Helper class for custom components
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods) Updates add/replace flags based on its usagestatic CustomComponentApiSelectionextractFromRequest(com.fasterxml.jackson.databind.JsonNode data) CallsextractFromRequest(JsonNode, String)withcustomComponentApiSelectionkeystatic CustomComponentApiSelectionextractFromRequest(com.fasterxml.jackson.databind.JsonNode data, String key) ExtractCustomComponentApiSelectionfrom the data witht the given key if present.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.static CustomComponentResponseDatagenerateResponse(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 UIgetClassHierarchyOfJavaClassNameOrReactTagFromRequest(com.fasterxml.jackson.databind.JsonNode data) Returns the hierarchy of dropped element onto a custom component.static booleanisDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, com.fasterxml.jackson.databind.JsonNode data, int uiId, int nodeId) Checks if the given component is drilled down.static booleanisDrilledDownComponent(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
-
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 UIcomponentsInProject- 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 componentdata- Sent data from client. It requiresACTIVE_CLASS_JSON_KEYandACTIVE_NODE_ID_JSON_KEYcomponent- 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 componentdata- Sent data from client. It requiresACTIVE_CLASS_JSON_KEYandACTIVE_NODE_ID_JSON_KEYuiId- uiIdnodeId- 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 eitherjavaClassNameorreactTagto 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 acceptComponentas parameter.draggedElementClassHierarchy- Hierarchy of dragged component. Strongly related togetClassHierarchyOfJavaClassNameOrReactTagFromRequest(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 locationmethods- Methods belonging to the given component- Throws:
IOException
-
extractFromRequest
public static CustomComponentApiSelection extractFromRequest(com.fasterxml.jackson.databind.JsonNode data) CallsextractFromRequest(JsonNode, String)withcustomComponentApiSelectionkey- 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) ExtractCustomComponentApiSelectionfrom the data witht the given key if present.- Parameters:
data- sent from the clientkey- 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
-