Skip to content

Commit

Permalink
KOGITO-9952: SWF Editor - Add Icon to show there are subflows defined…
Browse files Browse the repository at this point in the history
… in States (apache#2063)
  • Loading branch information
handreyrc authored Nov 28, 2023
1 parent 380b51b commit d8fef4b
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.CornerIcon;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.DataDepiction;
import org.kie.workbench.common.stunner.sw.definition.ActionNode;
import org.kie.workbench.common.stunner.sw.definition.CallbackState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;
Expand All @@ -34,17 +36,19 @@
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.EVENT;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.FILTER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SERVICE;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SUBFLOW;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.BOTTOM_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.CENTER_TOP;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.EVENT_REFERENCE;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_ACTION;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_EVENT;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_STATE;

public class CallbackStateShape extends StateShape implements HasActions,
HasEventAndDataFilter {
HasEventAndDataFilter {

public static final String ICON_COLOR = "#EC7A08";
public static final String ICON_SVG = "M63.97,36.13c0-2.13-1.64-3.95-3.76-4.07-2.31-.13-4.23,1.7-4.23,3.99,0,6.61-5.37,11.98-11.98,11.98H24.03v-4.99c0-1.18-.7-2.25-1.78-2.74-1.08-.47-2.34-.28-3.23,.52l-9.98,8.98c-.63,.56-.99,1.37-.99,2.22s.36,1.66,.99,2.23l9.98,8.98c.56,.51,1.28,.77,2,.77,.41,0,.83-.09,1.22-.26,1.08-.48,1.78-1.55,1.78-2.74v-4.99h19.97c10.98,0,19.92-8.91,19.97-19.89ZM20,16.08h19.85l.11,4.99c0,1.18,.7,2.25,1.78,2.74,.4,.17,.81,.26,1.11,.26,.73,0,1.44-.27,2.01-.77l9.98-8.98c.74-.57,1.1-1.38,1.1-2.34s-.36-1.66-.99-2.23L44.97,.76c-.88-.79-2.15-.98-3.22-.51-1.08,.6-1.89,1.67-1.89,2.85l.11,4.99H20C8.99,8.09,.03,17.05,.03,28.06c0,2.21,1.79,3.99,3.99,3.99s3.99-1.79,3.99-3.99c0-6.6,5.38-11.98,11.98-11.98Z";
Expand All @@ -60,9 +64,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
if (state.getTimeouts() != null && state.getTimeouts() instanceof WorkflowTimeouts) {
getView().addChild(new CornerIcon(CLOCK,
CENTER_TOP,
getTranslation(TIMEOUT_EVENT) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getEventTimeout() + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getStateExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getActionExecTimeout()));
getTranslation(TIMEOUT_EVENT) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getEventTimeout() + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout()));
}

getView().addChild(new CornerIcon(EVENT,
Expand All @@ -75,10 +79,14 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut

if (state.getStateDataFilter() != null || state.getEventDataFilter() != null) {
getView().addChild(new CornerIcon(FILTER,
BOTTOM_FROM_RIGHT_TOP_CORNER,
getStateDataFilter(state.getStateDataFilter())
+ "\r\n\r\n"
+ getEventFilter(state.getEventDataFilter())));
BOTTOM_FROM_RIGHT_TOP_CORNER,
getStateDataFilter(state.getStateDataFilter())
+ "\r\n\r\n"
+ getEventFilter(state.getEventDataFilter())));
}

if (null != state.getAction() && hasSubflows(new ActionNode[]{state.getAction()})) {
getView().addChild(new DataDepiction(SUBFLOW, LEFT_TOP_CORNER));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.BottomDepiction;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.CornerIcon;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.DataDepiction;
import org.kie.workbench.common.stunner.sw.definition.ForEachState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;
Expand All @@ -37,8 +38,10 @@
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.PARALLEL;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SEQUENTIAL;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SERVICE;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SUBFLOW;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.BOTTOM_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.RIGHT_BOTTOM;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_ACTION;
Expand Down Expand Up @@ -80,6 +83,10 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
}

getView().addChild(new BottomDepiction(isDefaultMode(state.getMode()) ? PARALLEL : SEQUENTIAL));

if (hasSubflows(state.getActions())) {
getView().addChild(new DataDepiction(SUBFLOW, LEFT_TOP_CORNER));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/

package org.kie.workbench.common.stunner.sw.client.shapes;
Expand Down Expand Up @@ -80,4 +80,19 @@ default String getActionString(ActionNode action) {

return getTranslation(ACTION_IS_NULL);
}

default boolean hasSubflows(ActionNode[] actions) {
if (actions == null || actions.length == 0) {
return false;
}

for (ActionNode action : actions) {
if (action.getSubFlowRef() != null) {
return true;
}
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/

package org.kie.workbench.common.stunner.sw.client.shapes;
Expand Down Expand Up @@ -44,4 +44,17 @@ default String getBranchesString(ParallelStateBranch[] branches) {

return result.toString();
}

default boolean hasSubflows(ParallelStateBranch[] branches) {
if (branches == null || branches.length == 0) {
return false;
}

for (ParallelStateBranch branch : branches) {
return hasSubflows(branch.getActions());
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.BottomDepiction;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.CornerIcon;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.DataDepiction;
import org.kie.workbench.common.stunner.sw.definition.OperationState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;
Expand All @@ -36,8 +37,10 @@
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.PARALLEL;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SEQUENTIAL;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SERVICE;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SUBFLOW;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.BOTTOM_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_ACTION;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_STATE;
Expand All @@ -59,8 +62,8 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
if (state.getTimeouts() != null && state.getTimeouts() instanceof WorkflowTimeouts) {
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getStateExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getActionExecTimeout()));
getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout()));
}

getView().addChild(new CornerIcon(SERVICE,
Expand All @@ -74,6 +77,10 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut

boolean isDefault = state.getActionMode() == null || !(state.getActionMode().equals("parallel"));
getView().addChild(new BottomDepiction(isDefault ? SEQUENTIAL : PARALLEL));

if (hasSubflows(state.getActions())) {
getView().addChild(new DataDepiction(SUBFLOW, LEFT_TOP_CORNER));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.BottomText;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.CornerIcon;
import org.kie.workbench.common.stunner.sw.client.shapes.icons.DataDepiction;
import org.kie.workbench.common.stunner.sw.definition.ParallelState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.BRANCH;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.CLOCK;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.FILTER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.SUBFLOW;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.BOTTOM_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_FROM_RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.LEFT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPosition.RIGHT_TOP_CORNER;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_BRANCH;
import static org.kie.workbench.common.stunner.sw.resources.i18n.SWConstants.TIMEOUT_STATE;

public class ParallelStateShape extends StateShape implements HasDataFilter, HasBranches {
public class ParallelStateShape extends StateShape implements HasDataFilter,
HasBranches {

public static final String ICON_COLOR = "#4CB140";
public static final String ICON_SVG = "M50.54,.01c2.34,.16,4.24,2.31,4.24,4.65V59.43c0,2.64-2.23,4.75-4.91,4.56-2.33-.17-4.23-2.31-4.23-4.65V4.57c0-2.63,2.22-4.75,4.9-4.56M13.46,63.99c-2.34-.16-4.24-2.31-4.24-4.65V4.57c0-2.52,2.04-4.57,4.57-4.57s4.57,2.05,4.57,4.57V59.43c0,2.64-2.22,4.75-4.9,4.56Z";
Expand All @@ -56,8 +60,8 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
if (state.getTimeouts() != null && state.getTimeouts() instanceof WorkflowTimeouts) {
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_BRANCH) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getBranchExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts)state.getTimeouts()).getStateExecTimeout()));
getTranslation(TIMEOUT_BRANCH) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getBranchExecTimeout() + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()));
}

getView().addChild(new CornerIcon(BRANCH,
Expand All @@ -74,6 +78,10 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
? getTranslation("Enum.atleast") + ": " + state.getNumCompleted()
: getTranslation("Enum.allof");
getView().addChild(new BottomText(completionType));

if (hasSubflows(state.getBranches())) {
getView().addChild(new DataDepiction(SUBFLOW, LEFT_TOP_CORNER));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


package org.kie.workbench.common.stunner.sw.client.shapes.icons;

import com.ait.lienzo.client.core.shape.Group;
import com.ait.lienzo.client.core.shape.MultiPath;
import com.ait.lienzo.client.core.types.Point2D;

public class DataDepiction extends Group {

public DataDepiction(final String icon, final Point2D location) {
setLocation(location);
setListening(true);

MultiPath multiPath = new MultiPath(icon)
.setStrokeWidth(0)
.setFillColor("#4F5255")
.setListening(false);
add(multiPath);
}

@Override
public void destroy() {
super.destroy();
}
}
Loading

0 comments on commit d8fef4b

Please sign in to comment.