Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Create a connection in a context menu and few other things
Create a connection in a context menu and few other things [message #216686] Tue, 23 May 2006 15:56 Go to next message
Nicolas Rousseau is currently offline Nicolas Rousseau
Messages: 18
Registered: July 2009
Junior Member
Hello,

Since i started with gef, i did many things, but there's still a few that i
don't know how to do, and that i need to add.

I've checked in the newsgroup, but i've seen nothing about create a
connection from a context menu in an editor.
I've seen few things about a ConnectionCreationTool, but nothing about how
really use it, and not even sure it's what i need.
Is there an example? Or if someone could explain how to do.


I'd like also to show the feedback of the connections when i move one node,
is it possible ?
I've seen several people asking and there was no answer. It's not
implemented in the examples, so i guess it's just not possible now...

Thanks

Nicolas
Re: Create a connection in a context menu and few other things [message #216798 is a reply to message #216686] Wed, 24 May 2006 14:04 Go to previous message
Nicolas Rousseau is currently offline Nicolas Rousseau
Messages: 18
Registered: July 2009
Junior Member
I've finally found something from the newsgroup to create a new connection
from a context menu, and it seems to work, but not sure it's the best way to
do it.

here what i've done:
(this part is in the SelectionAction)
public void run() {
Point point = null;
point = nodePart.getFigure().getClientArea().getCenter();

Point p = point;
nodePart.getFigure().translateToAbsolute(p);

Canvas canvas = (Canvas)nodePart.getViewer().getControl();
Event event = new Event();
event.button = 1;
event.count = 0;
event.detail = 0;
event.end = 0;
event.height = 0;
event.keyCode = 0;
event.start = 0;
event.stateMask = 0;
event.time = 9516624; // any old time... doesn't matter
event.type = 3;
event.widget = canvas;
event.width = 0;
event.x = p.x + 3;
event.y = p.y + 3;


MyConnectionCreationTool myConnectTool=new
MyConnectionCreationTool(new CreationFactory() {
public Object getNewObject() { return null; }
public Object getObjectType() { return Connection.SOLID_CONNECTION; }
});
myConnectTool.performConnectionStartWith(nodePart);
nodePart.getViewer().getEditDomain().setActiveTool(myConnect Tool);

canvas.notifyListeners(3,event);

}


(and here the class of the connection tool)

public class MyConnectionCreationTool extends ConnectionCreationTool {
public MyConnectionCreationTool(CreationFactory factory) {
super(factory);
setUnloadWhenFinished(true);
}

public void performConnectionStartWith(EditPart sourcePart) {
setConnectionSource(sourcePart);
updateTargetRequest();
Command cmd = ((NodePart)sourcePart).getCommand(getTargetRequest());
setCurrentCommand(cmd);
setState(STATE_CONNECTION_STARTED);
}
}


"news.eclipse.org" <nicolasrousseau@hotmail.com> a
Previous Topic:EditPart controling a sub-figure ?
Next Topic:DND in a EditPartViewer
Goto Forum:
  


Current Time: Thu Sep 18 17:46:29 GMT 2014

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

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