Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsDispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/485946/#msg_485946
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]]>Chris2009-09-15T15:41:51-00:00Re: Dispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/486365/#msg_486365
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!]]>Chris2009-09-17T12:55:25-00:00Re: Dispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/486435/#msg_486435
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.
*Because performance matters.*]]>Pascal G2009-09-17T15:44:16-00:00Re: Dispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/486437/#msg_486437
> 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 ...
*Because performance matters.*]]>Pascal G2009-09-17T15:52:43-00:00Re: Dispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/486444/#msg_486444
That looks like a clean solution to my problem.
I will get back with my results in a week from now.]]>Chris2009-09-17T16:20:41-00:00Re: Dispatching Event from Figure to EditPart
https://www.eclipse.org/forums/index.php/mv/msg/154276/486453/#msg_486453
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??