Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2019-10-04 13:18:22 +0000
committerFlorian Barbin2019-10-04 13:27:21 +0000
commit6548447cde3fd9ff2ef1f52c0ca58e1343b77461 (patch)
tree664c0f4712aec832338f5043e8af6874536fde41
parent7e36558156e19018d5ec575f7cce01e41a9e5c2a (diff)
downloadorg.eclipse.sirius-6548447cde3fd9ff2ef1f52c0ca58e1343b77461.tar.gz
org.eclipse.sirius-6548447cde3fd9ff2ef1f52c0ca58e1343b77461.tar.xz
org.eclipse.sirius-6548447cde3fd9ff2ef1f52c0ca58e1343b77461.zip
[551053] Check if the session is still opened when refreshing tabbar.
Bug: 551053 Change-Id: I0a2abece94a98cd95461da449c1f7165e460e76a Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarRefresher.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarRefresher.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarRefresher.java
index 89391368bb..6411570a52 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarRefresher.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarRefresher.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2019 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -12,12 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar;
+import java.util.Optional;
+
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil;
import org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl;
-import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -48,15 +50,20 @@ public class TabbarRefresher extends ResourceSetListenerImpl {
EclipseUIUtil.displayAsyncExec(new Runnable() {
@Override
public void run() {
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (activeWorkbenchWindow != null) {
- IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
- if (activePage != null) {
- IEditorPart activeEditor = activePage.getActiveEditor();
- if (activeEditor instanceof DDiagramEditorImpl && ((DDiagramEditorImpl) activeEditor).getTabbar() != null) {
- ((DDiagramEditorImpl) activeEditor).getTabbar().reinitToolBar(((DDiagramEditorImpl) activeEditor).getDiagramGraphicalViewer().getSelection());
- }
- }
+ //@formatter:off
+ Optional<DDiagramEditorImpl> optionalDDiagramEditor = Optional.ofNullable(PlatformUI.getWorkbench().getActiveWorkbenchWindow())
+ .map(IWorkbenchWindow::getActivePage)
+ .map(IWorkbenchPage::getActiveEditor)
+ .filter(DDiagramEditorImpl.class::isInstance)
+ .map(DDiagramEditorImpl.class::cast)
+ .filter(dDiagramEditor -> dDiagramEditor.getTabbar() != null)
+ .filter(dDiagramEditor -> {
+ Session session = dDiagramEditor.getSession();
+ return session != null && session.isOpen();
+ });
+ //@formatter:on
+ if (optionalDDiagramEditor.isPresent()) {
+ optionalDDiagramEditor.get().getTabbar().reinitToolBar(optionalDDiagramEditor.get().getDiagramGraphicalViewer().getSelection());
}
}
});

Back to the top