fix(selection): select element replacements after move

Closes #335
This commit is contained in:
pedesen 2015-08-20 17:52:49 +02:00
parent fed7aefabe
commit 1cdce93f5b
5 changed files with 61 additions and 16 deletions

View File

@ -11,16 +11,16 @@ var isEventSubProcess = require('../../../util/DiUtil').isEventSubProcess;
/** /**
* Defines the behavior when a start event is moved * Defines the behavior when a start event is moved
*/ */
function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry) { function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry, selection) {
CommandInterceptor.call(this, eventBus); CommandInterceptor.call(this, eventBus);
this.postExecuted([ 'elements.move' ], function(event) { this.postExecuted([ 'elements.move' ], function(event) {
var target = event.context.newParent, var context = event.context,
target = context.newParent,
elements = []; elements = [];
forEach(event.context.closure.topLevel, function(topLevelElements) { forEach(context.closure.topLevel, function(topLevelElements) {
if (isEventSubProcess(topLevelElements)) { if (isEventSubProcess(topLevelElements)) {
elements = elements.concat(topLevelElements.children); elements = elements.concat(topLevelElements.children);
} else { } else {
@ -30,17 +30,27 @@ function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistr
var canReplace = bpmnRules.canReplace(elements, target); var canReplace = bpmnRules.canReplace(elements, target);
forEach(canReplace.replace, function(newElementData) { forEach(canReplace.replace, function(replacements) {
var newElement = { var newElement = {
type: newElementData.type type: replacements.newElementType
}; };
bpmnReplace.replaceElement(elementRegistry.get(newElementData.id), newElement); var oldElement = elementRegistry.get(replacements.oldElementId);
var idx = elements.indexOf(oldElement);
elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
}); });
if (canReplace.replace) {
selection.select(elements);
}
}); });
} }
MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry' ]; MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry', 'selection' ];
inherits(MoveStartEventBehavior, CommandInterceptor); inherits(MoveStartEventBehavior, CommandInterceptor);

View File

@ -431,8 +431,8 @@ function canReplace(elements, target) {
canDrop(element, target)) { canDrop(element, target)) {
canExecute.replace.push({ canExecute.replace.push({
id: element.id, oldElementId: element.id,
type: 'bpmn:StartEvent' newElementType: 'bpmn:StartEvent'
}); });
} }
} }

View File

@ -23,12 +23,12 @@ function BpmnReplacePreview(eventBus, elementRegistry, elementFactory, canvas, m
var replacements = context.canExecute.replace; var replacements = context.canExecute.replace;
forEach(replacements, function(newElementData) { forEach(replacements, function(replacement) {
var id = newElementData.id; var id = replacement.oldElementId;
var newElement = { var newElement = {
type: newElementData.type type: replacement.newElementType
}; };
// if the visual of the element is already replaced // if the visual of the element is already replaced

View File

@ -54,9 +54,12 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin
* *
* @param {djs.model.Base} element * @param {djs.model.Base} element
* @param {Object} target * @param {Object} target
* @param {Object} [hints]
* @return {djs.model.Base} the newly created element * @return {djs.model.Base} the newly created element
*/ */
function replaceElement(element, target) { function replaceElement(element, target, hints) {
hints = hints || {};
var type = target.type, var type = target.type,
oldBusinessObject = element.businessObject, oldBusinessObject = element.businessObject,
@ -103,7 +106,9 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin
newElement = replace.replaceElement(element, newElement); newElement = replace.replaceElement(element, newElement);
if (hints.select !== false) {
selection.select(newElement); selection.select(newElement);
}
return newElement; return newElement;
} }

View File

@ -11,7 +11,7 @@ var replacePreviewModule = require('../../../../../lib/features/replace-preview'
var is = require('../../../../../lib/util/ModelUtil').is, var is = require('../../../../../lib/util/ModelUtil').is,
Events = require('diagram-js/test/util/Events'); Events = require('diagram-js/test/util/Events');
describe.only('features/modeling - move start event behavior', function() { describe('features/modeling - move start event behavior', function() {
var testModules = [ replacePreviewModule, modelingModule, coreModule ]; var testModules = [ replacePreviewModule, modelingModule, coreModule ];
@ -60,6 +60,36 @@ describe.only('features/modeling - move start event behavior', function() {
// then // then
expect(selection.get()).to.include(replacement); expect(selection.get()).to.include(replacement);
expect(selection.get()).not.to.include(startEvent);
}));
it('should select all moved shapes after some of them got replaced',
inject(function(elementRegistry, canvas, dragging, move, selection) {
// given
var startEvent1 = elementRegistry.get('StartEvent_1'),
startEvent2 = elementRegistry.get('StartEvent_2'),
startEvent3 = elementRegistry.get('StartEvent_3'),
rootElement = canvas.getRootElement();
// when
selection.select([ startEvent1, startEvent2, startEvent3 ]);
moveShape(startEvent1, rootElement, { x: 140, y: 250 });
dragging.end();
var replacements = elementRegistry.filter(function(element) {
if(is(element, 'bpmn:StartEvent') && element.type !== 'label') {
return true;
}
});
// then
expect(selection.get()).to.include(replacements[0]);
expect(selection.get()).to.include(replacements[1]);
expect(selection.get()).to.include(replacements[2]);
})); }));