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 07:22   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #333277 is a reply to message #333255] | 
Wed, 03 December 2008 03:00    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 10:43    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 05:45   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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
 |  
 |  
  |   
Goto Forum:
 
 Current Time: Mon Nov 03 21:18:52 EST 2025 
 Powered by  FUDForum. Page generated in 0.06161 seconds  
 |