Search in sources :

Example 46 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.

the class LocationControlImpl method handleArrowKeys.

private void handleArrowKeys(final KeyboardEvent.Key... keys) {
    final int selectedIDsCount = selectedIDs.size();
    if (selectedIDsCount == 0) {
        return;
    }
    double movementDistance = NORMAL_DISTANCE;
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.CONTROL)) {
        movementDistance = LARGE_DISTANCE;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.SHIFT)) {
        movementDistance = SHORT_DISTANCE;
    }
    double horizontalDistance = 0d;
    double verticalDistance = 0d;
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_LEFT)) {
        horizontalDistance = -movementDistance;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_RIGHT)) {
        horizontalDistance = movementDistance;
    }
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_UP)) {
        verticalDistance = -movementDistance;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_DOWN)) {
        verticalDistance = movementDistance;
    }
    if (verticalDistance == 0 && horizontalDistance == 0) {
        return;
    }
    List<Element> moveNodes = new ArrayList<>();
    List<Point2D> movePositions = new ArrayList<>();
    for (String uuid : selectedIDs) {
        final Node<View<?>, Edge> node = canvasHandler.getGraphIndex().getNode(uuid);
        if (node != null) {
            final Point2D nodePosition = GraphUtils.getPosition(node.getContent());
            final Point2D movePosition = new Point2D(nodePosition.getX() + horizontalDistance, nodePosition.getY() + verticalDistance);
            moveNodes.add(node);
            movePositions.add(movePosition);
        }
    }
    move(moveNodes.toArray(new Element[] {}), movePositions.toArray(new Point2D[] {}));
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 47 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.

the class ConnectorDragProxyImpl method show.

@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, DragProxyCallback> show(final Item item, final int x, final int y, final DragProxyCallback callback) {
    // Source connector's shape - Obtain the shape for the source node.
    final Node<View<?>, Edge> sourceNode = item.getSourceNode();
    final Shape<?> sourceNodeShape = getCanvas().getShape(sourceNode.getUUID());
    // Target connector's shape - Create a temporary shape view, that will act as the connector's target node.
    final WiresShapeView transientShapeView = new WiresShapeView<>(new MultiPath().rect(0, 0, 1, 1).setFillAlpha(0).setStrokeAlpha(0));
    getWiresManager().getMagnetManager().createMagnets(transientShapeView);
    // Create the transient connector's shape and view.
    final Edge<View<?>, Node> edge = item.getEdge();
    final Shape<?> edgeShape = ((ShapeFactory<Object, ?>) item.getShapeFactory()).newShape(edge.getContent().getDefinition());
    final EdgeShape connectorShape = (EdgeShape) edgeShape;
    this.connectorShapeView = (WiresConnectorView<?>) edgeShape.getShapeView();
    // Register and update shape's view as for edge bean's state.
    getWiresManager().register(connectorShapeView);
    connectorShape.applyProperties(edge, MutationContext.STATIC);
    // Apply connector's connections for both source and target shapes.
    // Using center connector strategy, so magnet index 0.
    final MagnetConnection centerConnection = new MagnetConnection.Builder().atX(0).atY(0).magnet(0).build();
    connectorShapeView.connect(sourceNodeShape.getShapeView(), centerConnection, transientShapeView, centerConnection);
    // Optimize the index and show the drag proxy for the temporary shape view.
    graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
    shapeViewDragProxyFactory.show(transientShapeView, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            callback.onStart(x, y);
            // As using center magnet, update the connection.
            connectorShapeView.updateForCenterConnection();
        }

        @Override
        public void onMove(final int x, final int y) {
            callback.onMove(x, y);
            // As using center magnet, update the connection.
            connectorShapeView.updateForCenterConnection();
        }

        @Override
        public void onComplete(final int x, final int y) {
            callback.onComplete(x, y);
            deregisterTransientConnector();
            getCanvas().draw();
        }
    });
    return this;
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) View(org.kie.workbench.common.stunner.core.graph.content.view.View) WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 48 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.

