Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350383 - org.eclipse.core.commands.Command ICommandListener listener does not work
Summary: org.eclipse.core.commands.Command ICommandListener listener does not work
Status: CLOSED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-26 12:52 EDT by Mekk Elek CLA
Modified: 2011-06-26 15:47 EDT (History)
1 user (show)

See Also:


Attachments
Eclipse project to reproduce the fault (23.97 KB, application/octet-stream)
2011-06-26 12:53 EDT, Mekk Elek CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mekk Elek CLA 2011-06-26 12:52:39 EDT
Build Identifier: 20110218-0911

I have a command and a RegistryToggleState state atteched to it. I subscribe for command state changes from code using:
public final void addCommandListener(final ICommandListener commandListener);

When a state change occurs in the State object, I get no notification at all. When I track down with debugger why, I can see that the event ends up in org.eclipse.ui.internal.handlers.HandlerProxy's method:
public void handleStateChange(State state, Object oldValue);

But this method, even though the "handler" variable is my command listener, will not call my function, because it is implementing the ICommandListener interface and not IStateListener, which this method expects:

if (handler instanceof IStateListener) {
  ((IStateListener) handler).handleStateChange(state, oldValue);
}

Note that ICommandListener and IStateListener are unrelated interfaces.

I would expect that if I call addCommandListener(), I should get back notifications, no matter what.

I have attached a snapshot of my complete eclipse project, which should be enough to check the fault.


Reproducible: Always

Steps to Reproduce:
1. Open the attched eclipse project.
2. When you start the project, you will see a file system view with some buttons on the toolbar. Press the "Show directories on top" button (it has this text as a tooltip).
3. Now the fsview.views.FSView :: public void commandChanged(CommandEvent commandEvent) should be fired, but this does not happen.
4. You can put a breakpoint to fsview.handlers.ToggleCommandHandler :: public Object execute(ExecutionEvent event) method and take step by step and you will reach org.eclipse.ui.internal.handlers.HandlerProxy.
Comment 1 Mekk Elek CLA 2011-06-26 12:53:24 EDT
Created attachment 198611 [details]
Eclipse project to reproduce the fault
Comment 2 Mekk Elek CLA 2011-06-26 15:47:52 EDT
Sorry. I think the help page mislead me be it:

Method detail of org.eclipse.core.commands.Command:

"addCommandListener

public final void addCommandListener(ICommandListener commandListener)
Adds a listener to this command that will be notified when this command's state changes."

Where state is obviously NOT the attached state, but the internal state of the Command object. Hence the bug is not a bug at all, but user error :>, so I'm closing it.