Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Monnier2020-06-19 15:54:19 +0000
committerSteve Monnier2020-06-24 13:56:25 +0000
commit3e8943d1a7e6773e03b7926cc2aa69165769f547 (patch)
tree21a1cd0cca2780317f860909d07be8d149efab0c
parent9cf25ac4dc47cae0076ee32a9cb6deb0b059f18c (diff)
downloadorg.eclipse.sirius-3e8943d1a7e6773e03b7926cc2aa69165769f547.tar.gz
org.eclipse.sirius-3e8943d1a7e6773e03b7926cc2aa69165769f547.tar.xz
org.eclipse.sirius-3e8943d1a7e6773e03b7926cc2aa69165769f547.zip
[fix] Catch of an exception that can be thrown with remote resources
Catches an IllegalStateException that can be thrown when closing a session with remote resources while having a diagram opened Change-Id: I7d3222e4eb4c0f71cb6d975c821d0bf6ade6c026 Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java12
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/ContainerWithTitleBlockFigure.java44
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/business/api/query/EditPartQuery.java8
3 files changed, 38 insertions, 26 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
index a9c875206a..10649f555a 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDDiagramEditPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2019 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2020 THALES GLOBAL SERVICES and others.
* 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
@@ -116,8 +116,12 @@ public abstract class AbstractDDiagramEditPart extends DiagramEditPart implement
@Override
public final Option<DDiagram> resolveDDiagram() {
- final EObject resolveSemanticElement = resolveSemanticElement();
-
+ EObject resolveSemanticElement = null;
+ try {
+ resolveSemanticElement = resolveSemanticElement();
+ } catch (IllegalStateException e) {
+ // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource).
+ }
if (resolveSemanticElement instanceof DDiagram) {
return Options.newSome((DDiagram) resolveSemanticElement);
}
@@ -355,7 +359,7 @@ public abstract class AbstractDDiagramEditPart extends DiagramEditPart implement
if (mappingManager != null) {
LayerHelper.setActiveParentLayersCacheEnabled(mappingManager, true);
}
-
+
DDiagramQuery dDiagramQuery = new DDiagramQuery(dDiagram);
for (final DDiagramElement diagramElement : dDiagram.getDiagramElements()) {
if (dDiagramQuery.isHidden(session, diagramElement)) {
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/ContainerWithTitleBlockFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/ContainerWithTitleBlockFigure.java
index eead4fea33..31e378960b 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/ContainerWithTitleBlockFigure.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/ContainerWithTitleBlockFigure.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2010, 2020 THALES GLOBAL SERVICES and others.
* 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
@@ -33,8 +33,7 @@ import org.eclipse.swt.graphics.Color;
import com.google.common.collect.Iterables;
/**
- * A figure that draw a line around the container label to represent a title
- * block.
+ * A figure that draw a line around the container label to represent a title block.
*
* @author smonnier
*/
@@ -176,45 +175,54 @@ public class ContainerWithTitleBlockFigure extends SiriusDefaultSizeNodeFigure {
}
/**
- * Investigate the border color of the DDiagramElement to use it as the
- * color of the title block.
+ * Investigate the border color of the DDiagramElement to use it as the color of the title block.
*
* @return the defined color of the title block
*/
private Color geBorderColor() {
- if (viewNode.getStyle() instanceof BorderedStyle) {
- RGBValues borderColor = ((BorderedStyle) viewNode.getStyle()).getBorderColor();
- if (borderColor != null) {
- return new Color(null, borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue());
+ try {
+ if (viewNode.getStyle() instanceof BorderedStyle) {
+ RGBValues borderColor = ((BorderedStyle) viewNode.getStyle()).getBorderColor();
+ if (borderColor != null) {
+ return new Color(null, borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue());
+ }
}
+ } catch (IllegalStateException e) {
+ // We do not log this exception that might be caused by an unreachable distant resource.
}
return ColorConstants.black;
}
/**
- * Investigate the border size of the DDiagramElement to use it as the width
- * of the title block.
+ * Investigate the border size of the DDiagramElement to use it as the width of the title block.
*
* @return the defined width of the title block
*/
public int getBorderWidth() {
- if (viewNode.getStyle() instanceof BorderedStyle) {
- // The title block width must value at least 1
- return Math.max(((BorderedStyle) viewNode.getStyle()).getBorderSize(), 1);
+ try {
+ if (viewNode.getStyle() instanceof BorderedStyle) {
+ // The title block width must value at least 1
+ return Math.max(((BorderedStyle) viewNode.getStyle()).getBorderSize(), 1);
+ }
+ } catch (IllegalStateException e) {
+ // We do not log this exception that might be caused by an unreachable distant resource.
}
return 1;
}
/**
- * Investigate the label alignment of the DDiagramElement to use it as the
- * alignment of the title block.
+ * Investigate the label alignment of the DDiagramElement to use it as the alignment of the title block.
*
* @return the defined label alignment of the title block
*/
private LabelAlignment getLabelAlignment() {
LabelAlignment alignment = (LabelAlignment) ViewpointPackage.eINSTANCE.getLabelStyle_LabelAlignment().getDefaultValue();
- if (viewNode.getStyle() instanceof LabelStyle) {
- alignment = ((LabelStyle) viewNode.getStyle()).getLabelAlignment();
+ try {
+ if (viewNode.getStyle() instanceof LabelStyle) {
+ alignment = ((LabelStyle) viewNode.getStyle()).getLabelAlignment();
+ }
+ } catch (IllegalStateException e) {
+ // We do not log this exception that might be caused by an unreachable distant resource.
}
return alignment;
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/business/api/query/EditPartQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/business/api/query/EditPartQuery.java
index a4498cc0f0..a77008b2a1 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/business/api/query/EditPartQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/business/api/query/EditPartQuery.java
@@ -16,7 +16,6 @@ import java.util.List;
import java.util.Optional;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
@@ -30,6 +29,7 @@ import org.eclipse.sirius.diagram.ui.edit.api.part.IDDiagramEditPart;
import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.NoteEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart;
+import org.eclipse.sirius.ext.base.Option;
/**
* A class aggregating all the queries (read-only!) having an {@link IGraphicalEditPart} as a starting point.
@@ -80,9 +80,9 @@ public final class EditPartQuery {
effectiveDiagramEditPart = (IDDiagramEditPart) editPart;
}
if (effectiveDiagramEditPart != null) {
- EObject resolvedSemanticElement = effectiveDiagramEditPart.resolveSemanticElement();
- if (resolvedSemanticElement instanceof DDiagram) {
- return Optional.of((DDiagram) resolvedSemanticElement);
+ Option<DDiagram> ddiagram = effectiveDiagramEditPart.resolveDDiagram();
+ if (ddiagram.some()) {
+ return Optional.of(ddiagram.get());
}
}
return Optional.empty();

Back to the top