summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2014-05-06 02:33:28 (EDT)
committerRemi Schnekenburger2014-05-13 09:27:34 (EDT)
commit29805c9996e145cde48aa4b8a91bb5f3bb1ed92e (patch)
treea0994c59d79b2a948b80a4b6335b91392f3f8f85
parent1893285f280c0b80e14e6cc41b281102a8a383be (diff)
downloadorg.eclipse.papyrus-29805c9996e145cde48aa4b8a91bb5f3bb1ed92e.zip
org.eclipse.papyrus-29805c9996e145cde48aa4b8a91bb5f3bb1ed92e.tar.gz
org.eclipse.papyrus-29805c9996e145cde48aa4b8a91bb5f3bb1ed92e.tar.bz2
[433192] - Explicit synchronization between active inner IEditorPage inrefs/changes/08/26008/4
multi-editor and PaletteView Change-Id: I88d9e13b0347ae809b836766040e6ee458d2a7b7 Signed-off-by: mgolubev <golubev@montages.com>
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusMultiDiagramEditor.java30
-rw-r--r--plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusPaletteSynchronizer.java104
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/ISashWindowsContainer.java5
3 files changed, 135 insertions, 4 deletions
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 0e073e6..bd10758 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
@@ -15,15 +15,14 @@
package org.eclipse.papyrus.editor;
import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
-
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
/**
- * Papyrus main MultiEditor.
- * This class add GMF adaptation dedicated to Papyrus.
+ * 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 {
@@ -31,4 +30,27 @@ 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();
+ }
+
}
diff --git a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusPaletteSynchronizer.java b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusPaletteSynchronizer.java
new file mode 100644
index 0000000..ad19bc2
--- /dev/null
+++ b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/PapyrusPaletteSynchronizer.java
@@ -0,0 +1,104 @@
+package org.eclipse.papyrus.editor;
+
+import org.eclipse.gef.ui.views.palette.PaletteView;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IEditorPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageChangedListener;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.ActivePageTracker.IActiveEditorChangedListener;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.PagePart;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * Synchronizes the detached palette view with the contents provided by the active inner editor
+ */
+/* package */class PapyrusPaletteSynchronizer implements IActiveEditorChangedListener, IPageChangedListener {
+
+ private final PapyrusMultiDiagramEditor myMultiDiagramEditor;
+
+ private IEditorPart myLastActivePart;
+
+ public PapyrusPaletteSynchronizer(PapyrusMultiDiagramEditor multiEditor) {
+ myMultiDiagramEditor = multiEditor;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.infra.core.sasheditor.internal.ActivePageTracker.IActiveEditorChangedListener
+ * #activeEditorChanged(org.eclipse.papyrus.infra.core.sasheditor.internal.PagePart,
+ * org.eclipse.papyrus.infra.core.sasheditor.internal.PagePart)
+ */
+ public void activeEditorChanged(PagePart oldEditor, PagePart newEditor) {
+ synchronizePaletteView(newEditor);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.infra.core.sasheditor.editor.IPageChangedListener#pageChanged(org.eclipse
+ * .papyrus.infra.core.sasheditor.editor.IPage)
+ */
+ public void pageChanged(IPage newPage) {
+ synchronizePaletteView(newPage);
+ }
+
+ /**
+ * If {@link PaletteView} is available, synchronizes it with the content provided by active
+ * inner page
+ *
+ * @param activePage
+ * inner page to synchronize palette view with
+ */
+ private void synchronizePaletteView(IPage activePage) {
+ PaletteView paletteView = findPaletteView();
+ if (paletteView == null) {
+ return;
+ }
+
+ // IEditorPage is not granted, it may be, e.g ErrorComponentPart
+ IEditorPart activePart = activePage instanceof IEditorPage ? ((IEditorPage) activePage).getIEditorPart() : null;
+ if (activePart == myLastActivePart) {
+ return;
+ }
+
+ if (activePart == null) {
+ paletteView.partClosed(myLastActivePart);
+ } else {
+ // multi-editor may be activated outside of this code
+ // and palette view may already remember its (now outdated) palette
+ // sending partClosed will enforce palette view to request fresh version
+ paletteView.partClosed(myMultiDiagramEditor);
+ paletteView.partActivated(activePart);
+ }
+ myLastActivePart = activePart;
+ }
+
+ /**
+ * Called when host editor is disposed, cleans up
+ */
+ public void dispose() {
+ if (myLastActivePart == null) {
+ // nothing to do
+ return;
+ }
+ PaletteView paletteView = findPaletteView();
+ if (paletteView == null) {
+ return;
+ }
+ paletteView.partClosed(myLastActivePart);
+ }
+
+ /**
+ * Finds the {@link PaletteView} at the same page as the host multi-editor
+ *
+ * @return palette view or <code>null</code> if not found
+ */
+ private PaletteView findPaletteView() {
+ IWorkbenchPage samePage = myMultiDiagramEditor.getSite().getPage();
+ return (PaletteView) samePage.findView(PaletteView.ID);
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/ISashWindowsContainer.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/ISashWindowsContainer.java
index f074398..e6bc2cf 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/ISashWindowsContainer.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/ISashWindowsContainer.java
@@ -133,4 +133,9 @@ public interface ISashWindowsContainer {
public abstract void selectPage(IPage page);
public abstract void visit(IPageVisitor pageVisitor);
+
+ /**
+ * @return <code>true</code> if already disposed
+ */
+ public boolean isDisposed();
}