use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method prepareBpmnModel.
protected void prepareBpmnModel(BpmnModel bpmnModel) {
// Need to make sure all elements have positive x and y.
// Check all graphicInfo and update the elements accordingly
List<GraphicInfo> allGraphicInfos = new ArrayList<GraphicInfo>();
if (bpmnModel.getLocationMap() != null) {
allGraphicInfos.addAll(bpmnModel.getLocationMap().values());
}
if (bpmnModel.getLabelLocationMap() != null) {
allGraphicInfos.addAll(bpmnModel.getLabelLocationMap().values());
}
if (bpmnModel.getFlowLocationMap() != null) {
for (List<GraphicInfo> flowGraphicInfos : bpmnModel.getFlowLocationMap().values()) {
allGraphicInfos.addAll(flowGraphicInfos);
}
}
if (allGraphicInfos.size() > 0) {
boolean needsTranslationX = false;
boolean needsTranslationY = false;
double lowestX = 0.0;
double lowestY = 0.0;
// Collect lowest x and y
for (GraphicInfo graphicInfo : allGraphicInfos) {
double x = graphicInfo.getX();
double y = graphicInfo.getY();
if (x < lowestX) {
needsTranslationX = true;
lowestX = x;
}
if (y < lowestY) {
needsTranslationY = true;
lowestY = y;
}
}
// Update all graphicInfo objects
if (needsTranslationX || needsTranslationY) {
double translationX = Math.abs(lowestX);
double translationY = Math.abs(lowestY);
for (GraphicInfo graphicInfo : allGraphicInfos) {
if (needsTranslationX) {
graphicInfo.setX(graphicInfo.getX() + translationX);
}
if (needsTranslationY) {
graphicInfo.setY(graphicInfo.getY() + translationY);
}
}
}
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method connectionPerfectionizer.
/**
* This method makes coordinates of connection flow better.
* @param processDiagramCanvas
* @param bpmnModel
* @param sourceElement
* @param targetElement
* @param graphicInfoList
* @return
*/
protected static List<GraphicInfo> connectionPerfectionizer(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, BaseElement sourceElement, BaseElement targetElement, List<GraphicInfo> graphicInfoList) {
GraphicInfo sourceGraphicInfo = bpmnModel.getGraphicInfo(sourceElement.getId());
GraphicInfo targetGraphicInfo = bpmnModel.getGraphicInfo(targetElement.getId());
DefaultProcessDiagramCanvas.SHAPE_TYPE sourceShapeType = getShapeType(sourceElement);
DefaultProcessDiagramCanvas.SHAPE_TYPE targetShapeType = getShapeType(targetElement);
return processDiagramCanvas.connectionPerfectionizer(sourceShapeType, targetShapeType, sourceGraphicInfo, targetGraphicInfo, graphicInfoList);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method drawActivity.
protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor) {
ActivityDrawInstruction drawInstruction = activityDrawInstructions.get(flowNode.getClass());
if (drawInstruction != null) {
drawInstruction.draw(processDiagramCanvas, bpmnModel, flowNode);
// Gather info on the multi instance marker
boolean multiInstanceSequential = false, multiInstanceParallel = false, collapsed = false;
if (flowNode instanceof Activity) {
Activity activity = (Activity) flowNode;
MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = activity.getLoopCharacteristics();
if (multiInstanceLoopCharacteristics != null) {
multiInstanceSequential = multiInstanceLoopCharacteristics.isSequential();
multiInstanceParallel = !multiInstanceSequential;
}
}
// Gather info on the collapsed marker
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
if (flowNode instanceof SubProcess) {
collapsed = graphicInfo.getExpanded() != null && !graphicInfo.getExpanded();
} else if (flowNode instanceof CallActivity) {
collapsed = true;
}
if (scaleFactor == 1.0) {
// Actually draw the markers
processDiagramCanvas.drawActivityMarkers((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight(), multiInstanceSequential, multiInstanceParallel, collapsed);
}
// Draw highlighted activities
if (highLightedActivities.contains(flowNode.getId())) {
drawHighLight(processDiagramCanvas, bpmnModel.getGraphicInfo(flowNode.getId()));
}
}
// Outgoing transitions of activity
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
boolean highLighted = (highLightedFlows.contains(sequenceFlow.getId()));
String defaultFlow = null;
if (flowNode instanceof Activity) {
defaultFlow = ((Activity) flowNode).getDefaultFlow();
} else if (flowNode instanceof Gateway) {
defaultFlow = ((Gateway) flowNode).getDefaultFlow();
}
boolean isDefault = false;
if (defaultFlow != null && defaultFlow.equalsIgnoreCase(sequenceFlow.getId())) {
isDefault = true;
}
boolean drawConditionalIndicator = sequenceFlow.getConditionExpression() != null && !(flowNode instanceof Gateway);
String sourceRef = sequenceFlow.getSourceRef();
String targetRef = sequenceFlow.getTargetRef();
FlowElement sourceElement = bpmnModel.getFlowElement(sourceRef);
FlowElement targetElement = bpmnModel.getFlowElement(targetRef);
List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
if (graphicInfoList != null && graphicInfoList.size() > 0) {
graphicInfoList = connectionPerfectionizer(processDiagramCanvas, bpmnModel, sourceElement, targetElement, graphicInfoList);
int[] xPoints = new int[graphicInfoList.size()];
int[] yPoints = new int[graphicInfoList.size()];
for (int i = 1; i < graphicInfoList.size(); i++) {
GraphicInfo graphicInfo = graphicInfoList.get(i);
GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);
if (i == 1) {
xPoints[0] = (int) previousGraphicInfo.getX();
yPoints[0] = (int) previousGraphicInfo.getY();
}
xPoints[i] = (int) graphicInfo.getX();
yPoints[i] = (int) graphicInfo.getY();
}
processDiagramCanvas.drawSequenceflow(xPoints, yPoints, drawConditionalIndicator, isDefault, highLighted, scaleFactor);
// Draw sequenceflow label
GraphicInfo labelGraphicInfo = bpmnModel.getLabelGraphicInfo(sequenceFlow.getId());
if (labelGraphicInfo != null) {
processDiagramCanvas.drawLabel(sequenceFlow.getName(), labelGraphicInfo, false);
}
}
}
// Nested elements
if (flowNode instanceof FlowElementsContainer) {
for (FlowElement nestedFlowElement : ((FlowElementsContainer) flowNode).getFlowElements()) {
if (nestedFlowElement instanceof FlowNode) {
drawActivity(processDiagramCanvas, bpmnModel, (FlowNode) nestedFlowElement, highLightedActivities, highLightedFlows, scaleFactor);
}
}
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class AssociationJsonConverter method convertToJson.
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
Association association = (Association) baseElement;
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(association.getId(), STENCIL_ASSOCIATION, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(association.getSourceRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(association.getSourceRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(association.getId());
if (graphicInfoList.size() > 2) {
for (int i = 1; i < graphicInfoList.size() - 1; i++) {
GraphicInfo graphicInfo = graphicInfoList.get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
}
GraphicInfo targetGraphicInfo = model.getGraphicInfo(association.getTargetRef());
GraphicInfo flowGraphicInfo = graphicInfoList.get(graphicInfoList.size() - 1);
double diffTopY = Math.abs(flowGraphicInfo.getY() - targetGraphicInfo.getY());
double diffRightX = Math.abs(flowGraphicInfo.getX() - (targetGraphicInfo.getX() + targetGraphicInfo.getWidth()));
double diffBottomY = Math.abs(flowGraphicInfo.getY() - (targetGraphicInfo.getY() + targetGraphicInfo.getHeight()));
dockNode = objectMapper.createObjectNode();
if (diffTopY < 5) {
dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, 0.0);
} else if (diffRightX < 5) {
dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth());
dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
} else if (diffBottomY < 5) {
dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight());
} else {
dockNode.put(EDITOR_BOUNDS_X, 0.0);
dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
}
dockersArrayNode.add(dockNode);
flowNode.put("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
flowNode.put("outgoing", outgoingArrayNode);
flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, association.getId());
flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertToJson.
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
this.model = model;
this.processor = processor;
this.subProcessX = subProcessX;
this.subProcessY = subProcessY;
this.shapesArrayNode = shapesArrayNode;
GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
String stencilId = null;
if (baseElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) baseElement;
if ("mail".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MAIL;
} else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_CAMEL;
} else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MULE;
} else {
stencilId = getStencilId(baseElement);
}
} else {
stencilId = getStencilId(baseElement);
}
flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
shapesArrayNode.add(flowElementNode);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getName())) {
propertiesNode.put(PROPERTY_NAME, flowElement.getName());
}
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
}
}
convertElementToJson(propertiesNode, baseElement);
flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
if (baseElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) baseElement;
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(flowNode.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
}
propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
if (activity.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
if (loopDef.isSequential() == false) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
} else {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
}
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
}
if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
}
if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
}
if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
}
}
}
if (activity instanceof UserTask) {
BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
}
BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, propertiesNode);
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
createDataAssociation(dataAssociation, true, activity);
}
}
}
if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
createDataAssociation(dataAssociation, false, activity);
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
}
}
}
for (Artifact artifact : container.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
}
}
}
if (baseElement instanceof DataStoreReference) {
for (Process process : model.getProcesses()) {
processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
}
}
flowElementNode.put("outgoing", outgoingArrayNode);
}
Aggregations