From 6a3bdd32ea901ba0afd458f4a9acd5c185ff051a Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sat, 10 Oct 2015 01:28:04 +0200 Subject: [PATCH] chore(context-pad): make lane actions available Lanes are going to be modeled via the parents context-pad only. This commit * removes lanes from the palette * adds lane actions to the context-pad Related to #379 --- .../context-pad/ContextPadProvider.js | 92 +++++++++++++++---- lib/features/palette/PaletteProvider.js | 13 --- .../features/palette/PaletteProviderSpec.js | 2 +- 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/lib/features/context-pad/ContextPadProvider.js b/lib/features/context-pad/ContextPadProvider.js index c6a36a94..b094b297 100644 --- a/lib/features/context-pad/ContextPadProvider.js +++ b/lib/features/context-pad/ContextPadProvider.js @@ -4,6 +4,8 @@ var assign = require('lodash/object/assign'), forEach = require('lodash/collection/forEach'), is = require('../../util/ModelUtil').is, + isAny = require('../modeling/util/ModelingUtil').isAny, + getChildLanes = require('../modeling/util/LaneUtil').getChildLanes, isEventSubProcess = require('../../util/DiUtil').isEventSubProcess; @@ -37,6 +39,9 @@ ContextPadProvider.$inject = [ 'canvas' ]; +module.exports = ContextPadProvider; + + ContextPadProvider.prototype.getContextPadEntries = function(element) { var contextPad = this._contextPad, @@ -54,7 +59,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { return actions; } - var bpmnElement = element.businessObject; + var businessObject = element.businessObject; function startConnect(event, element, autoActivate) { connect.start(event, element, autoActivate); @@ -111,12 +116,69 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { }; } - if (is(bpmnElement, 'bpmn:FlowNode')) { + if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ])) { - if (!is(bpmnElement, 'bpmn:EndEvent') && - !is(bpmnElement, 'bpmn:EventBasedGateway') && - !isEventType(bpmnElement, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') && - !isEventSubProcess(bpmnElement)) { + var childLanes = getChildLanes(element); + + assign(actions, { + 'lane-insert-above': { + group: 'lane-insert-above', + className: 'icon-lane-insert-above', + title: 'Add Lane above', + action: { + click: function(event, element) { + modeling.addLane(element, 'top'); + } + } + } + }); + + if (childLanes.length < 2) { + assign(actions, { + 'lane-divide-two': { + group: 'lane-divide', + className: 'icon-lane-divide-two', + title: 'Divide into two Lanes', + action: { + click: function(event, element) { + modeling.splitLane(element, 2); + } + } + }, + 'lane-divide-three': { + group: 'lane-divide', + className: 'icon-lane-divide-three', + title: 'Divide into three Lanes', + action: { + click: function(event, element) { + modeling.splitLane(element, 3); + } + } + } + }); + } + + assign(actions, { + 'lane-insert-below': { + group: 'lane-insert-below', + className: 'icon-lane-insert-below', + title: 'Add Lane below', + action: { + click: function(event, element) { + modeling.addLane(element, 'bottom'); + } + } + } + }); + + } + + if (is(businessObject, 'bpmn:FlowNode')) { + + if (!is(businessObject, 'bpmn:EndEvent') && + !is(businessObject, 'bpmn:EventBasedGateway') && + !isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') && + !isEventSubProcess(businessObject)) { assign(actions, { 'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event-none'), @@ -127,7 +189,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { }); } - if (is(bpmnElement, 'bpmn:EventBasedGateway')) { + if (is(businessObject, 'bpmn:EventBasedGateway')) { assign(actions, { 'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'), @@ -147,9 +209,9 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { } } - if (is(bpmnElement, 'bpmn:FlowNode') || - (is(bpmnElement, 'bpmn:SequenceFlow') && (is(bpmnElement.sourceRef, 'bpmn:Activity') || - is(bpmnElement.sourceRef, 'bpmn:ExclusiveGateway') || is(bpmnElement.sourceRef, 'bpmn:InclusiveGateway')))) { + var replaceOptions = bpmnReplace.getReplaceOptions(element); + + if (replaceOptions.length) { // Replace menu entry assign(actions, { 'replace': { @@ -165,8 +227,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { }); } - if (is(bpmnElement, 'bpmn:FlowNode') || - is(bpmnElement, 'bpmn:InteractionNode')) { + if (isAny(businessObject, [ 'bpmn:FlowNode', 'bpmn:InteractionNode' ])) { assign(actions, { 'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation'), @@ -183,7 +244,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { }); } - if (is(bpmnElement, 'bpmn:DataObjectReference')) { + if (is(businessObject, 'bpmn:DataObjectReference')) { assign(actions, { 'connect': { group: 'connect', @@ -226,7 +287,4 @@ function isEventType(eventBo, type, definition) { }); return isType && isDefinition; -} - - -module.exports = ContextPadProvider; +} \ No newline at end of file diff --git a/lib/features/palette/PaletteProvider.js b/lib/features/palette/PaletteProvider.js index 2b61e302..fc8612a4 100644 --- a/lib/features/palette/PaletteProvider.js +++ b/lib/features/palette/PaletteProvider.js @@ -58,10 +58,6 @@ PaletteProvider.prototype.getPaletteEntries = function(element) { create.start(event, elementFactory.createParticipantShape(collapsed)); } - function createLane(event) { - create.start(event, elementFactory.createShape({ type: 'bpmn:Lane' })); - } - assign(actions, { 'lasso-tool': { group: 'tools', @@ -117,15 +113,6 @@ PaletteProvider.prototype.getPaletteEntries = function(element) { dragstart: createParticipant, click: createParticipant } - }, - 'create.lane': { - group: 'collaboration', - className: 'icon-lane', - title: 'Create Lane', - action: { - dragstart: createLane, - click: createLane - } } }); diff --git a/test/spec/features/palette/PaletteProviderSpec.js b/test/spec/features/palette/PaletteProviderSpec.js index fc7cb8d9..36bb5a61 100644 --- a/test/spec/features/palette/PaletteProviderSpec.js +++ b/test/spec/features/palette/PaletteProviderSpec.js @@ -27,7 +27,7 @@ describe('features/palette', function() { var entries = domQuery.all('.entry', paletteElement); // then - expect(entries.length).to.equal(11); + expect(entries.length).to.equal(10); })); });