aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2012-02-13 12:19:07 (EST)
committerTom Schindl2012-02-13 12:19:07 (EST)
commitf2a8ce2a9c2725653391ee3326262a984a9fa896 (patch)
tree9863fc21025bd97d7c9932680bb14c1d593a9e5e
parent1436a6ae6c3d1256d6806af7a9e70bdb8011ff95 (diff)
downloadeclipse.platform.ui-f2a8ce2a9c2725653391ee3326262a984a9fa896.zip
eclipse.platform.ui-f2a8ce2a9c2725653391ee3326262a984a9fa896.tar.gz
eclipse.platform.ui-f2a8ce2a9c2725653391ee3326262a984a9fa896.tar.bz2
Bug 371087 - [EAP] No way to store UI-State like in 3.x with IMementov20120213-1719
* added new annotation * implemented in rendering lifecycle * added unit tests
-rw-r--r--bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/PersistState.java33
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java17
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java62
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SampleView.java19
4 files changed, 129 insertions, 2 deletions
diff --git a/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/PersistState.java b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/PersistState.java
new file mode 100644
index 0000000..6f6d3ff
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.di/src/org/eclipse/e4/ui/di/PersistState.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.e4.ui.di;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Parts can specify this annotation on one of the methods to tag it as the
+ * method that performs the "visual state persit" operation
+ * <p>
+ * This annotation must not be applied to more than one method on a class. If multiple methods of
+ * the class are tagged with this this annotation, only one of them will be called to persist visual
+ * state.
+ * </p>
+ */
+@Documented
+@Target({ ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface PersistState {
+ // intentionally left empty
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
index 98417fb..1c170d8 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
@@ -38,6 +38,7 @@ import org.eclipse.e4.ui.css.core.util.impl.resources.OSGiResourceLocator;
import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.e4.ui.css.swt.theme.IThemeManager;
+import org.eclipse.e4.ui.di.PersistState;
import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.internal.workbench.Policy;
@@ -814,6 +815,22 @@ public class PartRenderingEngine implements IPresentationEngine {
}
}
+ if (element instanceof MContribution) {
+ MContribution contribution = (MContribution) element;
+ Object client = contribution.getObject();
+ IEclipseContext parentContext = renderer.getContext(element);
+ if (parentContext != null && client != null) {
+ try {
+ ContextInjectionFactory.invoke(client,
+ PersistState.class, parentContext);
+ } catch (Exception e) {
+ if (logger != null) {
+ logger.error(e);
+ }
+ }
+ }
+ }
+
renderer.disposeWidget(element);
// unset the client object
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java
index 3a0b33a..7cacc50 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java
@@ -3235,4 +3235,66 @@ public class PartRenderingEngineTests extends TestCase {
assertFalse(logged);
}
+
+ public void test_persistState_371087() {
+ MApplication application = ApplicationFactoryImpl.eINSTANCE
+ .createApplication();
+ MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
+ application.getChildren().add(window);
+ application.setSelectedElement(window);
+
+ MPart part = BasicFactoryImpl.eINSTANCE.createPart();
+ part.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView");
+ window.getChildren().add(part);
+ window.setSelectedElement(part);
+
+ application.setContext(appContext);
+ appContext.set(MApplication.class.getName(), application);
+
+ wb = new E4Workbench(application, appContext);
+ wb.createAndRunUI(window);
+
+ assertNotNull(part.getObject());
+ assertNotNull(part.getContext());
+
+ SampleView view = (SampleView) part.getObject();
+ view.errorOnWidgetDisposal = true;
+
+ part.setToBeRendered(false);
+ assertTrue("The view should have been destroyed",
+ view.isStatePersisted());
+ assertNull(part.getObject());
+ assertNull(part.getContext());
+ }
+
+ public void test_persistState_371087_1() {
+ MApplication application = ApplicationFactoryImpl.eINSTANCE
+ .createApplication();
+ MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
+ application.getChildren().add(window);
+ application.setSelectedElement(window);
+
+ MPart part = BasicFactoryImpl.eINSTANCE.createPart();
+ part.setContributionURI("bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView");
+ window.getChildren().add(part);
+ window.setSelectedElement(part);
+
+ application.setContext(appContext);
+ appContext.set(MApplication.class.getName(), application);
+
+ wb = new E4Workbench(application, appContext);
+ wb.createAndRunUI(window);
+
+ assertNotNull(part.getObject());
+ assertNotNull(part.getContext());
+
+ SampleView view = (SampleView) part.getObject();
+ view.errorOnWidgetDisposal = true;
+
+ window.setToBeRendered(false);
+ assertTrue("The view should have been destroyed",
+ view.isStatePersisted());
+ assertNull(part.getObject());
+ assertNull(part.getContext());
+ }
}
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SampleView.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SampleView.java
index 0e188d5..3b8b498 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SampleView.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SampleView.java
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.di.PersistState;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -46,6 +47,10 @@ public class SampleView {
boolean nullParentContext = false;
+ private TreeViewer viewer;
+
+ private boolean statePersisted;
+
/**
* Create the sample view.
*
@@ -65,8 +70,7 @@ public class SampleView {
}
});
- TreeViewer viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL
- | SWT.V_SCROLL);
+ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.getTree().setData("class", "navigator"); //$NON-NLS-1$ //$NON-NLS-2$
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
@@ -165,6 +169,17 @@ public class SampleView {
}
}
+ @PersistState
+ void persistState() {
+ if (!viewer.getControl().isDisposed()) {
+ statePersisted = true;
+ }
+ }
+
+ public boolean isStatePersisted() {
+ return statePersisted;
+ }
+
public boolean isDestroyed() {
return destroyed;
}