mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-14 11:04:15 +00:00
921de712d2
This commit extracts the main import logic found in import/Importer into the core/BpmnImporter module. By doing so we we are able to reuse it during modeling. Related to #6
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
var BpmnTreeWalker = require('./BpmnTreeWalker');
|
|
|
|
|
|
/**
|
|
* Import the definitions into the given diagram, reporting errors and warnings
|
|
* via the specified callback.
|
|
*
|
|
* @param {Diagram} diagram
|
|
* @param {ModdleElement} definitions
|
|
* @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
|
|
*/
|
|
function importBpmnDiagram(diagram, definitions, done) {
|
|
|
|
var importer = diagram.get('bpmnImporter'),
|
|
commandStack = diagram.get('commandStack');
|
|
|
|
var warnings = [];
|
|
|
|
var visitor = {
|
|
|
|
element: function(element, di, parent) {
|
|
return importer.add(element, di, parent);
|
|
},
|
|
|
|
error: function(message, context) {
|
|
warnings.push({ message: message, context: context });
|
|
}
|
|
};
|
|
|
|
var walker = new BpmnTreeWalker(visitor);
|
|
|
|
try {
|
|
// import
|
|
walker.handleDefinitions(definitions);
|
|
|
|
// clear command stack
|
|
commandStack.clear();
|
|
|
|
done(null, warnings);
|
|
} catch (e) {
|
|
done(e);
|
|
}
|
|
}
|
|
|
|
module.exports.importBpmnDiagram = importBpmnDiagram; |