protected double getLayoutInformationThreshold(final Graph<?, ?> graph) { final List<Node> list = new ArrayList<>(); graph.nodes().iterator().forEachRemaining(list::add); return list.size() / 4.0D; }
protected void onFormFieldChanged(@Observes FormFieldChanged formFieldChanged) { Optional.ofNullable(isSelected) .map(Supplier::get) .filter(Boolean.TRUE::equals) .map(focus -> getDiagram() .map(d -> d.getGraph().getNode(formFieldChanged.getUuid())) ).ifPresent(focus -> refresh()); }
private Optional<String> getGraphUUID() { if (Objects.isNull(getGraph())) { return Optional.empty(); } return Optional.of(getGraph().getUUID()); }
@Override public void startGraphTraversal(final Graph<DefinitionSet, Node<View, Edge>> graph) { if (graph == null) { error("Graph is null!"); } else { final DefinitionSet view = graph.getContent(); log(indent + "Graph UUID: " + graph.getUUID()); log(indent + " Graph Starting nodes"); log(indent + " ===================="); } }
@Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { // Clear outgoing edges for canvas root element. node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; }
@SuppressWarnings("unchecked") public void init() { MockitoAnnotations.initMocks(this); when(graph.getUUID()).thenReturn(GRAPH_UUID); when(graph.getContent()).thenReturn(graphContent); when(graph.nodes()).thenReturn(graphNodes); when(definitionManager.adapters()).thenReturn(adapterManager); when(adapterManager.registry()).thenReturn(adapterRegistry); when(adapterManager.forDefinition()).thenReturn(definitionAdapter); when(adapterManager.forProperty()).thenReturn(propertyAdapter); when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter); when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter); when(graphCommandExecutionContext.getDefinitionManager()).thenReturn(definitionManager); when(graphCommandExecutionContext.getFactoryManager()).thenReturn(factoryManager); when(graphCommandExecutionContext.getRuleManager()).thenReturn(ruleManager); when(graphCommandExecutionContext.getGraphIndex()).thenReturn(graphIndex); when(graphCommandExecutionContext.getRuleSet()).thenReturn(ruleSet); when(graphIndex.getGraph()).thenReturn(graph); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(EMPTY_VIOLATIONS); }
@Test @SuppressWarnings("unchecked") public void testExecute() { CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.INFO, result.getType()); verify(graph, times(1)).addNode(eq(node)); verify(graphIndex, times(1)).addNode(eq(node)); verify(graphIndex, times(0)).addEdge(any(Edge.class)); verify(graph, times(0)).removeNode(eq(UUID)); verify(graphIndex, times(0)).removeNode(eq(node)); verify(graphIndex, times(0)).removeEdge(any(Edge.class)); }
graph.getLabels().add("org.kie.workbench.common.stunner.cm.CaseManagementDefinitionSet"); graph.setContent(definitionSet); graph.addNode(rootNode); graph.addNode(stage1Node); graph.addNode(stage2Node); graph.addNode(task1Node); graph.addNode(case1Node); graph.addNode(case2Node); graph.addNode(process2Node);
@SuppressWarnings("unchecked") private void preMarshallProcess(final Diagram<Graph, Metadata> diagram) { Iterable<Node<View<?>, Edge>> nodes = diagram.getGraph().nodes(); diagram.getGraph().addNode(startNoneEvent); createChild(UUID.uuid(), rootNode, startNoneEvent, 0); diagram.getGraph().addNode(endNoneEvent); createChild(UUID.uuid(), rootNode, endNoneEvent, -1);
@Test @SuppressWarnings("unchecked") public void testExecuteCheckFailed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); verify(graph, times(0)).addNode(eq(node)); verify(graphIndex, times(0)).addNode(eq(node)); verify(graphIndex, times(0)).addEdge(any(Edge.class)); verify(graph, times(0)).removeNode(eq(UUID)); verify(graphIndex, times(0)).removeNode(eq(node)); verify(graphIndex, times(0)).removeEdge(any(Edge.class)); }
@SuppressWarnings("unchecked") private void postUnmarshallProcess(final Graph<DefinitionSet, Node> graph) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(graph.nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); if (StartNoneEvent.class.isInstance(startNode.getContent().getDefinition())) { deleteChild(root, startNode); graph.removeNode(startNode.getUUID()); if (EndNoneEvent.class.isInstance(endNode.getContent().getDefinition())) { deleteChild(root, endNode); graph.removeNode(endNode.getUUID());
@SuppressWarnings("unchecked") protected void doStartGraphTraversal(final Graph graph, final K callback) { if (graph.getContent() instanceof View) { callback.startGraphTraversal(graph); } }
@Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph graph = getGraph(context); graph.addNode(candidate); getMutableIndex(context).addNode(candidate); } return results; }
when(graph.getContent()).thenReturn(graphContent); when(graphContent.getDefinition()).thenReturn(DEFINITION_SET); when(graph.getNode(DIAGRAM_UUID)).thenReturn(graphNode); when(graphNode.getContent()).thenReturn(graphContent); when(metadata.getCanvasRootUUID()).thenReturn(DIAGRAM_UUID);
@Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { LOGGER.log(Level.FINE, "Executing..."); final org.kie.workbench.common.stunner.core.graph.Graph graph = getGraph(context); final Node<?, Edge> candidate = getCandidate(context); this.removed = candidate; graph.removeNode(candidate.getUUID()); getMutableIndex(context).removeNode(candidate); LOGGER.log(Level.FINE, "Node [" + uuid + " removed from strcture and index."); } return results; }
protected void destroyGraph(final Command callback) { destroyGraphIndex(() -> { if (null != diagram && null != diagram.getGraph()) { diagram.getGraph().clear(); } callback.execute(); }); }
@Test @SuppressWarnings("unchecked") public void testUndo() { tested.removed = node; CommandResult<RuleViolation> result = tested.undo(graphCommandExecutionContext); assertEquals(CommandResult.Type.INFO, result.getType()); verify(graph, times(1)).addNode(any(Node.class)); verify(graphIndex, times(1)).addNode(any(Node.class)); verify(graph, times(0)).removeNode(eq(UUID)); verify(graphIndex, times(0)).removeNode(eq(node)); verify(graphIndex, times(0)).removeEdge(any(Edge.class)); verify(graphIndex, times(0)).addEdge(any(Edge.class)); } }
graph.getLabels().add("org.kie.workbench.common.stunner.cm.CaseManagementDefinitionSet"); graph.setContent(definitionSet); graph.addNode(rootNode); graph.addNode(stageNode); graph.addNode(subprocessNode);
@Override public void startGraphTraversal(final Graph graph) { if (graph.getContent() instanceof DefinitionSet) { callback.startGraphTraversal(graph); } }