diff options
| author | Florian Barbin | 2017-07-18 15:06:52 +0000 |
|---|---|---|
| committer | Florian Barbin | 2017-07-20 13:23:25 +0000 |
| commit | 937506018a1ca8bdf97710cd03be387742454b96 (patch) | |
| tree | 34425f8f37c94bad60bd5a23876f42c29d00de8c | |
| parent | 2fa24434b4640ff352cfa7061e79514c1994799b (diff) | |
| download | org.eclipse.sirius-937506018a1ca8bdf97710cd03be387742454b96.tar.gz org.eclipse.sirius-937506018a1ca8bdf97710cd03be387742454b96.tar.xz org.eclipse.sirius-937506018a1ca8bdf97710cd03be387742454b96.zip | |
[516669] Fixes editor memento when restarting Eclipse.
* When restarting eclipse with Sirius editors opened, The
DRepresentation was loaded using the URIEditorInput, without using the
DRepresentationDescriptor.getRepresentation() method. Bypass this API to
load a representation is not recommended and in that case the
DRepresentationDescriptor#representation feature is not added in the
XRef.
* The SessionEditorInput has now an additional attribute to held the
DRepresentationDescriptor URI.
* Since the SessionEditorInput expected uri value in many places is the
GMF Diagram uri, this commit does not modify the value of this
attribute. Instead, the new attribute repDescURI is used during editor
initialization to retrieve the DRepresentation by using the
DRepresentationDescriptor. This attribute is also saved and loaded in
the IMemento.
* Also fixes the SessionEditorInputTest
Bug: 516669
Change-Id: I7cfd19ad93fa96ba516faaaad0b673c1df19d743
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
11 files changed, 145 insertions, 78 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java index 8feff8df50..9be80390b7 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java @@ -20,6 +20,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.eclipse.core.runtime.CoreException; @@ -57,6 +58,7 @@ import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.SiriusResourceHelper; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.query.EObjectQuery; import org.eclipse.sirius.business.api.query.URIQuery; import org.eclipse.sirius.business.api.session.CustomDataConstants; @@ -198,8 +200,10 @@ public class DiagramDialectUIServices implements DialectUIServices { DialectEditor dialectEditor = null; URI uri = EcoreUtil.getURI(gmfDiag); String editorName = DialectUIManager.INSTANCE.getEditorName(dRepresentation); + DRepresentationQuery query = new DRepresentationQuery(dRepresentation); + URI repDescURI = Optional.ofNullable(query.getRepresentationDescriptor()).map(repDesc -> EcoreUtil.getURI(repDesc)).orElse(null); monitor.worked(1); - final IEditorInput editorInput = new SessionEditorInput(uri, editorName, session); + final IEditorInput editorInput = new SessionEditorInput(uri, repDescURI, editorName, session); monitor.subTask(MessageFormat.format(Messages.DiagramDialectUIServices_diagramEditorOpeningMonitorTaskName, dRepresentation.getName())); RunnableWithResult<DialectEditor> runnable = new RunnableWithResult.Impl<DialectEditor>() { 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 260a325600..a66bcd50ab 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 @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import org.eclipse.core.commands.operations.IOperationHistoryListener; import org.eclipse.core.commands.operations.IUndoContext; @@ -191,6 +192,7 @@ import org.eclipse.sirius.ui.business.api.session.SessionEditorInputFactory; import org.eclipse.sirius.ui.business.api.session.SessionUIManager; import org.eclipse.sirius.ui.tools.internal.editor.SelectDRepresentationElementsListener; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.swt.SWT; @@ -1739,19 +1741,28 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE IEditorInput updatedEditorInput = input; if (session != null && input instanceof URIEditorInput) { URI uri = ((URIEditorInput) input).getURI(); - if (uri != null && !StringUtil.isEmpty(uri.fragment())) { - EObject eObject = session.getTransactionalEditingDomain().getResourceSet().getEObject(uri, false); - if (eObject instanceof DDiagram) { - DDiagram dDiagram = (DDiagram) eObject; - final DiagramCreationUtil util = new DiagramCreationUtil(dDiagram); - if (!util.findAssociatedGMFDiagram()) { - DiagramPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DiagramPlugin.ID, Messages.DDiagramEditorImpl_noAssociatedGMFDiagramMsg)); + URI repDescURI = Optional.of(input).filter(SessionEditorInput.class::isInstance).map(SessionEditorInput.class::cast).map(s -> s.getRepDescUri()).orElse(null); + Optional<DDiagram> dDiagramOptional = Optional.ofNullable(repDescURI).map(rduri -> session.getTransactionalEditingDomain().getResourceSet().getEObject(rduri, false)) + .filter(DRepresentationDescriptor.class::isInstance).map(rd -> ((DRepresentationDescriptor) rd).getRepresentation()).map(DDiagram.class::cast); + DDiagram dDiagram = dDiagramOptional.orElse(null); + + if (dDiagram == null) { + if (uri != null && !StringUtil.isEmpty(uri.fragment())) { + EObject eObject = session.getTransactionalEditingDomain().getResourceSet().getEObject(uri, false); + if (eObject instanceof DDiagram) { + dDiagram = (DDiagram) eObject; } - final Diagram gmfDiag = util.getAssociatedGMFDiagram(); - updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(gmfDiag), dDiagram.getName(), session); - } } + if (dDiagram != null) { + final DiagramCreationUtil util = new DiagramCreationUtil(dDiagram); + if (!util.findAssociatedGMFDiagram()) { + DiagramPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DiagramPlugin.ID, Messages.DDiagramEditorImpl_noAssociatedGMFDiagramMsg)); + } + final Diagram gmfDiag = util.getAssociatedGMFDiagram(); + updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(gmfDiag), repDescURI, dDiagram.getName(), session); + } + } super.setInput(updatedEditorInput); if (getGraphicalViewer() != null) { diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java index 30732bb30d..0a3e7c1267 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/business/internal/dialect/TableDialectUIServices.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Optional; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -33,6 +34,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.DslCommonPlugin; import org.eclipse.sirius.common.tools.api.util.StringUtil; @@ -97,11 +99,13 @@ public class TableDialectUIServices implements DialectUIServices { monitor.beginTask(Messages.TableDialectUIServices_tableOpening, 10); if (dRepresentation instanceof DTable) { DTable dTable = (DTable) dRepresentation; + DRepresentationQuery query = new DRepresentationQuery(dTable); + URI repDescURI = Optional.ofNullable(query.getRepresentationDescriptor()).map(repDesc -> EcoreUtil.getURI(repDesc)).orElse(null); DslCommonPlugin.PROFILER.startWork(SiriusTasksKey.OPEN_TABLE_KEY); final URI uri = EcoreUtil.getURI(dTable); final String editorName = DialectUIManager.INSTANCE.getEditorName(dTable); monitor.worked(2); - final IEditorInput editorInput = new SessionEditorInput(uri, editorName, session); + final IEditorInput editorInput = new SessionEditorInput(uri, repDescURI, editorName, session); final String editorId; if (dTable.getDescription() instanceof EditionTableDescription) { diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java index f31a8c65c1..8057219ec2 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java @@ -15,6 +15,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -62,6 +63,7 @@ import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.ui.tools.internal.editor.AbstractDTableViewerManager; import org.eclipse.sirius.ui.tools.internal.editor.AbstractDTreeEditor; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; @@ -269,10 +271,10 @@ public abstract class AbstractDTableEditor extends AbstractDTreeEditor implement if (session != null) { InterpreterRegistry.prepareImportsFromSession(session.getInterpreter(), session); } - + refreshAtOpeningActivator = new RefreshAtOpeningActivator(session, this); getSite().getPage().addPartListener(refreshAtOpeningActivator); - + // Activate the context for this site. IContextService contextService = getSite().getService(IContextService.class); contextService.activateContext(CONTEXT_ID); @@ -342,7 +344,7 @@ public abstract class AbstractDTableEditor extends AbstractDTreeEditor implement * Get the DTable corresponding to this URI * * @param uri - * the URI to resolve. + * the URI of the {@link DRepresentationDescriptor} to resolve. * @param loadOnDemand * whether to create and load the resource, if it doesn't already exists. * @return the DTable resource resolved by the URI, or <code>null</code> if there isn't one and it's not being @@ -356,6 +358,8 @@ public abstract class AbstractDTableEditor extends AbstractDTreeEditor implement final EObject rootElement = resource.getEObject(uri.fragment()); if (rootElement instanceof DTable) { result = (DTable) rootElement; + } else if (rootElement instanceof DRepresentationDescriptor) { + result = Optional.ofNullable(((DRepresentationDescriptor) rootElement).getRepresentation()).filter(DTable.class::isInstance).map(DTable.class::cast).orElse(null); } } } 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 index b317986d3b..6d9df1c0be 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Obeo. + * Copyright (c) 2015, 2017 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 @@ -26,6 +26,7 @@ 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.DRepresentationQuery; import org.eclipse.sirius.business.api.query.DViewQuery; import org.eclipse.sirius.business.api.query.URIQuery; import org.eclipse.sirius.business.api.session.Session; @@ -41,6 +42,7 @@ 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.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DView; import org.eclipse.sirius.viewpoint.description.Viewpoint; import org.eclipse.ui.IEditorInput; @@ -98,10 +100,9 @@ public class SessionEditorInputTests extends TestCase { } /** - * Test that opening a {@link DRepresentation} whose {@link URI} has changed - * to be same as an already opened {@link DRepresentation} doesn't open the - * already opened {@link DRepresentation} but a new editor for the requested - * {@link DRepresentation}. + * Test that opening a {@link DRepresentation} whose {@link URI} has changed to be same as an 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()); @@ -114,12 +115,18 @@ public class SessionEditorInputTests extends TestCase { assertEquals(1, EclipseUIUtil.getActivePage().getEditorReferences().length); // Change URI of DRepresentations by changing order as uriFragments are // xpath based + DRepresentationQuery query = new DRepresentationQuery(dRepresentation1); + DRepresentationDescriptor descriptor1 = query.getRepresentationDescriptor(); + query = new DRepresentationQuery(dRepresentation2); + DRepresentationDescriptor descriptor2 = query.getRepresentationDescriptor(); URI dRepresentation1URI = EcoreUtil.getURI(dRepresentation1); URI dRepresentation2URI = EcoreUtil.getURI(dRepresentation2); Command moveCmd = new RecordingCommand(session.getTransactionalEditingDomain()) { @Override protected void doExecute() { dView.eResource().getContents().move(1, dRepresentation2); + descriptor1.updateRepresentation(dRepresentation1); + descriptor2.updateRepresentation(dRepresentation2); } }; session.getTransactionalEditingDomain().getCommandStack().execute(moveCmd); diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java index 7090b99a53..62292c0b02 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/business/internal/dialect/TreeDialectUIServices.java @@ -13,6 +13,7 @@ package org.eclipse.sirius.tree.ui.business.internal.dialect; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Optional; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -31,6 +32,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.DslCommonPlugin; import org.eclipse.sirius.common.tools.api.util.StringUtil; @@ -111,7 +113,9 @@ public class TreeDialectUIServices implements DialectUIServices { if (dRepresentation instanceof DTree) { DslCommonPlugin.PROFILER.startWork(SiriusTasksKey.OPEN_TREE_KEY); URI uri = EcoreUtil.getURI(dRepresentation); - final IEditorInput editorInput = new SessionEditorInput(uri, getEditorName(dRepresentation), session); + DRepresentationQuery query = new DRepresentationQuery(dRepresentation); + URI repDescURI = Optional.ofNullable(query.getRepresentationDescriptor()).map(repDesc -> EcoreUtil.getURI(repDesc)).orElse(null); + final IEditorInput editorInput = new SessionEditorInput(uri, repDescURI, getEditorName(dRepresentation), session); monitor.worked(2); monitor.subTask(Messages.TreeDialectUIServices_treeOpening + " : " + dRepresentation.getName()); //$NON-NLS-1$ RunnableWithResult<IEditorPart> runnable = new RunnableWithResult.Impl<IEditorPart>() { diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java index f2cd0d9569..97f3c9995b 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -55,6 +56,7 @@ import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.ui.tools.internal.editor.AbstractDTableViewerManager; import org.eclipse.sirius.ui.tools.internal.editor.AbstractDTreeEditor; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; @@ -225,17 +227,17 @@ public class DTreeEditor extends AbstractDTreeEditor implements org.eclipse.siri treeViewerManager = new DTreeViewerManager(parent, getTreeModel(), getEditingDomain(), accessor, emfCommandFactory, this); // DslCommonPlugin.PROFILER.stopWork(SiriusTasks.CREATE_TREE); getSite().setSelectionProvider(treeViewerManager.getTreeViewer()); - + /* initialize interpreter. */ if (session != null) { InterpreterRegistry.prepareImportsFromSession(session.getInterpreter(), session); } // Add the CreateTreeItem menu of the toolbar ((DTreeActionBarContributor) getEditorSite().getActionBarContributor()).addCreateTreeItemMenu(((DTreeViewerManager) this.getTableViewer()).getCreateTreeItemMenu()); - + refreshAtOpeningActivator = new RefreshAtOpeningActivator(this); getSite().getPage().addPartListener(refreshAtOpeningActivator); - + // Activate context IContextService contextService = getSite().getService(IContextService.class); contextService.activateContext(CONTEXT_ID); @@ -326,6 +328,8 @@ public class DTreeEditor extends AbstractDTreeEditor implements org.eclipse.siri final EObject rootElement = resource.getEObject(uri.fragment()); if (rootElement instanceof DTree) { result = (DTree) rootElement; + } else if (rootElement instanceof DRepresentationDescriptor) { + result = Optional.ofNullable(((DRepresentationDescriptor) rootElement).getRepresentation()).filter(DTree.class::isInstance).map(DTree.class::cast).orElse(null); } } } 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 47615e078b..86fd85b7ec 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, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2017 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 @@ -27,6 +27,8 @@ 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; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.ui.IMemento; @@ -39,17 +41,17 @@ import org.eclipse.ui.IMemento; public class SessionEditorInput extends URIEditorInput { /** - * Constant to store the uri of the main resource of the session. We can't - * use the URI that is already store in the URIEditorInput because it can be - * different in case of fragmentation. + * Constant to store the uri of the main resource of the session. We can't use the URI that is already store in the + * URIEditorInput because it can be different in case of fragmentation. */ private static final String SESSION_RESOURCE_URI = "SESSION_RESOURCE_URI"; //$NON-NLS-1$ + private static final String REP_DESC_URI = "REP_DESC_URI"; //$NON-NLS-1$ + private WeakReference<Session> sessionRef; /** - * add a name field to override the {@link URIEditorInput} one's with - * possibility to update it. + * add a name field to override the {@link URIEditorInput} one's with possibility to update it. */ private String name; @@ -59,6 +61,8 @@ public class SessionEditorInput extends URIEditorInput { private IStatus status = Status.OK_STATUS; + private URI repDescURI; + /** * Create a new SessionEditorInput with the current session and ui session. * @@ -79,6 +83,25 @@ public class SessionEditorInput extends URIEditorInput { } /** + * Create a new SessionEditorInput with the current session and ui session. + * + * @param uri + * element URI. + * @param repDescURI + * The URI of the {@link DRepresentationDescriptor}. This URI is Used for loading the + * {@link DRepresentation} from the {@link DRepresentationDescriptor#getRepresentation()}. Can be null. + * @param name + * name of the editor. + * @param session + * the current session. + */ + public SessionEditorInput(URI uri, URI repDescURI, String name, Session session) { + this(uri, name, session); + this.repDescURI = repDescURI; + + } + + /** * Create a new SessionEditorInput with a memento. * * @param memento @@ -102,8 +125,7 @@ public class SessionEditorInput extends URIEditorInput { * Return the model editing session. * * @param restore - * true to restore the session if it is not instantiated or - * closed. + * true to restore the session if it is not instantiated or closed. * @return the model editing session. */ public Session getSession(boolean restore) { @@ -137,8 +159,7 @@ public class SessionEditorInput extends URIEditorInput { * Get the input of this editor input. * * @param restore - * true to restore the input and associated session if they are - * not instantiated + * true to restore the input and associated session if they are not instantiated * @return the input of this editor input */ private EObject getInput(boolean restore) { @@ -164,6 +185,14 @@ public class SessionEditorInput extends URIEditorInput { this.name = string; } + public URI getRepDescUri() { + return repDescURI; + } + + public void setRepDescURI(URI repDescURI) { + this.repDescURI = repDescURI; + } + @Override public void saveState(final IMemento memento) { super.saveState(memento); @@ -173,6 +202,9 @@ public class SessionEditorInput extends URIEditorInput { if (sessionResourceURI != null) { memento.putString(SessionEditorInput.SESSION_RESOURCE_URI, sessionResourceURI.toString()); } + if (repDescURI != null) { + memento.putString(SessionEditorInput.REP_DESC_URI, repDescURI.toString()); + } } @Override @@ -180,6 +212,7 @@ public class SessionEditorInput extends URIEditorInput { super.loadState(memento); setName(memento.getString(URIEditorInput.NAME_TAG)); final String sessionResourceURIString = memento.getString(SessionEditorInput.SESSION_RESOURCE_URI); + final String repDescURIString = memento.getString(SessionEditorInput.REP_DESC_URI); if (sessionResourceURIString != null) { sessionResourceURI = URI.createURI(sessionResourceURIString); Session newSession = getSession(sessionResourceURI); @@ -187,6 +220,9 @@ public class SessionEditorInput extends URIEditorInput { this.sessionRef = new WeakReference<Session>(newSession); } } + if (repDescURIString != null) { + repDescURI = URI.createURI(repDescURIString); + } } /** @@ -293,16 +329,12 @@ public class SessionEditorInput extends URIEditorInput { } /** - * To avoid memory leak, the session is not kept during the closing of the - * corresponding editor. Indeed, editorInput is kept by - * {@link org.eclipse.ui.INavigationHistory} and - * org.eclipse.ui.internal.EditorHistory. This method must not be called by - * client, it is automatically called by the dispose of - * {@link DDiagramEditor}. + * To avoid memory leak, the session is not kept during the closing of the corresponding editor. Indeed, editorInput + * is kept by {@link org.eclipse.ui.INavigationHistory} and 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 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() { @@ -344,14 +376,13 @@ public class SessionEditorInput extends URIEditorInput { } /** - * Get the status of the session opening from this - * {@link SessionEditorInput}. + * Get the status of the session opening from this {@link SessionEditorInput}. * * <ul> - * <li>A status with severity {@link IStatus#CANCEL} is returned for a - * session opening canceled through {@link OperationCanceledException}.</li> - * <li>A status with severity {@link IStatus#ERROR} is returned for a - * session opening failing because of another {@link RuntimeException}.</li> + * <li>A status with severity {@link IStatus#CANCEL} is returned for a session opening canceled through + * {@link OperationCanceledException}.</li> + * <li>A status with severity {@link IStatus#ERROR} is returned for a session opening failing because of another + * {@link RuntimeException}.</li> * <li>Otherwise a status with severity {@link IStatus#OK} is returned.</li> * </ul> * diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusControlHandler.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusControlHandler.java index a93ceea6aa..ed1d344777 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusControlHandler.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusControlHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2017 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 @@ -64,9 +64,8 @@ import org.eclipse.ui.handlers.HandlerUtil; import com.google.common.collect.Sets; /** - * Implements the UI part of the "Control" operation. This class gathers the - * required parameters from the user and the invokes the properly configured - * {@link org.eclipse.sirius.business.internal.command.control.ControlCommand} . + * Implements the UI part of the "Control" operation. This class gathers the required parameters from the user and the + * invokes the properly configured {@link org.eclipse.sirius.business.internal.command.control.ControlCommand} . * * @since 0.9.0 * @@ -101,9 +100,8 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Performs the control operation on the specified semantic element, using - * the provided shell to interact with the end-user, gathering the required - * parameters. + * Performs the control operation on the specified semantic element, using the provided shell to interact with the + * end-user, gathering the required parameters. * * @param shell * the shell to use to interact with the user @@ -133,7 +131,8 @@ public class SiriusControlHandler extends AbstractHandler { DialectEditor editor = uiSession.getEditor(dRepDescriptor.getRepresentation()); if (editor instanceof IReusableEditor) { IReusableEditor iReusableEditor = (IReusableEditor) editor; - SessionEditorInput updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(dRepDescriptor.getRepresentation()), dRepDescriptor.getRepresentation().getName(), session); + SessionEditorInput updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(dRepDescriptor.getRepresentation()), EcoreUtil.getURI(dRepDescriptor), + dRepDescriptor.getRepresentation().getName(), session); iReusableEditor.setInput(updatedEditorInput); } } @@ -166,8 +165,7 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Creation of the dialog to ask the user for the URI of the controlled - * resource to create. + * Creation of the dialog to ask the user for the URI of the controlled resource to create. * * @param shell * the shell to use to interact with the user. @@ -192,8 +190,7 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Finds the URI of the default corresponding Aird of a semantic model with - * its URI. + * Finds the URI of the default corresponding Aird of a semantic model with its URI. * * @param semanticModelUri * URI of a semantic model @@ -204,9 +201,8 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Asks the end-user which representations should be controlled in - * conjunction with the semantic elements. The default is to control all the - * representations which target an element of the specified resource. + * Asks the end-user which representations should be controlled in conjunction with the semantic elements. The + * default is to control all the representations which target an element of the specified resource. * * @param shell * the shell to use to interact with the user. @@ -225,8 +221,7 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Asks the end-user to select a sub-set of the representations existing in - * the session. + * Asks the end-user to select a sub-set of the representations existing in the session. * * @param shell * the shell to use to interact with the user. @@ -256,9 +251,8 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Returns all the existing representation descriptors in the given session - * which representation is associated to a semantic element of the specified - * resource (excluding elements of sub-resources). + * Returns all the existing representation descriptors in the given session which representation is associated to a + * semantic element of the specified resource (excluding elements of sub-resources). * * @param session * the session opened for semanticRoot. @@ -278,9 +272,8 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * Returns the text of the URI proposed by default when controlling the - * specified object. The URI is based on the initial parent resource and the - * "name" feature of the controlled element. + * Returns the text of the URI proposed by default when controlling the specified object. The URI is based on the + * initial parent resource and the "name" feature of the controlled element. * * @param obj * the controlled element. @@ -298,8 +291,7 @@ public class SiriusControlHandler extends AbstractHandler { } /** - * A dialog to ask the user for the URI of the resource to put controlled - * elements into. + * A dialog to ask the user for the URI of the resource to put controlled elements into. */ private class ControlResourceDialog extends ResourceDialog { private final String defaultURI; diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusUncontrolHandler.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusUncontrolHandler.java index 9032f818c9..17508f2584 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusUncontrolHandler.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/control/SiriusUncontrolHandler.java @@ -11,6 +11,7 @@ package org.eclipse.sirius.ui.tools.api.control; import java.lang.reflect.InvocationTargetException; +import java.util.Optional; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -21,6 +22,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.util.TransactionUtil; @@ -106,7 +108,9 @@ public class SiriusUncontrolHandler extends AbstractHandler { if (editor instanceof IReusableEditor) { IReusableEditor iReusableEditor = (IReusableEditor) editor; DRepresentation representation = editor.getRepresentation(); - SessionEditorInput updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(representation), representation.getName(), session); + URI repDescURI = Optional.ofNullable(editor.getEditorInput()).filter(SessionEditorInput.class::isInstance).map(SessionEditorInput.class::cast) + .map(SessionEditorInput::getRepDescUri).orElse(null); + SessionEditorInput updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(representation), repDescURI, representation.getName(), session); iReusableEditor.setInput(updatedEditorInput); } } 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 63d58455a6..5d37bdc197 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 @@ -13,6 +13,7 @@ package org.eclipse.sirius.ui.tools.internal.editor; import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; +import java.util.Optional; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -349,8 +350,9 @@ public abstract class AbstractDTreeEditor extends EditorPart SessionEditorInput sessionEditorInput = (SessionEditorInput) input; final URI uri = sessionEditorInput.getURI(); this.session = sessionEditorInput.getSession(); + URI uriToUse = Optional.ofNullable(sessionEditorInput.getRepDescUri()).orElse(uri); if (session != null) { - setRepresentation(uri, false); + setRepresentation(uriToUse, false); } } else if (input instanceof URIEditorInput) { /* This happens when Eclipse is launched with an open tree editor */ @@ -489,10 +491,10 @@ public abstract class AbstractDTreeEditor extends EditorPart protected abstract void updateEditorAfterAirdResourceReload(); /** - * Retrieve and set the representation from the given URI. + * Retrieve and set the representation from the given {@link DRepresentationDescriptor} URI. * * @param uri - * the URI to resolve. + * the URI of the {@link DRepresentationDescriptor} to resolve. * @param loadOnDemand * whether to create and load the resource, if it doesn't already exists. */ |