the class ObserverBuilderControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
            view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0)));
            Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
            item.setContent(view);
            callback.onSuccess(item);
            return null;
        }
    }).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
    when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
    AdapterManager adapters = mock(AdapterManager.class);
    DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
    DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
    when(definitionAdapter.getId(any())).thenReturn("Object");
    when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
    when(adapters.forDefinition()).thenReturn(definitionAdapter);
    when(adapters.forRules()).thenReturn(rulesAdapter);
    when(clientDefinitionManager.adapters()).thenReturn(adapters);
    when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
    when(canvasCommandFactory.addNode(any(Node.class), anyString())).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            String uid = (String) invocationOnMock.getArguments()[1];
            return new AddCanvasNodeCommand(node, uid);
        }
    });
    when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            Point2D location = (Point2D) invocationOnMock.getArguments()[1];
            return new UpdateElementPositionCommand(node, location);
        }
    });
    when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
    ShapeSet shapeSet = mock(ShapeSet.class);
    ShapeFactory shapeFactory = mock(ShapeFactory.class);
    when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
    when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
    when(shapeManager.getShapeSet(anyString())).thenReturn(shapeSet);
    when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
    tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.class));
    Diagram diagram = mock(Diagram.class);
    Metadata metadata = mock(Metadata.class);
    when(metadata.getCanvasRootUUID()).thenReturn("ID");
    when(diagram.getMetadata()).thenReturn(metadata);
    MutableIndex index = mock(MutableIndex.class);
    Graph graph = mock(Graph.class);
    DefinitionSet graphContent = mock(DefinitionSet.class);
    when(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
    when(graph.getContent()).thenReturn(graphContent);
    when(index.getGraph()).thenReturn(graph);
    when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
    canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
    canvasHandler.handle(mock(AbstractCanvas.class));
    canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.emptyList());
    CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Command command = (Command) invocationOnMock.getArguments()[1];
            command.execute(invocationOnMock.getArguments()[0]);
            return null;
        }
    }).when(commandManager).execute(any(), any(Command.class));
    when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
    tested.enable(canvasHandler);
    tested.setCommandManagerProvider(commandManagerProvider);
}
Also used : TypeDefinitionSetRegistry(org.kie.workbench.common.stunner.core.registry.definition.TypeDefinitionSetRegistry) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) ObserverBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.ObserverBuilderControl) Matchers.anyString(org.mockito.Matchers.anyString) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) CanvasHandlerImpl(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandlerImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CanvasCommandManager(org.kie.workbench.common.stunner.core.client.command.CanvasCommandManager) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) DefinitionSetRuleAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionSetRuleAdapter) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Before(org.junit.Before)

Example 49 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.

the class AbstractElementBuilderControl method build.

@Override
@SuppressWarnings("unchecked")
public void build(final ElementBuildRequest<AbstractCanvasHandler> request, final BuildCallback buildCallback) {
    if (null == canvasHandler) {
        buildCallback.onSuccess(null);
        return;
    }
    double x = request.getX();
    ;
    double y = request.getY();
    ;
    if (checkOutOfBoundsCanvas(x, y)) {
        buildCallback.onError(new ClientRuntimeError(new ElementOutOfBoundsException("Element is placed outside canvas bounds")));
        return;
    }
    final Object definition = request.getDefinition();
    // Notify processing starts.
    fireProcessingStarted();
    final Node<View<?>, Edge> parent = getParent(x, y);
    final Point2D childCoordinates = getChildCoordinates(parent, x, y);
    getCommands(definition, parent, childCoordinates.getX(), childCoordinates.getY(), new CommandsCallback() {

        @Override
        public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
            getCommandManager().execute(canvasHandler, new CompositeCommand.Builder().addCommands(commands).build());
            buildCallback.onSuccess(uuid);
            // Notify processing ends.
            fireProcessingCompleted();
        }

        @Override
        public void onError(final ClientRuntimeError error) {
            buildCallback.onError(error);
            // Notify processing ends.
            fireProcessingCompleted();
        }
    });
}
Also used : ElementOutOfBoundsException(org.kie.workbench.common.stunner.core.client.canvas.controls.exceptions.ElementOutOfBoundsException) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 50 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.

the class CanvasLayoutUtils method getNext.

@SuppressWarnings("unchecked")
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) {
    final double[] rootBounds = getBoundCoordinates(root.getContent());
    final double[] rootSize = GraphUtils.getNodeSize(root.getContent());
    final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent());
    Point2D[] offset = { new Point2D(PADDING_X, 0) };
    Point2D[] parentOffset = { new Point2D(0, 0) };
    double[] maxNodeY = { 0 };
    if (root.getOutEdges().size() > 0) {
        root.getOutEdges().stream().filter(e -> e.getContent() instanceof ViewConnector).filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)).forEach(n -> {
            final Node<View<?>, Edge> node = n.getTargetNode();
            final Point2D nodePos = GraphUtils.getPosition(node.getContent());
            final Point2D rootPos = GraphUtils.getPosition(root.getContent());
            if (nodePos.getY() > maxNodeY[0]) {
                maxNodeY[0] = nodePos.getY();
                final double[] nodeSize = GraphUtils.getNodeSize(node.getContent());
                offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY());
            }
        });
        offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y);
    } else {
        offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2);
    }
    offset[0].setX(offset[0].getX() + PADDING_X);
    final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY());
    final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]);
    return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Violation(org.kie.workbench.common.stunner.core.validation.Violation) GraphBoundsIndexer(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexer) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) Graph(org.kie.workbench.common.stunner.core.graph.Graph) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

View (org.kie.workbench.common.stunner.core.graph.content.view.View)144 Edge (org.kie.workbench.common.stunner.core.graph.Edge)100 Node (org.kie.workbench.common.stunner.core.graph.Node)57 Test (org.junit.Test)49 Graph (org.kie.workbench.common.stunner.core.graph.Graph)45 Element (org.kie.workbench.common.stunner.core.graph.Element)36 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)32 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)31 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)31 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)31 FlowElement (org.eclipse.bpmn2.FlowElement)26 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)26 RootElement (org.eclipse.bpmn2.RootElement)26 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)21 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)16 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ProcessVariables (org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables)10