Search in sources :

Example 1 with HasControlPoints

use of org.kie.workbench.common.stunner.core.graph.content.HasControlPoints 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 2 with HasControlPoints

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

the class AddControlPointCommand method execute.

@Override
public CommandResult<RuleViolation> execute(GraphCommandExecutionContext context) {
    if (checkExistingControlPoints(getEdgeContent().getControlPoints())) {
        // skipping in case adding already existing control points
        return GraphCommandResultBuilder.SUCCESS;
    }
    CommandResult<RuleViolation> allowResult = allow(context);
    if (CommandUtils.isError(allowResult)) {
        return allowResult;
    }
    HasControlPoints edgeContent = getEdgeContent();
    if (Objects.isNull(edgeContent.getControlPoints())) {
        edgeContent.setControlPoints(new LinkedList<>());
    }
    // add on the right index position on the list
    getControlPointList().stream().forEach(cp -> {
        // the effective index should not consider the head point that is a control point on the connector
        int effectiveIndex = cp.getIndex() - 1;
        if (edgeContent.getControlPoints().size() > effectiveIndex) {
            edgeContent.getControlPoints().add(effectiveIndex, cp);
        } else {
            edgeContent.getControlPoints().add(cp);
        }
    });
    // update index control points
    updateControlPointsIndex(edgeContent.getControlPoints());
    return GraphCommandResultBuilder.SUCCESS;
}
Also used : HasControlPoints(org.kie.workbench.common.stunner.core.graph.content.HasControlPoints) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Aggregations

HasControlPoints (org.kie.workbench.common.stunner.core.graph.content.HasControlPoints)2 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)2 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)1