Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Menus on wrapped objects
Menus on wrapped objects [message #452952] Tue, 29 March 2005 01:30 Go to next message
Eclipse UserFriend
Originally posted by: sabell.txesystems.com

I understand how to add object-based menu items using extensions in
plugin.xml.
Now I have been given objects that are wrapped in some proprietary wrapper
objects.
I need to create menus based on the contents of the wrappers.
I found the class MenuManager, but don't see how to inject one into this
scenario.
Any suggestions?

Thanks,

Steve
Re: Menus on wrapped objects [message #452960 is a reply to message #452952] Tue, 29 March 2005 07:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hoeggerand.post.ch

i can give you an example how it works with tables.

MenuManager manager = new MenuManager("context");
manager.setRemoveAllWhenShown(true);
P_ContextMenuListener contextMenuListener = new
P_ContextMenuListener();
manager.addMenuListener(contextMenuListener);
Menu contextMenu = manager.createContextMenu(m_table);
m_table.setMenu(contextMenu);

// somewhere else

private class P_ContextMenuListener implements IMenuListener
{
public void menuAboutToShow(IMenuManager manager)
{
internalMenuAboutToShow((MenuManager) manager);
}
private void internalMenuAboutToShow(MenuManager manager)
{
manager.add(new Action(){
public void run()
{
// do some stuff
}
});
}
} // end class P_ContextMenuListener

hope it helps
siambalam


Steven T Abell schrieb:
> I understand how to add object-based menu items using extensions in
> plugin.xml.
> Now I have been given objects that are wrapped in some proprietary wrapper
> objects.
> I need to create menus based on the contents of the wrappers.
> I found the class MenuManager, but don't see how to inject one into this
> scenario.
> Any suggestions?
>
> Thanks,
>
> Steve
>
>
Re: Menus on wrapped objects [message #457129 is a reply to message #452952] Fri, 17 June 2005 17:06 Go to previous messageGo to next message
Aaron Greenhouse is currently offline Aaron GreenhouseFriend
Messages: 14
Registered: July 2009
Junior Member
Steven T Abell wrote:
> I understand how to add object-based menu items using extensions in
> plugin.xml.
> Now I have been given objects that are wrapped in some proprietary wrapper
> objects.
> I need to create menus based on the contents of the wrappers.
> I found the class MenuManager, but don't see how to inject one into this
> scenario.
> Any suggestions?

Steven,

Have you made any progress with this problem? I am having a similar
problem, and, frankly, I am suprised by how badly EMF seems to handle
this situation.

We have an EMF model in which all our EMF classes descend from a
class AObject. I want to have plug-ins that add actions that are
enabled based on the specific subclass of AObject of the currently
selected objects in the genered EMF editor. But this is hard becuase
most of the time when I get ahold of the selected object is a
DelegatingWrapperItemProvider or some other wrapper introduced by the
editor's item providers. My thought was to create IActionFilter
implementations for AObject and the wrapper classes so that I could use
the <objectState> element in the action description in the plugin.xml
file. I wanted to create my own attribute "MetaModelClass" so I could
do soemthign like this:

<action ...>
...
<enablement>
<objectState name="MetaModelClass" value="EMFClassName"/>
</enablement>
</action>

The action filter would know how to unwrap the object (if necesary) and
then use reflection to test whether the class of the unwrapped object is
a subclass of the named class.

The problem with this approach is getting Eclipse to use the action
filter. I can either have the classes involved implement IActionFilter
directory, or have the classes be adaptable to an action filter. I
chose the 2nd option because it seemed more elegant. But there is a
fundamental problem: I don't see any really useful way to add the
necessary methods to classes used as wrappers. If the wrappers
implemented IAdaptable (which they don't) things would be greate. I
could just install using an extension point in the plugin.xml an adapter
factory that adapts wrappers to action filters.

I know this approach would work, because we do have one class of wrapper
that we defined (I don't know why, I didn't write that part), and I was
able to make it implement IAdapter, and implement and appropriate
IAdapterFactory and IActionFilter, and it worked very well for the items
that happend to be wrapped with our own wrapper. Similarly, I added
adapters and action filters for our root-class AObject. But I don't
know what to do for the other wrapper implementations that I cannot modify.

The only solution that comes to mind is to completely rewrite the
generated item providers so that they always create instances of some
new subclass that we declare that is adaptable, but that seems like a
lot of work and not very maintainable.

--Aaron
Re: Menus on wrapped objects [message #457172 is a reply to message #457129] Mon, 20 June 2005 16:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Aaron,

The wrappers are created by callout methods in ItemProviderAdapter,
e.g., createWrapper, so you can have control over the wrapper
implementations.


Aaron Greenhouse wrote:

> Steven T Abell wrote:
>
>> I understand how to add object-based menu items using extensions in
>> plugin.xml.
>> Now I have been given objects that are wrapped in some proprietary
>> wrapper objects.
>> I need to create menus based on the contents of the wrappers.
>> I found the class MenuManager, but don't see how to inject one into
>> this scenario.
>> Any suggestions?
>
>
> Steven,
>
> Have you made any progress with this problem? I am having a similar
> problem, and, frankly, I am suprised by how badly EMF seems to handle
> this situation.
>
> We have an EMF model in which all our EMF classes descend from a
> class AObject. I want to have plug-ins that add actions that are
> enabled based on the specific subclass of AObject of the currently
> selected objects in the genered EMF editor. But this is hard becuase
> most of the time when I get ahold of the selected object is a
> DelegatingWrapperItemProvider or some other wrapper introduced by the
> editor's item providers. My thought was to create IActionFilter
> implementations for AObject and the wrapper classes so that I could
> use the <objectState> element in the action description in the
> plugin.xml file. I wanted to create my own attribute "MetaModelClass"
> so I could do soemthign like this:
>
> <action ...>
> ...
> <enablement>
> <objectState name="MetaModelClass" value="EMFClassName"/>
> </enablement>
> </action>
>
> The action filter would know how to unwrap the object (if necesary)
> and then use reflection to test whether the class of the unwrapped
> object is a subclass of the named class.
>
> The problem with this approach is getting Eclipse to use the action
> filter. I can either have the classes involved implement
> IActionFilter directory, or have the classes be adaptable to an action
> filter. I chose the 2nd option because it seemed more elegant. But
> there is a fundamental problem: I don't see any really useful way to
> add the necessary methods to classes used as wrappers. If the
> wrappers implemented IAdaptable (which they don't) things would be
> greate. I could just install using an extension point in the
> plugin.xml an adapter factory that adapts wrappers to action filters.
>
> I know this approach would work, because we do have one class of
> wrapper that we defined (I don't know why, I didn't write that part),
> and I was able to make it implement IAdapter, and implement and
> appropriate IAdapterFactory and IActionFilter, and it worked very well
> for the items that happend to be wrapped with our own wrapper.
> Similarly, I added adapters and action filters for our root-class
> AObject. But I don't know what to do for the other wrapper
> implementations that I cannot modify.
>
> The only solution that comes to mind is to completely rewrite the
> generated item providers so that they always create instances of some
> new subclass that we declare that is adaptable, but that seems like a
> lot of work and not very maintainable.
>
> --Aaron


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Resize a Dialog Does not work??
Next Topic:Determine occuied space in Shell
Goto Forum:
  


Current Time: Fri Apr 26 21:37:36 GMT 2024

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

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

Back to the top