2014-05-21 14:23:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-30 15:01:00 +00:00
|
|
|
var BpmnTreeWalker = require('./BpmnTreeWalker');
|
2014-04-25 14:14:36 +00:00
|
|
|
|
|
|
|
|
2014-05-21 14:23:52 +00:00
|
|
|
/**
|
2014-06-30 15:01:00 +00:00
|
|
|
* 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
|
2014-05-21 14:23:52 +00:00
|
|
|
*/
|
2014-03-13 15:06:30 +00:00
|
|
|
function importBpmnDiagram(diagram, definitions, done) {
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
var importer = diagram.get('bpmnImporter');
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
var warnings = [];
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2014-03-21 15:46:56 +00:00
|
|
|
var visitor = {
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
root: function(element) {
|
|
|
|
return importer.add(element);
|
2014-07-01 09:33:28 +00:00
|
|
|
},
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
element: function(element, parentShape) {
|
|
|
|
return importer.add(element, parentShape);
|
2014-03-21 15:46:56 +00:00
|
|
|
},
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2014-03-21 15:46:56 +00:00
|
|
|
error: function(message, context) {
|
2014-06-23 12:44:03 +00:00
|
|
|
warnings.push({ message: message, context: context });
|
2014-03-21 15:46:56 +00:00
|
|
|
}
|
2014-03-13 15:06:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var walker = new BpmnTreeWalker(visitor);
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
try {
|
|
|
|
// import
|
|
|
|
walker.handleDefinitions(definitions);
|
2014-06-18 11:05:32 +00:00
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
done(null, warnings);
|
|
|
|
} catch (e) {
|
|
|
|
done(e);
|
|
|
|
}
|
2014-03-13 15:06:30 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 12:44:03 +00:00
|
|
|
module.exports.importBpmnDiagram = importBpmnDiagram;
|