Search in sources :

Example 1 with JSIDMNStyle

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle in project kie-wb-common by kiegroup.

the class StunnerConverterTest method testDecision.

@Test
public void testDecision() {
    final StylingSet decisionStylingSet = mock(StylingSet.class);
    final Decision decision = spy(new Decision());
    when(decision.getStylingSet()).thenReturn(decisionStylingSet);
    final JSITDecision jsitDecision = mock(JSITDecision.class);
    when(jsitDecision.getTYPE_NAME()).thenReturn(JSITDecision.TYPE);
    final JSIStyle style = mock(JSIStyle.class);
    final JSIDMNShape shape = mock(JSIDMNShape.class);
    final JSIDMNStyle dmnStyleOfDrgShape = mock(JSIDMNStyle.class);
    when(shape.getStyle()).thenReturn(style);
    doReturn(style).when(converter).getUnwrappedJSIStyle(style);
    doReturn(true).when(converter).isJSIDMNStyle(style);
    doReturn(dmnStyleOfDrgShape).when(converter).getJSIDmnStyle(style);
    final NodeEntry nodeEntry = mock(NodeEntry.class);
    when(nodeEntry.getDmnElement()).thenReturn(jsitDecision);
    when(nodeEntry.getId()).thenReturn("_id");
    when(nodeEntry.getDmnShape()).thenReturn(shape);
    final Element graphElement = mock(Element.class);
    final Node graphNode = mock(Node.class);
    final View content = mock(View.class);
    when(factoryManager.newElement(anyString(), anyString())).thenReturn(graphElement);
    when(graphElement.asNode()).thenReturn(graphNode);
    when(graphNode.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(decision);
    final JSIColor randomColor = mock(JSIColor.class);
    when(randomColor.getRed()).thenReturn(12);
    when(randomColor.getGreen()).thenReturn(34);
    when(randomColor.getBlue()).thenReturn(56);
    when(dmnStyleOfDrgShape.getFontColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getStrokeColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getFillColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getFontSize()).thenReturn(11d);
    converter.make(nodeEntry);
    verify(decisionStylingSet).setFontSize(fontSizeArgumentCaptor.capture());
    Assertions.assertThat(fontSizeArgumentCaptor.getValue().getValue()).isEqualTo(11d);
    verify(decisionStylingSet).setBorderColour(borderColourArgumentCaptor.capture());
    Assertions.assertThat(borderColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
    verify(decisionStylingSet).setBgColour(bgColourArgumentCaptor.capture());
    Assertions.assertThat(bgColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
    verify(decisionStylingSet).setFontColour(fontColourArgumentCaptor.capture());
    Assertions.assertThat(fontColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
}
Also used : JSIColor(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIColor) JSIStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIStyle) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 2 with JSIDMNStyle

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle in project kie-wb-common by kiegroup.

the class WrapperUtils method getWrappedJSIDMNStyle.

public static JSIDMNStyle getWrappedJSIDMNStyle(final JSIDMNStyle toWrap) {
    final JSIDMNStyle toReturn = Js.uncheckedCast(JsUtils.getWrappedElement(toWrap));
    final JSIName jsiName = JSIDMNStyle.getJSIName();
    updateJSIName(jsiName, "dmndi", "DMNStyle");
    JsUtils.setNameOnWrapped(toReturn, jsiName);
    return toReturn;
}
Also used : JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle)

Example 3 with JSIDMNStyle

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle in project kie-wb-common by kiegroup.

the class FontStylingSetPropertyConverterTest method testWbFromDMN.

@Test
public void testWbFromDMN() {
    final JSIDMNStyle jsiDmnStyle = mock(JSIDMNStyle.class);
    final JSIColor fontColor = mock(JSIColor.class);
    when(fontColor.getRed()).thenReturn(10);
    when(fontColor.getGreen()).thenReturn(20);
    when(fontColor.getBlue()).thenReturn(30);
    final String fontFamily = "Arial";
    final double fontSize = 11.0;
    when(jsiDmnStyle.getFontColor()).thenReturn(fontColor);
    when(jsiDmnStyle.getFontFamily()).thenReturn(fontFamily);
    when(jsiDmnStyle.getFontSize()).thenReturn(fontSize);
    final StylingSet convertedResult = FontStylingSetPropertyConverter.wbFromDMN(jsiDmnStyle);
    assertThat(convertedResult.getFontColour().getValue()).isEqualTo("#0a141e");
    assertThat(convertedResult.getFontFamily().getValue()).isEqualTo(fontFamily);
    assertThat(convertedResult.getFontSize().getValue()).isEqualTo(fontSize);
}
Also used : JSIColor(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIColor) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) Test(org.junit.Test)

Example 4 with JSIDMNStyle

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle in project kie-wb-common by kiegroup.

the class StunnerConverter method internalAugmentStyles.

private void internalAugmentStyles(final JSIDMNShape drgShape, final StylingSet stylingSet) {
    final JSIStyle jsiStyle = drgShape.getStyle();
    if (Objects.isNull(jsiStyle)) {
        return;
    }
    final JSIStyle drgStyle = getUnwrappedJSIStyle(jsiStyle);
    final JSIDMNStyle dmnStyleOfDrgShape = isJSIDMNStyle(drgStyle) ? getJSIDmnStyle(drgStyle) : null;
    if (Objects.nonNull(dmnStyleOfDrgShape)) {
        if (Objects.nonNull(dmnStyleOfDrgShape.getFillColor())) {
            stylingSet.setBgColour(new BgColour(ColorUtils.wbFromDMN(dmnStyleOfDrgShape.getFillColor())));
        }
        if (Objects.nonNull(dmnStyleOfDrgShape.getStrokeColor())) {
            stylingSet.setBorderColour(new BorderColour(ColorUtils.wbFromDMN(dmnStyleOfDrgShape.getStrokeColor())));
        }
    }
    final StylingSet fontStylingSet = new StylingSet();
    if (Objects.nonNull(dmnStyleOfDrgShape)) {
        mergeFontStylingSet(fontStylingSet, FontStylingSetPropertyConverter.wbFromDMN(dmnStyleOfDrgShape));
    }
    if (Objects.nonNull(drgShape.getDMNLabel())) {
        final JSIDMNShape jsiLabel = Js.uncheckedCast(drgShape.getDMNLabel());
        final JSIStyle jsiLabelStyle = jsiLabel.getStyle();
        final Object jsiLabelSharedStyle = Js.uncheckedCast(jsiLabel.getSharedStyle());
        if (Objects.nonNull(jsiLabelSharedStyle) && JSIDMNStyle.instanceOf(jsiLabelSharedStyle)) {
            mergeFontStylingSet(fontStylingSet, FontStylingSetPropertyConverter.wbFromDMN((Js.uncheckedCast(jsiLabelSharedStyle))));
        }
        if (Objects.nonNull(jsiLabelStyle) && isJSIDMNStyle(jsiLabelStyle)) {
            mergeFontStylingSet(fontStylingSet, FontStylingSetPropertyConverter.wbFromDMN(Js.uncheckedCast(jsiLabelStyle)));
        }
    }
    mergeFontStylingSet(stylingSet, fontStylingSet);
}
Also used : BgColour(org.kie.workbench.common.dmn.api.property.styling.BgColour) JSIStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIStyle) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) BorderColour(org.kie.workbench.common.dmn.api.property.styling.BorderColour)

