Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 139958 - [Commands] Global Action Handlers and Commands issue
Summary: [Commands] Global Action Handlers and Commands issue
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P5 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 137091
Blocks:
  Show dependency tree
 
Reported: 2006-05-03 10:33 EDT by Alex Bernstein CLA
Modified: 2022-01-01 17:49 EST (History)
4 users (show)

See Also:


Attachments
Debug trace of application (139.35 KB, text/plain)
2007-10-30 06:51 EDT, Alexander Haag CLA
no flags Details
Debugtrace of application run with eclipse 3.3.1 (166.91 KB, text/plain)
2007-10-30 08:44 EDT, Alexander Haag CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Bernstein CLA 2006-05-03 10:33:30 EDT
Hi,

My editor presentation space consists of a number of widgets (StyledText, Trees, Tables etc). These widgets have context menus with Cut, Copy, Paste, SelectAll and Delete actions. I also need to make sure that when user selects same actions from Eclipse's main menu, my code is executed. I achive this by calling the following (this is a snippet from Copy action):

When the action object is created:
Action myCopyAction = new MyCopyAction();
actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), myCopyAction);

And in the constructor:
setId( ActionFactory.COPY.getId() );
setActionDefinitionId( IWorkbenchActionDefinitionIds.COPY );
activateHandler( true );

I also need hotkeys (such as Ctrl+C) to work, so I use HandlerService and ActionHandler (from org.eclipse.jface.commands) to associate my action and Eclipse's command, like this:

void activateHandler( boolean active ) 
{
    if( m_testEditor == null ) {
        return;
    }
    if( active ){
        IHandlerService handlerServer = (IHandlerService)getEditorPart().getEditorSite().getService(IHandlerService.class);
        final String id = getActionDefinitionId();
        ActionHandler a = new ActionHandler( this );
        m_handlerActivation = handlerServer.activateHandler( id, a);
    } else {
        if( m_handlerActivation != null ){
            m_handlerActivation.getHandlerService().deactivateHandler(m_handlerActivation);
            m_handlerActivation = null;
        }
    }
}

I have the following problem:

When there are two editors opened at the same time side by side (both of them create and setup actions as descibed above), global actions (including hotkeys) are taken from one of them (usually the second one that becomes active) and never from the other. When I activate the first editor, going to the main menu and selecting an action, results in the code being executed inside the second, now inactive editor. Of course, when I execute the same action from the context menu, it works alright, because I am construcing popup menus myself. But Eclipse is confused. When there is only one editor open, hotkeys usually do not work at all (sometimes they do after lots of switching between multiple views and editors).

Please tell me what am I doing wrong or what is missing? There are no errors or exceptions of any kind.
Comment 1 Alex Bernstein CLA 2006-05-05 13:16:20 EDT
This issue is regarded as critical in our product
Comment 2 Paul Webster CLA 2006-05-05 14:57:51 EDT
This counts as loss of functionality.

PW
Comment 3 Alex Bernstein CLA 2006-05-05 14:58:57 EDT
That's why I thought it was critical :-)
Comment 4 Paul Webster CLA 2006-05-06 12:16:01 EDT
Alex,

actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), myCopyAction); will activate your action for your editor.  You don't need to activate it your constructor.

AFAIK, you also have to target the actions at your editor.  Check out how TextEditorActionContributor in org.eclipse.ui.editors uses this method in setActiveEditor(IEditorPart) (technically, doSetActiveEditor(*)) or BasicJavaEditorActionContributor.

in setActiveEditor(IEditorPart) they update the action with the new editor having called setGlobalActionHandler(*) in the init(*) method.

PW

Comment 5 Alex Bernstein CLA 2006-05-07 22:08:01 EDT
Does this mean that there supposed to be exactly one instance of each (global) action per editor type? And that each such instance should react not only to the selection change, but also track editors activations? This is not at all obvious from any documentation I have read.

