2014-06-30 15:01:00 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
var hasExternalLabel = require('../util/Label').hasExternalLabel,
|
|
|
|
isExpanded = require('../util/Di').isExpanded;
|
2014-06-30 15:01:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An importer that adds bpmn elements to the canvas
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
* @param {Canvas} canvas
|
|
|
|
*/
|
2014-07-18 12:39:15 +00:00
|
|
|
function BpmnImporter(eventBus, canvas, elementFactory) {
|
2014-06-30 15:01:00 +00:00
|
|
|
this._eventBus = eventBus;
|
|
|
|
this._canvas = canvas;
|
2014-07-18 12:39:15 +00:00
|
|
|
|
|
|
|
this._elementFactory = elementFactory;
|
2014-06-30 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
BpmnImporter.$inject = [ 'eventBus', 'canvas', 'elementFactory' ];
|
2014-06-30 15:01:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:15:23 +00:00
|
|
|
* Add bpmn element (semantic) to the canvas onto the
|
|
|
|
* specified parent shape.
|
2014-06-30 15:01:00 +00:00
|
|
|
*/
|
2014-07-18 12:39:15 +00:00
|
|
|
BpmnImporter.prototype.add = function(semantic, parentElement) {
|
|
|
|
|
|
|
|
var di = semantic.di,
|
|
|
|
element;
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-01 09:33:28 +00:00
|
|
|
// handle the special case that we deal with a
|
|
|
|
// invisible root element (process or collaboration)
|
|
|
|
if (di.$instanceOf('bpmndi:BPMNPlane')) {
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
// add a virtual element (not being drawn)
|
2014-07-18 12:39:15 +00:00
|
|
|
element = this._elementFactory.createRoot(semantic);
|
|
|
|
}
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
// SHAPE
|
|
|
|
else if (di.$instanceOf('bpmndi:BPMNShape')) {
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
var collapsed = !isExpanded(semantic);
|
|
|
|
var hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
element = this._elementFactory.createShape(semantic, {
|
|
|
|
collapsed: collapsed,
|
|
|
|
hidden: hidden
|
2014-07-16 14:15:23 +00:00
|
|
|
});
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
this._canvas.addShape(element, parentElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CONNECTION
|
|
|
|
else {
|
|
|
|
element = this._elementFactory.createConnection(semantic, parentElement);
|
|
|
|
this._canvas.addConnection(element, parentElement);
|
2014-06-30 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
// (optional) LABEL
|
|
|
|
if (hasExternalLabel(semantic)) {
|
|
|
|
this.addLabel(semantic, element);
|
2014-07-16 14:15:23 +00:00
|
|
|
}
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
this._eventBus.fire('bpmnElement.added', { element: element });
|
2014-06-30 15:01:00 +00:00
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
return element;
|
2014-06-30 15:01:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-18 12:39:15 +00:00
|
|
|
/**
|
|
|
|
* add label for an element
|
|
|
|
*/
|
|
|
|
BpmnImporter.prototype.addLabel = function (semantic, element) {
|
|
|
|
var label = this._elementFactory.createLabel(semantic, element);
|
|
|
|
return this._canvas.addShape(label, element.parent);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-30 15:01:00 +00:00
|
|
|
module.exports = BpmnImporter;
|