How to use the diagram-js/lib/util/Collections.add function in diagram-js

To help you get started, we’ve selected a few diagram-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpmn-io / bpmn-js / lib / features / modeling / cmd / UpdateCanvasRootHandler.js View on Github external
UpdateCanvasRootHandler.prototype.execute = function(context) {

  var canvas = this._canvas;

  var newRoot = context.newRoot,
      newRootBusinessObject = newRoot.businessObject,
      oldRoot = canvas.getRootElement(),
      oldRootBusinessObject = oldRoot.businessObject,
      bpmnDefinitions = oldRootBusinessObject.$parent,
      diPlane = oldRootBusinessObject.di;

  // (1) replace process old <> new root
  canvas.setRootElement(newRoot, true);

  // (2) update root elements
  collectionAdd(bpmnDefinitions.rootElements, newRootBusinessObject);
  newRootBusinessObject.$parent = bpmnDefinitions;

  collectionRemove(bpmnDefinitions.rootElements, oldRootBusinessObject);
  oldRootBusinessObject.$parent = null;

  // (3) wire di
  oldRootBusinessObject.di = null;

  diPlane.bpmnElement = newRootBusinessObject;
  newRootBusinessObject.di = diPlane;

  context.oldRoot = oldRoot;

  // TODO(nikku): return changed elements?
  // return [ newRoot, oldRoot ];
};
github WPS / domain-story-modeler / app / domain-story-modeler / modeler / DomainStoryUpdater.js View on Github external
let context = e.context,
        shape = context.shape,
        businessObject = shape.businessObject;

    if (!isDomainStory(shape)) {
      return;
    }

    let parent = shape.parent;
    let customElements = bpmnjs._customElements;

    // make sure element is added / removed from bpmnjs.customElements
    if (!parent) {
      collectionRemove(customElements, businessObject);
    } else {
      collectionAdd(customElements, businessObject);
    }

    // save custom element position
    assign(businessObject, pick(shape, ['x', 'y']));

    // save custom element size if resizable
    if (isDomainStoryGroup(shape)) {
      assign(businessObject, pick(shape, ['height', 'width']));

      // rework the child-parent relations if a group was moved, such that all Objects that are visually in the group are also associated with it
      // since we do not have access to the standard-canvas object here, we cannot use the function correctGroupChildren() from DSLabelUtil
      if (parent != null) {
        reworkGroupElements(parent, shape);
      }
    }
github bpmn-io / bpmn-js / lib / features / modeling / BpmnUpdater.js View on Github external
// make sure the participants process is properly attached / detached
    // from the XML document

    var process = businessObject.processRef,
        definitions;

    if (process) {
      definitions = getDefinitions(businessObject.$parent || newParent);

      if (businessObject.$parent) {
        collectionRemove(definitions.get('rootElements'), process);
        process.$parent = null;
      }

      if (newParent) {
        collectionAdd(definitions.get('rootElements'), process);
        process.$parent = definitions;
      }
    }
  } else

  if (is(businessObject, 'bpmn:DataOutputAssociation')) {
    containment = 'dataOutputAssociations';
  } else

  if (is(businessObject, 'bpmn:DataInputAssociation')) {
    containment = 'dataInputAssociations';
  }

  if (!containment) {
    throw new Error(translate(
      'no parent for {element} in {parent}',
github bpmn-io / bpmn-js / lib / features / modeling / cmd / UpdateFlowNodeRefsHandler.js View on Github external
update.add.forEach(function(newLane) {
      collectionAdd(lanes, newLane);
      collectionAdd(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
    });
  });
github bpmn-io / bpmn-js / lib / features / modeling / cmd / UpdateFlowNodeRefsHandler.js View on Github external
update.remove.forEach(function(oldLane) {
      collectionAdd(lanes, oldLane);
      collectionAdd(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
    });
  });
github bpmn-io / bpmn-js / lib / features / modeling / behavior / DataInputAssociationBehavior.js View on Github external
function getTargetRef(element, create) {

    var properties = element.get('properties');

    var targetRefProp = find(properties, function(p) {
      return p.name === TARGET_REF_PLACEHOLDER_NAME;
    });

    if (!targetRefProp && create) {
      targetRefProp = bpmnFactory.create('bpmn:Property', {
        name: TARGET_REF_PLACEHOLDER_NAME
      });

      collectionAdd(properties, targetRefProp);
    }

    return targetRefProp;
  }
github bpmn-io / bpmn-js / lib / features / modeling / behavior / GroupBehavior.js View on Github external
this.reverted('shape.delete', function(event) {

    var context = event.context,
        shape = context.shape;

    if (is(shape, 'bpmn:Group')) {

      var businessObject = getBusinessObject(shape),
          categoryValueRef = businessObject.categoryValueRef,
          definitions = getDefinitions(),
          category = categoryValueRef ? categoryValueRef.$parent : null;

      collectionAdd(category.get('categoryValue'), categoryValueRef);
      collectionAdd(definitions.get('rootElements'), category);
    }
  });
github bpmn-io / bpmn-js / lib / features / modeling / cmd / UpdateFlowNodeRefsHandler.js View on Github external
update.add.forEach(function(newLane) {
      collectionAdd(lanes, newLane);
      collectionAdd(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
    });
  });
github bpmn-io / bpmn-js / lib / features / modeling / behavior / GroupBehavior.js View on Github external
this.reverted('shape.delete', function(event) {

    var context = event.context,
        shape = context.shape;

    if (is(shape, 'bpmn:Group')) {

      var businessObject = getBusinessObject(shape),
          categoryValueRef = businessObject.categoryValueRef,
          definitions = getDefinitions(),
          category = categoryValueRef ? categoryValueRef.$parent : null;

      collectionAdd(category.get('categoryValue'), categoryValueRef);
      collectionAdd(definitions.get('rootElements'), category);
    }
  });