As for the constructor, I call my method 'activateHandler' from it. I need to do this in order to make sure the hotkeys (mnemonics) work. Sorry if I have not made this clear enough. The 'setGlobalActionhandler' method is called by outside code when the actionas are created.
Comment 6 Alex Bernstein CLA 2006-05-11 17:16:26 EDT
I have re-written my code so that there is just one instance of each type of action. Each action gets updated when either the selection within current editor changes, or when another editor becomes active.

The end result -- Hotkeys work in unpredictable manner. Usually it requires second editor to be opended and activated for hotkeys to begin to work. Later on it hotkeys stop working again. However, the actions themselves become enabled and disabled in a proper way and always refer to the correct selection.
Comment 7 Paul Webster CLA 2006-05-11 18:08:34 EDT
There is still an open bug 137091 that effects proper operation of keybindings set using setGlobalActionHandler(*).  You might now be hitting that.

PW
Comment 8 Alex Bernstein CLA 2006-05-12 09:34:37 EDT
Looks very similar. Do you know what the plans are for fixing this problem?
Comment 9 Alex Bernstein CLA 2006-05-12 12:21:10 EDT
I have noticed that in most cases the LegacyHandlerWrapper::isEnabled() returns false, which prevents hotkeys to work.

public final boolean isEnabled() {
  final Object enabled = handler.getAttributeValuesByName().get(
	ILegacyAttributeNames.ENABLED);
  if (enabled instanceof Boolean) {
	return ((Boolean) enabled).booleanValue();
  }
  return true;
}
The 'isEnabled' method is called from Command.executeWithChecks(ExecutionEvent).
if (!isEnabled()) {
  final NotEnabledException exception = new NotEnabledException(
	"Trying to execute a disabled command"); //$NON-NLS-1$
  fireNotEnabled(exception);
  throw exception;
} 

The Command->handler(LegacyActionHandler)->handler(ActionHandler)->action is not my action (registered via setGlobalActionHandler), but some other action (which is in the disabled state). 

'fireNotEnabled' does not actually log anything because the DEBUG and DEBUG_VERBOSE are both false. How do I set them to true?

Hope this info helps.
Comment 10 Alex Bernstein CLA 2006-05-12 13:43:20 EDT
I have mention in my report that in the constructors of my edit actions I make the following call:

For my copy action:
setId( ActionFactory.COPY.getId() );

I think that creating actions with factory IDs is wrong and that I have to use unique IDs. Is this correct?
Comment 11 Paul Webster CLA 2006-05-12 14:52:14 EDT
(In reply to comment #10)
> I have mention in my report that in the constructors of my edit actions I make
> the following call:
> 
> For my copy action:
> setId( ActionFactory.COPY.getId() );

yes, it's a good idea to use your unique action IDs for your specific actions.  But it is correct to use:
setActionDefinitionId( IWorkbenchActionDefinitionIds.COPY );
and 
actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), myCopyAction);


