delete Node and Connections [message #208676] |
Wed, 08 February 2006 02:24 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 );
}
|
|
|
Powered by
FUDForum. Page generated in 0.20629 seconds