Search in sources :

Example 6 with EditExpressionEvent

use of org.kie.workbench.common.dmn.client.events.EditExpressionEvent in project kie-wb-common by kiegroup.

the class DecisionNavigatorNestedItemFactoryTest method testMakeEditExpressionEventWhenIsReadOnly.

@Test
public void testMakeEditExpressionEventWhenIsReadOnly() {
    final ClientSession currentSession = mock(ClientSession.class);
    final HasName hasName = mock(HasName.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final View view = mock(View.class);
    final String uuid = "uuid";
    when(readOnlyProvider.isReadOnlyDiagram()).thenReturn(true);
    when(node.getUUID()).thenReturn(uuid);
    when(sessionManager.getCurrentSession()).thenReturn(currentSession);
    when(node.getContent()).thenReturn(view);
    when(view.getDefinition()).thenReturn(hasName);
    when(boxedExpressionHelper.getHasExpression(node)).thenReturn(hasExpression);
    final EditExpressionEvent expressionEvent = factory.makeEditExpressionEvent(node);
    assertEquals(uuid, expressionEvent.getNodeUUID());
    assertEquals(currentSession, expressionEvent.getSession());
    assertEquals(Optional.of(hasName), expressionEvent.getHasName());
    assertEquals(hasExpression, expressionEvent.getHasExpression());
    assertTrue(expressionEvent.isOnlyVisualChangeAllowed());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 7 with EditExpressionEvent

use of org.kie.workbench.common.dmn.client.events.EditExpressionEvent in project kie-wb-common by kiegroup.

the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for BusinessKnowledgeModel definitions, next cast is safe.
    final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) CanvasLayoutUtils.getElement(canvasHandler, uuid).asNode();
    final BusinessKnowledgeModel bkm = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(bkmNode);
    final boolean isReadOnly = bkm.isAllowOnlyVisualChange() || readOnlyProvider.isReadOnlyDiagram();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.asHasExpression(), Optional.of(bkm), isReadOnly));
    return this;
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 8 with EditExpressionEvent

use of org.kie.workbench.common.dmn.client.events.EditExpressionEvent in project kie-wb-common by kiegroup.

the class DMNEditDecisionToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for Decision definitions, next cast is safe.
    final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) CanvasLayoutUtils.getElement(canvasHandler, uuid).asNode();
    final Decision decision = (Decision) DefinitionUtils.getElementDefinition(decisionNode);
    final boolean isReadOnly = decision.isAllowOnlyVisualChange() || readOnlyProvider.isReadOnlyDiagram();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision), isReadOnly));
    return this;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision)

Example 9 with EditExpressionEvent

use of org.kie.workbench.common.dmn.client.events.EditExpressionEvent in project kie-wb-common by kiegroup.

the class DecisionNavigatorNestedItemFactory method makeEditExpressionEvent.

EditExpressionEvent makeEditExpressionEvent(final Node<View, Edge> node) {
    final ClientSession currentSession = sessionManager.getCurrentSession();
    final Object definition = DefinitionUtils.getElementDefinition(node);
    final HasExpression hasExpression = helper.getHasExpression(node);
    final Optional<HasName> hasName = Optional.of((HasName) definition);
    final boolean isOnlyVisualChangeAllowed = isOnlyVisualChangeAllowed(definition) || readOnlyProvider.isReadOnlyDiagram();
    return new EditExpressionEvent(currentSession, node.getUUID(), hasExpression, hasName, isOnlyVisualChangeAllowed);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent)

Example 10 with EditExpressionEvent

use of org.kie.workbench.common.dmn.client.events.EditExpressionEvent in project kie-wb-common by kiegroup.

the class DecisionNavigatorNestedItemFactoryTest method testMakeEditExpressionEvent.

@Test
public void testMakeEditExpressionEvent() {
    final ClientSession currentSession = mock(ClientSession.class);
    final HasName hasName = mock(HasName.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final View view = mock(View.class);
    final String uuid = "uuid";
    when(node.getUUID()).thenReturn(uuid);
    when(sessionManager.getCurrentSession()).thenReturn(currentSession);
    when(node.getContent()).thenReturn(view);
    when(view.getDefinition()).thenReturn(hasName);
    when(boxedExpressionHelper.getHasExpression(node)).thenReturn(hasExpression);
    final EditExpressionEvent expressionEvent = factory.makeEditExpressionEvent(node);
    assertEquals(uuid, expressionEvent.getNodeUUID());
    assertEquals(currentSession, expressionEvent.getSession());
    assertEquals(Optional.of(hasName), expressionEvent.getHasName());
    assertEquals(hasExpression, expressionEvent.getHasExpression());
    assertFalse(expressionEvent.isOnlyVisualChangeAllowed());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Aggregations

EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)15 Test (org.junit.Test)12 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 HasName (org.kie.workbench.common.dmn.api.definition.HasName)3 ClientSession (org.kie.workbench.common.stunner.core.client.session.ClientSession)3 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1