feat(BpmnTreeWalker): handle loose processes / only selected DI
This commit is contained in:
parent
d2e71b64b5
commit
7ccc9bf48e
|
@ -5,6 +5,9 @@ function BpmnTraverser(handler) {
|
||||||
var elementDiMap = {};
|
var elementDiMap = {};
|
||||||
var elementGfxMap = {};
|
var elementGfxMap = {};
|
||||||
|
|
||||||
|
// list of containers already walked
|
||||||
|
var handledProcesses = [];
|
||||||
|
|
||||||
///// Helpers /////////////////////////////////
|
///// Helpers /////////////////////////////////
|
||||||
|
|
||||||
function contextual(fn, ctx) {
|
function contextual(fn, ctx) {
|
||||||
|
@ -19,8 +22,15 @@ function BpmnTraverser(handler) {
|
||||||
|
|
||||||
function visit(element, di, ctx) {
|
function visit(element, di, ctx) {
|
||||||
|
|
||||||
|
var gfx = elementGfxMap[element.id];
|
||||||
|
|
||||||
|
// avoid multiple rendering of elements
|
||||||
|
if (gfx) {
|
||||||
|
return gfx;
|
||||||
|
}
|
||||||
|
|
||||||
// call handler
|
// call handler
|
||||||
var gfx = handler.element(element, di, ctx);
|
gfx = handler.element(element, di, ctx);
|
||||||
|
|
||||||
// and log returned result
|
// and log returned result
|
||||||
elementGfxMap[element.id] = gfx;
|
elementGfxMap[element.id] = gfx;
|
||||||
|
@ -78,8 +88,6 @@ function BpmnTraverser(handler) {
|
||||||
////// Semantic handling //////////////////////
|
////// Semantic handling //////////////////////
|
||||||
|
|
||||||
function handleDefinitions(definitions, diagram) {
|
function handleDefinitions(definitions, diagram) {
|
||||||
buildDiMap(definitions);
|
|
||||||
|
|
||||||
// make sure we walk the correct bpmnElement
|
// make sure we walk the correct bpmnElement
|
||||||
|
|
||||||
var diagrams = definitions.diagrams;
|
var diagrams = definitions.diagrams;
|
||||||
|
@ -99,6 +107,9 @@ function BpmnTraverser(handler) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load DI from selected diagram only
|
||||||
|
handleDiagram(diagram);
|
||||||
|
|
||||||
var rootElement = diagram.plane.bpmnElement;
|
var rootElement = diagram.plane.bpmnElement;
|
||||||
|
|
||||||
if (is(rootElement, 'bpmn:Process')) {
|
if (is(rootElement, 'bpmn:Process')) {
|
||||||
|
@ -106,11 +117,25 @@ function BpmnTraverser(handler) {
|
||||||
} else
|
} else
|
||||||
if (is(rootElement, 'bpmn:Collaboration')) {
|
if (is(rootElement, 'bpmn:Collaboration')) {
|
||||||
handleCollaboration(rootElement);
|
handleCollaboration(rootElement);
|
||||||
|
|
||||||
|
// force drawing of everything not yet drawn that is part of the target DI
|
||||||
|
handleUnhandledProcesses(definitions.rootElements);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('unsupported root element for bpmndi:Diagram: ' + type.name);
|
throw new Error('unsupported root element for bpmndi:Diagram: ' + type.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleUnhandledProcesses(rootElements) {
|
||||||
|
|
||||||
|
// walk through all processes that have not yet been drawn and draw them
|
||||||
|
// (in case they contain lanes with DI information)
|
||||||
|
var processes = _.forEach(rootElements, function(e) {
|
||||||
|
return e.$type === 'bpmn:Process' && e.laneSets && handledProcesses.indexOf(e) !== -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
processes.forEach(contextual(handleProcess));
|
||||||
|
}
|
||||||
|
|
||||||
function handleDataAssociation(association, context) {
|
function handleDataAssociation(association, context) {
|
||||||
visitIfDi(association, context);
|
visitIfDi(association, context);
|
||||||
}
|
}
|
||||||
|
@ -265,6 +290,9 @@ function BpmnTraverser(handler) {
|
||||||
handleIoSpecification(process.ioSpecification, context);
|
handleIoSpecification(process.ioSpecification, context);
|
||||||
|
|
||||||
handleArtifacts(process.artifacts, context);
|
handleArtifacts(process.artifacts, context);
|
||||||
|
|
||||||
|
// log process handled
|
||||||
|
handledProcesses.push(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessageFlow(messageFlow, context) {
|
function handleMessageFlow(messageFlow, context) {
|
||||||
|
|
Loading…
Reference in New Issue