diff options
| author | Steve Monnier | 2019-09-13 12:43:54 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2019-09-18 21:27:40 +0000 |
| commit | a180a55700cbd57922d030f889d2264ed349889a (patch) | |
| tree | 5fc3f28dd3f7e9e3e0259546980fbec07746a913 | |
| parent | 0ed52c947fa97569c078cde3ee9c6250c3c11508 (diff) | |
| download | org.eclipse.sirius-a180a55700cbd57922d030f889d2264ed349889a.tar.gz org.eclipse.sirius-a180a55700cbd57922d030f889d2264ed349889a.tar.xz org.eclipse.sirius-a180a55700cbd57922d030f889d2264ed349889a.zip | |
[551053] Catch exceptions on session close with dirty state
When closing a session with a dirty state, a popup is opened to ask the
user if he want to save before closing. If the choice is to save, it is
saved as expected but some exception are thrown because some refresh are
triggered even though the session is already closed. These exception
should be silently catched.
Bug: 551053
Change-Id: Iebfd46cf5712dcd73a5071ec8519895e4a22cfe4
Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
8 files changed, 109 insertions, 69 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java index f9c8210ef3..ec094ca768 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java @@ -186,24 +186,28 @@ public class EditPartAuthorityListener implements IAuthorityListener { final DDiagramEditPart ddep = (DDiagramEditPart) part; RootEditPart rootEditPart = ddep.getRoot(); if (rootEditPart instanceof DiagramRootEditPart) { - EObject target = ((DSemanticDecorator) semanticElement).getTarget(); - LockStatus lockStatus = diagramEditor.getPermissionAuthority().getLockStatus(target); - switch (lockStatus) { - case LOCKED_BY_ME: - DiagramSemanticElementLockedNotificationFigure.createNotification((DiagramRootEditPart) rootEditPart, LockStatus.LOCKED_BY_ME); - break; - case LOCKED_BY_OTHER: - String tooltip = ""; //$NON-NLS-1$ - IToolTipProvider tooltipProvider = Platform.getAdapterManager().getAdapter(semanticElement, IToolTipProvider.class); - if (tooltipProvider != null) { - tooltip = tooltipProvider.getToolTipText(target); + try { + EObject target = ((DSemanticDecorator) semanticElement).getTarget(); + LockStatus lockStatus = diagramEditor.getPermissionAuthority().getLockStatus(target); + switch (lockStatus) { + case LOCKED_BY_ME: + DiagramSemanticElementLockedNotificationFigure.createNotification((DiagramRootEditPart) rootEditPart, LockStatus.LOCKED_BY_ME); + break; + case LOCKED_BY_OTHER: + String tooltip = ""; //$NON-NLS-1$ + IToolTipProvider tooltipProvider = Platform.getAdapterManager().getAdapter(semanticElement, IToolTipProvider.class); + if (tooltipProvider != null) { + tooltip = tooltipProvider.getToolTipText(target); + } + DiagramSemanticElementLockedNotificationFigure.createNotification((DiagramRootEditPart) rootEditPart, "", tooltip, LockStatus.LOCKED_BY_OTHER); //$NON-NLS-1$ + break; + case NOT_LOCKED: + default: + DiagramSemanticElementLockedNotificationFigure.removeNotification((DiagramRootEditPart) rootEditPart); + break; } - DiagramSemanticElementLockedNotificationFigure.createNotification((DiagramRootEditPart) rootEditPart, "", tooltip, LockStatus.LOCKED_BY_OTHER); //$NON-NLS-1$ - break; - case NOT_LOCKED: - default: - DiagramSemanticElementLockedNotificationFigure.removeNotification((DiagramRootEditPart) rootEditPart); - break; + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } } } @@ -217,10 +221,18 @@ public class EditPartAuthorityListener implements IAuthorityListener { * @return true if the target value is valid, false otherwise */ private boolean isTargetValid(final EObject semanticElement) { - boolean result = true; - if (semanticElement instanceof DDiagramElement) { - final EObject target = ((DDiagramElement) semanticElement).getTarget(); - result = target != null && target.eResource() != null; + boolean result = false; + try { + + if (semanticElement instanceof DDiagramElement) { + final EObject target = ((DDiagramElement) semanticElement).getTarget(); + result = target != null && target.eResource() != null; + } else { + result = true; + } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). + result = false; } return result; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/style/ResetStylePropertiesToDefaultValuesAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/style/ResetStylePropertiesToDefaultValuesAction.java index d634a39d00..9214ceb60f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/style/ResetStylePropertiesToDefaultValuesAction.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/style/ResetStylePropertiesToDefaultValuesAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2019 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 @@ -95,20 +95,24 @@ public class ResetStylePropertiesToDefaultValuesAction extends Action implements if (selection instanceof StructuredSelection) { for (final IGraphicalEditPart part : Iterables.filter(((StructuredSelection) selection).toList(), IGraphicalEditPart.class)) { View view = part.getNotationView(); - EObject element = view.getElement(); - if (element instanceof DDiagramElement) { - DDiagramElement dDiagramElement = (DDiagramElement) element; - if (shouldBeEnable(dDiagramElement)) { + try { + EObject element = view.getElement(); + if (element instanceof DDiagramElement) { + DDiagramElement dDiagramElement = (DDiagramElement) element; + if (shouldBeEnable(dDiagramElement)) { + result = true; + break; + } + } + + ViewQuery viewQuery = new ViewQuery(view); + if (viewQuery.isCustomized()) { result = true; break; } - } - - ViewQuery viewQuery = new ViewQuery(view); - if (viewQuery.isCustomized()) { - result = true; - break; - } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). + } } // for } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/EditModeDecorationDescriptorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/EditModeDecorationDescriptorProvider.java index ae70bd9247..a55e9fb885 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/EditModeDecorationDescriptorProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/EditModeDecorationDescriptorProvider.java @@ -80,13 +80,17 @@ public class EditModeDecorationDescriptorProvider extends AbstractSiriusDecorati } private String getToolTip(IDiagramElementEditPart editPart) { - EObject representedObject = editPart.resolveTargetSemanticElement(); - - if (representedObject != null) { - IToolTipProvider tooltipProvider = Platform.getAdapterManager().getAdapter(representedObject, IToolTipProvider.class); - if (tooltipProvider != null) { - return tooltipProvider.getToolTipText(representedObject); + try { + EObject representedObject = editPart.resolveTargetSemanticElement(); + + if (representedObject != null) { + IToolTipProvider tooltipProvider = Platform.getAdapterManager().getAdapter(representedObject, IToolTipProvider.class); + if (tooltipProvider != null) { + return tooltipProvider.getToolTipText(representedObject); + } } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } return null; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SiriusGenericDecorator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SiriusGenericDecorator.java index f24719172a..f884361ec5 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SiriusGenericDecorator.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SiriusGenericDecorator.java @@ -307,16 +307,20 @@ public class SiriusGenericDecorator extends AbstractDecorator { // When resizing the node the figure is not painted yet so we get the // resized width or height from the GMF node if (editPart.getModel() instanceof Node) { - LayoutConstraint layoutConstraint = ((Node) editPart.getModel()).getLayoutConstraint(); - if (layoutConstraint instanceof Bounds) { - int width = ((Bounds) layoutConstraint).getWidth(); - int height = ((Bounds) layoutConstraint).getHeight(); - if (width > 0) { - figureDimension.width = width; - } - if (height > 0) { - figureDimension.height = height; + try{ + LayoutConstraint layoutConstraint = ((Node) editPart.getModel()).getLayoutConstraint(); + if (layoutConstraint instanceof Bounds) { + int width = ((Bounds) layoutConstraint).getWidth(); + int height = ((Bounds) layoutConstraint).getHeight(); + if (width > 0) { + figureDimension.width = width; + } + if (height > 0) { + figureDimension.height = height; + } } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java index ea237d78a8..01330cff43 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java @@ -70,9 +70,13 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD @Override public boolean provides(IDiagramElementEditPart editPart) { - if (editPart instanceof GraphicalEditPart || editPart instanceof AbstractConnectionEditPart) { - Optional<View> view = Optional.ofNullable((View) editPart.getModel()); - return view.filter(View::isSetElement).map(View::getElement).filter(model -> model instanceof DNode || model instanceof DDiagramElementContainer).isPresent(); + try { + if (editPart instanceof GraphicalEditPart || editPart instanceof AbstractConnectionEditPart) { + Optional<View> view = Optional.ofNullable((View) editPart.getModel()); + return view.filter(View::isSetElement).map(View::getElement).filter(model -> model instanceof DNode || model instanceof DDiagramElementContainer).isPresent(); + } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } return false; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/ValidationDecorationDescriptorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/ValidationDecorationDescriptorProvider.java index aca5827193..4ad84e59b0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/ValidationDecorationDescriptorProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/ValidationDecorationDescriptorProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2017, 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 @@ -81,11 +81,15 @@ public class ValidationDecorationDescriptorProvider extends AbstractSiriusDecora Object model = editPart.getModel(); if (model instanceof View) { View view = (View) model; - if ((view instanceof Edge || view.isSetElement()) && view.eResource() != null) { - EditDomain ed = editPart.getViewer().getEditDomain(); - if (ed instanceof DiagramEditDomain) { - provides = DDiagramEditPart.MODEL_ID.equals(SiriusVisualIDRegistry.getModelID(view)); + try { + if ((view instanceof Edge || view.isSetElement()) && view.eResource() != null) { + EditDomain ed = editPart.getViewer().getEditDomain(); + if (ed instanceof DiagramEditDomain) { + provides = DDiagramEditPart.MODEL_ID.equals(SiriusVisualIDRegistry.getModelID(view)); + } } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/FiltersContributionItem.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/FiltersContributionItem.java index 2a20050fe8..4c15eddcad 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/FiltersContributionItem.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/FiltersContributionItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2019 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 @@ -55,13 +55,17 @@ public class FiltersContributionItem extends AbstractMenuContributionItem { private Image getImage() { final Diagram gmfDiagram = this.part.getDiagram(); if (gmfDiagram != null) { - EObject diagram = gmfDiagram.getElement(); - if (diagram instanceof DDiagram) { - super.setDiagram((DDiagram) diagram); - if (!((DDiagram) diagram).getActivatedFilters().isEmpty()) { - return DiagramUIPlugin.Implementation.getDecoratedCheckedImage(DESC_FILTER); + try { + EObject diagram = gmfDiagram.getElement(); + if (diagram instanceof DDiagram) { + super.setDiagram((DDiagram) diagram); + if (!((DDiagram) diagram).getActivatedFilters().isEmpty()) { + return DiagramUIPlugin.Implementation.getDecoratedCheckedImage(DESC_FILTER); + } } - } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). + } } return DiagramUIPlugin.getPlugin().getImage(DESC_FILTER); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/LayersContribution.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/LayersContribution.java index 5a13da9af7..b34086d584 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/LayersContribution.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/LayersContribution.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2019 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 @@ -62,12 +62,16 @@ public class LayersContribution extends AbstractMenuContributionItem { protected Image getMenuImage() { final Diagram gmfDiagram = this.part.getDiagram(); if (gmfDiagram != null) { - EObject diagram = gmfDiagram.getElement(); - if (diagram instanceof DDiagram) { - super.setDiagram((DDiagram) diagram); - if (!getActivatedOptionalLayers().isEmpty()) { - return DiagramUIPlugin.Implementation.getDecoratedCheckedImage(DESC_LAYER); + try { + EObject diagram = gmfDiagram.getElement(); + if (diagram instanceof DDiagram) { + super.setDiagram((DDiagram) diagram); + if (!getActivatedOptionalLayers().isEmpty()) { + return DiagramUIPlugin.Implementation.getDecoratedCheckedImage(DESC_LAYER); + } } + } catch (IllegalStateException e) { + // Nothing to log here, this can happen if the resource is not accessible anymore (distant resource). } } return DiagramUIPlugin.getPlugin().getImage(DESC_LAYER); |
