[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.tools.gef] Re: Dispatching Event from Figure to EditPart
|
ngotme@xxxxxx 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.*