75435

Eclipse plugin : disable/enable dynamically an action from main menubar

EDIT : SOLVED

<strong>Background</strong>

I have implemented a eclipse plugin (on indigo, 3.7.2) that provide a new icon in the bar menu.

This new action is fully initialized few seconds after eclipse startup (some configuration files are loaded from my maven repository).

I'm trying to disable this action until my activator finish initalization.

<strong>What I'm looking for</strong>

Before initialization

<img src="https://i.stack.imgur.com/xPdSH.png" alt="Disabled">

After initialization

<img src="https://i.stack.imgur.com/Vspof.png" alt="Enabled">

<strong>What I've already done</strong>

I added an enablement test on my action. My action will be enabled only if my plugin is activated.

<extension point="org.eclipse.ui.actionSets"> <actionSet label="Action Set" visible="true" id="com.eclipse.plugins.extarcheytpe.actionSet"> <action class="com.eclipse.plugins.extarchetype.actions.ShortcutsAction" icon="src/main/resources/icons/generic_box_16x16.png" id="com.eclipse.plugins.extarcheytpe.actions.ShortcutsAction" label="Shortcuts List" style="pulldown" toolbarPath="Shortcuts" tooltip="Shortcuts"> <enablement> <pluginState id="com.eclipse.plugins.extarchetype" value="activated"> </pluginState> </enablement> </action> </actionSet> </extension> [...] <extension point="org.eclipse.ui.startup"> <startup class="com.eclipse.plugins.extarchetype.Startup"> </startup> </extension>

I defined a startup class, where ignite() method initialize my plugin configuration :

public class Startup implements org.eclipse.ui.IStartup{ @Override public void earlyStartup() { try { Activator.getDefault().ignite(); Activator.getDefault().setChanged(); Activator.getDefault().notifyObservers(); } catch (Exception e) { e.printStackTrace(); } } }

I implemented an observing design pattern between my action and my activator (to notify the initialization end).

public class ShortcutsAction extends Action implements IWorkbenchWindowPulldownDelegate, IMenuCreator, IObserver { private IAction action; private Menu menu; public boolean enabled = false; public ShortcutsAction() { super(); Activator.getDefault().addObserver(this); } @Override public void selectionChanged(IAction action, ISelection selection) { // Change action object instance at first selection if (action != this.action) { this.action = action; } // If property enabled is true, enable this action if (enabled) { action.setEnabled(true); } else { action.setEnabled(false); } } [...] @Override public void update(IObservable obs, Object obj) { this.enabled = true; ConsoleHandler.logInfo("Shortcut enabled"); action.setEnabled(true); } }

<strong>Conclusion</strong>

I got what I was looking for :

<ol> <li>At loading, my action is disabled</li> <li>Since my plugin is initialized, my action is enabled</li> </ol>

Thank you.

Answer1:

<objectState> and <objectClass> test the state and class of the currently selected objects <strong>not</strong> the action handler class.

I think you would have to use <systemProperty> to check a property that you set. Or use the selectionChanged method to enable the IAction.

The selectionChanged method is part of the IActionDelegate interface that you are indirectly implementing with IWorkbenchWindowPulldownDelegate:

public void selectionChanged(IAction action, ISelection selection)

The action parameter is the actual action, call action.setEnabled(true) to enable the action.

Recommend

  • Accessing another variable in the same class with a click event
  • Why can't UI components be accessed from a backgroundworker?
  • Any nice way to generate a timeline view of commits from subversion?
  • Sybase Error Implicit Conversion from datatype 'VARCHAR' to 'INT' not allowed
  • jquery validation - waiting for remote check to complete
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • How to retrieve information from antrun back to maven?
  • Do query loads all the data in memory
  • aapt.exe'' finished with non-zero exit value 1
  • Salesforce Different WSDL files and when to use
  • How to getText() from the input field of an angularjs Application
  • Sending HTML Form Data to Spring REST Web Service
  • AndEngine Applying Transparancy to AndEngine View
  • Automatically associate new Sonar project with custom quality profile and quality gate
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • Jetty 9 HashLoginService
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Read a local file using javascript
  • ImageMagick, replace semi-transparent white with opaque white
  • Cannot connect to cassandra from Spark
  • Cross-Platform Protobuf Serialization
  • what is the difference between the asp.net mvc application and asp.net web application
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • jQuery tmpl and DataLink beta
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to set the response of a form post action to a iframe source?
  • Java static initializers and reflection
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • Qt: Run a script BEFORE make
  • unknown Exception android
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app