Eclipse 4 application/window lifecycle - eclipse-rcp

How to hook application or window lifecycle events? At least I need to handle the moment when the application can be closed and to cancel this attempt if it is necessary.
I didn't find the possibility to enter the URI for application or windows like URI for parts

For Application lifecycle have a look at Eclipse 4 RCP Tutorial - Lifecycle Hooks .
Window lifecycle events are not yet directly accessible, Bug392903 has been filed for this.

Related

How to switch off Google "Analytics Ping" in Eclipse

In Eclipse Neon I started getting a dubious background job called "Analytics Ping", if I build (ie. save a file!) or synchronise with eGIT. I believe this is due to GWT (2.8.0). It appears to be poorly implemented in that:
1) Other background jobs queue unnecessarily behind it (it prevents me from updating/committing code!).
2) Like many other background jobs in Eclipse, it doesn't respond to cancellation requests.
Thus, if it has problems "pinging" back, it prevents me from working (And why does it need to ping for every file save?!).
Does anybody know how to switch this off for these versions? Thank you.
In Eclipse Preferences > GWT, disable "Share anonymous usage statistics of the GWT Eclipse Plugin..."
I turned Off the tick mark here.

Multiple instances of Eclipse4 RCP application

I have created an Eclipse4 RCP application and I would like to be able to launch multiple instances. By default when a second RCP instance is launched it says "The workspace is already in use". I know that it is possible to use options so that the application runs with no workspace but in my case I still wont to preserve the layout of the application. So is there a way to avoid workspace lock or to manually save the application state somewhere?
Thanks
Only one instance can use a workspace at a time so you would need to use different workspaces for each instance.
It is possible to set the workspace location during startup. The #PostContextCreate of your LifeCycle class is a suitable place to do this.
Use something like:
Location instanceLoc = Platform.getInstanceLocation();
instanceLoc.set(URL of workspace location, false);

Can eclipse notify me when a task has finished running?

I am often stuck twiddling my thumbs for a couple minutes while eclipse cleans, builds, or loads my projects. It would be nice if eclipse could notify me with a beep when the last task in the Progress view has finished running, so I can stop reading the internet and get back to work. Is there a setting or plugin that does this?
Edit: I tried adapting the plugin template that nonty provided below, which adds a listener to the JobManager. I tried implementing done() to beep only when the job change event's name contains "Building workspace," as that is the task that usually takes the longest in my setup. Exasperatingly, the task that builds the workspace never sends a done() call, just scheduled() and aboutToRun() calls. Any other ideas?
There are no preference for this - yet.
The JobManager have the needed API to support this functionality...
EDIT: I have constructed and attached a very simple plug-in that will beep for every job that terminates. That turns out to be rather often :-) . You can modify it to filter out all the false positives, e.g. by getPriority() and getName(). Also you can make the listener play a tune, popup a message (don't!) or whatever...
See jobnotifier.zip.
UPDATED the link above again

Eclipse plugin - handling events when stepping or breaking

Is there a generic way of receiving event notifications from the Eclipse debugger. Specifically I would just like to know when the user steps over/into and when a breakpoint is hit.
I have already got this working in JDT (see my other question: Eclipse Debugger Events) but the same technique doesn't work in CDT (I am using DebugPlugin.addDebugEventListener).
If there is no generic way of doing this, then is there a way to avoid the CDT dependencies from breaking the plugin when it is run in JDT?
Thanks,
Alan
OK, I've found an alternative that may be of use for others. You can use the method outlined above to listen for debug events when the session is created and terminated.
For any stepping events, one way I found was to register an IExecutionListener to be notified of all commands that take place in the Eclipse workspace. You can register an execution listener by getting hold of an ICommandService as follows:
ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)
Then add an execution listener:
commandService.addExecutionListener(this);
This will give you various event handlers (notHandled, postExecuteFailure, postExecuteSuccess, preExecute) from which you can filter by the commandId value.
I hope this helps someone else.
Alan

Eclipse Debugger Events

In my Eclipse plugin, I would like to be notified on debugger events (e.g. when stepping or a breakpoint is hit). I've managed to get this working in a JDT environment by subscribing to debug events using this code:
DebugPlugin.getDefault().addDebugEventListener(this);
Which gives this event handler:
public void handleDebugEvents(DebugEvent[] events)
{
}
In JDT this is fired on Breakpoint or Suspend events and I was hoping the behaviour would be the same in CDT. However, it is not. I only get two Create events at the start of the debug session:
DebugEvent[org.eclipse.cdt.dsf.gdb.launching.GDBProcess#ae0aae, CREATE, UNSPECIFIED]
DebugEvent[org.eclipse.debug.core.model.RuntimeProcess#920d5d, CREATE, UNSPECIFIED]
Is there a generic solution that wouldn't require specific dependencies on JDT or CDT?
Thanks,
Alan
I did find a solution and have answered my other question here: Eclipse plugin - handling events when stepping or breaking
Alan
I think what you want can't be achieved (generic, implementation-independent solution) without listening and digging through every single action in the Eclipse environment, as I understand that the Eclipse generic debug plug-in is just the framework on which to build a implementation-specific debugger, like Java's own debugger.
The static call you're making to DebugPlugin is a call to this basic 'framework' on which the CDT or JDT is running. For example, if I wanted to register a breakpoint listener to the Java debugger, I would call JDIDebugModel.addJavaBreakpointListener(<Your Java breakpoint listener class>);.
P.S. If there is a way to maybe listen to just the events fired from/under the generic platform debug plug-in, which would include the events fired from plug-ins that extend from this generic debugger, that may ease the task you seek to accomplish.