Search in sources :

Example 76 with GraphCommandExecutionContext

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

the class DeleteRelationRowCommandTest method testGraphCommandExecuteRemoveMiddleWithColumns.

@Test
public void testGraphCommandExecuteRemoveMiddleWithColumns() {
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendRow(new BaseGridRow());
    final List firstRow = new List();
    final List lastRow = new List();
    relation.getRow().add(0, firstRow);
    relation.getRow().add(lastRow);
    relation.getColumn().add(new InformationItem());
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
    makeCommand(1);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, relation.getRow().size());
    assertEquals(firstRow, relation.getRow().get(0));
    assertEquals(lastRow, relation.getRow().get(1));
    assertEquals(1, relation.getColumn().size());
}
Also used : BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(org.kie.workbench.common.dmn.api.definition.model.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 77 with GraphCommandExecutionContext

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

the class ConnectorParentsMatchLevel1Tests method testAddNewEdgeAndNode.

@Test
public void testAddNewEdgeAndNode() {
    Command<GraphCommandExecutionContext, RuleViolation> command = addNewEdgeAndNodeIntoParent(graph.containerNode);
    ContextualGraphCommandExecutionContext executionContext = createConstrainedExecutionContext();
    CommandResult<RuleViolation> result = command.allow(executionContext);
    assertSuccessfullResult(result);
}
Also used : ContextualGraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.ContextualGraphCommandExecutionContext) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContextualGraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.ContextualGraphCommandExecutionContext) Test(org.junit.Test)

Example 78 with GraphCommandExecutionContext

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

the class GraphBuilder method addEdge.

@SuppressWarnings("unchecked")
private void addEdge(Edge<? extends View<?>, Node> edge, Node source, Connection sourceConnection, List<Point2D> controlPoints, Node target, Connection targetConnection) {
    final DeferredCompositeCommand.Builder<GraphCommandExecutionContext, RuleViolation> commandBuilder = new DeferredCompositeCommand.Builder<>();
    addConnector(commandBuilder, source, edge, sourceConnection);
    final ControlPoint[] cps = new ControlPoint[controlPoints.size()];
    for (int i = 0; i < cps.length; i++) {
        final ControlPoint cp = ControlPoint.build(controlPoints.get(i));
        addControlPoint(commandBuilder, edge, cp, i);
    }
    setTargetNode(commandBuilder, target, edge, targetConnection);
    execute(commandBuilder.build());
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) DirectGraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.DirectGraphCommandExecutionContext) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 79 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testGraphCommandExecuteInsertBelowThenUndo.

@Test
public void testGraphCommandExecuteInsertBelowThenUndo() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    dtable.getRule().add(existingRule);
    makeCommand(1);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    graphCommand.undo(graphCommandExecutionContext);
    assertEquals(1, dtable.getRule().size());
    assertEquals(existingRule, dtable.getRule().get(0));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 80 with GraphCommandExecutionContext

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

the class AddOutputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.

@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    // Graph command will insert new OutputClause at index 0 of the OutputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getOutput().size());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
    assertNull(dtable.getOutput().get(1).getName());
    // first rule
    final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
    assertEquals(2, outputEntriesRuleOne.size());
    assertEquals(ruleOneOldOutput, outputEntriesRuleOne.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleOne.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(0), outputEntriesRuleOne.get(0).getParent());
    // second rule
    final List<LiteralExpression> outputEntriesRuleTwo = dtable.getRule().get(1).getOutputEntry();
    assertEquals(2, outputEntriesRuleTwo.size());
    assertEquals(ruleTwoOldOutput, outputEntriesRuleTwo.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleTwo.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(1), outputEntriesRuleTwo.get(0).getParent());
    assertEquals(dtable, outputClause.getParent());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Aggregations

GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)85 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)84 Test (org.junit.Test)66 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)20 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)19 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)14 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)11 List (org.kie.workbench.common.dmn.api.definition.model.List)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)8 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)8 Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)7 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)7 List (java.util.List)6 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)6 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)5 Command (org.kie.workbench.common.stunner.core.command.Command)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)4