| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- export default function CreateConnectionHandler(canvas, layouter) {
- this._canvas = canvas;
- this._layouter = layouter;
- }
- CreateConnectionHandler.$inject = [ 'canvas', 'layouter' ];
- // api //////////////////////
- /**
- * Appends a shape to a target shape
- *
- * @param {Object} context
- * @param {djs.element.Base} context.source the source object
- * @param {djs.element.Base} context.target the parent object
- * @param {Point} context.position position of the new element
- */
- CreateConnectionHandler.prototype.execute = function(context) {
- var connection = context.connection,
- source = context.source,
- target = context.target,
- parent = context.parent,
- parentIndex = context.parentIndex,
- hints = context.hints;
- if (!source || !target) {
- throw new Error('source and target required');
- }
- if (!parent) {
- throw new Error('parent required');
- }
- connection.source = source;
- connection.target = target;
- if (!connection.waypoints) {
- connection.waypoints = this._layouter.layoutConnection(connection, hints);
- }
- // add connection
- this._canvas.addConnection(connection, parent, parentIndex);
- return connection;
- };
- CreateConnectionHandler.prototype.revert = function(context) {
- var connection = context.connection;
- this._canvas.removeConnection(connection);
- connection.source = null;
- connection.target = null;
- return connection;
- };
|