diff options
| author | Laurent Redor | 2018-04-20 15:08:30 +0000 |
|---|---|---|
| committer | Laurent Redor | 2018-04-27 15:08:53 +0000 |
| commit | eed514a1d97259f0b6bb664b87e60fb5adc69ebd (patch) | |
| tree | 4481e7af33092ae3dcab08ba0f919f8d04274531 | |
| parent | 493133833fe23f315882b3c45a8cc4e97e891be4 (diff) | |
| download | org.eclipse.sirius-eed514a1d97259f0b6bb664b87e60fb5adc69ebd.tar.gz org.eclipse.sirius-eed514a1d97259f0b6bb664b87e60fb5adc69ebd.tar.xz org.eclipse.sirius-eed514a1d97259f0b6bb664b87e60fb5adc69ebd.zip | |
[509970] Avoid to open a new Sirius session on GoTo marker
This commit fixes several problems:
1- SessionEditorInput: Only add a getExistingSession() in the
create(URI) method of SessionEditorInput is OK, if there is
no refresh that modifies the editor at opening. Tested with
o.e.s.t.swtbot.GoToMarkerTraceabilityWithUserInteractionTest.testTraceabilityWithNoOpenedRepresentationsWithoutRefreshAtOpening().
In other cases, there is an "IllegalStateException: Cannot activate
read/write transaction in read-only transaction context" because we try
to refresh the diagram (modify it) in the read transaction launched by
editingDomain.runExclusive() of
AbstractModelMarkerNavigationProvider.gotoMarker().
2- Copy of AbstractModelMarkerNavigationProvider: To avoid above problem
the GMF class AbstractModelMarkerNavigationProvider has been copied to
not launch the gotoMarker in runExclusive if the "refresh at opening" is
set to true. Tested with
o.e.s.t.swtbot.GoToMarkerTraceabilityWithUserInteractionTest.testTraceabilityWithNoOpenedRepresentationsWithRefreshAtOpening()
3- SessionEditorInput: If the session does not exist, we create it and
open it. It is then reused by the "real" editor. Tested with
o.e.s.t.swtbot.GoToMarkerTraceabilityWithUserInteractionTest.testTraceabilityWithClosedSession().
4- In SessionEditorInput, the status initialization has also been
changed (to avoid regressions detected by
DialectEditorsOpeningWithFailingSessionOpeningTests). The initialization
of the field can override a setting done indirectly by the super() that
calls getSession().
Bug: 509970
Change-Id: Ic26b562bf867621ad563e4a8f095e960518791ee
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
4 files changed, 364 insertions, 39 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/AbstractModelMarkerNavigationProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/AbstractModelMarkerNavigationProvider.java new file mode 100644 index 0000000000..406360da69 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/AbstractModelMarkerNavigationProvider.java @@ -0,0 +1,220 @@ +/****************************************************************************** + * Copyright (c) 2002, 2018 IBM Corporation 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: + * IBM Corporation - initial API and implementation + ****************************************************************************/ +package org.eclipse.sirius.diagram.ui.internal.providers; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IPath; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.common.util.WrappedException; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.util.Log; +import org.eclipse.gmf.runtime.common.core.util.Trace; +import org.eclipse.gmf.runtime.common.ui.services.marker.AbstractMarkerNavigationProvider; +import org.eclipse.gmf.runtime.emf.ui.internal.MslUIDebugOptions; +import org.eclipse.gmf.runtime.emf.ui.internal.MslUIPlugin; +import org.eclipse.gmf.runtime.emf.ui.internal.MslUIStatusCodes; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.ui.IEditorPart; + +/** + * Abstract Model Marker Navigation Provider this abstract class provides the necessary wrapping required to perform + * model operations related to the navigation of markers. If the marker attributes contain model element information + * that needs to be resolved, the corresponding marker provider should be derived from this class. + * <p> + * Derived classes should implement the getContext() and the doGotoMarker() methods. The latter method will be called + * within a model read operation. + * <p> + * Class copied from org.eclipse.gmf.runtime.emf.ui.providers.marker.AbstractModelMarkerNavigationProvider to not run + * the goto marker in exclusive if refresh at opening is set to true (as the refresh can make modification). + * + * @author Kevin Cornell + */ +public abstract class AbstractModelMarkerNavigationProvider + extends AbstractMarkerNavigationProvider { + + private TransactionalEditingDomain editingDomain; + + /** + * Perform the feedback for navigating to the given marker within a + * model read action. + */ + @Override + public final void gotoMarker( + final IEditorPart editor, + final IMarker marker) { + + // Must save the editor first since it will probably be used in + // the logic to obtain the model operation context. + setEditor(editor); + + // Remember the editing domain associated with this editor + IEditingDomainProvider domainProvider = getEditor().getAdapter(IEditingDomainProvider.class); + + if (domainProvider != null) { + EditingDomain domain = domainProvider.getEditingDomain(); + + if (domain instanceof TransactionalEditingDomain) { + editingDomain = (TransactionalEditingDomain) domain; + } + } + + // If the refresh at opening is activated, we do not run the gotoMarker + // in runExclusive since the refresh can modify the model. See bug + // 509970. + if (DialectUIManager.INSTANCE.isRefreshActivatedOnRepresentationOpening()) { + AbstractModelMarkerNavigationProvider.super.gotoMarker(editor, marker); + } else if (editingDomain != null) { + if (editingDomain != null) { + + // Perform the "goto" in a read operation. + try { + editingDomain.runExclusive(new Runnable() { + + @Override + public void run() { + AbstractModelMarkerNavigationProvider.super.gotoMarker(editor, marker); + } + }); + + } catch (InterruptedException e) { + Trace.catching(MslUIPlugin.getDefault(), MslUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "gotoMarker", e); //$NON-NLS-1$ + Log.error(MslUIPlugin.getDefault(), MslUIStatusCodes.IGNORED_EXCEPTION_WARNING, e.getLocalizedMessage(), e); + } + } + } + } + + /** + * Determines the EMF resource to which a marker is attached. + * + * @param marker a marker + * @return the corresponding EMF resource, or <code>null</code> if either + * the marker doesn't {@link IMarker#exists() exist} or its resource + * cannot be loaded by EMF + */ + protected Resource getResource(IMarker marker) { + Resource result = null; + + if (marker.exists()) { + // a non-existent marker cannot have a resource + + IPath resourcePath = marker.getResource().getLocation(); + + if (resourcePath != null) { + // if the resource path is null, then I can't locate any objects + // referenced in this marker on that non-existent resource + + ResourceSet resourceSet = editingDomain.getResourceSet(); + URI uri = URI.createFileURI(resourcePath.toOSString()); + result = resourceSet.getResource(uri, true); + } + } + + return result; + } + + /** + * Given a list of element IDs, looks up the elements, themselves, and + * returns them in the same order. + * <p> + * The <code>ids</code> passed to this method should follow a couple of + * conventions for compactness of implementation in a marker: + * <ul> + * <li>any ID in the list that is a URI fragment (i.e., does not include + * a resource URI) is assumed to be relative to the URI of the + * specified <code>resource</code></li> + * <li>any ID in the list that does not reference an object in the + * specified <code>resource</code> must be a fully-qualified URI + * (i.e., it must include a resource URI part)</li> + * </ul> + * Thus, in the majority of cases (where all referenced objects are in the + * resource that has the marker), the object IDs in the marker will be as + * compact as possible. + * </p> + * + * + * @param ids a list of element IDs, as described above + * @param resource the resource that has a marker from which the list of + * IDs was extracted. URI fragments in the <code>ids</code> list are + * assumed to be relative to this resource's URI. Must not be + * <code>null</code> + * @return the corresponding list of {@link EObject}s, in the same order as + * the <code>ids</code>, though not including any elements that could + * not be located (due to stale IDs) + */ + protected List getEObjects(List ids, Resource resource) { + List result = new java.util.ArrayList(ids.size()); + + URI resourceUri = resource.getURI(); + ResourceSet rset = resource.getResourceSet(); + + if (rset != null) { + // can't do anything if the resource is not in a resource set + + for (Iterator iter = ids.iterator(); iter.hasNext();) { + String nextId = (String) iter.next(); + + URI nextUri; + + int hashPos = nextId.indexOf('#'); + + if (hashPos <= 0) { + // the ID is a URI fragment. Make sure not to omit the + // hash symbol in the fragment if there is one + nextUri = resourceUri.appendFragment( + nextId.substring(hashPos + 1)); + } else { + // the URI is a fully-qualified one. The Resource URI + // portion will need to be decoded but the EObject fragment + // portion will not, because it is decoded by MSL + String resUriStr = nextId.substring(0, hashPos); + String elemIdStr = nextId.substring(hashPos + 1); + + try { + // use UTF-8 encoding for the URI, which is the + // standard encoding for XMI + resUriStr = URLDecoder.decode(resUriStr, "UTF-8"); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + // UTF-8 is always available in any Java platform + } + + nextUri = URI.createURI(resUriStr).appendFragment(elemIdStr); + } + + // load on demand because we need to select the element in an + // open model in the UI + try { + EObject element = rset.getEObject(nextUri, true); + + if (element != null) { + result.add(element); + } + } catch (WrappedException e) { + // this is expected in the case of cross-reference URIs that + // can no longer be resolved because of a bad resource + } + } + } + + return result; + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusMarkerNavigationProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusMarkerNavigationProvider.java index 946bbf1944..8790e7529e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusMarkerNavigationProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusMarkerNavigationProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES 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 @@ -22,7 +22,6 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; -import org.eclipse.gmf.runtime.emf.ui.providers.marker.AbstractModelMarkerNavigationProvider; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.sirius.diagram.DiagramPlugin; import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditorUtil; diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java index 9631ca88b7..4a0ea3f80d 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES. * 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 @@ -21,7 +21,9 @@ import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.command.RemoveCommand; import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gmf.runtime.common.ui.util.WorkbenchPartDescriptor; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; @@ -29,6 +31,8 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditor; import org.eclipse.sirius.diagram.ui.part.ValidateAction; @@ -36,12 +40,15 @@ import org.eclipse.sirius.table.metamodel.table.DTable; import org.eclipse.sirius.tests.swtbot.support.api.business.UILocalSession; import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource; import org.eclipse.sirius.tests.swtbot.support.api.condition.SessionClosedCondition; +import org.eclipse.sirius.tests.swtbot.support.api.condition.SessionSavedCondition; import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor; import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; import org.eclipse.sirius.ui.business.api.dialect.marker.TraceabilityMarkerNavigationProvider; +import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.ui.tools.internal.editor.AbstractDTreeEditor; import org.eclipse.sirius.viewpoint.DRepresentationElement; +import org.eclipse.sirius.viewpoint.provider.Messages; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; @@ -52,6 +59,9 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IGotoMarker; import org.junit.Assert; @@ -97,6 +107,59 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena private UILocalSession localSession; /** + * A part listener to detect "Default Editor" activation and store the + * session of this editor to be compared after with the "real" editor. + */ + private IPartListener2 defaultEditorPartListener = new IPartListener2() { + @Override + public void partActivated(IWorkbenchPartReference partRef) { + if (partRef instanceof IEditorReference && Messages.SessionEditorInput_defaultEditorName.equals(partRef.getTitle())) { + try { + if (((IEditorReference) partRef).getEditorInput() instanceof SessionEditorInput) { + sessionOfDummyEditor = ((SessionEditorInput) ((IEditorReference) partRef).getEditorInput()).getSession(); + } + } catch (PartInitException e) { + // Do nothing + } + } + } + + @Override + public void partVisible(IWorkbenchPartReference partRef) { + } + + @Override + public void partOpened(IWorkbenchPartReference partRef) { + } + + @Override + public void partInputChanged(IWorkbenchPartReference partRef) { + } + + @Override + public void partHidden(IWorkbenchPartReference partRef) { + } + + @Override + public void partDeactivated(IWorkbenchPartReference partRef) { + } + + @Override + public void partClosed(IWorkbenchPartReference partRef) { + } + + @Override + public void partBroughtToTop(IWorkbenchPartReference partRef) { + } + }; + + /** + * This variable is initialized when the above part listener is called and + * so when the dummy editor is activated. + */ + private Session sessionOfDummyEditor; + + /** * The icon in the outline displayed when labels are shown (not hidden). */ protected Image shownImage; @@ -124,6 +187,8 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena if (traceMarker != null) { traceMarker.delete(); } + sessionOfDummyEditor = null; + defaultEditorPartListener = null; } /** @@ -176,10 +241,22 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena } /** - * Ensure that after closing a representation editor having validation - * errors, it can be reopened using an error marker from the Problem view. + * Ensure that after closing a representation editor (with refresh at + * opening) having validation errors, it can be reopened using an error + * marker from the Problem view. + */ + public void testTraceabilityWithNoOpenedRepresentationsWithRefreshAtOpening() { + changeSiriusUIPreference(org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys.PREF_REFRESH_ON_REPRESENTATION_OPENING.name(), true); + processEditorOpeningFromMarker(false); + } + + /** + * Ensure that after closing a representation editor (without refresh at + * opening) having validation errors, it can be reopened using an error + * marker from the Problem view. */ - public void testTraceabilityWithNoOpenedRepresentations() { + public void testTraceabilityWithNoOpenedRepresentationsWithoutRefreshAtOpening() { + changeSiriusUIPreference(org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys.PREF_REFRESH_ON_REPRESENTATION_OPENING.name(), false); processEditorOpeningFromMarker(false); } @@ -205,6 +282,15 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena editor.close(); SWTBotUtils.waitAllUiEvents(); + // Make a semantic change that implies a change at the next + // diagram refresh (at opening in this case) + TransactionalEditingDomain ted = localSession.getOpenedSession().getTransactionalEditingDomain(); + URI uri = URI.createURI("platform:/resource/DesignerTestProject/vp1038.ecore#//p3"); + semanticElementForTraceability = ted.getResourceSet().getEObject(uri, true); + ted.getCommandStack().execute(RemoveCommand.create(ted, semanticElementForTraceability)); + localSession.getOpenedSession().save(new NullProgressMonitor()); + bot.waitUntil(new SessionSavedCondition(localSession.getOpenedSession())); + if (fromClosedSession) { // Close session SessionClosedCondition sessionClosedCondition = new SessionClosedCondition(localSession.getOpenedSession()); @@ -217,15 +303,26 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena problemsView.setFocus(); SWTBotTree problemsTree = problemsView.bot().tree(); problemsTree.getTreeItem("Errors (3 items)").expand(); - - // Reopen the editor using a marker created during the validation final SWTBotTreeItem node = problemsTree.getTreeItem("Errors (3 items)").getNode("The namespace URI '' is not well formed"); node.select(); - // Double click the error marker to reopen the diagram Assert.assertFalse("An error happened before opening an editor using an error marker: " + getErrorLoggersMessage(), doesAnErrorOccurs()); - node.doubleClick(); - Assert.assertFalse("An error happened on opening of an editor using an error marker: " + getErrorLoggersMessage(), doesAnErrorOccurs()); + // Add a listener to detect the dummy editor opened after the goto + // marker + EclipseUIUtil.getActivePage().addPartListener(defaultEditorPartListener); + try { + // Double click the error marker to reopen the diagram + node.doubleClick(); + Assert.assertFalse("An error happened on opening of an editor using an error marker: " + getErrorLoggersMessage(), doesAnErrorOccurs()); + IEditorPart currentEditor = EclipseUIUtil.getActiveEditor(); + assertTrue("The current editor, opened through a GoTo marker must have a SessionEditorInput as editor input", currentEditor.getEditorInput() instanceof SessionEditorInput); + if (sessionOfDummyEditor != null) { + assertEquals("The session of the editor, opened through a GoTo marker, must be the same as the dummy editor, temporarly opened to correctly resolve the GoTo marker.", + sessionOfDummyEditor, ((SessionEditorInput) currentEditor.getEditorInput()).getSession()); + } + } finally { + EclipseUIUtil.getActivePage().removePartListener(defaultEditorPartListener); + } } /** @@ -258,10 +355,10 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena public void testTraceabilityWhenGoToMarkerIsCalledOnAllOpenedEditors() { setUpMarker(REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram", "platform:/resource/DesignerTestProject/vp1038.ecore#//p1/A"); - final SWTBotSiriusDiagramEditor emptyDiagramEditor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram2", + openRepresentation(localSession.getOpenedSession(), REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram2", DDiagram.class); - final SWTBotSiriusDiagramEditor emptyDiagramEditor3 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram3", + openRepresentation(localSession.getOpenedSession(), REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram3", DDiagram.class); callGoToMarkerOnAllOpenedEditors(traceMarker); @@ -332,6 +429,7 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena * * @return a shadow marker simulating Traceability behavior * @throws CoreException + * In case of marker problem */ protected IMarker createShadowTraceabilityMarker() throws CoreException { 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 86fd85b7ec..e662703f5e 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES 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 @@ -13,7 +13,6 @@ package org.eclipse.sirius.ui.business.api.session; import java.lang.ref.WeakReference; import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -26,7 +25,6 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; -import org.eclipse.sirius.business.api.session.factory.SessionFactory; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.provider.Messages; @@ -59,7 +57,7 @@ public class SessionEditorInput extends URIEditorInput { private WeakReference<EObject> inputRef; - private IStatus status = Status.OK_STATUS; + private IStatus status; private URI repDescURI; @@ -261,23 +259,8 @@ public class SessionEditorInput extends URIEditorInput { // previously closed session. if (sessionFromURI == null && restore) { status = Status.OK_STATUS; - sessionFromURI = SessionManager.INSTANCE.openSession(sessionModelURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback()); - } - - 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); - } - if (uiSession != null && !uiSession.isOpen()) { - uiSession.open(); - } } + sessionFromURI = openSession(sessionModelURI, restore, sessionFromURI); } catch (OperationCanceledException e) { sessionFromURI = null; status = new Status(IStatus.CANCEL, SiriusEditPlugin.ID, e.getLocalizedMessage(), e); // $NON-NLS-1$ @@ -294,6 +277,29 @@ public class SessionEditorInput extends URIEditorInput { return sessionFromURI; } + private static Session openSession(URI sessionModelURI, boolean restore, Session sessionFromURI) { + Session session = sessionFromURI; + if (session == null && restore) { + session = SessionManager.INSTANCE.openSession(sessionModelURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback()); + } + + if (session != null && session.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(session); + if (uiSession == null && restore) { + uiSession = SessionUIManager.INSTANCE.getOrCreateUISession(session); + } + if (uiSession != null && !uiSession.isOpen()) { + uiSession.open(); + } + } + return session; + } + @Override protected String getBundleSymbolicName() { return SiriusEditPlugin.getPlugin().getSymbolicName(); @@ -314,11 +320,10 @@ public class SessionEditorInput extends URIEditorInput { * @since 0.9.0 */ public static SessionEditorInput create(final URI sessionResourceURI) { - Session session; - try { - session = SessionFactory.INSTANCE.createSession(sessionResourceURI, new NullProgressMonitor()); - } catch (CoreException e) { - return null; + // Use the existing session if there is one + Session session = SessionManager.INSTANCE.getExistingSession(sessionResourceURI); + if (session == null) { + session = SessionEditorInput.openSession(sessionResourceURI, true, null); } return new SessionEditorInput(sessionResourceURI, Messages.SessionEditorInput_defaultEditorName, session); } @@ -389,6 +394,9 @@ public class SessionEditorInput extends URIEditorInput { * @return the status of the session opening, null is never returned */ public IStatus getStatus() { + if (status == null) { + status = Status.OK_STATUS; + } return status; } @@ -421,7 +429,7 @@ public class SessionEditorInput extends URIEditorInput { if (equals && o instanceof SessionEditorInput) { SessionEditorInput otherSessionEditorInput = (SessionEditorInput) o; IStatus otherStatus = otherSessionEditorInput.getStatus(); - if (status != otherStatus) { + if (getStatus() != otherStatus) { equals = false; } else { EObject input = getInput(false); |
