use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallDataObject.
protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
putDocumentationProperty(dataObject, properties);
if (dataObject.getName() != null && dataObject.getName().length() > 0) {
properties.put(NAME, StringEscapeUtils.unescapeXml(dataObject.getName()));
} else {
// we need a name, use id instead
properties.put(NAME, dataObject.getId());
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put(NAME, elementName);
}
if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) {
if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) {
properties.put(STANDARDTYPE, dataObject.getItemSubjectRef().getStructureRef());
} else {
properties.put(CUSTOMTYPE, dataObject.getItemSubjectRef().getStructureRef());
}
}
Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject);
Association incomingAssociation = null;
Process process = (Process) plane.getBpmnElement();
for (Artifact artifact : process.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getTargetRef() == dataObject) {
incomingAssociation = association;
}
}
}
if (outgoingAssociaton != null && incomingAssociation == null) {
properties.put(INPUT_OUTPUT, "Input");
}
if (outgoingAssociaton == null && incomingAssociation != null) {
properties.put(INPUT_OUTPUT, "Output");
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "DataObject");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
List<Association> associations = findOutgoingAssociations(plane, dataObject);
if (associations != null) {
for (Association as : associations) {
generator.writeStartObject();
generator.writeObjectField("resourceId", as.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds();
generator.writeObjectFieldStart("bounds");
generator.writeObjectFieldStart("lowerRight");
generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
generator.writeEndObject();
generator.writeObjectFieldStart("upperLeft");
generator.writeObjectField("x", bounds.getX() - xOffset);
generator.writeObjectField("y", bounds.getY() - yOffset);
generator.writeEndObject();
generator.writeEndObject();
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallGroup.
protected void marshallGroup(Group group, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<>();
if (group.getCategoryValueRef() != null && group.getCategoryValueRef().getValue() != null) {
properties.put("name", StringEscapeUtils.unescapeXml(group.getCategoryValueRef().getValue()));
}
putDocumentationProperty(group, properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "Group");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
if (findOutgoingAssociation(plane, group) != null) {
generator.writeStartObject();
generator.writeObjectField("resourceId", findOutgoingAssociation(plane, group).getId());
generator.writeEndObject();
}
generator.writeEndArray();
Bounds bounds = ((BPMNShape) findDiagramElement(plane, group)).getBounds();
generator.writeObjectFieldStart("bounds");
generator.writeObjectFieldStart("lowerRight");
generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
generator.writeEndObject();
generator.writeObjectFieldStart("upperLeft");
generator.writeObjectField("x", bounds.getX() - xOffset);
generator.writeObjectField("y", bounds.getY() - yOffset);
generator.writeEndObject();
generator.writeEndObject();
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallAssociation.
protected void marshallAssociation(Association association, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>();
Iterator<FeatureMap.Entry> iter = association.getAnyAttribute().iterator();
boolean foundBrColor = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("type")) {
properties.put(TYPE, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("bordercolor")) {
properties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
}
if (!foundBrColor) {
properties.put("bordercolor", defaultSequenceflowColor);
}
putDocumentationProperty(association, properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
if (association.getAssociationDirection().equals(AssociationDirection.ONE)) {
generator.writeObjectField("id", "Association_Unidirectional");
} else if (association.getAssociationDirection().equals(AssociationDirection.BOTH)) {
generator.writeObjectField("id", "Association_Bidirectional");
} else {
generator.writeObjectField("id", "Association_Undirected");
}
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
generator.writeStartObject();
generator.writeObjectField("resourceId", association.getTargetRef().getId());
generator.writeEndObject();
generator.writeEndArray();
Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, association.getSourceRef())).getBounds();
Bounds targetBounds = null;
float tbx = 0;
float tby = 0;
if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNShape) {
targetBounds = ((BPMNShape) findDiagramElement(plane, association.getTargetRef())).getBounds();
} else if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNEdge) {
// connect it to first waypoint on edge
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association.getTargetRef())).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
tbx = waypoints.get(0).getX();
tby = waypoints.get(0).getY();
}
}
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", sourceBounds.getWidth() / 2);
generator.writeObjectField("y", sourceBounds.getHeight() / 2);
generator.writeEndObject();
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association)).getWaypoint();
for (int i = 1; i < waypoints.size() - 1; i++) {
Point waypoint = waypoints.get(i);
generator.writeStartObject();
generator.writeObjectField("x", waypoint.getX());
generator.writeObjectField("y", waypoint.getY());
generator.writeEndObject();
}
if (targetBounds != null) {
generator.writeStartObject();
// text annotations have to be treated specia
if (association.getTargetRef() instanceof TextAnnotation) {
generator.writeObjectField("x", 1);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
} else {
generator.writeObjectField("x", targetBounds.getWidth() / 2);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
}
generator.writeEndObject();
generator.writeEndArray();
} else {
generator.writeStartObject();
generator.writeObjectField("x", tbx);
generator.writeObjectField("y", tby);
generator.writeEndObject();
generator.writeEndArray();
}
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method updateEdgeBoundsInLanes.
public void updateEdgeBoundsInLanes(Definitions def, BPMNPlane plane, BPMNEdge edge, BaseElement ele) {
if (ele instanceof SequenceFlow) {
SequenceFlow sq = (SequenceFlow) ele;
// update the source and target on BPMNEdge
if (sq.getSourceRef() != null) {
edge.setSourceElement(getBPMNShapeForElement(sq.getSourceRef(), plane));
}
if (sq.getTargetRef() != null) {
edge.setTargetElement(getBPMNShapeForElement(sq.getTargetRef(), plane));
}
List<RootElement> rootElements = def.getRootElements();
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
if (sq.getSourceRef() != null && sq.getTargetRef() != null) {
if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
for (LaneSet ls : process.getLaneSets()) {
for (Lane newLane : ls.getLanes()) {
List<FlowNode> laneFlowNodes = newLane.getFlowNodeRefs();
Bounds laneBounds = getBoundsForElement(newLane, plane);
for (FlowNode newFlowNode : laneFlowNodes) {
if (newFlowNode.getId().equals(sq.getSourceRef().getId())) {
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
if (shape.getBpmnElement().getId().equals(sq.getSourceRef().getId())) {
Bounds eleBounds = shape.getBounds();
List<Point> edgePoints = edge.getWaypoint();
if (edgePoints != null && edgePoints.size() > 1) {
if (eleBounds != null) {
Point first = edgePoints.get(0);
first.setX(first.getX() + laneBounds.getX());
first.setY(first.getY() + laneBounds.getY());
}
}
}
}
}
} else if (newFlowNode.getId().equals(sq.getTargetRef().getId())) {
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
if (shape.getBpmnElement().getId().equals(sq.getTargetRef().getId())) {
Bounds eleBounds = shape.getBounds();
List<Point> edgePoints = edge.getWaypoint();
if (edgePoints != null && edgePoints.size() > 1) {
if (eleBounds != null) {
Point last = edgePoints.get(edgePoints.size() - 1);
last.setX(last.getX() + laneBounds.getX());
last.setY(last.getY() + laneBounds.getY());
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitDIColors.
public void revisitDIColors(Definitions def) {
BPMNPlane plane = def.getDiagrams().get(0).getPlane();
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
updateShapeColors(shape);
}
if (dia instanceof BPMNEdge) {
BPMNEdge edge = (BPMNEdge) dia;
updateEdgeColors(edge);
}
}
}
Aggregations