Skip to main content



      Home
Home » Eclipse Projects » GEF » Simulate initial connection using ConnectionCreationTool.
Simulate initial connection using ConnectionCreationTool. [message #89932] Wed, 06 August 2003 18:53 Go to next message
Eclipse UserFriend
Originally posted by: djrobd.aol.com

Hi,

I am trying to simulate the initial connection using
ConnectionCreationTool. The way I would like it to work is that if you
right click on a figure a popup menu appears and then once you select one
of the menu items the connection tool is activated and the initial
connection is created. I have the popup menu and activation of the tool
working fine, but I can't simulate the initial connection. Any ideas on
how to do this?

Thanks,

Roberto DeGennaro
Re: Simulate initial connection using ConnectionCreationTool. [message #89961 is a reply to message #89932] Thu, 07 August 2003 10:04 Go to previous messageGo to next message
Eclipse UserFriend
....here's how I did it...... and Randy can jump up and down and say it's not
the right way...... but it works :-)
If you have the context menu going then you must have a menu action.... mine
is called ContextMenuConnectionAction. Here is my run() method.....
============================================================ ================
=========
/**
* Set the connection tool as the currently active tool and then create and
dispatch
* a mouse down event over the selected edit part
*/
public void run() {
/**
* Create a mouse down event that thinks it is over the blob and dispatch
it.
* This is a bit of a fudge to mimic what the user ought to do.
*/
IStrutsGraphicalNodeEditPart nodeEditPart =
((IStrutsGraphicalNodeEditPart)getSelectedObjects().get(0));
StrutsGraphicalNodePart modelPart =
((StrutsGraphicalNodePart)nodeEditPart.getModelPart());
Point point = null;
if (modelPart.getPartType() == Wire.STRUTS_GRAPHICAL_ATTRIB_ID) {
point =
((StrutsPolylineConnection)nodeEditPart.getFigure()).getPoin ts().getMidpoint
();
} else {
point = modelPart.getLocation();
}
Point p = new Point(point.x, point.y);
nodeEditPart.getFigure().translateToAbsolute(p);
Canvas canvas = (Canvas)
((StrutsGraphicalEditor)getEditorPart()).getPrimaryViewer(). 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;
/**
* Set the connection tool to be the current tool
*/

((DefaultEditDomain)((StrutsGraphicalEditor)getEditorPart()) .getEditDomain()
).setActiveTool(new StrutsGraphicalConnectionTool());
/**
* Dispatch the mouse down event
*/
canvas.notifyListeners(3,event);
}
============================================================ ================
=========

You may have implement a different way of determining a point that targets
the blob on the FFS.

Guy





"Roberto DeGennaro" <djrobd@aol.com> wrote in message
news:bgs0tk$652$1@eclipse.org...
> Hi,
>
> I am trying to simulate the initial connection using
> ConnectionCreationTool. The way I would like it to work is that if you
> right click on a figure a popup menu appears and then once you select one
> of the menu items the connection tool is activated and the initial
> connection is created. I have the popup menu and activation of the tool
> working fine, but I can't simulate the initial connection. Any ideas on
> how to do this?
>
> Thanks,
>
> Roberto DeGennaro
>
Re: Simulate initial connection using ConnectionCreationTool. [message #89976 is a reply to message #89961] Thu, 07 August 2003 10:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

That's one way :-).

Another way would be to subclass ConnectionCreationTool, and create some
method called:
performConnectionStartWith(EditPart sourcePart);

That method would:
1) update the Request
2) Use the request to query the sourcePart for its connection start command
3) Set the current command field on the tool
4) set the tool in STATE_CONNECTION_STARTED.

I think this will work.

If this works, you might submit such code to us, and we could merge it with
the existing code.

"Guy Slade" <gslade@us.ibm.com> wrote in message
news:bgtm8g$pa2$1@eclipse.org...
> ...here's how I did it...... and Randy can jump up and down and say it's
not
> the right way...... but it works :-)
> If you have the context menu going then you must have a menu action....
mine
> is called ContextMenuConnectionAction. Here is my run() method.....
>
============================================================ ================
> =========
> /**
> * Set the connection tool as the currently active tool and then create and
> dispatch
> * a mouse down event over the selected edit part
> */
> public void run() {
> /**
> * Create a mouse down event that thinks it is over the blob and
dispatch
> it.
> * This is a bit of a fudge to mimic what the user ought to do.
> */
> IStrutsGraphicalNodeEditPart nodeEditPart =
> ((IStrutsGraphicalNodeEditPart)getSelectedObjects().get(0));
> StrutsGraphicalNodePart modelPart =
> ((StrutsGraphicalNodePart)nodeEditPart.getModelPart());
> Point point = null;
> if (modelPart.getPartType() == Wire.STRUTS_GRAPHICAL_ATTRIB_ID) {
> point =
>
((StrutsPolylineConnection)nodeEditPart.getFigure()).getPoin ts().getMidpoint
> ();
> } else {
> point = modelPart.getLocation();
> }
> Point p = new Point(point.x, point.y);
> nodeEditPart.getFigure().translateToAbsolute(p);
> Canvas canvas = (Canvas)
> ((StrutsGraphicalEditor)getEditorPart()).getPrimaryViewer(). 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;
> /**
> * Set the connection tool to be the current tool
> */
>
>
((DefaultEditDomain)((StrutsGraphicalEditor)getEditorPart()) .getEditDomain()
> ).setActiveTool(new StrutsGraphicalConnectionTool());
> /**
> * Dispatch the mouse down event
> */
> canvas.notifyListeners(3,event);
> }
>
============================================================ ================
> =========
>
> You may have implement a different way of determining a point that targets
> the blob on the FFS.
>
> Guy
>
>
>
>
>
> "Roberto DeGennaro" <djrobd@aol.com> wrote in message
> news:bgs0tk$652$1@eclipse.org...
> > Hi,
> >
> > I am trying to simulate the initial connection using
> > ConnectionCreationTool. The way I would like it to work is that if you
> > right click on a figure a popup menu appears and then once you select
one
> > of the menu items the connection tool is activated and the initial
> > connection is created. I have the popup menu and activation of the tool
> > working fine, but I can't simulate the initial connection. Any ideas on
> > how to do this?
> >
> > Thanks,
> >
> > Roberto DeGennaro
> >
>
>
Re: Simulate initial connection using ConnectionCreationTool. [message #90034 is a reply to message #89976] Thu, 07 August 2003 12:23 Go to previous message
Eclipse UserFriend
Originally posted by: djrobd.aol.com

Guy I tried it your way and it works great...
Randy I will try it your way when I have time and if I get it to work I
will submit the code...

Thank you both,

Roberto
Previous Topic:CDAG layout algorithm
Next Topic:Scaling to viewport?
Goto Forum:
  


Current Time: Tue Jul 22 00:56:22 EDT 2025

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

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

Back to the top