Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Disabling a menu that uses dynamic clause
Disabling a menu that uses dynamic clause [message #333063] Mon, 24 November 2008 12:22 Go to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

We have a context menu displayed in our application on right-clicking on an
object. In this context menu, some 4 or 5 menu items are displayed.
Additionally, it has a sub-menu that shows further menu items.

Our menu structure is somewhat like this:

ABC1
ABC2
ABC3
submenu1 --> sub-item-1
sub-item-2
sub-item-3
ABC4
ABC5

In this context menu, "submenu1" uses the "dynamic" clause, and the sub menu
items are contributed dynamically. On right-clicking the first time,
submenu1 is enabled, and then when the user hovers the mouse over submenu1,
it evaluates and populates the sub menu items, and keeps submenu1 enabled if
there are sub menu items to display, or disables submenu1 when there are no
sub menu items to display.

According to our application logic, sometimes there are no sub menu items to
display, but this is evaluated only when the user hovers the mouse over
submenu1, and then disables it. If the user does not hover the mouse over
submenu1, it remains enabled even if there are no sub menu items.

What we would like to do is one of the below options:

1. Disable "submenu1" when the initial context menu is displayed, if there
are no sub menu items to be displayed (not when the user hovers the mouse
over it).
2. Or keep submenu1 enabled, even if it has no sub menu items to display.

What is the best approach to get this desired behavior?
Re: Disabling a menu that uses dynamic clause [message #333137 is a reply to message #333063] Wed, 26 November 2008 18:47 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

One common pattern I've seen is that if your dynamic menu gets filled in
obviously it is there, but if there is nothing to place there you still
fill in one disabled MenuItem. Usually the text is set to "(empty)" or
"No <whatever> currently available"

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Disabling a menu that uses dynamic clause [message #333184 is a reply to message #333137] Fri, 28 November 2008 10:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Thanks! Paul, for your response. I am not able to disable the menuitem in
our case (dynamic clause). Please let me know, how we can disable the
MenuItem. Is there any API we need for this desired behavior (disabling the
menu item in dynamic clause)?

Regards,
Prasad.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:ggk624$1qa$1@build.eclipse.org...
> One common pattern I've seen is that if your dynamic menu gets filled in
> obviously it is there, but if there is nothing to place there you still
> fill in one disabled MenuItem. Usually the text is set to "(empty)" or
> "No <whatever> currently available"
>
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Disabling a menu that uses dynamic clause [message #333186 is a reply to message #333137] Fri, 28 November 2008 11:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Thanks!Paul for your response. I am not able to disable the MenuItem text
( "(empty)" or

"No <whatever> currently available" ) in our case. Could you please let me
know how we can achieve it? Whether we need any API for this desired
behavior?

Regards,
Prasad.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:ggk624$1qa$1@build.eclipse.org...
> One common pattern I've seen is that if your dynamic menu gets filled in
> obviously it is there, but if there is nothing to place there you still
> fill in one disabled MenuItem. Usually the text is set to "(empty)" or
> "No <whatever> currently available"
>
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Disabling a menu that uses dynamic clause [message #333188 is a reply to message #333186] Fri, 28 November 2008 15:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Prasad Guttikonda wrote:
> Thanks!Paul for your response. I am not able to disable the MenuItem text
> ( "(empty)" or
>
> "No <whatever> currently available" ) in our case. Could you please let me
> know how we can achieve it? Whether we need any API for this desired
> behavior?
>

What is providing each of you bits? What provides ABC3? submenu1?
sub-item-1? I'm particularly interested in what provides sub-item-1.
Is it a subclass of CompoundContributionItem? You're own subclass of
ContributionItem? That's a good candidate for providing a disabled
MenuItem("(empty)")

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Disabling a menu that uses dynamic clause [message #333204 is a reply to message #333188] Mon, 01 December 2008 08:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Hi Paul,
Sub-item-1 is a sub-class of CompoundContributionItem.

Regards,
Prasad
"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:ggp2nb$cgl$1@build.eclipse.org...
> Prasad Guttikonda wrote:
>> Thanks!Paul for your response. I am not able to disable the MenuItem text
>> ( "(empty)" or
>>
>> "No <whatever> currently available" ) in our case. Could you please let
>> me know how we can achieve it? Whether we need any API for this desired
>> behavior?
>>
>
> What is providing each of you bits? What provides ABC3? submenu1?
> sub-item-1? I'm particularly interested in what provides sub-item-1. Is
> it a subclass of CompoundContributionItem? You're own subclass of
> ContributionItem? That's a good candidate for providing a disabled
> MenuItem("(empty)")
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Disabling a menu that uses dynamic clause [message #333235 is a reply to message #333204] Mon, 01 December 2008 15:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Prasad Guttikonda wrote:
> Hi Paul,
> Sub-item-1 is a sub-class of CompoundContributionItem.

So then can it not return your sub-item-1 if their are items and a
disabled MenuItem with the text "(empty)" if you have nothing to fill in?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Disabling a menu that uses dynamic clause [message #333254 is a reply to message #333235] Tue, 02 December 2008 15:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Hi Paul,
I am able to return sub-item-1 if there are items and a text message
"(empty)" if nothing is there. But the problem is, I am not able to disable
text "(empty)". I didn't find any option to disable it.

Regards,
Prasad.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gh10qf$963$3@build.eclipse.org...
> Prasad Guttikonda wrote:
>> Hi Paul,
>> Sub-item-1 is a sub-class of CompoundContributionItem.
>
> So then can it not return your sub-item-1 if their are items and a
> disabled MenuItem with the text "(empty)" if you have nothing to fill in?
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Disabling a menu that uses dynamic clause [message #333255 is a reply to message #333254] Tue, 02 December 2008 15:27 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Prasad Guttikonda wrote:
> Hi Paul,
> I am able to return sub-item-1 if there are items and a text message
> "(empty)" if nothing is there. But the problem is, I am not able to disable
> text "(empty)". I didn't find any option to disable it.

Please post the code you are using to create the "(empty)" item.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Disabling a menu that uses dynamic clause [message #333277 is a reply to message #333255] Wed, 03 December 2008 08:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Hi Paul,
Please find the code herewith.

protected IContributionItem[] getContributionItems()
{

List<IContributionItem> items = new ArrayList<IContributionItem>();

try
{

XXXXLine theLine = null;

theLine = XXXXHandler.getCurrentlySelectedXXXX();

if( theLine == null )
{
return new IContributionItem[ items.size() ];
}

if( theLine.hasXXXXX() )
{

XXXXLine[] lines = theLine.listXXXXX();

for( XXXXLine element : lines )
{

Map<String,String> parms = new HashMap<String,
String>();

parms.put( XXXXHandler.XXXXXXX_ID, element.toString() );

IContributionItem i = new CommandContributionItem(
PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
"XXXXXXXX",
"XXXXXXXX",
parms, null, null, null, element.toString(),
null,
null, CommandContributionItem.STYLE_PUSH );

items.add( i );

}
}
else
{
IContributionItem i = new CommandContributionItem(
PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
"XXXXXXXX",
"XXXXXXXX",
null, null, null, null, "(empty)", null,
null, CommandContributionItem.STYLE_PUSH );

items.add( i );

}
}
catch (Exception e)
{
e.printStackTrace();
}

return items.toArray( new IContributionItem[items.size()] );

}





"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gh3kji$6ai$1@build.eclipse.org...
> Prasad Guttikonda wrote:
>> Hi Paul,
>> I am able to return sub-item-1 if there are items and a text message
>> "(empty)" if nothing is there. But the problem is, I am not able to
>> disable text "(empty)". I didn't find any option to disable it.
>
> Please post the code you are using to create the "(empty)" item.
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Disabling a menu that uses dynamic clause [message #333299 is a reply to message #333277] Wed, 03 December 2008 15:43 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Prasad Guttikonda wrote:

> else
> {
> IContributionItem i = new CommandContributionItem(
> PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
> "XXXXXXXX",
> "XXXXXXXX",
> null, null, null, null, "(empty)", null,
> null, CommandContributionItem.STYLE_PUSH );
>
> items.add( i );
>
> }
> }

If you want to use a CommandContributionItem you would need to point to
a disabled command.

You can either implement your own EmptyContributionItem (extends
ContributionItem) and in your fill(Menu,int) method do something like
org.eclipse.ui.internal.ShowInMenu.fill(Menu, int):

MenuItem item = new MenuItem(menu, SWT.NONE, index++);
item.setText("(empty)");
item.setEnabled(false);

or do a little hack:
IAction a = new Action("(empty)") {};
a.setEnabled(false);
IContributionItem item = new ActionContributionItem(a);

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Disabling a menu that uses dynamic clause [message #333330 is a reply to message #333299] Thu, 04 December 2008 10:45 Go to previous message
Eclipse UserFriend
Originally posted by: x_guttik.ugs.com

Thanks! Paul.

Regards,
Prasad

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gh69t6$3ph$1@build.eclipse.org...
> Prasad Guttikonda wrote:
>
>> else
>> {
>> IContributionItem i = new CommandContributionItem(
>>
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
>> "XXXXXXXX",
>> "XXXXXXXX",
>> null, null, null, null, "(empty)", null,
>> null, CommandContributionItem.STYLE_PUSH );
>>
>> items.add( i );
>>
>> }
>> }
>
> If you want to use a CommandContributionItem you would need to point to a
> disabled command.
>
> You can either implement your own EmptyContributionItem (extends
> ContributionItem) and in your fill(Menu,int) method do something like
> org.eclipse.ui.internal.ShowInMenu.fill(Menu, int):
>
> MenuItem item = new MenuItem(menu, SWT.NONE, index++);
> item.setText("(empty)");
> item.setEnabled(false);
>
> or do a little hack:
> IAction a = new Action("(empty)") {};
> a.setEnabled(false);
> IContributionItem item = new ActionContributionItem(a);
>
> PW
>
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Previous Topic:"Too many open files" problem
Next Topic:MessageDialog constructor not showing image on titlebox for Linux???
Goto Forum:
  


Current Time: Wed Nov 06 02:13:20 GMT 2024

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

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

Back to the top