Search in sources :

Example 1 with ControlPoint

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

the class AbstractCanvasControlPointCommandTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    Point2D location1 = new Point2D(0, 0);
    controlPoint1 = new ControlPointImpl(location1);
    ControlPoint controlPoint2 = new ControlPointImpl(location1, 1);
    controlPointList = Arrays.asList(controlPoint1);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shape.addControlPoints(controlPoint1)).thenReturn(Arrays.asList(controlPoint2));
    when(edge.getUUID()).thenReturn(EDGE_UUID);
    when(edge.getContent()).thenReturn(viewConnector);
    when(canvasHandler.getCanvas().getShape(EDGE_UUID)).thenReturn(shape);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Before(org.junit.Before)

Example 2 with ControlPoint

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

the class DeleteControlPointCommand method execute.

@Override
public CommandResult<RuleViolation> execute(GraphCommandExecutionContext context) {
    HasControlPoints edgeContent = getEdgeContent();
    List<ControlPoint> connectorControlPoints = edgeContent.getControlPoints();
    connectorControlPoints.removeAll(getControlPointList());
    // update index
    updateControlPointsIndex(connectorControlPoints);
    return GraphCommandResultBuilder.SUCCESS;
}
Also used : HasControlPoints(org.kie.workbench.common.stunner.core.graph.content.HasControlPoints) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 3 with ControlPoint

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

the class AbstractControlPointCommandTest method setUp.

public void setUp() {
    super.init(0, 0);
    newLocation = new Point2D(0, 0);
    controlPoint1 = new ControlPointImpl(new Point2D(1, 1), 1);
    controlPoint2 = new ControlPointImpl(new Point2D(2, 2), 2);
    controlPoint3 = new ControlPointImpl(new Point2D(3, 3), 3);
    controlPointList = new ArrayList<ControlPoint>() {

        {
            add(controlPoint1);
            add(controlPoint2);
            add(controlPoint3);
        }
    };
    when(edge.getContent()).thenReturn(viewConnector);
    when(viewConnector.getControlPoints()).thenReturn(controlPointList);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 4 with ControlPoint

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

the class AddCanvasConnectorCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
    context.register(shapeSetId, candidate);
    context.applyElementMutation(candidate, MutationContext.STATIC);
    if (candidate.getContent() instanceof ViewConnector) {
        ControlPoint[] controlPoints = ((ViewConnector) candidate.getContent()).getControlPoints().stream().toArray(ControlPoint[]::new);
        CommandResult<CanvasViolation> addControlPointsResult = new AddCanvasControlPointCommand(candidate, controlPoints).execute(context);
        ShapeUtils.hideControlPoints(candidate, context);
        if (CommandUtils.isError(addControlPointsResult)) {
            return addControlPointsResult;
        }
    }
    ShapeUtils.updateEdgeConnections(candidate, context);
    ShapeUtils.applyConnections(candidate, context, MutationContext.STATIC);
    final Node source = candidate.getSourceNode();
    if (null != source) {
        context.notifyCanvasElementUpdated(source);
    }
    return buildResult();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 5 with ControlPoint

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

the class AddCanvasControlPointCommand method allow.

@Override
public CommandResult<CanvasViolation> allow(AbstractCanvasHandler context) {
    if (checkExistingControlPoints(ShapeUtils.getControlPoints(candidate, context))) {
        return buildResult();
    }
    ShapeUtils.hideControlPoints(candidate, context);
    List<ControlPoint> addedControlPoints = ShapeUtils.addControlPoints(candidate, context, this.controlPoints);
    if (addedControlPoints.stream().map(ControlPoint::getIndex).anyMatch(Objects::isNull)) {
        return new CanvasCommandResultBuilder().setType(CommandResult.Type.ERROR).addViolation(new CanvasViolationImpl.Builder().build(new RuleViolationImpl("Control Point out of connector"))).build();
    }
    ShapeUtils.showControlPoints(candidate, context);
    allowed = Boolean.TRUE;
    return buildResult();
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) Objects(java.util.Objects) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) CanvasViolationImpl(org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)

Aggregations

ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)9 ControlPointImpl (org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 Point2D (com.ait.lienzo.client.core.types.Point2D)2 Objects (java.util.Objects)2 Test (org.junit.Test)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Bpmn2OryxManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager)1 ArrayParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser)1 ObjectParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser)1 StringFieldParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)1 BPMNDefinition (org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition)1 FactoryManager (org.kie.workbench.common.stunner.core.api.FactoryManager)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CanvasViolationImpl (org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)1 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)1