use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method createBpmnShapeForElement.
private void createBpmnShapeForElement(BpmnDiFactory factory, BPMNPlane plane, BaseElement element) {
Bounds bounds = _bounds.get(element.getId());
if (bounds != null) {
BPMNShape shape = factory.createBPMNShape();
shape.setBpmnElement(element);
shape.setBounds(bounds);
plane.getPlaneElement().add(shape);
}
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitDI.
public void revisitDI(Definitions def) {
revisitDIColors(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;
updateShapeBounds(def, plane, shape.getBpmnElement());
}
}
revisitEdgeBoundsInLanes(def);
revisitEdgeBoundsInContainers(def);
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class DIZorderComparator method compareShape.
private int compareShape(BPMNShape a, BPMNShape b) {
BaseElement aElem = a.getBpmnElement();
BaseElement bElem = b.getBpmnElement();
boolean aIsSecondTier = aElem instanceof Lane || aElem instanceof SubProcess;
boolean bIsSecondTier = bElem instanceof Lane || bElem instanceof SubProcess;
if (aIsSecondTier && bIsSecondTier) {
if (isParent(aElem, bElem)) {
return -1;
} else if (isParent(bElem, aElem)) {
return 1;
}
return 0;
} else if (aIsSecondTier && !bIsSecondTier) {
return -1;
} else if (!aIsSecondTier && bIsSecondTier) {
return 1;
}
return 0;
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallLanes.
private List<String> marshallLanes(Lane lane, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Bounds bounds = ((BPMNShape) findDiagramElement(plane, lane)).getBounds();
List<String> nodeRefIds = new ArrayList<String>();
if (bounds != null) {
generator.writeStartObject();
generator.writeObjectField("resourceId", lane.getId());
Map<String, Object> laneProperties = new LinkedHashMap<String, Object>();
if (lane.getName() != null) {
laneProperties.put(NAME, StringEscapeUtils.unescapeXml(lane.getName()));
} else {
laneProperties.put(NAME, "");
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(lane.getExtensionValues(), "elementname");
if (elementName != null) {
laneProperties.put(NAME, elementName);
}
putDocumentationProperty(lane, laneProperties);
Iterator<FeatureMap.Entry> iter = lane.getAnyAttribute().iterator();
boolean foundBgColor = false;
boolean foundBrColor = false;
boolean foundFontColor = false;
boolean foundSelectable = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("background-color") || entry.getEStructuralFeature().getName().equals("bgcolor")) {
laneProperties.put(BGCOLOR, entry.getValue());
foundBgColor = true;
}
if (entry.getEStructuralFeature().getName().equals("border-color") || entry.getEStructuralFeature().getName().equals("bordercolor")) {
laneProperties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("fontsize")) {
laneProperties.put(FONTSIZE, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("color") || entry.getEStructuralFeature().getName().equals("fontcolor")) {
laneProperties.put(FONTCOLOR, entry.getValue());
foundFontColor = true;
}
if (entry.getEStructuralFeature().getName().equals("selectable")) {
laneProperties.put(ISSELECTABLE, entry.getValue());
foundSelectable = true;
}
}
if (!foundBgColor) {
laneProperties.put(BGCOLOR, defaultBgColor_Swimlanes);
}
if (!foundBrColor) {
laneProperties.put(BORDERCOLOR, defaultBrColor);
}
if (!foundFontColor) {
laneProperties.put(FONTCOLOR, defaultFontColor);
}
if (!foundSelectable) {
laneProperties.put(ISSELECTABLE, "true");
}
marshallProperties(laneProperties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "Lane");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
for (FlowElement flowElement : lane.getFlowNodeRefs()) {
nodeRefIds.add(flowElement.getId());
if (coordianteManipulation) {
marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, lane.getId(), generator);
generator.writeEndArray();
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();
generator.writeEndObject();
} else {
// dont marshall the lane unless it has BPMNDI info (eclipse editor does not generate it for lanes currently.
for (FlowElement flowElement : lane.getFlowNodeRefs()) {
nodeRefIds.add(flowElement.getId());
// we dont want an offset here!
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
return nodeRefIds;
}
use of org.eclipse.bpmn2.di.BPMNShape in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallNode.
protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
if (properties == null) {
properties = new LinkedHashMap<String, Object>();
}
putDocumentationProperty(node, properties);
if (node.getName() != null) {
properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
} else {
if (node instanceof TextAnnotation) {
if (((TextAnnotation) node).getText() != null) {
properties.put(NAME, ((TextAnnotation) node).getText());
} else {
properties.put(NAME, "");
}
} else {
properties.put(NAME, "");
}
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put("name", elementName);
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", stencil);
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
for (SequenceFlow outgoing : node.getOutgoing()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", outgoing.getId());
generator.writeEndObject();
}
// we need to also add associations as outgoing elements
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, node.getId(), generator);
// and boundary events for activities
List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
findBoundaryEvents(process, boundaryEvents);
for (BoundaryEvent be : boundaryEvents) {
if (be.getAttachedToRef().getId().equals(node.getId())) {
generator.writeStartObject();
generator.writeObjectField("resourceId", be.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
// boundary events have a docker
if (node instanceof BoundaryEvent) {
Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
boolean foundDockerInfo = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
foundDockerInfo = true;
String dockerInfoStr = String.valueOf(entry.getValue());
if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
if (dockerInfoStr.endsWith("|")) {
dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
String[] dockerInfoParts = dockerInfoStr.split("\\|");
String infoPartsToUse = dockerInfoParts[0];
String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
// backwards compatibility to older versions -- BZ 1196259
if (!foundDockerInfo) {
// find the edge associated with this boundary event
for (DiagramElement element : plane.getPlaneElement()) {
if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
// one per boundary event
Point p = waypoints.get(0);
if (p != null) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", p.getX());
generator.writeObjectField("y", p.getY());
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
}
BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
Bounds bounds = shape.getBounds();
correctEventNodeSize(shape);
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();
}
Aggregations