From 57f516ef32371a9d287e32ecfd4dae955f924857 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Wed, 22 May 2019 08:39:05 +0200 Subject: [PATCH] chore(group-behavior): move category creation to util --- .../modeling/behavior/GroupBehavior.js | 16 ++++------ .../modeling/behavior/util/CategoryUtil.js | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 lib/features/modeling/behavior/util/CategoryUtil.js diff --git a/lib/features/modeling/behavior/GroupBehavior.js b/lib/features/modeling/behavior/GroupBehavior.js index 4e5bfb5d..193beffe 100644 --- a/lib/features/modeling/behavior/GroupBehavior.js +++ b/lib/features/modeling/behavior/GroupBehavior.js @@ -12,6 +12,9 @@ import { is } from '../../../util/ModelUtil'; +import { + createCategoryValue +} from './util/CategoryUtil'; /** * BPMN specific Group behavior @@ -146,17 +149,8 @@ export default function GroupBehavior(eventBus, bpmnFactory, canvas, elementRegi if (is(businessObject, 'bpmn:Group') && !businessObject.categoryValueRef) { - var definitions = getDefinitions(); - - var categoryValue = bpmnFactory.create('bpmn:CategoryValue'), - category = bpmnFactory.create('bpmn:Category', { - categoryValue: [ categoryValue ] - }); - - // add to correct place - collectionAdd(definitions.get('rootElements'), category); - getBusinessObject(category).$parent = definitions; - getBusinessObject(categoryValue).$parent = category; + var definitions = getDefinitions(), + categoryValue = createCategoryValue(definitions, bpmnFactory); // link the reference to the Group businessObject.categoryValueRef = categoryValue; diff --git a/lib/features/modeling/behavior/util/CategoryUtil.js b/lib/features/modeling/behavior/util/CategoryUtil.js new file mode 100644 index 00000000..4d0b7c09 --- /dev/null +++ b/lib/features/modeling/behavior/util/CategoryUtil.js @@ -0,0 +1,30 @@ +import { + add as collectionAdd +} from 'diagram-js/lib/util/Collections'; + +import { + getBusinessObject +} from '../../../../util/ModelUtil'; + +/** + * Creates a new bpmn:CategoryValue inside a new bpmn:Category + * + * @param {ModdleElement} definitions + * @param {BpmnFactory} bpmnFactory + * + * @return {ModdleElement} categoryValue. + */ +export function createCategoryValue(definitions, bpmnFactory) { + var categoryValue = bpmnFactory.create('bpmn:CategoryValue'), + category = bpmnFactory.create('bpmn:Category', { + categoryValue: [ categoryValue ] + }); + + // add to correct place + collectionAdd(definitions.get('rootElements'), category); + getBusinessObject(category).$parent = definitions; + getBusinessObject(categoryValue).$parent = category; + + return categoryValue; + +} \ No newline at end of file