Dynamic context menu for an editpart [message #218723] |
Wed, 28 June 2006 19:03  |
Eclipse User |
|
|
|
Originally posted by: hlau.cs.tu-berlin.de
Hello!
Perhaps you can help me with this problem.
I am working on a GEF-Editor where Items (with EditParts) could be mapped
to another. Each Item can be mapped to many others, so each mapping should
be deleteable on its own. The mappings are part of the metamodel but have
no editparts themself.
In the context menu for each Item I would like to add actions like
unmap from 0
unmap from 1
...
unmap from n
, so I have to add new Actions each time the mapping changes or each time
the menu pops up.
Is their any chance to do this in GEF?
I would be glad for any answer!
Hannes Lau
|
|
|
Re: Dynamic context menu for an editpart [message #218738 is a reply to message #218723] |
Thu, 29 June 2006 06:18  |
Eclipse User |
|
|
|
I have achived similar functionality in this way:
I have a TimeContextMenuProvider that extends the ContextMenuProvider.
The contextMenuProvider is set in the configureGraphicalViewer()
and is something like:
TimeContextMenuProvider provider = new TimeContextMenuProvider(viewer,
this);
getGraphicalViewer().setContextMenu(provider);
This class has a method buildContextMenu().
This class also nows the currently selected edit part!
When the TimeContextMenuProvider builds the menu it does the following:
for (Iterator iter=editPart.getNewActionsList().listIterator();
iter.hasNext();) {
menu.add(iter.next());
}
This way the editPart returns the actions that make sence to be run on it.
So when you mapping change you update the editPart. When the
contextMenuProvider build the menu it will ask the editPart for the
actions. And because the editPart was updated it will return the new
action list.
Now how can the TimeContextMenuProvider now which is the currently
selected editPart? The selection mechanisum I have implemented in this
editor is rather complex(other issues are concerned) but you may start
with a look at EditPartListener, SelectionEditPolicy,
AbstractEditPartViewer::addSelectionChangedListener(ISelecti onChangedListener).
Hope this helps
kiril
Hannes Lau wrote:
>
> Hello!
>
> Perhaps you can help me with this problem.
>
> I am working on a GEF-Editor where Items (with EditParts) could be
> mapped to another. Each Item can be mapped to many others, so each
> mapping should be deleteable on its own. The mappings are part of the
> metamodel but have no editparts themself.
> In the context menu for each Item I would like to add actions like
>
> unmap from 0
> unmap from 1
> ...
> unmap from n
>
> , so I have to add new Actions each time the mapping changes or each
> time the menu pops up.
> Is their any chance to do this in GEF?
>
> I would be glad for any answer!
> Hannes Lau
>
|
|
|
Powered by
FUDForum. Page generated in 0.02126 seconds