Пример #1
0
  function parseMember(node, context) {
    var parent = stack.peek(),
        value = parseElement(node, context),
        type = node.attributes['xmi:type'],
        id = value.id;

    var byType = elementsByType[type];

    if (!byType) {
      console.error('[modelgen] unknown type', type);
    }

    // normalize superClass: 'Foo Bar' to superClass: [ 'Foo', 'Bar' ]
    if (value.superClass) {
      value.superClass = map(value.superClass.split(/\s/), replaceNs);
    }

    byType.push(value);
    elementsById[id] = value;

    if (!parent) {
      console.error('[modelgen] no parent', node);
    }

    var collection = collectionMap[type];

    parent[collection] = (parent[collection] || []);
    parent[collection].push(value);

    return value;
  }
Пример #2
0
BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
  var self = this;

  return map(waypoints, function(pos) {
    return self.createDiWaypoint(pos);
  });
};
Пример #3
0
  function createModel(packageNames) {

    var packages = map(packageNames, function(f) {
      var pkg = cache[f];
      var file = base + f + '.json';

      if (!pkg) {
        try {
          pkg = cache[f] = JSON.parse(readFile(base + f + '.json'));
        } catch (e) {
          throw new Error('[Helper] failed to parse <' + file + '> as JSON: ' +  e.message);
        }
      }

      return pkg;
    });

    return new Moddle(packages);
  }
Пример #4
0
  return getBpmnJS().invoke(function(canvas, elementRegistry, modeling) {

    function getElement(id) {

      var element = elementRegistry.get(id);

      expect(element).to.exist;

      return element;
    }

    var elements = map(elementIds, getElement),
        target;

    if (targetId === 'Root') {
      target = canvas.getRootElement();
    } else {
      target = targetId && getElement(targetId);
    }

    var hints = isAttach ? { attach: true } : {};

    return modeling.moveElements(elements, delta, target, hints);
  });
Пример #5
0
CopyPaste.prototype.createTree = function(elements) {
  var rules = this._rules,
      self = this;

  var tree = {},
      includedElements = [],
      _elements;

  var topLevel = getTopLevel(elements);

  tree.allShapes = [];

  function canCopy(collection, element) {
    return rules.allowed('element.copy', {
      collection: collection,
      element: element
    });
  }

  function includeElement(data) {
    var idx = findIndex(includedElements, matchPattern({ element: data.element })),
        element;

    if (idx !== -1) {
      element = includedElements[idx];
    } else {
      return includedElements.push(data);
    }

    // makes sure that it has the correct depth
    if (element.depth < data.depth) {
      includedElements.splice(idx, 1);

      includedElements.push(data);
    }
  }


  eachElement(topLevel, function(element, i, depth) {
    var nestedChildren = element.children;

    // don't add labels directly
    if (element.labelTarget) {
      return;
    }

    function getNested(lists) {
      forEach(lists, function(list) {
        if (list && list.length) {

          forEach(list, function(elem) {

            forEach(elem.labels, function(label) {
              includeElement({
                element: label,
                depth: depth
              });
            });

            includeElement({
              element: elem,
              depth: depth
            });
          });
        }
      });
    }

    // fetch element's labels
    forEach(element.labels, function(label) {

      includeElement({
        element: label,
        depth: depth
      });
    });

    getNested([ element.attachers, element.incoming, element.outgoing ]);

    includeElement({
      element: element,
      depth: depth
    });

    if (nestedChildren) {
      return nestedChildren;
    }
  });

  includedElements = map(includedElements, function(data) {
    // this is where other registered descriptors hook in
    return self._executeDescriptors(data);
  });

  // order the elements to check if the ones dependant on others (by relationship)
  // can be copied. f.ex: label needs it's label target
  includedElements = sortBy(includedElements, function(data) {
    return data.descriptor.priority;
  });

  _elements = map(includedElements, function(data) {
    return data.element;
  });

  forEach(includedElements, function(data) {
    var depth = data.depth;

    if (!self.hasRelations(tree.allShapes, data.element)) {
      return;
    }

    if (!canCopy(_elements, data.element)) {
      return;
    }

    tree.allShapes.push(data.element);

    // create depth branches
    if (!tree[depth]) {
      tree[depth] = [];
    }

    tree[depth].push(data.descriptor);
  });

  return tree;
};