diff options
| author | Esteban Dugueperoux | 2015-07-02 08:22:55 +0000 |
|---|---|---|
| committer | Esteban Dugueperoux | 2015-07-08 08:29:26 +0000 |
| commit | 3654fcc127fdc08cc639aa6cb58985c14d137da3 (patch) | |
| tree | ed84f194542a251d8ad21836a0b9bf167a337bde | |
| parent | 0820dd70e7bd9757787d3df2bdb1965f4c010e13 (diff) | |
| download | org.eclipse.sirius-3654fcc127fdc08cc639aa6cb58985c14d137da3.tar.gz org.eclipse.sirius-3654fcc127fdc08cc639aa6cb58985c14d137da3.tar.xz org.eclipse.sirius-3654fcc127fdc08cc639aa6cb58985c14d137da3.zip | |
[471456] Have SessionEditorInput override URIEditorInput.equals()
- Have SessionEditorInput override URIEditorInput.equals() to not open
Sirius editor which don't corresponds to a specified DRepresentation
when using xpath based URI fragment.
- Update also SiriusMatchingStrategy to leave responsibility of
IEditorInput matching test to IEditorInput.equals() method.
- Deprecate SessionEditorInput.dispose() as a IEditorInput can be reused
by
several IEditorPart instance with the NavigationHistory feature. To
avoid memory leak on SessionEditorInput fields, we use WeakReference.
- Update Release Notes about SessionEditorInput.getInput()/dispose()
methods.
- Add SessionEditorInputTests.
- Avoid "One modeling project is invalid" message with
SaveWhenNoEditorsTests.
- Avoid NPE on VisibilityPostCommitListener asyncExec with
EntitiesDiagramHideRevealTests.
Bug: 471456
Change-Id: Iaff308d54cfb76f77e47c3f09d3cb3fecaf1cbca
Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
12 files changed, 260 insertions, 164 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusMatchingStrategy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusMatchingStrategy.java index 11a4163a4e..9b8f552cd0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusMatchingStrategy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusMatchingStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -25,6 +25,7 @@ public class SiriusMatchingStrategy implements IEditorMatchingStrategy { /** * @was-generated */ + @Override public boolean matches(IEditorReference editorRef, IEditorInput input) { IEditorInput editorInput; try { @@ -39,13 +40,8 @@ public class SiriusMatchingStrategy implements IEditorMatchingStrategy { if (editorInput.equals(input)) { return true; } - if (editorInput instanceof URIEditorInput && input instanceof URIEditorInput) { - return ((URIEditorInput) editorInput).getURI().equals(((URIEditorInput) input).getURI()); - } + // Manage FileEditorInput to support Sirius editor opening from a marker if (input instanceof FileEditorInput && editorInput instanceof URIEditorInput) { - // Check if the file is the same - // CDO Bridge for Sirius : uriEditorPath can be null, - // as the URI is a cdo URI String uriEditorInputPath = ((URIEditorInput) editorInput).getURI().toPlatformString(false); String fileEditorInputPath = ((FileEditorInput) input).getFile().getFullPath().toString(); return ((uriEditorInputPath != null) && (fileEditorInputPath != null) && (uriEditorInputPath.equals(fileEditorInputPath))); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java index 3689530f2b..2e33159c20 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java @@ -470,6 +470,9 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE } private IEditorInput getCorrectedInput(IEditorInput input) { + // input is a FileEditorInput in case editor is opened from a marker + // then we don't have yet uriFragment to gmf Diagram, we will get it + // when gotoMarker() method will be called if (input instanceof FileEditorInput) { IFile file = ((FileEditorInput) input).getFile(); URI analysisURI = URI.createPlatformResourceURI("/" + file.getProject().getName() + "/" + file.getProjectRelativePath(), true); @@ -740,12 +743,6 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE } sGViewer = null; } - - // Dispose the session editor input to keep the minimum information to - // be restore from the INavigationHistory and EditorHistory. - if (getEditorInput() instanceof SessionEditorInput) { - ((SessionEditorInput) getEditorInput()).dispose(); - } IUndoContext savedUndoContext = getUndoContext(); // to avoid dispose of current session related IUndoeableOperation setUndoContext(new UndoContext()); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/marker/SiriusMarkerNavigationProviderSpec.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/marker/SiriusMarkerNavigationProviderSpec.java index 9eca37f988..820ad00467 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/marker/SiriusMarkerNavigationProviderSpec.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/marker/SiriusMarkerNavigationProviderSpec.java @@ -27,6 +27,7 @@ import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DSemanticDiagram; import org.eclipse.sirius.diagram.DiagramPlugin; +import org.eclipse.sirius.diagram.business.api.query.EObjectQuery; import org.eclipse.sirius.diagram.ui.internal.providers.SiriusMarkerNavigationProvider; import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditor; import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditorUtil; @@ -34,6 +35,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; import org.eclipse.sirius.diagram.ui.tools.internal.resource.NavigationMarkerConstants; import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob; import org.eclipse.sirius.viewpoint.description.validation.ValidationRule; import org.eclipse.ui.IEditorReference; @@ -94,12 +96,19 @@ public class SiriusMarkerNavigationProviderSpec extends SiriusMarkerNavigationPr if (defaultEditor.getDiagram().equals(markerDiagram)) { targetEditor = defaultEditor; } else { - final URIEditorInput editorInput = new URIEditorInput(markerDiagramURI, SiriusMarkerNavigationProviderSpec.resolveSemanticElement(markerDiagram).getName()); + URIEditorInput editorInput = null; + String editorName = SiriusMarkerNavigationProviderSpec.resolveSemanticElement(markerDiagram).getName(); + Session session = new EObjectQuery(markerDiagram).getSession(); + if (session != null) { + editorInput = new SessionEditorInput(markerDiagramURI, editorName, session); + } else { + editorInput = new URIEditorInput(markerDiagramURI, editorName); + } final SiriusDiagramEditor searchEditor = searchEditor(editorInput); if (searchEditor != null) { targetEditor = searchEditor; } else { - Session session = getOrOpenTargetSession(sessionResourceUri); + session = getOrOpenTargetSession(sessionResourceUri); // Open the corresponding editor SiriusDiagramEditor openedEditor = null; @@ -137,8 +146,8 @@ public class SiriusMarkerNavigationProviderSpec extends SiriusMarkerNavigationPr } /** - * Search a {@link SiriusDiagramEditor} with the <code>editorInput</code> - * in the opened editors. + * Search a {@link SiriusDiagramEditor} with the <code>editorInput</code> in + * the opened editors. * * @param editorInput * The editorInput to find. @@ -183,7 +192,8 @@ public class SiriusMarkerNavigationProviderSpec extends SiriusMarkerNavigationPr * defined by the platform. * @return The added marker. */ - public static IMarker addMarker(final IFile file, final String elementId, final String diagramURI, final String semanticURI, final String location, final String message, final int statusSeverity) { + public static IMarker addMarker(final IFile file, final String elementId, final String diagramURI, final String semanticURI, final String location, final String message, + final int statusSeverity) { final IMarker marker = SiriusMarkerNavigationProvider.addMarker(file, elementId, location, message, statusSeverity); try { marker.setAttribute(NavigationMarkerConstants.DIAGRAM_URI, diagramURI); diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 2c9cc4b88d..1b284b1185 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -93,6 +93,20 @@ <code>IUndoableCommand</code> because useless since undo/redo is managed by EMF Transaction. </li> </ul> + <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <code>org.eclipse.sirius.ui</code> + </h4> + <ul> + <li> + <code>org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()</code> method has been deprecated as a + <code>IEditorInput</code> can be reused by several instances of + <code>IEditorPart</code> through the navigation history view. + </li> + <li> + <code>org.eclipse.sirius.ui.business.api.session.SessionEditorInput.getInput()</code> method has been added to get the real input for a + <code>DRepresentation</code>. + </li> + </ul> <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support">Changes in <code>org.eclipse.sirius.tests.swtbot.support</code> </h4> @@ -556,7 +570,7 @@ <code>org.eclipse.sirius.viewpoint.DContainer</code> has been removed. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1206,7 +1220,7 @@ <code>org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter</code>. However considering the way Sirius uses GMF, this adapter is not needed. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1494,4 +1508,4 @@ </li> </ul> </body> -</html> +</html>
\ No newline at end of file diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index c651e7772c..be0321a27b 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -23,6 +23,11 @@ h4. Changes in @org.eclipse.sirius@ * @org.eclipse.sirius.tools.api.command.IUndoableCommand@ interface removed because it is useless since undo/redo is managed by EMF Transaction. * @org.eclipse.sirius.tools.api.command.DCommand@ no more inherits of @IUndoableCommand@ because useless since undo/redo is managed by EMF Transaction. +h4. Changes in @org.eclipse.sirius.ui@ + +* @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.dispose()@ method has been deprecated as a @IEditorInput@ can be reused by several instances of @IEditorPart@ through the navigation history view. +* @org.eclipse.sirius.ui.business.api.session.SessionEditorInput.getInput()@ method has been added to get the real input for a @DRepresentation@. + h4. Changes in @org.eclipse.sirius.tests.swtbot.support@ * <span class="label label-success">Added</span> The methods @closePerspective(String)@, @closeSiriusPerspective()@ and @closeModelingPerspective()@ have been added in class @org.eclipse.sirius.tests.swtbot.support.api.perspective.DesignerPerspectives@ to allow the closing of perspectives. diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java index b91555f588..76bbfa5a5b 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java @@ -41,6 +41,7 @@ import org.eclipse.sirius.tests.unit.api.session.DAnalysisSessionTests; import org.eclipse.sirius.tests.unit.api.session.OpenSessionTest; import org.eclipse.sirius.tests.unit.api.session.ReloadSessionTest; import org.eclipse.sirius.tests.unit.api.session.SampleSessionTest; +import org.eclipse.sirius.tests.unit.api.session.SessionEditorInputTests; import org.eclipse.sirius.tests.unit.api.session.SessionManagerListener2Tests; import org.eclipse.sirius.tests.unit.api.session.SessionSemanticResourceTests; import org.eclipse.sirius.tests.unit.api.session.SessionServiceTest; @@ -226,6 +227,7 @@ public class AllCommonPluginTests extends TestCase { suite.addTestSuite(DAnalysisSessionTests.class); suite.addTestSuite(SampleSessionTest.class); + suite.addTestSuite(SessionEditorInputTests.class); suite.addTestSuite(SiriusRegistryTests.class); suite.addTestSuite(SiriusRegistryListener2Tests.class); suite.addTestSuite(SessionSemanticResourceTests.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/modelingproject/SaveWhenNoEditorsTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/modelingproject/SaveWhenNoEditorsTests.java index 00c4745b2d..1de9c4f7ed 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/modelingproject/SaveWhenNoEditorsTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/modelingproject/SaveWhenNoEditorsTests.java @@ -47,7 +47,6 @@ public class SaveWhenNoEditorsTests extends SiriusDiagramTestCase implements Eco @Override protected void setUp() throws Exception { - super.createModelingProject = true; super.setUp(); changePlatformUIPreference(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN, true); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionEditorInputTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionEditorInputTests.java new file mode 100644 index 0000000000..dad2f38b95 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionEditorInputTests.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.api.session; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.command.MoveCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; +import org.eclipse.sirius.business.api.dialect.DialectManager; +import org.eclipse.sirius.business.api.dialect.command.CopyRepresentationCommand; +import org.eclipse.sirius.business.api.query.URIQuery; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.api.session.factory.SessionFactory; +import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.tools.api.command.semantic.AddSemanticResourceCommand; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.ui.business.api.viewpoint.ViewpointSelectionCallback; +import org.eclipse.sirius.ui.business.internal.commands.ChangeViewpointSelectionCommand; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DView; +import org.eclipse.sirius.viewpoint.ViewpointPackage; +import org.eclipse.sirius.viewpoint.description.Viewpoint; +import org.eclipse.ui.IEditorPart; + +import junit.framework.TestCase; + +/** + * Tests about https://bugs.eclipse.org/bugs/show_bug.cgi?id=471456. + * + * @author <a href="mailto:esteban.dugueperoux@obeo.fr">Esteban Dugueperoux</a> + */ +public class SessionEditorInputTests extends TestCase { + + private static final String TEMPORARY_PROJECT_NAME = "DesignerTestProject"; + + private static final String SESSION_MODEL_FILENAME = "My.aird"; + + private static final String SEMANTIC_MODEL_FILENAME = "My.ecore"; + + private Session session; + + private DView dView; + + private DRepresentation dRepresentation1; + + private DRepresentation dRepresentation2; + + @Override + public void setUp() throws Exception { + super.setUp(); + URI sessionResourceURI = URI.createURI(URIQuery.INMEMORY_URI_SCHEME + ":/" + TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_FILENAME); + session = SessionFactory.INSTANCE.createSession(sessionResourceURI, new NullProgressMonitor()); + session.open(new NullProgressMonitor()); + URI semanticResourceURI = URI.createURI(URIQuery.INMEMORY_URI_SCHEME + ":/" + TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME); + Resource semanticResource = new ResourceSetImpl().createResource(semanticResourceURI); + semanticResource.getContents().add(EcoreFactory.eINSTANCE.createEPackage()); + semanticResource.save(Collections.emptyMap()); + Command addSemanticResourceCmd = new AddSemanticResourceCommand(session, semanticResourceURI, new NullProgressMonitor()); + TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); + CommandStack commandStack = domain.getCommandStack(); + commandStack.execute(addSemanticResourceCmd); + URI designViewpointURI = URI.createURI("viewpoint:/org.eclipse.sirius.sample.ecore.design/Design"); + Viewpoint viewpoint = ViewpointRegistry.getInstance().getViewpoint(designViewpointURI); + viewpoint = (Viewpoint) session.getTransactionalEditingDomain().getResourceSet().getEObject(EcoreUtil.getURI(viewpoint), true); + commandStack.execute( + new ChangeViewpointSelectionCommand(session, new ViewpointSelectionCallback(), Collections.singleton(viewpoint), Collections.<Viewpoint> emptySet(), new NullProgressMonitor())); + Collection<DRepresentation> allRepresentations = DialectManager.INSTANCE.getAllRepresentations(session); + commandStack.execute(new CopyRepresentationCommand(domain, allRepresentations, "copy", session)); + DAnalysis dAnalysis = (DAnalysis) session.getSessionResource().getContents().get(0); + dView = dAnalysis.getOwnedViews().get(0); + dRepresentation1 = dView.getOwnedRepresentations().get(0); + dRepresentation2 = dView.getOwnedRepresentations().get(1); + session.save(new NullProgressMonitor()); + } + + /** + * Test that opening a {@link DRepresentation} whose {@link URI} has changed + * to be same a already opened {@link DRepresentation} doesn't open the + * already opened {@link DRepresentation} but a new editor for the requested + * {@link DRepresentation}. + */ + public void testSessionEditorInputWithInputURIChange() { + IEditorPart editor1 = DialectUIManager.INSTANCE.openEditor(session, dRepresentation1, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + IEditorPart editor2 = DialectUIManager.INSTANCE.openEditor(session, dRepresentation2, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + assertEquals(2, EclipseUIUtil.getActivePage().getEditorReferences().length); + DialectUIManager.INSTANCE.closeEditor(editor1, false); + TestsUtil.synchronizationWithUIThread(); + assertEquals(1, EclipseUIUtil.getActivePage().getEditorReferences().length); + // Change URI of DRepresentations by changing order as uriFragments are + // xpath based + URI dRepresentation1URI = EcoreUtil.getURI(dRepresentation1); + URI dRepresentation2URI = EcoreUtil.getURI(dRepresentation2); + Command moveCmd = MoveCommand.create(session.getTransactionalEditingDomain(), dView, ViewpointPackage.Literals.DVIEW__OWNED_REPRESENTATIONS, dRepresentation2, 0); + session.getTransactionalEditingDomain().getCommandStack().execute(moveCmd); + String assertMessage = "DRepresentation's URI should have changed as they are stored in a InMemoryResourceImpl with xpath based uriFragment"; + assertEquals(assertMessage, dRepresentation1URI, EcoreUtil.getURI(dRepresentation2)); + assertEquals(assertMessage, dRepresentation2URI, EcoreUtil.getURI(dRepresentation1)); + IEditorPart newEditor = DialectUIManager.INSTANCE.openEditor(session, dRepresentation1, new NullProgressMonitor()); + assertNotSame(editor1, newEditor); + assertEquals("Editor for representation1 should be opened", 2, EclipseUIUtil.getActivePage().getEditorReferences().length); + DialectUIManager.INSTANCE.closeEditor(editor1, false); + DialectUIManager.INSTANCE.closeEditor(editor2, false); + TestsUtil.synchronizationWithUIThread(); + } + + @Override + public void tearDown() throws Exception { + dRepresentation2 = null; + dRepresentation1 = null; + dView = null; + session.close(new NullProgressMonitor()); + session = null; + super.tearDown(); + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/EntitiesDiagramHideRevealTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/EntitiesDiagramHideRevealTests.java index 8a2c0c6454..f3da8cc8ea 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/EntitiesDiagramHideRevealTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/EntitiesDiagramHideRevealTests.java @@ -39,7 +39,6 @@ import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper; import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.tests.unit.diagram.modeler.ecore.EcoreModeler; -import org.eclipse.sirius.tools.api.command.SiriusCommand; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.ui.IEditorPart; @@ -424,7 +423,7 @@ public class EntitiesDiagramHideRevealTests extends SiriusDiagramTestCase implem * the new visibility for this element */ protected void changeDiagramElementVisiblity(final DDiagramElement element, final boolean newVisibility) { - session.getTransactionalEditingDomain().getCommandStack().execute(new SiriusCommand(session.getTransactionalEditingDomain()) { + session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) { @Override protected void doExecute() { if (newVisibility) { @@ -434,6 +433,7 @@ public class EntitiesDiagramHideRevealTests extends SiriusDiagramTestCase implem } } }); + TestsUtil.synchronizationWithUIThread(); } private int getNbVisibleDiagramElements(final DDiagram diagram) { 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 703c78cd17..55abd31708 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 @@ -10,6 +10,8 @@ *******************************************************************************/ 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.NullProgressMonitor; @@ -17,6 +19,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.emf.common.EMFPlugin; import org.eclipse.emf.common.ui.URIEditorInput; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; @@ -45,7 +48,7 @@ public class SessionEditorInput extends URIEditorInput { */ private static final String DEFAULT_EDITOR_NAME = "Representation"; - private Session session; + private WeakReference<Session> sessionRef; /** * add a name field to override the {@link URIEditorInput} one's with @@ -55,6 +58,8 @@ public class SessionEditorInput extends URIEditorInput { private URI sessionResourceURI; + private WeakReference<EObject> inputRef; + /** * Create a new SessionEditorInput with the current session and ui session. * @@ -68,7 +73,7 @@ public class SessionEditorInput extends URIEditorInput { public SessionEditorInput(final URI uri, final String name, final Session session) { super(uri, name); this.name = name; - this.session = session; + this.sessionRef = new WeakReference<Session>(session); if (session.getSessionResource() != null) { this.sessionResourceURI = session.getSessionResource().getURI(); } @@ -91,23 +96,38 @@ public class SessionEditorInput extends URIEditorInput { * @return the model editing session. */ public Session getSession() { + Session session = sessionRef != null ? sessionRef.get() : null; if (session == null) { - // It will probably be clean during the dispose, so recreate it from - // URI. URI sessionModelURI = getURI().trimFragment(); if (sessionResourceURI != null) { sessionModelURI = sessionResourceURI; } session = getSession(sessionModelURI); + if (session != null) { + this.sessionRef = new WeakReference<Session>(session); + } } return session; } /** - * {@inheritDoc} + * Get the input of this editor input. * - * @see org.eclipse.emf.common.ui.URIEditorInput#getName() + * @return the input of this editor input */ + public EObject getInput() { + EObject input = inputRef != null ? inputRef.get() : null; + if (input == null) { + if (getSession() != null && getSession().isOpen() && getURI().hasFragment()) { + input = getSession().getTransactionalEditingDomain().getResourceSet().getEObject(getURI(), false); + if (input != null) { + inputRef = new WeakReference<EObject>(input); + } + } + } + return input; + } + @Override public String getName() { return name == null ? super.getName() : name; @@ -121,9 +141,6 @@ public class SessionEditorInput extends URIEditorInput { this.name = string; } - /** - * {@inheritDoc} - */ @Override public void saveState(final IMemento memento) { super.saveState(memento); @@ -134,9 +151,6 @@ public class SessionEditorInput extends URIEditorInput { } } - /** - * {@inheritDoc} - */ @Override protected void loadState(final IMemento memento) { super.loadState(memento); @@ -144,7 +158,10 @@ public class SessionEditorInput extends URIEditorInput { final String sessionResourceURIString = memento.getString(SESSION_RESOURCE_URI); if (sessionResourceURIString != null) { sessionResourceURI = URI.createURI(sessionResourceURIString); - session = getSession(sessionResourceURI); + Session newSession = getSession(sessionResourceURI); + if (newSession != null) { + this.sessionRef = new WeakReference<Session>(newSession); + } } } @@ -172,7 +189,7 @@ public class SessionEditorInput extends URIEditorInput { sessionFromURI = null; // Silent catch: can happen if failing to retrieve the session from // its URI - } catch (OperationCanceledException e) { + } catch (OperationCanceledException e) { sessionFromURI = null; // Silent catch: can happen if failing to retrieve the session from // its URI @@ -180,17 +197,11 @@ public class SessionEditorInput extends URIEditorInput { return sessionFromURI; } - /** - * {@inheritDoc} - */ @Override protected String getBundleSymbolicName() { return SiriusEditPlugin.getPlugin().getSymbolicName(); } - /** - * {@inheritDoc} - */ @Override public String getFactoryId() { return SessionEditorInputFactory.ID; @@ -201,7 +212,7 @@ public class SessionEditorInput extends URIEditorInput { * * @param sessionResourceURI * a session Resource URI. - * @return a new Sessioneditorinput. + * @return a new SessionEditorinput. * * @since 0.9.0 */ @@ -215,9 +226,6 @@ public class SessionEditorInput extends URIEditorInput { return new SessionEditorInput(sessionResourceURI, DEFAULT_EDITOR_NAME, session); } - /** - * {@inheritDoc} - */ @Override public String getToolTipText() { return getURI().trimFragment().toString() + "/" + getName(); @@ -230,9 +238,13 @@ public class SessionEditorInput extends URIEditorInput { * org.eclipse.ui.internal.EditorHistory. This method must not be called by * client, it is automatically called by the dispose of * {@link DDiagramEditor}. + * + * @deprecated since a {@link org.eclipse.ui.IEditorInput} can be reused by + * several instances of {@link org.eclipse.ui.IEditorPart} + * through the navigation history view. */ + @Deprecated public void dispose() { - session = null; } /** @@ -249,9 +261,9 @@ public class SessionEditorInput extends URIEditorInput { @Override public boolean exists() { boolean exists = super.exists(); - if (!exists && session != null) { + if (!exists && getSession() != null) { URI resourceURI = getURI().trimFragment(); - for (Resource resource : session.getAllSessionResources()) { + for (Resource resource : getSession().getAllSessionResources()) { if (resource.getURI().equals(resourceURI)) { exists = true; break; @@ -275,4 +287,20 @@ public class SessionEditorInput extends URIEditorInput { return a; } + @Override + public int hashCode() { + if (getInput() != null) { + return getInput().hashCode(); + } + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof SessionEditorInput && getInput() != null) { + SessionEditorInput otherSessionEditorInput = (SessionEditorInput) o; + return getInput().equals(otherSessionEditorInput.getInput()); + } + return super.equals(o); + } } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionSpecificEditorInput.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionSpecificEditorInput.java index 40ef5c693f..3cd2545dc7 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionSpecificEditorInput.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionSpecificEditorInput.java @@ -88,11 +88,6 @@ public class SessionSpecificEditorInput extends SessionEditorInput { this.myRepresentationDescriptionName = representationDescriptionName; } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.ui.business.api.session.SessionEditorInput#saveState(org.eclipse.ui.IMemento) - */ @Override public void saveState(IMemento memento) { super.saveState(memento); @@ -107,23 +102,12 @@ public class SessionSpecificEditorInput extends SessionEditorInput { } } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.ui.business.api.session.SessionEditorInput#loadState(org.eclipse.ui.IMemento) - */ @Override protected void loadState(IMemento memento) { super.loadState(memento); restoreValuesFromMemento(memento); } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.ui.business.api.session.SessionEditorInput#getSession(org.eclipse.emf.transaction.TransactionalEditingDomain, - * org.eclipse.ui.IMemento, org.eclipse.emf.common.util.URI) - */ @Override protected Session getSession(URI sessionModelURI) { final URI uriWithoutFragment = sessionModelURI.trimFragment(); @@ -131,17 +115,21 @@ public class SessionSpecificEditorInput extends SessionEditorInput { } private Session createSessionFromURIAndMemento(final URI uri) { + Session session = null; SpecificEditorInputTranformer tranformer = new SpecificEditorInputTranformer(); tranformer.init(mySiriusURI, myRepresentationDescriptionName); try { - final DRepresentation representation = tranformer.createSessionAndRepresentation(mySemanticModelPath, uri.toString()); - return SessionManager.INSTANCE.getSession(((DSemanticDecorator) representation).getTarget()); + session = SessionManager.INSTANCE.getExistingSession(uri); + if (session == null) { + final DRepresentation representation = tranformer.createSessionAndRepresentation(mySemanticModelPath, uri.toString()); + session = SessionManager.INSTANCE.getSession(((DSemanticDecorator) representation).getTarget()); + } } catch (final IOException exception) { SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, "Failing of EditorInput transformation.", exception)); } catch (CoreException exception) { SiriusEditPlugin.getPlugin().getLog().log(exception.getStatus()); } - return null; + return session; } private void restoreValuesFromMemento(final IMemento memento) { diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java index 2ae520603d..f3aa7df8ee 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2015 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 @@ -49,7 +49,6 @@ import org.eclipse.sirius.tools.api.permission.DRepresentationPermissionStatusQu import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; import org.eclipse.sirius.ui.business.api.dialect.DialectEditorDialogFactory; import org.eclipse.sirius.ui.business.api.session.IEditingSession; -import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.ui.business.api.session.SessionUIManager; import org.eclipse.sirius.ui.business.internal.dialect.TreeEditorDialogFactory; import org.eclipse.sirius.ui.tools.api.properties.DTablePropertySheetpage; @@ -234,7 +233,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE } /** - * Lasily gets the image when there is no write permission of the + * Lazily gets the image when there is no write permission of the * DRepresentation. * * @return the image when there is no write permission of the @@ -254,6 +253,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE */ public abstract Image getFrozenRepresentationImage(); + @Override public TransactionalEditingDomain getEditingDomain() { return session.getTransactionalEditingDomain(); } @@ -354,29 +354,17 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE } } - /** - * - * {@inheritDoc} - */ @Override public boolean isDirty() { final boolean dirty = this.session.getStatus() == SessionStatus.DIRTY; return dirty; } - /** - * - * {@inheritDoc} - */ @Override public boolean isSaveAsAllowed() { return false; } - /** - * - * {@inheritDoc} - */ @Override public void setFocus() { if (treeViewerManager != null) { @@ -421,11 +409,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return editorDesc; } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectEditor#needsRefresh(int) - */ + @Override public boolean needsRefresh(int propId) { boolean result = false; if (propId == DialectEditor.PROP_REFRESH) { @@ -443,11 +427,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE */ protected abstract void launchRefresh(); - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class) - */ @Override public Object getAdapter(@SuppressWarnings("rawtypes") final Class type) { Object result = super.getAdapter(type); @@ -471,11 +450,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE } } - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.ui.viewer.IViewerProvider#getViewer() - */ + @Override public Viewer getViewer() { Viewer viewer = null; if (treeViewerManager != null) { @@ -497,11 +472,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return accessor; } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.WorkbenchPart#dispose() - */ @Override public void dispose() { @@ -521,12 +491,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE if (getTableViewer() != null) { getTableViewer().dispose(); } - // Dispose the session editor input to keep the minimum information to - // be restore from the INavigationHistory and EditorHistory. - if (getEditorInput() instanceof SessionEditorInput) { - ((SessionEditorInput) getEditorInput()).dispose(); - } - // We need to perform the detachEditor after having disposed the viewer // and the editor input to avoid a refresh. A refresh can occurs in the // case where the detach triggers the reload of the modified resources @@ -541,11 +505,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) - */ @Override public void setInput(final IEditorInput input) { super.setInput(input); @@ -599,9 +558,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return propertiesUpdateEnabled; } - /** - * {@inheritDoc} - */ + @Override public void notify(final int changeKind) { AbstractDTreeEditorSessionListenerDelegate abstractDTreeEditorSessionListenerDelegate = new AbstractDTreeEditorSessionListenerDelegate(this, changeKind); if (Display.getCurrent() == null) { @@ -640,11 +597,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return SessionUIManager.INSTANCE.getUISession(session); } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.EditorPart#isSaveOnCloseNeeded() - */ @Override public boolean isSaveOnCloseNeeded() { /* @@ -669,20 +621,12 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return autoRefresh; } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.ui.business.api.dialect.DialectEditor#setDialogFactory(org.eclipse.sirius.ui.business.api.dialect.DialectEditorDialogFactory) - */ + @Override public void setDialogFactory(DialectEditorDialogFactory dialogFactory) { myDialogFactory = dialogFactory; } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.ISaveablesSource#getSaveables() - */ + @Override public Saveable[] getSaveables() { if (session != null && session.isOpen()) { IEditingSession uiSession = getUISession(); @@ -693,20 +637,12 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return new Saveable[0]; } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables() - */ + @Override public Saveable[] getActiveSaveables() { return getSaveables(); } - /** - * {@inheritDoc} - * - * @see ISaveablePart2#promptToSaveOnClose() - */ + @Override public int promptToSaveOnClose() { choice = ISaveablePart2.DEFAULT; if (session != null && session.isOpen()) { @@ -720,11 +656,6 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return choice; } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) - */ @Override public void createPartControl(Composite parent) { // setting up a UndoActionHandler @@ -733,31 +664,19 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE setUpUndoRedoActionHandler(); } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.IPageListener#pageOpened(org.eclipse.ui.IWorkbenchPage) - */ + @Override public void pageOpened(IWorkbenchPage page) { } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.IPageListener#pageActivated(org.eclipse.ui.IWorkbenchPage) - */ + @Override public void pageActivated(IWorkbenchPage page) { // As the page has been activated, we now can create the // UndoRedoActionHandler setUpUndoRedoActionHandler(); } - /** - * {@inheritDoc} - * - * @see org.eclipse.ui.IPageListener#pageClosed(org.eclipse.ui.IWorkbenchPage) - */ + @Override public void pageClosed(IWorkbenchPage page) { } @@ -808,6 +727,7 @@ public abstract class AbstractDTreeEditor extends EditorPart implements DialectE return searchedTreeItem; } + @Override public DialectEditorDialogFactory getDialogFactory() { return myDialogFactory; } |
