Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Cannot get Menu Items in eclipse 3.4
Cannot get Menu Items in eclipse 3.4 [message #481234] Thu, 20 August 2009 08:11 Go to next message
sneha is currently offline snehaFriend
Messages: 25
Registered: July 2009
Junior Member
Hi,

I have moved from Target platform eclipse 3.3.2 to 3.4 recently.
I have developed an RCP application which has some toolbar icons.
These icons have an initial disabled state. However after running the
application using eclipse 3.4, the initial state of these icons is
toggled to "enabled".
On debugging the code I found that the method getItemCount() of
org.eclipse.swt.Menu class returns an empty list while retrieving the
menu items.
In my code, based on this return value, I am setting the enabled
/disabled state of the icons.But since we get an empty list, no further
operation is possible.
I have not done any code changes in my application. This behavior is
observed after switching the target platform.
I have searched on net if this is a side effect of some changes in
eclipse 3.4 but did not get any solution.
If anybody has come across this problem, please let me know about the
solution.

Thanks,
Sneha
Re: Cannot get Menu Items in eclipse 3.4 [message #481764 is a reply to message #481234] Mon, 24 August 2009 09:07 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Hi,

its hard to pinpoint your problem remotely. I suggest that you try the
small examples from the following tutorial and then check the difference
to your code:

http://www.vogella.de/articles/EclipseCommands/article.html

Best regards, Lars




sneha wrote:
> Hi,
>
> I have moved from Target platform eclipse 3.3.2 to 3.4 recently.
> I have developed an RCP application which has some toolbar icons.
> These icons have an initial disabled state. However after running the
> application using eclipse 3.4, the initial state of these icons is
> toggled to "enabled".
> On debugging the code I found that the method getItemCount() of
> org.eclipse.swt.Menu class returns an empty list while retrieving the
> menu items.
> In my code, based on this return value, I am setting the enabled
> /disabled state of the icons.But since we get an empty list, no further
> operation is possible.
> I have not done any code changes in my application. This behavior is
> observed after switching the target platform.
> I have searched on net if this is a side effect of some changes in
> eclipse 3.4 but did not get any solution.
> If anybody has come across this problem, please let me know about the
> solution.
>
> Thanks,
> Sneha




--
http://www.vogella.de/ - Eclipse plugin and Eclipse RCP Tutorials
http://www.twitter.com/vogella - vogella on Twitter
Re: Cannot get Menu Items in eclipse 3.4 [message #481835 is a reply to message #481234] Mon, 24 August 2009 13:52 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

What code do you have? Is it that you have a DROP_DOWN action?

PW


Re: Cannot get Menu Items in eclipse 3.4 [message #482103 is a reply to message #481234] Tue, 25 August 2009 11:52 Go to previous messageGo to next message
sneha is currently offline snehaFriend
Messages: 25
Registered: July 2009
Junior Member
Hi,

To enable/ disable action I had used code from following link:
(http://www.eclipsezone.com/eclipse/forums/t90781.rhtml) with some
modification.
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
Menu menubar = workbench.getActiveWorkbenchWindow().
getShell().getMenuBar();
if(menubar == null ){
return;
}
MenuItem[] mItems = menubar.getItems();
if(mItems == null){
return;
}
for(int j = 0 ;j < menuItems.length; j++) {
if(mItems .getText().equals("Tools")){
Menu menu = mItems .getMenu();
/**************************************************
for( int i = 0; i < menu.getItemCount(); ++i) {
/**************************************************
**** In the above marked line, menu.getItemCount returns 0 but i can
**** see actions entry (menu item) in main menu and toolbar
**** after this code I am trying to get the menu Item action and
** set its state to enabled.
**** But since the code is returning 0 from above line, I am not able to
****toggle the state of the action Item

SubContributionItem cItem = null;
Object menuItemData = item.getData();
if(menuItemData == null){
continue;
}
if(menuItemData instanceof SubContributionItem){
cItem = (SubContributionItem)menuItemData;
IContributionItem conItems = cItem.getInnerItem();
if(conItems instanceof ActionContributionItem){
ActionContributionItem items = (ActionContributionItem) conItems;
String id = cItem.getId();
if((id != null) && (toolsID.contains(id))){
items.getAction().setEnabled(state);
}
}
}
}
}
}
}
});

In my code, based on this return value, I am setting the enabled
/disabled state of the icons.But since we get an empty list from
menu.getItemCount(), no further operation is possible.
This code is working perfectly fine in eclipse 3.3.2. Same code gives
problem in Eclipse 3.4.
I have not done any code changes in my application. This behavior is
observed after switching the target platform.
I have searched on net if this is a side effect of some changes in
eclipse 3.4 but did not get any solution.


Any pointers would be of great help.
Thanks,
Sneha

Paul Webster wrote:
> What code do you have? Is it that you have a DROP_DOWN action?
>
> PW
>


sneha wrote:
> Hi,
>
> I have moved from Target platform eclipse 3.3.2 to 3.4 recently.
> I have developed an RCP application which has some toolbar icons.
> These icons have an initial disabled state. However after running the
> application using eclipse 3.4, the initial state of these icons is
> toggled to "enabled".
> On debugging the code I found that the method getItemCount() of
> org.eclipse.swt.Menu class returns an empty list while retrieving the
> menu items.
> In my code, based on this return value, I am setting the enabled
> /disabled state of the icons.But since we get an empty list, no further
> operation is possible.
> I have not done any code changes in my application. This behavior is
> observed after switching the target platform.
> I have searched on net if this is a side effect of some changes in
> eclipse 3.4 but did not get any solution.
> If anybody has come across this problem, please let me know about the
> solution.
>
> Thanks,
> Sneha
Re: Cannot get Menu Items in eclipse 3.4 [message #482104 is a reply to message #481764] Tue, 25 August 2009 11:55 Go to previous messageGo to next message
sneha is currently offline snehaFriend
Messages: 25
Registered: July 2009
Junior Member
Hi,
Thanks for the link. But I am facing this problem after switching from
Eclipse target platform 3.3.2 to 3.4.
please refer to details of my problem in the other mail thread.
Any suggestions would be of great help.
Thanks,
Sneha

Lars Vogel wrote:
> Hi,
>
> its hard to pinpoint your problem remotely. I suggest that you try the
> small examples from the following tutorial and then check the difference
> to your code:
>
> http://www.vogella.de/articles/EclipseCommands/article.html
>
> Best regards, Lars
>
>
>
>
> sneha wrote:
>> Hi,
>>
>> I have moved from Target platform eclipse 3.3.2 to 3.4 recently.
>> I have developed an RCP application which has some toolbar icons.
>> These icons have an initial disabled state. However after running the
>> application using eclipse 3.4, the initial state of these icons is
>> toggled to "enabled".
>> On debugging the code I found that the method getItemCount() of
>> org.eclipse.swt.Menu class returns an empty list while retrieving the
>> menu items.
>> In my code, based on this return value, I am setting the enabled
>> /disabled state of the icons.But since we get an empty list, no
>> further operation is possible.
>> I have not done any code changes in my application. This behavior is
>> observed after switching the target platform.
>> I have searched on net if this is a side effect of some changes in
>> eclipse 3.4 but did not get any solution.
>> If anybody has come across this problem, please let me know about the
>> solution.
>>
>> Thanks,
>> Sneha
>
>
>
>
Re: Cannot get Menu Items in eclipse 3.4 [message #482414 is a reply to message #482103] Wed, 26 August 2009 13:21 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

your code makes assumptions about the main menu (internal implementation details) that I'm surprised worked in 3.3 and definitely won't work in 3.4.

There isn't a fix. In 3.4, those menu items are created on the fly and are disposed more aggressively.

The correct way to update an actionSet action enabled state is to do it from the IWorkbenchWindowActionDelegate. On selection change or execution, the IActionDelegate has the opportunity to update its corresponding IAction.

Commands and Handlers have a more flexible lifecycle that allows updating some attributes at different points in time.

PW


Re: Cannot get Menu Items in eclipse 3.4 [message #482562 is a reply to message #482103] Thu, 27 August 2009 04:55 Go to previous messageGo to next message
sneha is currently offline snehaFriend
Messages: 25
Registered: July 2009
Junior Member
Hi,
I still don't have any solution to this problem. I have not yet found
whether the below mentioned problem is a known issue in Eclipse 3.4 or
whether there is a workaround to my problem.

If anybody has come across this problem, please let me know about the
solution.

Any pointers would be of great help!!

Thanks,
Sneha

sneha wrote:
> Hi,
>
> To enable/ disable action I had used code from following link:
> (http://www.eclipsezone.com/eclipse/forums/t90781.rhtml) with some
> modification.
> Display.getDefault().syncExec(new Runnable() {
> public void run() {
> IWorkbench workbench = PlatformUI.getWorkbench();
> Menu menubar = workbench.getActiveWorkbenchWindow().
> getShell().getMenuBar();
> if(menubar == null ){
> return;
> }
> MenuItem[] mItems = menubar.getItems();
> if(mItems == null){
> return;
> }
> for(int j = 0 ;j < menuItems.length; j++) {
> if(mItems .getText().equals("Tools")){
> Menu menu = mItems .getMenu();
> /**************************************************
> for( int i = 0; i < menu.getItemCount(); ++i) {
> /**************************************************
> **** In the above marked line, menu.getItemCount returns 0 but i can
> **** see actions entry (menu item) in main menu and toolbar
> **** after this code I am trying to get the menu Item action and
> ** set its state to enabled.
> **** But since the code is returning 0 from above line, I am not able to
> ****toggle the state of the action Item
>
> SubContributionItem cItem = null;
> Object menuItemData = item.getData();
> if(menuItemData == null){
> continue;
> }
> if(menuItemData instanceof SubContributionItem){
> cItem = (SubContributionItem)menuItemData;
> IContributionItem conItems = cItem.getInnerItem();
> if(conItems instanceof ActionContributionItem){
> ActionContributionItem items = (ActionContributionItem) conItems;
> String id = cItem.getId();
> if((id != null) && (toolsID.contains(id))){
> items.getAction().setEnabled(state);
> }
> }
> }
> }
> }
> }
> }
> });
>
> In my code, based on this return value, I am setting the enabled
> /disabled state of the icons.But since we get an empty list from
> menu.getItemCount(), no further operation is possible.
> This code is working perfectly fine in eclipse 3.3.2. Same code gives
> problem in Eclipse 3.4.
> I have not done any code changes in my application. This behavior is
> observed after switching the target platform.
> I have searched on net if this is a side effect of some changes in
> eclipse 3.4 but did not get any solution.
>
>
> Any pointers would be of great help.
> Thanks,
> Sneha
>
> Paul Webster wrote:
> > What code do you have? Is it that you have a DROP_DOWN action?
> >
> > PW
> >
>
>
> sneha wrote:
>> Hi,
>>
>> I have moved from Target platform eclipse 3.3.2 to 3.4 recently.
>> I have developed an RCP application which has some toolbar icons.
>> These icons have an initial disabled state. However after running the
>> application using eclipse 3.4, the initial state of these icons is
>> toggled to "enabled".
>> On debugging the code I found that the method getItemCount() of
>> org.eclipse.swt.Menu class returns an empty list while retrieving the
>> menu items.
>> In my code, based on this return value, I am setting the enabled
>> /disabled state of the icons.But since we get an empty list, no
>> further operation is possible.
>> I have not done any code changes in my application. This behavior is
>> observed after switching the target platform.
>> I have searched on net if this is a side effect of some changes in
>> eclipse 3.4 but did not get any solution.
>> If anybody has come across this problem, please let me know about the
>> solution.
>>
>> Thanks,
>> Sneha
Re: Cannot get Menu Items in eclipse 3.4 [message #482563 is a reply to message #482414] Thu, 27 August 2009 04:58 Go to previous message
sneha is currently offline snehaFriend
Messages: 25
Registered: July 2009
Junior Member
Hi,
Will try out both the solutions.
Thanks a lot!!

-Sneha

Paul Webster wrote:
> your code makes assumptions about the main menu (internal implementation
> details) that I'm surprised worked in 3.3 and definitely won't work in 3.4.
>
> There isn't a fix. In 3.4, those menu items are created on the fly and
> are disposed more aggressively.
>
> The correct way to update an actionSet action enabled state is to do it
> from the IWorkbenchWindowActionDelegate. On selection change or
> execution, the IActionDelegate has the opportunity to update its
> corresponding IAction.
>
> Commands and Handlers have a more flexible lifecycle that allows
> updating some attributes at different points in time.
>
> PW
>
Previous Topic:Is there a PRE_RUN listener
Next Topic:installing from feature based repository failed
Goto Forum:
  


Current Time: Thu Apr 25 08:16:29 GMT 2024

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

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

Back to the top