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);
});
}
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));
}
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());
}
Aggregations