Example 5 with JSIDMNStyle

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle in project kie-wb-common by kiegroup.

the class WrapperUtils method stunnerToDDExt.

private static JSIDMNShape stunnerToDDExt(final JSIDMNDiagram diagram, final List<String> dmnDiagramElementIds, final Definitions definitionsStunnerPojo, final View<? extends DMNElement> v, final String namespaceURI) {
    final JSIDMNShape result = new JSIDMNShape();
    final DMNElement definition = v.getDefinition();
    final String dmnElementId = definition.getId().getValue();
    final String shapeId = getShapeId(diagram, dmnDiagramElementIds, dmnElementId);
    result.setId(shapeId);
    result.setDmnElementRef(getDmnElementRef(definitionsStunnerPojo, v, namespaceURI));
    final JSIBounds bounds = new JSIBounds();
    result.setBounds(bounds);
    bounds.setX(xOfBound(upperLeftBound(v)));
    bounds.setY(yOfBound(upperLeftBound(v)));
    result.setDMNLabel(new JSIDMNLabel());
    // TODO {gcardosi}: HARDCODED
    result.setIsCollapsed(false);
    final JSIDMNStyle style = new JSIDMNStyle();
    if (v.getDefinition() instanceof Decision) {
        final Decision d = (Decision) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof InputData) {
        InputData d = (InputData) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
        final BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof KnowledgeSource) {
        final KnowledgeSource d = (KnowledgeSource) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof TextAnnotation) {
        final TextAnnotation d = (TextAnnotation) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof DecisionService) {
        final DecisionService d = (DecisionService) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
        final JSIDMNDecisionServiceDividerLine dl = new JSIDMNDecisionServiceDividerLine();
        final JSIPoint leftPoint = new JSIPoint();
        leftPoint.setX(v.getBounds().getUpperLeft().getX());
        final double dlY = v.getBounds().getUpperLeft().getY() + d.getDividerLineY().getValue();
        leftPoint.setY(dlY);
        dl.addWaypoint(leftPoint);
        final JSIPoint rightPoint = new JSIPoint();
        rightPoint.setX(v.getBounds().getLowerRight().getX());
        rightPoint.setY(dlY);
        dl.addWaypoint(rightPoint);
        result.setDMNDecisionServiceDividerLine(dl);
    }
    result.setStyle(getWrappedJSIDMNStyle(style));
    return result;
}
Also used : JSIDMNDecisionServiceDividerLine(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDecisionServiceDividerLine) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSIDMNLabel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNLabel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation)

Aggregations

JSIDMNStyle (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle)5 StylingSet (org.kie.workbench.common.dmn.api.property.styling.StylingSet)3 JSIDMNShape (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)3 Test (org.junit.Test)2 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)2 JSIColor (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIColor)2 JSIStyle (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIStyle)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)1 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)1 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)1 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)1 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)1 BgColour (org.kie.workbench.common.dmn.api.property.styling.BgColour)1 BorderColour (org.kie.workbench.common.dmn.api.property.styling.BorderColour)1 JSIBounds (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)1 JSIPoint (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint)1 JSITDecision (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision)1 JSITTextAnnotation (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation)1 JSIDMNDecisionServiceDividerLine (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDecisionServiceDividerLine)1