Eclipse Plugin: Enablement of an Action based on the current selection - before the

Posted by Itay on Stack Overflow See other posts from Stack Overflow or by Itay
Published on 2010-04-24T14:01:32Z Indexed on 2010/04/24 14:03 UTC
Read the original article Hit count: 176

Filed under:
|

Here's my problem:

I am using the org.eclipse.ui.popupMenus extension point for adding a sub-menu whose Action that is bounded to the following class:

  public class MyAction implements IObjectActionDelegate {

     private Logic logic = Logic.getInstance(); // Singleton

     public void setActivePart(IAction a, IWorkbenchPart targetPart) {
        // Nothing here
     }

     public void run(IAction a) {      
        // Do something...
     }

     public void selectionChanged(IAction a, ISelection s) {
        a.setEnabled(logic.isEnabled(s));
     }
  }

This action is working correctly in most cases (including the call a.setEnabled() in selectionChanged()). My problem at the very first time my action is being invoked. The selectionChanged method is called only after the menu item has been displayed (and not when the user has made the selection) which means that the call to a.setEnabled() will have no affect.

Any ideas on how to make my action receive selectionChanged() notifications even before the fist time it is being invoked?

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse-plugin