Bug 71701 - [Workbench] Allow plugins to veto shutdown
Summary: [Workbench] Allow plugins to veto shutdown
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
: 79986 113955 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-08-10 04:24 EDT by Juergen Weber CLA
Modified: 2006-02-13 16:14 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen Weber CLA 2004-08-10 04:24:58 EDT
The WorkbenchAdvisor should be accessible from Plugins to catch the workbench's
lifecycle events.

In an RCP application a plugin should be asked if the platform may shutdown on
File-Quit (e.g. a view might have unsaved data (sometimes an editor cannot be
used as long as there is no way from stopping an editor from being closed by the
user)).

Right now in WorkbenchAdvisor.preShutdown() I ask the views to prompt the user
if  the platform may shutdown. 
IPartListener cannot stop the platform from shutting down.

The views I find in my WorkbenchAdvisor via
configurer.getWindow().getActivePage().findView(IDVIEW). This works, but results
in a dependency of RCPWorkbenchAdvisor to the views. So I thought of having the
views register themselves in RCPWorkbenchAdvisor. 

But there is no way to access the WorkbenchAdvisor from a plugin. There should
be a method, e.g. IWorkbench.getAdvisor(). Right now there is
Workbench.getAdvisor() but it is package private.
Comment 1 Nick Edgar CLA 2004-08-10 13:34:28 EDT
It is intentional that regular plug-ins cannot access the WorkbenchAdvisor.  The
WorkbenchAdvisor gives special powers to the application that regular plugins
should not have.

It would be better to address the limitation you point out by providing new
workbench lifecycle events to regular plugins, including a pre-shutdown
notification, and giving the ability of any of the interested plugins to veto
the shutdown.
Comment 2 Juergen Weber CLA 2004-08-11 02:35:28 EDT
Yes, you are right, providing the workbench lifecycle events to regular plugins
would suffice and would be better.
Comment 3 Nick Edgar CLA 2004-08-11 13:11:50 EDT
We could provide API on IWorkbench, e.g.
IWorkbench.add/removeWorkbenchListener(IWorkbenchListener) where
IWorkbenchListener has something like:
interface IWorkbenchListener {
   void postStartup();
   boolean preShutdown();
   ...
}

However, the plugin would have to already be activated in order to hook the
listener.

It may be better to provide this as an extension point, allowing the extension
to specify which events it's interested in, so that we don't have this bootstrap
problem.

Which would be better for your scenario?
Comment 4 Juergen Weber CLA 2004-08-12 07:57:16 EDT
Un un-activated plugin would not have dirty data, so the need for a plugin to be
activated to register itself seems not to be a problem to me. Anyway, in an RCP
app the product plugin is activated on startup. 

I'd prefer a IWorkbenchListener, its idea is consistent to IPartListener. Also,
I don't like XML descriptions, it is too easy to make mistakes -> Bug 70198.
Comment 5 Teddy Walker CLA 2005-08-19 08:38:34 EDT
(In reply to comment #3)
A listener-method in IWorkbenchListener(2) would be good. Can you implement 
this in 3.2, please.
Comment 6 Nick Edgar CLA 2006-01-11 11:44:40 EST
*** Bug 79986 has been marked as a duplicate of this bug. ***
Comment 7 Nick Edgar CLA 2006-01-11 11:52:31 EST
*** Bug 113955 has been marked as a duplicate of this bug. ***
Comment 8 Nick Edgar CLA 2006-01-11 11:53:05 EST
With the current support in 3.1, views can implement ISaveablePart, and fire the appropriate dirty state change notifications.  The user would be prompted to save any changes on shutdown if the view reported that it was dirty, even if all editors were closed.  
See also bug 112225.
Comment 9 Dusko CLA 2006-01-11 12:10:46 EST
It would still be nice to have this ability from the plug-in. In our case the file (and its structure) is represented in multiple editors and a navigational view at the same time. The ideal UI for our users would be to let them close all of those parts (view and editors) and still be prompted to save the model during the app shutdown. Of course, they would be prompted when closing the last part displaying the model but they can decline to save at that point and chose to do so when closing the app.

It is a matter of perception. Our average user does not consider it mandatory to close his model just because the parts (views/editors) are closed. For example, it could be cross-referenced from another model whose editor is still up.
Comment 10 Teddy Walker CLA 2006-01-11 12:49:52 EST
In my case it's an external tool process.
The user should get a last chance to save the results of the tool. To save the results, the user have to interact with the console. It's not possible to save the results programmatically.
ISaveablePart(2) does not work: the process does not have its own view. A ConsolePage (IPageBookViewPage) does not support ISaveablePart (strictly speaking, there is no guarantee, that a ConsoleView is opened).
Comment 11 Nick Edgar CLA 2006-01-11 13:42:50 EST
Will consider for 3.2.
Comment 12 Nick Edgar CLA 2006-02-09 22:30:27 EST
Stefan, do you think this would help address the issue you mentioned today regarding doing saves in the background, and how such jobs can get interrupted due to the workbench shutting down?

I'm considering a programmatic API to allow adding a vetoing pre-shutdown listener to the workbench.  For example:
  IWorkbench.addWorkbenchListener(IWorkbenchListener)

where IWorkbenchListener has:
  boolean preShutdown()
(for consistency with WorkbenchAdvisor.preShutdown())
Comment 13 Nick Edgar CLA 2006-02-10 12:43:46 EST
For those building RCP apps, do you have any preference for whether clients get notified before or after WorkbenchAdvisor.preShutdown()?
I'm currently planning on notifying clients before the advisor.
Comment 14 Stephan Wahlbrink CLA 2006-02-10 12:59:49 EST
(In reply to comment #13)
I would agree to "before".
Comment 15 Nick Edgar CLA 2006-02-10 14:07:06 EST
Added IWorkbenchListener which has preShutdown and postShutdown methods, and corresponding add/removeWorkbenchListener methods in IWorkbench.

In the end, I decided to notify these listeners after the advisor; the rationale being that the advisor has overall control of the app and should have the first chance to veto shutdown.  Stephan, what was your rationale for preferring before?

Also added WorkbenchListenerTest to the RCP test suite.

Teddy, Stephan and others, could you give this a spin?
Comment 16 Nick Edgar CLA 2006-02-10 14:07:42 EST
The workbench listeners are also notified before checking for editors with unsaved changes.
Comment 17 Stephan Wahlbrink CLA 2006-02-11 04:25:01 EST
(In reply to comment #15)
It meets my demands; whether before or after is not important for me. 
Thanks.
Comment 18 Teddy Walker CLA 2006-02-11 06:42:52 EST
The workbench listener works as desired.
Thanks.
Comment 19 Nick Edgar CLA 2006-02-13 16:14:12 EST
Verified in I20060213-1200.