Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2015-07-16 16:59:04 +0000
committerMaxime Porhel2015-07-16 17:21:22 +0000
commit72b4deb7d37b374f1d204636faad9ed5e4dae8f3 (patch)
treeaecd52cbd342397ed91961cb0ba46d869d7959d3
parent825a429d73d1981cd9bc8e830ba410dcb8f0aa65 (diff)
downloadorg.eclipse.sirius-72b4deb7d37b374f1d204636faad9ed5e4dae8f3.tar.gz
org.eclipse.sirius-72b4deb7d37b374f1d204636faad9ed5e4dae8f3.tar.xz
org.eclipse.sirius-72b4deb7d37b374f1d204636faad9ed5e4dae8f3.zip
[453037] Avoid to reopen a session in the SessionEditorInput
Avoid to reopen a session in the SessionEditorInput when restore is not asked. Bug: 453037 Change-Id: Ia0fbafc8bf36cbceeea246c4998d2d4af91d4528 Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java8
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java35
2 files changed, 30 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
index 6f98a1357c..779ef44b72 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/RestoreSessionFromEditorInputTests.java
@@ -13,6 +13,7 @@ package org.eclipse.sirius.tests.unit.common;
import java.util.Collections;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.tests.SiriusTestsPlugin;
import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase;
@@ -120,6 +121,7 @@ public class RestoreSessionFromEditorInputTests extends SiriusDiagramTestCase {
if (closeSession) {
closeSession(session);
+ assertTrue("Session should be closed and removed from the manager", SessionManager.INSTANCE.getSessions().isEmpty() && !session.isOpen());
}
// Step 3: restore editor from navigation history
@@ -130,6 +132,12 @@ public class RestoreSessionFromEditorInputTests extends SiriusDiagramTestCase {
// => This should not have created a new session but use the current one
assertEquals("No new session should have been opened while restoring editor from navigation history", 1, SessionManager.INSTANCE.getSessions().size());
+ Session currentSession = SessionManager.INSTANCE.getSessions().iterator().next();
+ if (closeSession) {
+ assertNotSame(session, currentSession);
+ } else {
+ assertEquals(session, currentSession);
+ }
activePage.closeAllEditors(false);
TestsUtil.synchronizationWithUIThread();
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
index 8c4fdb5db1..59bf4ad437 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
@@ -108,8 +108,9 @@ public class SessionEditorInput extends URIEditorInput {
*/
private Session getSession(boolean restore) {
Session session = sessionRef != null ? sessionRef.get() : null;
- // Avoid to create a new session if the default editor name is used:
- // GoToMarker case.
+ // Avoid to create a new session if the default editor name is used: we
+ // do not known yet for which representation the input is, like
+ // in the GotoMarker case for example.
if (session == null || (!session.isOpen() && !DEFAULT_EDITOR_NAME.equals(name))) {
URI sessionModelURI = getURI().trimFragment();
if (sessionResourceURI != null) {
@@ -218,21 +219,29 @@ public class SessionEditorInput extends URIEditorInput {
private Session getSession(URI sessionModelURI, boolean restore) {
Session sessionFromURI;
try {
- sessionFromURI = null;
- if (restore) {
+ sessionFromURI = SessionManager.INSTANCE.getExistingSession(sessionModelURI);
+
+ // A session adds and removes itself from the session manager during
+ // open()/close()
+ // If restore, we try to create a new one and open it only in this
+ // case: the session lifecycle is not safe enough to try to open a
+ // previously closed session.
+ if (sessionFromURI == null && restore) {
sessionFromURI = SessionManager.INSTANCE.getSession(sessionModelURI, new NullProgressMonitor());
- } else {
- sessionFromURI = SessionManager.INSTANCE.getExistingSession(sessionModelURI);
- }
- if (sessionFromURI != null) {
- if (!sessionFromURI.isOpen()) {
+ if (sessionFromURI != null && !sessionFromURI.isOpen()) {
sessionFromURI.open(new NullProgressMonitor());
}
- IEditingSession uiSession = null;
- if (restore) {
+ }
+
+ if (sessionFromURI != null && sessionFromURI.isOpen()) {
+ // The SessionUIManager creates and open an IEditingSession when
+ // a session is added to the SessionManager. This
+ // IEditingSession is closed and removed from the ui manager
+ // when the corresponding session is removed from the session
+ // manager (closed).
+ IEditingSession uiSession = SessionUIManager.INSTANCE.getUISession(sessionFromURI);
+ if (uiSession == null && restore) {
uiSession = SessionUIManager.INSTANCE.getOrCreateUISession(sessionFromURI);
- } else {
- uiSession = SessionUIManager.INSTANCE.getUISession(sessionFromURI);
}
if (uiSession != null && !uiSession.isOpen()) {
uiSession.open();

Back to the top