Dispatching Event from Figure to EditPart [message #485946] |
Tue, 15 September 2009 15:41 |
Chris 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 #486435 is a reply to message #485946] |
Thu, 17 September 2009 15:44 |
Pascal G 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 |
Pascal G 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.*
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04105 seconds