Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » delete Node and Connections
delete Node and Connections [message #208676] Wed, 08 February 2006 02:24 Go to next message
Eclipse UserFriend
Originally posted by: null.sina.com

I want delete a Node in the GraphicalEditorWithPalette, how to automatic
delete the Connections, which connect the node?
thanks all
Re: delete Node and Connections [message #208743 is a reply to message #208676] Wed, 08 February 2006 11:07 Go to previous message
Eclipse UserFriend
Originally posted by: guen.my-lounge.net

richard schrieb:
> I want delete a Node in the GraphicalEditorWithPalette, how to automatic
> delete the Connections, which connect the node?
> thanks all
>
> From - Wed
Hi,

one way is to let the DeleteCommand for the node delete the connections.
Every node keeps his connections so that the command can get all
connections from the node. A connection keeps it source and target and
the two methods connect() and disconnect(). If you delete the node, you
just have to call the disconnect() method of the connection.

code snippet:

public class CommandClassDelete extends Command {

private ClassDiagramViewModel classDiagramViewModel;
private ClassViewModel classViewModel;
private List<ConnectionViewModel> connectionsIncoming;
private List<ConnectionViewModel> connectionsOutgoing;

public CommandClassDelete( ClassDiagramViewModel classDiagramViewModel,
ClassViewModel classViewModel ) {
this.classDiagramViewModel = classDiagramViewModel;
this.classViewModel = classViewModel;
}


public void execute() {
this.connectionsIncoming = this.classViewModel.getConnectionsIncoming();
this.connectionsOutgoing = this.classViewModel.getConnectionsOutgoing();
this.redo();
}

public void redo() {
for ( int i = 0; i < this.connectionsIncoming.size(); i++ )
this.connectionsIncoming.get(i).disconnect();

for ( int i = 0; i < this.connectionsOutgoing.size(); i++ )
this.connectionsOutgoing.get(i).disconnect();

this.classDiagramViewModel.removeClass( this.classViewModel );
}

public void undo() {
for ( int i = 0; i < this.connectionsIncoming.size(); i++ )
this.connectionsIncoming.get(i).connect();

for ( int i = 0; i < this.connectionsOutgoing.size(); i++ )
this.connectionsOutgoing.get(i).connect();

this.classDiagramViewModel.addClass( this.classViewModel );
}
}


public class ConnectionViewModel ...
public void disconnect() {
if ( this.source != null )
this.source.removeConnectionOutgoing( this );

if ( this.target != null )
this.target.removeConnectionIncoming( this );
}
Previous Topic:Scaling & Scrolling
Next Topic:disable saving for GEF
Goto Forum:
  


Current Time: Sun Aug 11 18:31:50 GMT 2024

Powered by FUDForum. Page generated in 0.03411 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top