Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Dispatching Event from Figure to EditPart
Dispatching Event from Figure to EditPart [message #485946] Tue, 15 September 2009 15:41 Go to next message
ChrisFriend
Messages: 12
Registered: September 2009
Location: Braunschweig
Junior Member
Hello all,

I want to react on a click on a label in a figure and pass it to the corresponding editpart in order to create a request and change the model.

What is the best practice to do so? How would I dispatch the mouseClick event to the editpart?

Thanks in advance
Re: Dispatching Event from Figure to EditPart [message #486365 is a reply to message #485946] Thu, 17 September 2009 12:55 Go to previous messageGo to next message
ChrisFriend
Messages: 12
Registered: September 2009
Location: Braunschweig
Junior Member
I did not solve the problem yet tho I tried two workarounds to react on the label click inside a figure:

1) install a SelectionEditPolicy on the EditPart - add a MouseListener to the figure's label which will toggle a boolean value - from the SelectionEditPolicy's ShowSelection methode read that boolean value of the figure and execute a command

2) Add the MouseListener as in 1) - also add a ProperyChangeListener to the figure - firePropertyChange when the label is clicked - handle that Event in the corresponding EditPart

I prefer the 2. workaround but neither is very clean and follows the philosophy - "models should only be modified by commands"

So if someone has a nice and clean solution please feel free to answer!
Re: Dispatching Event from Figure to EditPart [message #486435 is a reply to message #485946] Thu, 17 September 2009 15:44 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
ngotme@gmx.de wrote:
> Hello all,
>
> I want to react on a click on a label in a figure and pass it to the
> corresponding editpart in order to create a request and change the model.
> What is the best practice to do so? How would I dispatch the mouseClick
> event to the editpart?
> Thanks in advance

I'm guessing you want some custom behavior on a single click of the
figure, so I'll start from there. First of all, you need to have a
selection tool entry in your palette. You need to modify the tool it
gives you for your own SelectionTool. The default one does not ask the
edit part for a command, and that's what we want here. So, subclass
SelectionTool, and extend the #mouseDown() method as follow:
@Override
public void mouseDown(MouseEvent e, EditPartViewer viewer)
{
// Let the superclass treat it before you, so its state
updates.
super.mouseDown(e, viewer);
Command command = getCommand();
getCommandStack().execute(command);
}
note: you may which to extend something else, such has
#handleButtonUp(), or #mouseUp(). The #mouseDown() approach was only for
quick testing. Also, I didn't do any error checking which you may or
may not need.

Then, you need to tell the selection tool entry which tool to use. There
is two way for that:
1- pass your own class to the #setToolClass() method (I had no luck with
this tho)
2- subclass SelectionToolEntry and override #createTool as follow:
@Override
public Tool createTool()
{
Tool tool = new Test();
tool.setProperties(getToolProperties());
return tool;
}

Then, all you need is an edit policy on your edit part which understand
the REQ_SELECTION and gives you the command.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Dispatching Event from Figure to EditPart [message #486437 is a reply to message #486435] Thu, 17 September 2009 15:52 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
> ngotme@gmx.de wrote:
>> Hello all,
>>
>> I want to react on a click on a label in a figure and pass it to the
>> corresponding editpart in order to create a request and change the model.
>> What is the best practice to do so? How would I dispatch the
>> mouseClick event to the editpart?
>> Thanks in advance
>
> I'm guessing you want some custom behavior on a single click of the
> figure, so I'll start from there. First of all, you need to have a
> selection tool entry in your palette. You need to modify the tool it
> gives you for your own SelectionTool. The default one does not ask the
> edit part for a command, and that's what we want here. So, subclass
> SelectionTool, and extend the #mouseDown() method as follow:
> @Override
> public void mouseDown(MouseEvent e, EditPartViewer viewer)
> {
> // Let the superclass treat it before you, so its state
> updates.
> super.mouseDown(e, viewer);
> Command command = getCommand();
> getCommandStack().execute(command);
> }
> note: you may which to extend something else, such has
> #handleButtonUp(), or #mouseUp(). The #mouseDown() approach was only for
> quick testing. Also, I didn't do any error checking which you may or
> may not need.
>
> Then, you need to tell the selection tool entry which tool to use. There
> is two way for that:
> 1- pass your own class to the #setToolClass() method (I had no luck with
> this tho)
> 2- subclass SelectionToolEntry and override #createTool as follow:
> @Override
> public Tool createTool()
> {
> Tool tool = new Test();
> tool.setProperties(getToolProperties());
> return tool;
> }
>
> Then, all you need is an edit policy on your edit part which understand
> the REQ_SELECTION and gives you the command.
>
> Hope this helps.

wow, major typo. I meant:
note: you may wish to extend ...

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Dispatching Event from Figure to EditPart [message #486444 is a reply to message #486437] Thu, 17 September 2009 16:20 Go to previous messageGo to next message
ChrisFriend
Messages: 12
Registered: September 2009
Location: Braunschweig
Junior Member
Thanks for the solution Pascal! Smile

That looks like a clean solution to my problem.

I will get back with my results in a week from now.
Re: Dispatching Event from Figure to EditPart [message #486453 is a reply to message #486444] Thu, 17 September 2009 16:48 Go to previous message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
ngotme@gmx.de wrote:
> Thanks for the solution Pascal! :)
> That looks like a clean solution to my problem.
> I will get back with my results in a week from now.

No problem.

The problem with #setToolClass() is still bothering me though... I think
it might be caused by not declaring Gef as an Eclipse-registerBuddy in
the manifest.mf (since the default implementation of #createTool() use
reflection to create the tool), but I'm not sure and I'm not an expert
in those thing. Could anyone confirm/test this??

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Previous Topic:Zest: Bug in Graph setSelection() ?
Next Topic:Drawing JFreeChart chart in Draw2D figure
Goto Forum:
  


Current Time: Fri Mar 29 09:51:48 GMT 2024

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

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

Back to the top