Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2016-04-06 08:33:01 -0400
committerGerrit Code Review @ Eclipse.org2016-04-06 11:36:29 -0400
commit39507c0d322af147497a7b2d3fd375f1abc4afe3 (patch)
treedd59c569487cb7862f24a2f3c9f53f015b398735
parent68807040dd2940c712541996db0b2aa2bfa6887d (diff)
downloadorg.eclipse.papyrus-39507c0d322af147497a7b2d3fd375f1abc4afe3.tar.gz
org.eclipse.papyrus-39507c0d322af147497a7b2d3fd375f1abc4afe3.tar.xz
org.eclipse.papyrus-39507c0d322af147497a7b2d3fd375f1abc4afe3.zip
Bug 407733 - [General] Papyrus shall support navigation history with
back and next buttons - Update for post-refactoring Neon Change-Id: I23a0a26449c2bda1e162d07e659680bea218ebcd Signed-off-by: Shuai Li <shuai.li@cea.fr>
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF1
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java138
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationHistorySynchronizer.java35
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationLocation.java144
4 files changed, 262 insertions, 56 deletions
diff --git a/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF b/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF
index d23769077ef..e2ff9058a90 100644
--- a/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF
+++ b/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF
@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.editor
Require-Bundle: org.eclipse.gmf.runtime.diagram.ui;bundle-version="[1.8.0,2.0.0)",
+ org.eclipse.papyrus.infra.emf;bundle-version="2.0.0",
org.eclipse.papyrus.infra.ui;bundle-version="[1.2.0,2.0.0)";visibility:=reexport
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java
index a1d532815ab..9757e620993 100644
--- a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java
+++ b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java
@@ -1,56 +1,82 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.editor;
-
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.infra.ui.editor.CoreMultiDiagramEditor;
-
-/**
- * Papyrus main MultiEditor. This class add GMF adaptation dedicated to Papyrus.
- * <p/>
- * TODO : move GMF dependencies into this plugin.
- *
- * @author dumoulin
- */
-public class PapyrusMultiDiagramEditor extends CoreMultiDiagramEditor {
-
- /**
- * The Papyrus Editor ID
- */
- public static final String EDITOR_ID = "org.eclipse.papyrus.infra.core.papyrusEditor"; //$NON-NLS-1$
-
- private PapyrusPaletteSynchronizer myPaletteViewSynchronizer;
-
- @Override
- protected void activate() {
- super.activate();
- myPaletteViewSynchronizer = new PapyrusPaletteSynchronizer(this);
- getISashWindowsContainer().addPageChangedListener(myPaletteViewSynchronizer);
- }
-
- @Override
- protected void deactivate() {
- if (myPaletteViewSynchronizer != null) {
- ISashWindowsContainer sashContainer = getISashWindowsContainer();
- if (sashContainer != null && !sashContainer.isDisposed()) {
- sashContainer.removePageChangedListener(myPaletteViewSynchronizer);
- }
- myPaletteViewSynchronizer.dispose();
- myPaletteViewSynchronizer = null;
- }
- super.deactivate();
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.editor;
+
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.ui.editor.CoreMultiDiagramEditor;
+import org.eclipse.ui.INavigationLocation;
+import org.eclipse.ui.INavigationLocationProvider;
+
+/**
+ * Papyrus main MultiEditor. This class add GMF adaptation dedicated to Papyrus.
+ * <p/>
+ * TODO : move GMF dependencies into this plugin.
+ *
+ * @author dumoulin
+ */
+public class PapyrusMultiDiagramEditor extends CoreMultiDiagramEditor implements INavigationLocationProvider {
+
+ /**
+ * The Papyrus Editor ID
+ */
+ public static final String EDITOR_ID = "org.eclipse.papyrus.infra.core.papyrusEditor"; //$NON-NLS-1$
+
+ private PapyrusPaletteSynchronizer myPaletteViewSynchronizer;
+
+ private PapyrusNavigationHistorySynchronizer myNavigationHistorySynchronizer;
+
+ @Override
+ protected void activate() {
+ super.activate();
+ myPaletteViewSynchronizer = new PapyrusPaletteSynchronizer(this);
+ myNavigationHistorySynchronizer = new PapyrusNavigationHistorySynchronizer(this);
+ getISashWindowsContainer().addPageChangedListener(myPaletteViewSynchronizer);
+ getISashWindowsContainer().addPageChangedListener(myNavigationHistorySynchronizer);
+ }
+
+ @Override
+ protected void deactivate() {
+ if (myPaletteViewSynchronizer != null) {
+ ISashWindowsContainer sashContainer = getISashWindowsContainer();
+ if (sashContainer != null && !sashContainer.isDisposed()) {
+ sashContainer.removePageChangedListener(myPaletteViewSynchronizer);
+ sashContainer.removePageChangedListener(myNavigationHistorySynchronizer);
+ }
+ myPaletteViewSynchronizer.dispose();
+ myPaletteViewSynchronizer = null;
+ }
+ super.deactivate();
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocationProvider#createEmptyNavigationLocation()
+ *
+ * @return
+ */
+ @Override
+ public INavigationLocation createEmptyNavigationLocation() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocationProvider#createNavigationLocation()
+ *
+ * @return
+ */
+ @Override
+ public INavigationLocation createNavigationLocation() {
+ return new PapyrusNavigationLocation(this);
+ }
+}
diff --git a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationHistorySynchronizer.java b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationHistorySynchronizer.java
new file mode 100644
index 00000000000..3e54a979dd4
--- /dev/null
+++ b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationHistorySynchronizer.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST 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:
+ * Shuai Li (CEAL LIST) <shuai.li@cea.fr>
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.editor;
+
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageChangedListener;
+
+public class PapyrusNavigationHistorySynchronizer implements IPageChangedListener {
+
+ private final PapyrusMultiDiagramEditor myMultiDiagramEditor;
+
+ public PapyrusNavigationHistorySynchronizer(PapyrusMultiDiagramEditor multiEditor) {
+ myMultiDiagramEditor = multiEditor;
+ //synchronizeNavigationHistory(); // Mark the first page when the editor is opened
+ }
+
+ @Override
+ public void pageChanged(IPage newPage) {
+ synchronizeNavigationHistory();
+ }
+
+ private void synchronizeNavigationHistory() {
+ myMultiDiagramEditor.getSite().getPage().getNavigationHistory().markLocation(myMultiDiagramEditor);
+ }
+}
diff --git a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationLocation.java b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationLocation.java
new file mode 100644
index 00000000000..95168e01a75
--- /dev/null
+++ b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusNavigationLocation.java
@@ -0,0 +1,144 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST 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:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.editor;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.INavigationLocation;
+import org.eclipse.ui.NavigationLocation;
+
+public class PapyrusNavigationLocation extends NavigationLocation {
+ private URI pageURI;
+
+ /**
+ * Constructor: Save editor selection, selected editor part, and selected page
+ *
+ */
+ public PapyrusNavigationLocation(IEditorPart editorPart) {
+ super(editorPart);
+ if (editorPart instanceof PapyrusMultiDiagramEditor) {
+ PapyrusMultiDiagramEditor papyrusEditor = (PapyrusMultiDiagramEditor) editorPart;
+ // Important to set editorSelection and selectedEditorPart, otherwise navigation history breaks
+ /*ISelection editorSelection = papyrusEditor.getEditorSite().getSelectionProvider().getSelection();//papyrusEditor.getSite().getSelectionProvider().getSelection()
+ IEditorPart selectedEditorPart = papyrusEditor.getActiveEditor();*/
+ IPage selectedPage = papyrusEditor.getISashWindowsContainer().getActiveSashWindowsPage();
+
+ if (selectedPage != null && selectedPage.getRawModel() instanceof PageRef) {
+ PageRef pageRef = (PageRef) selectedPage.getRawModel();
+ if (pageRef != null && pageRef.getEmfPageIdentifier() != null) {
+ pageURI = EcoreUtil.getURI(pageRef.getEmfPageIdentifier());
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocation#restoreLocation()
+ *
+ */
+ @Override
+ public void restoreLocation() {
+ IEditorPart editorPart = getEditorPart();
+ if (editorPart instanceof PapyrusMultiDiagramEditor) {
+ try {
+ IPageManager pageManager = ServiceUtils.getInstance().getIPageManager(((PapyrusMultiDiagramEditor) editorPart).getServicesRegistry());
+ EObject objectToOpen = ServiceUtils.getInstance().getModelSet(((PapyrusMultiDiagramEditor) editorPart).getServicesRegistry()).getEObject(pageURI, false);
+
+ if (objectToOpen != null) {
+ EObject context = EMFHelper.getEObject(objectToOpen);
+ if (context != null) {
+ try {
+ pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(context);
+ if (pageManager.isOpen(objectToOpen)) {
+ pageManager.selectPage(objectToOpen);
+ } else {
+ pageManager.openPage(objectToOpen);
+ }
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ * If the selected editor part matches, then merge.
+ *
+ * @see org.eclipse.ui.INavigationLocation#mergeInto(org.eclipse.ui.INavigationLocation)
+ *
+ * @param currentLocation
+ * @return
+ */
+ @Override
+ public boolean mergeInto(INavigationLocation currentLocation) {
+ if (currentLocation instanceof PapyrusNavigationLocation) {
+ if (((PapyrusNavigationLocation) currentLocation).getPageURI() != null && pageURI != null) {
+ return ((PapyrusNavigationLocation) currentLocation).getPageURI().equals(pageURI);
+ }
+ }
+ return false;
+ }
+
+ public URI getPageURI() {
+ return this.pageURI;
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocation#saveState(org.eclipse.ui.IMemento)
+ *
+ * @param memento
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocation#restoreState(org.eclipse.ui.IMemento)
+ *
+ * @param memento
+ */
+ @Override
+ public void restoreState(IMemento memento) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.ui.INavigationLocation#update()
+ *
+ */
+ @Override
+ public void update() {
+ // TODO Auto-generated method stub
+
+ }
+}

Back to the top