Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 372799 - [Workbench] [GlobalActions] ViewPart cannot adapt ISaveablePart any longer but must implement it.
Summary: [Workbench] [GlobalActions] ViewPart cannot adapt ISaveablePart any longer bu...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.5 M7   Edit
Assignee: Andrey Loskutov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-28 16:04 EST by David Burkhart CLA
Modified: 2016-06-09 13:38 EDT (History)
9 users (show)

See Also:


Attachments
test project with two differently implemented views (18.00 KB, application/zip)
2015-04-28 17:54 EDT, Andrey Loskutov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Burkhart CLA 2012-02-28 16:04:24 EST
Build Identifier: M20120208-0800

The javadoc of ISaveablePart says: "Workbench parts implement or adapt to this interface to participate in the enablement and execution of the <code>Save</code> and <code>Save As</code> actions."

When a ViewPart implements ISaveablePart everything is well and property changes on dirty are recognized by the platform. But when the ViewPart doesn't implement ISaveablePart but adapts it, then the platform won't recognize changes on the dirty property any longer!

SaveHandler and SaveAsHandler could handle the adaption of ISaveablePart through using AbstractSaveHandler#getSaveablePart(ExecutionEvent) which is aware of the possible adapter. But the class org.eclipse.ui.internal.handlers.DirtyStateTracker, which was introduced in 3.7 according to its javadoc, only checks for instanceof but not for adapters of ISaveablePart. Also org.eclipse.ui.internal.WorkbenchPartReference doesn't respect adapters in isDirty().

Reproducible: Always

Steps to Reproduce:
1. Create RCP App with a view
2. Let the View adapt ISaveablePart which alwas returns true in isDirty()
3. Run application -> View is not dirty

(If the same steps are followed but in step 2 implementing ISaveablePart instead of adapting and also returning true in isDirty() leads to dirty view)
Comment 1 Paul Webster CLA 2012-02-29 07:50:31 EST
See http://wiki.eclipse.org/Platform_UI/How_to_Contribute

PW
Comment 2 Eclipse Genie CLA 2015-02-12 18:15:02 EST
New Gerrit change created: https://git.eclipse.org/r/41791
Comment 4 Andrey Loskutov CLA 2015-03-25 17:39:20 EDT
.
Comment 5 Andrey Loskutov CLA 2015-04-28 17:54:59 EDT
Created attachment 252868 [details]
test project with two differently implemented views

Seems that I've overlooked one place, see example. Both views must have "*" in view title if opened, but only one (old style) is dirty.

The fix is trivial.
Comment 6 Andrey Loskutov CLA 2015-04-28 17:55:50 EDT
.
Comment 7 Eclipse Genie CLA 2015-04-28 17:59:48 EDT
New Gerrit change created: https://git.eclipse.org/r/46720
Comment 9 Andrey Loskutov CLA 2015-04-29 00:33:51 EDT
.
Comment 10 Andrey Loskutov CLA 2015-04-29 15:48:09 EDT
Verified with I20150429-1330
Comment 11 Andrey Loskutov CLA 2015-04-29 17:06:37 EDT
Never ending story. Just one step further next issue...

!ENTRY org.eclipse.ui 4 0 2015-04-29 21:56:42.755
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.ClassCastException: test.View2 cannot be cast to org.eclipse.ui.ISaveablePart
	at org.eclipse.ui.internal.WorkbenchWindow$7.promptToSave(WorkbenchWindow.java:539)
	at org.eclipse.e4.ui.internal.workbench.PartServiceSaveHandler.save(PartServiceSaveHandler.java:44)
	at org.eclipse.ui.internal.WorkbenchWindow$7.save(WorkbenchWindow.java:593)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.savePart(PartServiceImpl.java:1342)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.closePart(StackRenderer.java:1277)
Comment 12 Eclipse Genie CLA 2015-04-29 17:43:30 EDT
New Gerrit change created: https://git.eclipse.org/r/46818
Comment 13 Eclipse Genie CLA 2015-04-29 18:16:53 EDT
New Gerrit change created: https://git.eclipse.org/r/46821
Comment 16 Andrey Loskutov CLA 2015-04-30 17:15:53 EDT
All fixes are now in I20150430-1445
Comment 17 Andrey Loskutov CLA 2015-04-30 17:16:02 EDT
.
Comment 18 Pierre-Charles David CLA 2015-06-16 09:30:38 EDT
Hi.

It seems that this change has caused a regression for us (in Sirius, bug 470076). Not sure if it's a real regression or if we need to adapt our own code (and how?).

Basically if we close Eclipse with a Sirius editor opened and dirty (and the Properties view open), since Mars WorkbenchPage.getDirtyWorkbenchParts() returns 2 parts: the editor itself (OK), and the PropertySheet, which is not an ISaveablePart, but can be adapted to one (the editor).

Because our editor implements ISaveablePart2, in processSaveable2() we get our promptToSaveOnClose() called once for the editor, and, if the user answered "No", a second time via the PropertySheet, whose ISaveablePart2 is the same editor (still dirty as the user asked not to save).

I believe this could be solved by changing this part of getDirtyWorkbenchParts (and getDirtyParts, and maybe others):

	ISaveablePart saveable = SaveableHelper.getSaveable(part);
	if (saveable != null) {
		if (saveable.isDirty()) {
			result.add(part);
		}
	}

into:

	ISaveablePart saveable = SaveableHelper.getSaveable(part);
	if (saveable != null && !result.contains(saveable)) {
		if (saveable.isDirty()) {
			result.add(part);
		}
	}

This would avoid to add a saveable virtually twice (or more): once for itself and once for each other part which proxies to it as its ISaveablePart.
Comment 19 ALOK MANJREKAR CLA 2016-06-08 13:48:41 EDT
Yes - I concur with Pierre. This fix has introduced a regression.
When we have an editor (that implements ISaveablePart) opened that is dirty, and the Properties View (which is showing some properties for the open editor) and then try to close the RCP application - a save is prompted for the editor as well as the Properties view, which does not look correct. 
This might have to be fixed.
Comment 20 Phil Beauvoir CLA 2016-06-09 13:35:00 EDT
Please re-open this. The regression is killing my RCP application. My app is getting prompted to save the Properties View - not a sensible proposition!
Comment 21 Andrey Loskutov CLA 2016-06-09 13:37:41 EDT
(In reply to Phil Beauvoir from comment #20)
> Please re-open this. 
See bug 495567.