2

I want to delete a connection between two objects in draw2d.js. I am trying to find direct method that delete a connection but i did not found it. So please tell me if any way or is there any method available that delete or disconnect connection. Thanks In advance!

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309

2 Answers2

2

Without CommandStack support:

canvas.remove(connection);

With CommandStack Support (undo/redo):

var cmd =  new draw2d.command.CommandDelete(connection);
canvas.getCommandStack().execute(cmd);
Gurnard
  • 1,773
  • 22
  • 43
0
 draw2d.ContextmenuConnection.prototype.getContextMenu = function() {    
     var menu = new draw2d.Menu();
     menu.appendMenuItem(new draw2d.MenuItem("Disconnect", null, function() {
         //draw2d.Connection.workflow.removeFigure(draw2d.Connection.prototype);
         var cmd =  new draw2d.CommandDelete(**draw2d.Connection**);
         draw2d.Connection.prototype.workflow.getCommandStack().excute(cmd);
     }));

 };

you must handover an object to the constructor of the CommandDelete and NOT draw2d.Connection

see below:

 draw2d.ContextmenuConnection.prototype.getContextMenu = function() {    
     var menu = new draw2d.Menu();
     var oThis = this;
     menu.appendMenuItem(new draw2d.MenuItem("Disconnect", null, function() {
         //draw2d.Connection.workflow.removeFigure(draw2d.Connection.prototype);
         var cmd =  new draw2d.CommandDelete(oThis);
         draw2d.Connection.prototype.workflow.getCommandStack().excute(cmd);
     }));

 };