Search in sources :

Example 1 with Vertex

use of io.sunshower.zephyr.ui.canvas.Vertex in project aire-components by aire-ux.

the class TopologyView method registerListeners.

private void registerListeners() {
    canvas.addCanvasListener(CanvasEvent.CanvasInteractionEventType.Clicked, click -> {
        setSelectedModule(null);
        setEnabled(State.VertexSelected, false);
    });
    val highlightAttributes = new CellAttributes();
    val body = highlightAttributes.addAttribute("body", new HashMap<String, Serializable>());
    body.put("strokeWidth", 3);
    body.put("stroke", "#a366a3");
    val normalAttributes = new CellAttributes();
    val normalbody = normalAttributes.addAttribute("body", new HashMap<String, Serializable>());
    normalbody.put("strokeWidth", 1);
    normalbody.put("stroke", "#660066");
    canvas.addCellListener(EventType.MouseEnter, event -> {
        highlightAttributes.setId(event.getTarget().getId());
        canvas.invoke(SetAllCellAttributesAction.class, List.of(highlightAttributes));
    });
    canvas.addCellListener(EventType.MouseLeave, event -> {
        normalAttributes.setId(event.getTarget().getId());
        canvas.invoke(SetAllCellAttributesAction.class, List.of(normalAttributes));
    });
    canvas.addCellListener(EventType.Clicked, click -> {
        if (click.getTarget() instanceof Vertex) {
            val target = (Vertex) click.getTarget();
            val coordinate = ModuleCoordinate.parse(target.getKey());
            setSelectedModule(getZephyr().getPlugins().stream().filter(module -> Objects.equals(coordinate, module.getCoordinate())).findAny().orElse(null));
        }
    // setEnabled(State.VertexSelected, true);
    });
}
Also used : lombok.val(lombok.val) ComponentEventListener(com.vaadin.flow.component.ComponentEventListener) Mode(io.sunshower.zephyr.management.ModuleScheduleOverlay.Mode) MenuBar(com.vaadin.flow.component.menubar.MenuBar) Getter(lombok.Getter) MenuBarVariant(com.vaadin.flow.component.menubar.MenuBarVariant) CanvasEvent(io.sunshower.zephyr.ui.canvas.listeners.CanvasEvent) Registration(com.vaadin.flow.shared.Registration) CondensationUtilities(io.sunshower.zephyr.condensation.CondensationUtilities) SetAllCellAttributesAction(io.sunshower.zephyr.ui.canvas.actions.SetAllCellAttributesAction) HashMap(java.util.HashMap) ContextMenu(io.sunshower.zephyr.ui.components.ContextMenu) Route(com.vaadin.flow.router.Route) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) EventType(io.sunshower.zephyr.ui.canvas.listeners.VertexEvent.EventType) Coordinate(io.zephyr.kernel.Coordinate) Vertex(io.sunshower.zephyr.ui.canvas.Vertex) Overlays(io.sunshower.zephyr.ui.components.Overlays) Map(java.util.Map) Canvas(io.sunshower.zephyr.ui.canvas.Canvas) CellAttributes(io.sunshower.zephyr.ui.canvas.CellAttributes) Zephyr(io.zephyr.cli.Zephyr) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) AddVerticesAction(io.sunshower.zephyr.ui.canvas.actions.AddVerticesAction) EnumMap(java.util.EnumMap) lombok.val(lombok.val) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Breadcrumb(io.sunshower.zephyr.ui.controls.Breadcrumb) ClickEvent(com.vaadin.flow.component.ClickEvent) VertexTemplate(io.sunshower.zephyr.ui.canvas.VertexTemplate) Actions(io.zephyr.kernel.module.ModuleLifecycle.Actions) CanvasReadyEvent(io.sunshower.zephyr.ui.canvas.CanvasReadyEvent) Edge(io.sunshower.zephyr.ui.canvas.Edge) Serializable(java.io.Serializable) Model(io.sunshower.zephyr.ui.canvas.Model) Objects(java.util.Objects) Button(com.vaadin.flow.component.button.Button) List(java.util.List) ConnectVerticesAction(io.sunshower.zephyr.ui.canvas.actions.ConnectVerticesAction) Lifecycle(io.zephyr.kernel.Lifecycle) ModuleCoordinate(io.zephyr.kernel.core.ModuleCoordinate) MainView(io.sunshower.zephyr.MainView) AddVertexTemplateAction(io.sunshower.zephyr.ui.canvas.actions.AddVertexTemplateAction) EdgeTemplate(io.sunshower.zephyr.ui.canvas.EdgeTemplate) Module(io.zephyr.kernel.Module) Vertex(io.sunshower.zephyr.ui.canvas.Vertex) Serializable(java.io.Serializable) CellAttributes(io.sunshower.zephyr.ui.canvas.CellAttributes)

