Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to populate context submenu with entries based on the same action?
How to populate context submenu with entries based on the same action? [message #194131] Tue, 30 August 2005 20:05 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.hurrelmann.de

Hey guys!

My plan is to add new objects via the context menu. The context menu
should show in a submenu all existing objects of a certain type as a
selectable list. To my understanding I need an action for each entry.
But the number of entries does not become clear until runtime. How do I
populate that list using a single action which is responsible for
creating the new objects? The following code is of course not
functional, but should clarify the issue:

public void buildContextMenu(IMenuManager menu) {
GEFActionConstants.addStandardActionGroups(menu);

IAction action;
HashMap map;

MenuManager submenu = new MenuManager("Add object");
map = XYZ.getMyObjects(); // get existing objects
Iterator it = map.keySet().iterator();

while (it.hasNext()) {
MyAction myAction =
(MyAction) getActionRegistry().getAction(MyAction.MYACTION);
MyObject o = map.get(it.next());
myAction.setText(o.getName());
myAction.setObject(o); // action needs reference
if (myAction.isEnabled())
submenu.add(myAction);
}

if (!submenu.isEmpty())
menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
}

Thanks for your help!

Cheers, Dennis
Re: How to populate context submenu with entries based on the same action? [message #194255 is a reply to message #194131] Wed, 31 August 2005 18:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pbeagan.yahoo_dontspamme_.com

That approach should work in your ContextMenuProvider, but you will also
need to dynamically add/remove those Actions in the ActionRegistry.


Dennis Hurrelmann wrote:

> Hey guys!
>
> My plan is to add new objects via the context menu. The context menu
> should show in a submenu all existing objects of a certain type as a
> selectable list. To my understanding I need an action for each entry.
> But the number of entries does not become clear until runtime. How do I
> populate that list using a single action which is responsible for
> creating the new objects? The following code is of course not
> functional, but should clarify the issue:
>
> public void buildContextMenu(IMenuManager menu) {
> GEFActionConstants.addStandardActionGroups(menu);
>
> IAction action;
> HashMap map;
>
> MenuManager submenu = new MenuManager("Add object");
> map = XYZ.getMyObjects(); // get existing objects
> Iterator it = map.keySet().iterator();
>
> while (it.hasNext()) {
> MyAction myAction =
> (MyAction) getActionRegistry().getAction(MyAction.MYACTION);
> MyObject o = map.get(it.next());
> myAction.setText(o.getName());
> myAction.setObject(o); // action needs reference
> if (myAction.isEnabled())
> submenu.add(myAction);
> }
>
> if (!submenu.isEmpty())
> menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
> }
>
> Thanks for your help!
>
> Cheers, Dennis
Re: How to populate context submenu with entries based on the same action? [message #194269 is a reply to message #194255] Wed, 31 August 2005 20:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.hurrelmann.de

How do I dynamically register actions? As far as I know the
ActionRegistry is filled only once. But at this point of time the amount
of actions needed isn't clear.
I do not really want to use a popup menu...

Regards, Dennis


Patrick schrieb am 31.08.2005 20:49:

> That approach should work in your ContextMenuProvider, but you will also
> need to dynamically add/remove those Actions in the ActionRegistry.
>
>
> Dennis Hurrelmann wrote:
>
>
>>Hey guys!
>>
>>My plan is to add new objects via the context menu. The context menu
>>should show in a submenu all existing objects of a certain type as a
>>selectable list. To my understanding I need an action for each entry.
>>But the number of entries does not become clear until runtime. How do I
>>populate that list using a single action which is responsible for
>>creating the new objects? The following code is of course not
>>functional, but should clarify the issue:
>>
>>public void buildContextMenu(IMenuManager menu) {
>> GEFActionConstants.addStandardActionGroups(menu);
>>
>> IAction action;
>> HashMap map;
>>
>> MenuManager submenu = new MenuManager("Add object");
>> map = XYZ.getMyObjects(); // get existing objects
>> Iterator it = map.keySet().iterator();
>>
>> while (it.hasNext()) {
>> MyAction myAction =
>> (MyAction) getActionRegistry().getAction(MyAction.MYACTION);
>> MyObject o = map.get(it.next());
>> myAction.setText(o.getName());
>> myAction.setObject(o); // action needs reference
>> if (myAction.isEnabled())
>> submenu.add(myAction);
>> }
>>
>> if (!submenu.isEmpty())
>> menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
>>}
>>
>>Thanks for your help!
>>
>>Cheers, Dennis
Re: How to populate context submenu with entries based on the same action? [message #194325 is a reply to message #194269] Thu, 01 September 2005 06:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sgplkrsh.uiuc.edu

Firstly, I think you'll need to create separate actions for each of the
objects. Your code seems to be overwriting the object-properties in the
action.

Regarding dynamically registering actions, can you not access the
action-registry thru GraphicalEditor.getActionRegistry() and add to it each
type a new object-type is created in your application?

Subhash

"Dennis Hurrelmann" <eclipse@hurrelmann.de> wrote in message
news:df540o$5v1$1@news.eclipse.org...
> How do I dynamically register actions? As far as I know the ActionRegistry
> is filled only once. But at this point of time the amount of actions
> needed isn't clear.
> I do not really want to use a popup menu...
>
> Regards, Dennis
>
>
> Patrick schrieb am 31.08.2005 20:49:
>
>> That approach should work in your ContextMenuProvider, but you will also
>> need to dynamically add/remove those Actions in the ActionRegistry.
>>
>>
>> Dennis Hurrelmann wrote:
>>
>>
>>>Hey guys!
>>>
>>>My plan is to add new objects via the context menu. The context menu
>>>should show in a submenu all existing objects of a certain type as a
>>>selectable list. To my understanding I need an action for each entry.
>>>But the number of entries does not become clear until runtime. How do I
>>>populate that list using a single action which is responsible for
>>>creating the new objects? The following code is of course not
>>>functional, but should clarify the issue:
>>>
>>>public void buildContextMenu(IMenuManager menu) {
>>> GEFActionConstants.addStandardActionGroups(menu);
>>>
>>> IAction action;
>>> HashMap map;
>>>
>>> MenuManager submenu = new MenuManager("Add object");
>>> map = XYZ.getMyObjects(); // get existing objects
>>> Iterator it = map.keySet().iterator();
>>>
>>> while (it.hasNext()) {
>>> MyAction myAction =
>>> (MyAction) getActionRegistry().getAction(MyAction.MYACTION);
>>> MyObject o = map.get(it.next());
>>> myAction.setText(o.getName());
>>> myAction.setObject(o); // action needs reference
>>> if (myAction.isEnabled())
>>> submenu.add(myAction);
>>> }
>>>
>>> if (!submenu.isEmpty())
>>> menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
>>>}
>>>
>>>Thanks for your help!
>>>
>>>Cheers, Dennis
Re: How to populate context submenu with entries based on the same action? [message #194361 is a reply to message #194325] Thu, 01 September 2005 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.hurrelmann.de

Hi Subhash!

Don't bother the setObject method ;-) That's just my own implementation
to inform the action about what to create.
getActionRegistry() is not static and I don't know how to obtain a
reference of my GraphicalEditor in the ContextMenuProvider...
As a workaround to display a selectable list I use a popup window which
seems to be easier to implement. But ideas are still welcome!

Dennis


Subhash Gopalakrishnan schrieb am 01.09.2005 08:47:

> Firstly, I think you'll need to create separate actions for each of the
> objects. Your code seems to be overwriting the object-properties in the
> action.
>
> Regarding dynamically registering actions, can you not access the
> action-registry thru GraphicalEditor.getActionRegistry() and add to it each
> type a new object-type is created in your application?
>
> Subhash
>
> "Dennis Hurrelmann" <eclipse@hurrelmann.de> wrote in message
> news:df540o$5v1$1@news.eclipse.org...
>
>>How do I dynamically register actions? As far as I know the ActionRegistry
>>is filled only once. But at this point of time the amount of actions
>>needed isn't clear.
>>I do not really want to use a popup menu...
>>
>>Regards, Dennis
>>
>>
>>Patrick schrieb am 31.08.2005 20:49:
>>
>>
>>>That approach should work in your ContextMenuProvider, but you will also
>>>need to dynamically add/remove those Actions in the ActionRegistry.
>>>
>>>
>>>Dennis Hurrelmann wrote:
>>>
>>>
>>>
>>>>Hey guys!
>>>>
>>>>My plan is to add new objects via the context menu. The context menu
>>>>should show in a submenu all existing objects of a certain type as a
>>>>selectable list. To my understanding I need an action for each entry.
>>>>But the number of entries does not become clear until runtime. How do I
>>>>populate that list using a single action which is responsible for
>>>>creating the new objects? The following code is of course not
>>>>functional, but should clarify the issue:
>>>>
>>>>public void buildContextMenu(IMenuManager menu) {
>>>> GEFActionConstants.addStandardActionGroups(menu);
>>>>
>>>> IAction action;
>>>> HashMap map;
>>>>
>>>> MenuManager submenu = new MenuManager("Add object");
>>>> map = XYZ.getMyObjects(); // get existing objects
>>>> Iterator it = map.keySet().iterator();
>>>>
>>>> while (it.hasNext()) {
>>>> MyAction myAction =
>>>> (MyAction) getActionRegistry().getAction(MyAction.MYACTION);
>>>> MyObject o = map.get(it.next());
>>>> myAction.setText(o.getName());
>>>> myAction.setObject(o); // action needs reference
>>>> if (myAction.isEnabled())
>>>> submenu.add(myAction);
>>>> }
>>>>
>>>> if (!submenu.isEmpty())
>>>> menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
>>>>}
>>>>
>>>>Thanks for your help!
>>>>
>>>>Cheers, Dennis
Re: How to populate context submenu with entries based on the same action? [message #194538 is a reply to message #194361] Fri, 02 September 2005 03:31 Go to previous message
Eclipse UserFriend
Originally posted by: sgplkrsh.uiuc.edu

A trivial way to get access to the editor within the action (that creates
the new object-types) is to maintain a static reference to the editor-object
in the action class and init the reference from the editor's constructor.

I am sure there are better ways to do the same thing, but the point is that
the action-registry is held by the editor object which is a singleton in the
plugin's space. So accessing the action-registry should be easy enough if
you allow your class-design to accommodate it.

Subhash


"Dennis Hurrelmann" <eclipse@hurrelmann.de> wrote in message
news:df710u$cv6$1@news.eclipse.org...
> Hi Subhash!
>
> Don't bother the setObject method ;-) That's just my own implementation to
> inform the action about what to create.
> getActionRegistry() is not static and I don't know how to obtain a
> reference of my GraphicalEditor in the ContextMenuProvider...
> As a workaround to display a selectable list I use a popup window which
> seems to be easier to implement. But ideas are still welcome!
>
> Dennis
>
>
> Subhash Gopalakrishnan schrieb am 01.09.2005 08:47:
>
>> Firstly, I think you'll need to create separate actions for each of the
>> objects. Your code seems to be overwriting the object-properties in the
>> action.
>>
>> Regarding dynamically registering actions, can you not access the
>> action-registry thru GraphicalEditor.getActionRegistry() and add to it
>> each type a new object-type is created in your application?
>>
>> Subhash
>>
>> "Dennis Hurrelmann" <eclipse@hurrelmann.de> wrote in message
>> news:df540o$5v1$1@news.eclipse.org...
>>
>>>How do I dynamically register actions? As far as I know the
>>>ActionRegistry is filled only once. But at this point of time the amount
>>>of actions needed isn't clear.
>>>I do not really want to use a popup menu...
>>>
>>>Regards, Dennis
>>>
>>>
>>>Patrick schrieb am 31.08.2005 20:49:
>>>
>>>
>>>>That approach should work in your ContextMenuProvider, but you will also
>>>>need to dynamically add/remove those Actions in the ActionRegistry.
>>>>
>>>>
>>>>Dennis Hurrelmann wrote:
>>>>
>>>>
>>>>
>>>>>Hey guys!
>>>>>
>>>>>My plan is to add new objects via the context menu. The context menu
>>>>>should show in a submenu all existing objects of a certain type as a
>>>>>selectable list. To my understanding I need an action for each entry.
>>>>>But the number of entries does not become clear until runtime. How do I
>>>>>populate that list using a single action which is responsible for
>>>>>creating the new objects? The following code is of course not
>>>>>functional, but should clarify the issue:
>>>>>
>>>>>public void buildContextMenu(IMenuManager menu) {
>>>>> GEFActionConstants.addStandardActionGroups(menu);
>>>>>
>>>>> IAction action;
>>>>> HashMap map;
>>>>>
>>>>> MenuManager submenu = new MenuManager("Add object");
>>>>> map = XYZ.getMyObjects(); // get existing objects
>>>>> Iterator it = map.keySet().iterator();
>>>>>
>>>>> while (it.hasNext()) {
>>>>> MyAction myAction =
>>>>> (MyAction)
>>>>> getActionRegistry().getAction(MyAction.MYACTION);
>>>>> MyObject o = map.get(it.next());
>>>>> myAction.setText(o.getName());
>>>>> myAction.setObject(o); // action needs reference
>>>>> if (myAction.isEnabled())
>>>>> submenu.add(myAction);
>>>>> }
>>>>>
>>>>> if (!submenu.isEmpty())
>>>>> menu.appendToGroup(GEFActionConstants.GROUP_REST, submenu);
>>>>>}
>>>>>
>>>>>Thanks for your help!
>>>>>
>>>>>Cheers, Dennis
Previous Topic:Handling references treated as strings from an existing .xsd model
Next Topic:about popupmenu in gef
Goto Forum:
  


Current Time: Sat Apr 27 00:46:56 GMT 2024

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

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

Back to the top