use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BPMNDIExport method writeBPMNDI.
public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
// BPMN DI information
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);
String processId = null;
if (!model.getPools().isEmpty()) {
processId = "Collaboration";
} else {
processId = model.getMainProcess().getId();
}
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);
for (String elementId : model.getLocationMap().keySet()) {
if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getPool(elementId) != null || model.getLane(elementId) != null) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);
GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
FlowElement flowElement = model.getFlowElement(elementId);
if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
}
xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
xtw.writeEndElement();
xtw.writeEndElement();
}
}
for (String elementId : model.getFlowLocationMap().keySet()) {
if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getMessageFlow(elementId) != null) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);
List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
for (GraphicInfo graphicInfo : graphicInfoList) {
xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
xtw.writeEndElement();
}
GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
FlowElement flowElement = model.getFlowElement(elementId);
MessageFlow messageFlow = null;
if (flowElement == null) {
messageFlow = model.getMessageFlow(elementId);
}
boolean hasName = false;
if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
hasName = true;
} else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
hasName = true;
}
if (labelGraphicInfo != null && hasName) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
xtw.writeEndElement();
xtw.writeEndElement();
}
xtw.writeEndElement();
}
}
// end BPMN DI elements
xtw.writeEndElement();
xtw.writeEndElement();
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class BpmnShapeParser method parse.
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
GraphicInfo graphicInfo = new GraphicInfo();
String strIsExpanded = xtr.getAttributeValue(null, ATTRIBUTE_DI_IS_EXPANDED);
if ("true".equalsIgnoreCase(strIsExpanded)) {
graphicInfo.setExpanded(true);
}
BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
while (xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)));
graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)));
graphicInfo.setWidth(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)));
graphicInfo.setHeight(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)));
model.addGraphicInfo(id, graphicInfo);
break;
} else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
break;
}
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class ProcessInstanceDetailPanel method addProcessImage.
protected void addProcessImage() {
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
// Only show when graphical notation is defined
if (processDefinitionEntity != null) {
boolean didDrawImage = false;
if (ExplorerApp.get().isUseJavascriptDiagram()) {
try {
final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
if (!bpmnModel.getFlowLocationMap().isEmpty()) {
int maxX = 0;
int maxY = 0;
for (String key : bpmnModel.getLocationMap().keySet()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
double elementX = graphicInfo.getX() + graphicInfo.getWidth();
if (maxX < elementX) {
maxX = (int) elementX;
}
double elementY = graphicInfo.getY() + graphicInfo.getHeight();
if (maxY < elementY) {
maxY = (int) elementY;
}
}
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
URL explorerURL = ExplorerApp.get().getURL();
URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId());
Embedded browserPanel = new Embedded("", new ExternalResource(url));
browserPanel.setType(Embedded.TYPE_BROWSER);
browserPanel.setWidth(maxX + 350 + "px");
browserPanel.setHeight(maxY + 220 + "px");
HorizontalLayout panelLayoutT = new HorizontalLayout();
panelLayoutT.setSizeUndefined();
imagePanel.setContent(panelLayoutT);
imagePanel.addComponent(browserPanel);
panelLayout.addComponent(imagePanel);
didDrawImage = true;
}
} catch (Exception e) {
LOGGER.error("Error loading process diagram component", e);
}
}
if (!didDrawImage && processDefinitionEntity.isGraphicalNotationDefined()) {
ProcessEngineConfiguration processEngineConfiguration = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance, repositoryService, runtimeService, diagramGenerator, processEngineConfiguration);
if (diagram != null) {
Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
header.addStyleName(ExplorerLayout.STYLE_H3);
header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
panelLayout.addComponent(header);
Embedded embedded = new Embedded(null, diagram);
embedded.setType(Embedded.TYPE_IMAGE);
embedded.setSizeUndefined();
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.setScrollable(true);
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
HorizontalLayout panelLayoutT = new HorizontalLayout();
panelLayoutT.setSizeUndefined();
imagePanel.setContent(panelLayoutT);
imagePanel.addComponent(embedded);
panelLayout.addComponent(imagePanel);
}
}
}
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class ProcessDefinitionInfoComponent method initImage.
protected void initImage() {
processImageContainer = new VerticalLayout();
Label processTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
processTitle.addStyleName(ExplorerLayout.STYLE_H3);
processImageContainer.addComponent(processTitle);
boolean didDrawImage = false;
if (ExplorerApp.get().isUseJavascriptDiagram()) {
try {
final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
if (!bpmnModel.getFlowLocationMap().isEmpty()) {
int maxX = 0;
int maxY = 0;
for (String key : bpmnModel.getLocationMap().keySet()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
double elementX = graphicInfo.getX() + graphicInfo.getWidth();
if (maxX < elementX) {
maxX = (int) elementX;
}
double elementY = graphicInfo.getY() + graphicInfo.getHeight();
if (maxY < elementY) {
maxY = (int) elementY;
}
}
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
URL explorerURL = ExplorerApp.get().getURL();
URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId());
Embedded browserPanel = new Embedded("", new ExternalResource(url));
browserPanel.setType(Embedded.TYPE_BROWSER);
browserPanel.setWidth(maxX + 350 + "px");
browserPanel.setHeight(maxY + 220 + "px");
HorizontalLayout panelLayout = new HorizontalLayout();
panelLayout.setSizeUndefined();
imagePanel.setContent(panelLayout);
imagePanel.addComponent(browserPanel);
processImageContainer.addComponent(imagePanel);
didDrawImage = true;
}
} catch (Exception e) {
LOGGER.error("Error loading process diagram component", e);
}
}
if (didDrawImage == false) {
StreamResource diagram = null;
// Try generating process-image stream
if (processDefinition.getDiagramResourceName() != null) {
diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processDefinition, repositoryService);
}
if (diagram != null) {
Embedded embedded = new Embedded(null, diagram);
embedded.setType(Embedded.TYPE_IMAGE);
embedded.setSizeUndefined();
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
HorizontalLayout panelLayout = new HorizontalLayout();
panelLayout.setSizeUndefined();
imagePanel.setContent(panelLayout);
imagePanel.addComponent(embedded);
processImageContainer.addComponent(imagePanel);
didDrawImage = true;
}
}
if (didDrawImage == false) {
Label noImageAvailable = new Label(i18nManager.getMessage(Messages.PROCESS_NO_DIAGRAM));
processImageContainer.addComponent(noImageAvailable);
}
addComponent(processImageContainer);
}
use of org.activiti.bpmn.model.GraphicInfo in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method initProcessDiagramCanvas.
protected static DefaultProcessDiagramCanvas initProcessDiagramCanvas(BpmnModel bpmnModel, String imageType, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {
// We need to calculate maximum values to know how big the image will be in its entirety
double minX = Double.MAX_VALUE;
double maxX = 0;
double minY = Double.MAX_VALUE;
double maxY = 0;
for (Pool pool : bpmnModel.getPools()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
minX = graphicInfo.getX();
maxX = graphicInfo.getX() + graphicInfo.getWidth();
minY = graphicInfo.getY();
maxY = graphicInfo.getY() + graphicInfo.getHeight();
}
List<FlowNode> flowNodes = gatherAllFlowNodes(bpmnModel);
for (FlowNode flowNode : flowNodes) {
GraphicInfo flowNodeGraphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
// width
if (flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth() > maxX) {
maxX = flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth();
}
if (flowNodeGraphicInfo.getX() < minX) {
minX = flowNodeGraphicInfo.getX();
}
// height
if (flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight() > maxY) {
maxY = flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight();
}
if (flowNodeGraphicInfo.getY() < minY) {
minY = flowNodeGraphicInfo.getY();
}
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
if (graphicInfoList != null) {
for (GraphicInfo graphicInfo : graphicInfoList) {
// width
if (graphicInfo.getX() > maxX) {
maxX = graphicInfo.getX();
}
if (graphicInfo.getX() < minX) {
minX = graphicInfo.getX();
}
// height
if (graphicInfo.getY() > maxY) {
maxY = graphicInfo.getY();
}
if (graphicInfo.getY() < minY) {
minY = graphicInfo.getY();
}
}
}
}
}
List<Artifact> artifacts = gatherAllArtifacts(bpmnModel);
for (Artifact artifact : artifacts) {
GraphicInfo artifactGraphicInfo = bpmnModel.getGraphicInfo(artifact.getId());
if (artifactGraphicInfo != null) {
// width
if (artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth() > maxX) {
maxX = artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth();
}
if (artifactGraphicInfo.getX() < minX) {
minX = artifactGraphicInfo.getX();
}
// height
if (artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight() > maxY) {
maxY = artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight();
}
if (artifactGraphicInfo.getY() < minY) {
minY = artifactGraphicInfo.getY();
}
}
List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
if (graphicInfoList != null) {
for (GraphicInfo graphicInfo : graphicInfoList) {
// width
if (graphicInfo.getX() > maxX) {
maxX = graphicInfo.getX();
}
if (graphicInfo.getX() < minX) {
minX = graphicInfo.getX();
}
// height
if (graphicInfo.getY() > maxY) {
maxY = graphicInfo.getY();
}
if (graphicInfo.getY() < minY) {
minY = graphicInfo.getY();
}
}
}
}
int nrOfLanes = 0;
for (Process process : bpmnModel.getProcesses()) {
for (Lane l : process.getLanes()) {
nrOfLanes++;
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(l.getId());
// // width
if (graphicInfo.getX() + graphicInfo.getWidth() > maxX) {
maxX = graphicInfo.getX() + graphicInfo.getWidth();
}
if (graphicInfo.getX() < minX) {
minX = graphicInfo.getX();
}
// height
if (graphicInfo.getY() + graphicInfo.getHeight() > maxY) {
maxY = graphicInfo.getY() + graphicInfo.getHeight();
}
if (graphicInfo.getY() < minY) {
minY = graphicInfo.getY();
}
}
}
// Special case, see https://activiti.atlassian.net/browse/ACT-1431
if (flowNodes.isEmpty() && bpmnModel.getPools().isEmpty() && nrOfLanes == 0) {
// Nothing to show
minX = 0;
minY = 0;
}
return new DefaultProcessDiagramCanvas((int) maxX + 10, (int) maxY + 10, (int) minX, (int) minY, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
}
Aggregations