I am writing an Eclipse plugin for a college project and should be able to run the code when the user logs out, and I cannot find the correct listener so that I can do this. An example of similar code is shown below, where I listen to successfully executed save events and the method is called when this happens.
public class ExecutionListener implements IExecutionListener{ private DataCollector dataCollector; public ExecutionListener(DataCollector dataCollector) { this.dataCollector = dataCollector; } public void postExecuteSuccess(String action, Object arg1) { if (action.equals("org.eclipse.ui.file.save")) { dataCollector.writeDatabase(); } }
So, I want a listener that will allow me to listen for exit events and call a method to run my code when this happens. I suppose I wonโt be able to ensure that the exit is completed successfully before running the code, but the pre-exit listener will work fine. In addition, if someone knows about the correct listener, they can also tell me the commandId that I will need for the exit event (for example, commandId for the save event in the above example is "org.eclipse.ui.file.save").
Thanks Jacob
EDIT: To answer the javamonkey79 question:
I add a listener as follows:
if (executionListener == null) { ICommandService service = (ICommandService) Activator.getDefault().getWorkbench(). getService(ICommandService.class); executionListener = new ExecutionListener(); service.addExecutionListener(executionListener); }
source share