private Predicate<Element<?>> isViewElement() { return e -> (null != e && (!(e instanceof Edge)) && (e.getContent() instanceof org.kie.workbench.common.stunner.core.graph.content.view.View)); }
public ActionsToolbox(final Supplier<AbstractCanvasHandler> canvasHandlerSupplier, final Element<?> element, final V view) { this.uuid = element.getUUID(); this.view = view; this.canvasHandlerSupplier = canvasHandlerSupplier; }
private boolean isDecision(final Element<?> element) { return null != element.asNode() && element.getContent() instanceof Definition && ((Definition) element.getContent()).getDefinition() instanceof Decision; }
@Override public void register(final Element element) { /** Conditions to be met: * - element is not registered * - element has visible representation */ if (!itemsRegistered().test(element.getUUID()) && element.getContent() instanceof View) { items.put(element.getUUID(), false); } }
@Override public ClipboardControl<Element, AbstractCanvas, ClientSession> set(Element... element) { clear(); elements.addAll(Arrays.stream(element).collect(Collectors.toSet())); elementsParent.putAll(elements.stream().filter(e -> e instanceof Node).collect(Collectors.toMap(Element::getUUID, e -> GraphUtils.getParent(e.asNode()).getUUID()))); return this; }
when(candidateContent.getBounds()).thenReturn(candidateBounds); when(factoryManager.newElement(anyString(), any(Class.class))).thenReturn(cloneElement); when(cloneElement.asNode()).thenReturn(clone); when(cloneElement.asEdge()).thenReturn(cloneEdge); when(cloneEdge.getContent()).thenReturn(connectorContent); when(cloneEdge.getUUID()).thenReturn(CLONE_EDGE_UUID); when(clone.getContent()).thenReturn(cloneContent); when(clone.getUUID()).thenReturn(CLONE_UUID); when(cloneElement.getUUID()).thenReturn(CLONE_UUID); when(cloneContent.getBounds()).thenReturn(bounds); when(bounds.getUpperLeft()).thenReturn(bound);
if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> {
@SuppressWarnings("unchecked") protected Element<View<?>> mockElement(String id, Set<String> labels) { Element<View<?>> e = mock(Element.class); View v = mock(View.class); Object d = mock(Object.class); when(e.getContent()).thenReturn(v); when(v.getDefinition()).thenReturn(d); when(definitionAdapter.getId(eq(d))).thenReturn(DefinitionId.build(id)); when(definitionAdapter.getLabels(eq(d))).thenReturn(labels); when(e.getLabels()).thenReturn(labels); return e; }
public static void logBounds(final Element<? extends View<?>> item) { final Bounds bounds = item.getContent().getBounds(); final Bound ul = bounds.getUpperLeft(); final Bound lr = bounds.getLowerRight(); LOGGER.log(Level.FINE, "Bounds for [" + item.getUUID() + "] ARE " + "{ UL=[" + ul.getX() + ", " + ul.getY() + "] " + "LR=[ " + lr.getX() + ", " + lr.getY() + "] }"); LOGGER.log(Level.FINE, "Bound attributes for [" + item.getUUID() + "] ARE " + "[X=" + ul.getX() + ", Y=" + ul.getY() + "] " + "[W=[ " + (lr.getX() - ul.getX()) + ", H=" + (lr.getY() - ul.getY()) + "] }"); }
DecisionNavigatorItem makeItem(final Element<?> element) { final Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge> node = (Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge>) element.asNode(); return itemFactory.makeItem(node); }
@Override @SuppressWarnings("unchecked") public void register(final Element element) { if (null != element.asNode() && checkNotRegistered(element)) { final AbstractCanvas<?> canvas = canvasHandler.getAbstractCanvas(); final Shape<?> shape = canvas.getShape(element.getUUID()); final ShapeView shapeView = shape.getShapeView();
@Override @SuppressWarnings("unchecked") public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) { // Obtain the connector and source node instances for proxying. final Element<?> element = CanvasLayoutUtils.getElement(canvasHandler, uuid); final Node<View<?>, Edge> sourceNode = (Node<View<?>, Edge>) element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), edgeId) .asEdge(); // Set the transient connection to the source node, for further rule evaluations. connector.setSourceNode(sourceNode); // Built and show a connector drag proxy, to check and finally set // candidate the target node. final double x = event.getX(); final double y = event.getY(); dragProxy = showDragProxy(canvasHandler, connector, sourceNode, (int) x, (int) y); return this; }
public void setup() throws Exception { MockitoAnnotations.initMocks(this); when(definitionManager.adapters()).thenReturn(adapterManager); when(adapterManager.forDefinition()).thenReturn(definitionAdapter); when(element.getContent()).thenReturn(elementContent); when(element.getLabels()).thenReturn(DEFINITION_LABELS); when(elementContent.getDefinition()).thenReturn(elementDefinition); when(definitionAdapter.getId(eq(elementDefinition))).thenReturn(DefinitionId.build(DEFINITION_ID)); when(definitionAdapter.getLabels(eq(elementDefinition))).thenReturn(DEFINITION_LABELS); when(candidate.getContent()).thenReturn(candidateContent); when(candidate.getLabels()).thenReturn(CANDIDATE_LABELS); when(candidateContent.getDefinition()).thenReturn(candidateDefinition); when(parent.getContent()).thenReturn(parentContent); when(parent.getLabels()).thenReturn(PARENT_LABELS); when(parentContent.getDefinition()).thenReturn(parentDefinition); when(definitionAdapter.getId(eq(candidateDefinition))).thenReturn(DefinitionId.build(CANDIDATE_ID)); when(definitionAdapter.getLabels(eq(candidateDefinition))).thenReturn(CANDIDATE_LABELS); when(definitionAdapter.getId(eq(parentDefinition))).thenReturn(DefinitionId.build(PARENT_ID)); when(definitionAdapter.getLabels(eq(parentDefinition))).thenReturn(PARENT_LABELS); }
@Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } //clone candidate ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); clone = context.getFactoryManager().newElement(UUID.uuid(), bean.getClass()).asEdge(); //Cloning the candidate content with properties Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); // Magnet being moved on node ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); // Add the candidate into index, so child commands can find it. getMutableIndex(context).addEdge(clone); return this; }
private Optional<Object> getBean(final Element element) { if (!(element.getContent() instanceof DefinitionSet) && element.getContent() instanceof Definition) { return Optional.ofNullable(((Definition) element.getContent()).getDefinition()); } return Optional.empty(); } }
protected String getUUID(final Element<?> element) { return null != element ? element.getUUID() : "null"; } }
private boolean isBusinessKnowledgeModel(final Element<?> element) { return null != element.asNode() && element.getContent() instanceof Definition && ((Definition) element.getContent()).getDefinition() instanceof BusinessKnowledgeModel; } }