From 6aceab9dbf316ccdfbc010762a5468a26acccd5b Mon Sep 17 00:00:00 2001 From: jdotzki Date: Fri, 6 Mar 2015 09:27:18 +0100 Subject: [PATCH] feature(contextpad): add catch events to pad for event based gateways close #206 --- lib/features/context-pad/ContextPadProvider.js | 17 +++++++++++++++-- lib/features/modeling/ElementFactory.js | 13 +++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/features/context-pad/ContextPadProvider.js b/lib/features/context-pad/ContextPadProvider.js index 440bdfa2..d2bd89ed 100644 --- a/lib/features/context-pad/ContextPadProvider.js +++ b/lib/features/context-pad/ContextPadProvider.js @@ -96,10 +96,11 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { - function appendAction(type, className) { + function appendAction(type, className, options) { function appendListener(event, element) { - var shape = elementFactory.createShape({ type: type }); + + var shape = elementFactory.createShape(assign({ type: type }, options)); create.start(event, shape, element); } @@ -139,6 +140,18 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { assign(actions, { 'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'), + 'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent', + 'icon-02-message-intermediate-event', + { _eventDefinitionType: 'bpmn:MessageEventDefinition'}), + 'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent', + 'icon-03-timer-intermediate-event', + { _eventDefinitionType: 'bpmn:TimerEventDefinition'}), + 'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent', + 'icon-05-conditional-intermediate-event', + { _eventDefinitionType: 'bpmn:ConditionalEventDefinition'}), + 'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent', + 'icon-10-signal-intermediate-event', + { _eventDefinitionType: 'bpmn:SignalEventDefinition'}), 'connect': { group: 'connect', className: 'icon-connection', diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 4cfa26eb..ae9477dc 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -9,15 +9,16 @@ var BaseElementFactory = require('diagram-js/lib/core/ElementFactory'), /** * A bpmn-aware factory for diagram-js shapes */ -function ElementFactory(bpmnFactory) { +function ElementFactory(bpmnFactory, moddle) { BaseElementFactory.call(this); this._bpmnFactory = bpmnFactory; + this._moddle = moddle; } ElementFactory.prototype = Object.create(BaseElementFactory.prototype); -ElementFactory.$inject = [ 'bpmnFactory' ]; +ElementFactory.$inject = [ 'bpmnFactory', 'moddle' ]; module.exports = ElementFactory; @@ -65,6 +66,14 @@ ElementFactory.prototype.create = function(elementType, attrs) { businessObject.di.isMarkerVisible = true; } + if (attrs._eventDefinitionType) { + var eventDefinitions = businessObject.get('eventDefinitions') || [], + newEventDefinition = this._moddle.create(attrs._eventDefinitionType); + + eventDefinitions.push(newEventDefinition); + businessObject.eventDefinitions = eventDefinitions; + } + size = this._getDefaultSize(businessObject); attrs = assign({