2014-04-25 09:05:08 +00:00
|
|
|
var _ = require('lodash');
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2014-04-25 09:05:08 +00:00
|
|
|
var bpmnModule = require('../di').defaultModule;
|
2014-04-03 09:47:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* A registry that keeps track of bpmn semantic / di elements and the
|
|
|
|
* corresponding shapes.
|
2014-04-25 09:05:08 +00:00
|
|
|
*
|
2014-04-03 09:47:26 +00:00
|
|
|
* @param {EventBus} events
|
|
|
|
* @param {ElementRegistry} elementRegistry
|
|
|
|
*/
|
|
|
|
function BpmnRegistry(events, elementRegistry) {
|
|
|
|
|
|
|
|
var elements = {
|
|
|
|
di: {},
|
|
|
|
semantic: {},
|
|
|
|
diagramElement: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
events.on('bpmn.element.add', function(e) {
|
|
|
|
var semantic = e.semantic,
|
|
|
|
id = semantic.id;
|
|
|
|
|
|
|
|
elements.di[id] = e.di;
|
|
|
|
elements.semantic[id] = e.semantic;
|
|
|
|
elements.diagramElement[id] = e.diagramElement;
|
|
|
|
});
|
|
|
|
|
|
|
|
events.on('bpmn.element.removed', function(e) {
|
|
|
|
var semantic = e.semantic,
|
|
|
|
id = semantic.id;
|
|
|
|
|
|
|
|
delete elements.di[id];
|
|
|
|
delete elements.semantic[id];
|
|
|
|
delete elements.diagramElement[id];
|
|
|
|
});
|
|
|
|
|
|
|
|
function get(type) {
|
|
|
|
var collection = elements[type];
|
|
|
|
|
2014-04-25 09:05:08 +00:00
|
|
|
return function(element) {
|
|
|
|
return collection[_.isObject(element) ? element.id : element];
|
2014-04-03 09:47:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// API
|
|
|
|
this.getSemantic = get('semantic');
|
|
|
|
this.getDi = get('di');
|
|
|
|
this.getDiagramElement = get('diagramElement');
|
|
|
|
}
|
|
|
|
|
|
|
|
bpmnModule.type('bpmnRegistry', [ 'eventBus', 'elementRegistry', BpmnRegistry ]);
|
|
|
|
|
|
|
|
module.exports = BpmnRegistry;
|