Example 2 with Vertex

use of io.sunshower.zephyr.ui.canvas.Vertex in project aire-components by aire-ux.

the class TopologyView method configureModuleNodes.

private void configureModuleNodes(VertexTemplate t) {
    val edges = new ArrayList<Edge>();
    val vertices = new HashMap<Coordinate, Vertex>();
    for (val module : getZephyr().getPlugins()) {
        val vertex = new Vertex();
        vertex.setLabel(module.getCoordinate().getName());
        vertex.setKey(module.getCoordinate().toCanonicalForm());
        vertex.setTemplate(t);
        vertices.put(module.getCoordinate(), vertex);
    }
    for (val module : getZephyr().getPlugins()) {
        for (val dependency : module.getDependencies()) {
            val target = vertices.get(dependency.getCoordinate());
            val source = vertices.get(module.getCoordinate());
            val edge = new Edge(source.getId(), target.getId(), defaultEdgeTemplate);
            edges.add(edge);
        }
    }
    canvas.invoke(AddVerticesAction.class, new ArrayList<>(vertices.values())).then(result -> canvas.invoke(ConnectVerticesAction.class, edges));
}
Also used : lombok.val(lombok.val) Vertex(io.sunshower.zephyr.ui.canvas.Vertex) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConnectVerticesAction(io.sunshower.zephyr.ui.canvas.actions.ConnectVerticesAction) Edge(io.sunshower.zephyr.ui.canvas.Edge) AddVerticesAction(io.sunshower.zephyr.ui.canvas.actions.AddVerticesAction)

Example 3 with Vertex

use of io.sunshower.zephyr.ui.canvas.Vertex in project aire-components by aire-ux.

the class AddVerticesRemoteActionTest method ensureConnectingNodesWorks.

@ViewTest
@DirtiesContext
void ensureConnectingNodesWorks(@View Canvas canvas) {
    val source = new Vertex();
    val target = new Vertex();
    canvas.invoke(AddVerticesAction.class, List.of(source, target));
    assertEquals(2, canvas.getModel().getVertices().size());
    assertTrue(canvas.getModel().getEdges().isEmpty());
    canvas.invoke(ConnectVerticesAction.class, List.of(new Edge(source.getId(), target.getId())));
    assertEquals(1, canvas.getModel().getEdges().size());
}
Also used : lombok.val(lombok.val) Vertex(io.sunshower.zephyr.ui.canvas.Vertex) Edge(io.sunshower.zephyr.ui.canvas.Edge) DirtiesContext(org.springframework.test.annotation.DirtiesContext) ViewTest(com.aire.ux.test.ViewTest)

Aggregations

Edge (io.sunshower.zephyr.ui.canvas.Edge)3 Vertex (io.sunshower.zephyr.ui.canvas.Vertex)3 lombok.val (lombok.val)3 AddVerticesAction (io.sunshower.zephyr.ui.canvas.actions.AddVerticesAction)2 ConnectVerticesAction (io.sunshower.zephyr.ui.canvas.actions.ConnectVerticesAction)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ViewTest (com.aire.ux.test.ViewTest)1 ClickEvent (com.vaadin.flow.component.ClickEvent)1 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 Button (com.vaadin.flow.component.button.Button)1 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)1 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)1 MenuBar (com.vaadin.flow.component.menubar.MenuBar)1 MenuBarVariant (com.vaadin.flow.component.menubar.MenuBarVariant)1 Route (com.vaadin.flow.router.Route)1 Registration (com.vaadin.flow.shared.Registration)1 MainView (io.sunshower.zephyr.MainView)1 CondensationUtilities (io.sunshower.zephyr.condensation.CondensationUtilities)1 Mode (io.sunshower.zephyr.management.ModuleScheduleOverlay.Mode)1