PW
Comment 12 Paul Webster CLA 2007-04-22 09:59:08 EDT
(In reply to comment #9)
> 
> 'fireNotEnabled' does not actually log anything because the DEBUG and
> DEBUG_VERBOSE are both false. How do I set them to true?
> 

Sorry, Alex,

http://wiki.eclipse.org/index.php/Platform_Command_Framework#Tracing_Option

You would probably want to add a commands tracing option to the file mentioned in the above link:

org.eclipse.ui/trace/commands=true

You can turn some of the others off if you want.  For evaluating if CTRL+C is calling the correct handler, you probably want handlers, keybindings, and commands.

PW
Comment 13 Alexander Haag CLA 2007-10-09 05:56:52 EDT
(In reply to comment #0)

> When I activate the first editor, going to the main menu
> and selecting an action, results in the code being executed inside the second,
> now inactive editor. 

I do have exactly the same problem using retagret undo/redo-actions in my graphical Editor which is based on GEF.

As this bug is quite old. Has there allready been a fix or workaround for this?

I'm using Eclipse  3.2.2
Build id: M20070212-1330

Thanks Alex Haag
Comment 14 Paul Webster CLA 2007-10-11 08:21:37 EDT
(In reply to comment #13)
> 
> I do have exactly the same problem using retagret undo/redo-actions in my
> graphical Editor which is based on GEF.
> 
> As this bug is quite old. Has there allready been a fix or workaround for this?

Quite a lot of the missing Command Framework was implemented in 3.3, but to find out if your particular problem has been sovled you would have to try on 3.3.1

PW

Comment 15 Alexander Haag CLA 2007-10-29 06:22:42 EDT
(In reply to comment #14)
> Quite a lot of the missing Command Framework was implemented in 3.3, but to
> find out if your particular problem has been sovled you would have to try on
> 3.3.1

Sorry, but after downloading the newest versions (Eclipse 3.3.1.1, GEF 3.2.101, EMF 2.3.0) the problem is still there.

Greets Alex Haag
Comment 16 Paul Webster CLA 2007-10-29 09:08:13 EDT
Alex, could you please attach a debug trace of the problem as per comment #12

Then either annotate it or provide the usecase steps (open editor one, open editor two, COPY, PASTE, UNDO, etc).

PW
Comment 17 Paul Webster CLA 2007-10-29 09:21:34 EDT
Alex, are you seeing bug 173361 ?

This seems to have been caused by bug 162964 and fixed by 200424 but not until 3.4M3 (which should come out the end of this week).

PW
Comment 18 Alexander Haag CLA 2007-10-30 06:51:59 EDT
Created attachment 81567 [details]
Debug trace of application

Hi,

here is the debugtrace of my application.
The actions made by the user were:
 - start of application
 - open editor 1 via doubleclick (editor 1 will be selected thereafter)
 - do move-action on open editor 1 
 - switch to filenavigator to open second editor
 - open editor 2 via doubleclick (editor 2 will be selected thereafter)
 - select editor 1
 - select special view for editor (this view has allways the commandstack of the current active editor and provides standard GEF undo/redo-actions using this commandstack; this time -- commandstack of editor 1!)
 - select editor 1
 - select editor 2
 - select special view for editor (this time the view has the commandstack of editor 2!)
 - shutdown of application.
Comment 19 Alexander Haag CLA 2007-10-30 08:44:20 EDT
Created attachment 81576 [details]
Debugtrace of application run with eclipse 3.3.1

Sorry I mixed the debug-traces. The one posted earlier has been from eclipse 3.2.2
This one here is logged while running the application using eclipse 3.3.1

Greets Alex
Comment 20 Alex Bernstein CLA 2007-10-30 09:35:44 EDT
Not sure which Alex you mean, but since I have submitted this defect more than a year ago, I have put several workarounds in my code to make it work. I will not be able to recreate environment I had back then in order to reproduce this defect.
Comment 21 Paul Webster CLA 2007-10-30 09:42:55 EDT
(In reply to comment #20)
> Not sure which Alex you mean, but since I have submitted this defect more than

Sorry, Alex, I've beem hassling  Alexander Haag :-)

PW
Comment 22 Paul Webster CLA 2007-10-30 13:15:32 EDT
(In reply to comment #19)
> Created an attachment (id=81576) [details]
> Debugtrace of application run with eclipse 3.3.1

Thank you for the stack traces, Alex.

Alex, are you seeing bug 173361 ?

PW
Comment 23 Alexander Haag CLA 2007-10-31 03:57:55 EDT
(In reply to comment #22)
> Alex, are you seeing bug 173361 ?

Thanks Paul,

yes I checked this bug. But while my problem is with GEF undo/redo, bug 173361 is about GMF. I'm not quite sure but I think GMF provides its own undo/redo actions and does not use the ones from GEF.

I'll follow up that matter after my two days break!
As for now if there is anything I can provide, please let me know.

Greets Alex Haag
Comment 24 Paul Webster CLA 2009-03-02 11:40:14 EST
Updated as per http://wiki.eclipse.org/Platform_UI/Bug_Triage
PW
Comment 25 Eclipse Webmaster CLA 2019-09-06 16:13:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 26 Eclipse Genie CLA 2022-01-01 17:49:20 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.