Bug 541020 - IndexOutOfBoundsException below
DefaultConnectionEditPolicy.getAddCommand
Change-Id: Id2b8fa7216392d41544f511847a26b5a0d161abb
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/DefaultConnectionEditPolicy.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/DefaultConnectionEditPolicy.java
index 8fe87da..5484405 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/DefaultConnectionEditPolicy.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/DefaultConnectionEditPolicy.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2016 SAP AG, Redhat.
+ * Copyright (c) 2005, 2018 SAP AG, Redhat.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* Aurelien Pupier - Bug 499720 - DefaultConnectionEditPolicy doesn't support scroll
+ * mwenz - Bug 541020 - IndexOutOfBoundsException below DefaultConnectionEditPolicy.getAddCommand
*
* </copyright>
*
@@ -99,33 +100,38 @@
Connection connection = (Connection) hostModel;
- Object model = ((EditPart) request.getEditParts().get(0)).getModel();
- if (model instanceof org.eclipse.graphiti.mm.pictograms.Shape) {
- org.eclipse.graphiti.mm.pictograms.Shape shape = (org.eclipse.graphiti.mm.pictograms.Shape) model;
- IFeatureProvider featureProvider = getConfigurationProvider().getDiagramTypeProvider().getFeatureProvider();
+ List editParts = request.getEditParts();
+ if (editParts != null && editParts.size() > 0) {
+ Object model = ((EditPart) editParts.get(0)).getModel();
+ if (model instanceof org.eclipse.graphiti.mm.pictograms.Shape) {
+ org.eclipse.graphiti.mm.pictograms.Shape shape = (org.eclipse.graphiti.mm.pictograms.Shape) model;
+ IFeatureProvider featureProvider = getConfigurationProvider().getDiagramTypeProvider()
+ .getFeatureProvider();
- ContainerShape oldContainer = shape.getContainer();
+ ContainerShape oldContainer = shape.getContainer();
- ContainerShape targetContainerShape = null;
+ ContainerShape targetContainerShape = null;
- Point location = request.getLocation();
+ Point location = request.getLocation();
- GraphicalViewer graphicalViewer = getConfigurationProvider().getDiagramContainer().getGraphicalViewer();
- Point searchLocation = getAbsolutePosition(request.getLocation(), graphicalViewer);
- EditPart findEditPartAt = GraphitiUiInternal.getGefService().findEditPartAt(graphicalViewer, searchLocation,
- false);
- if (findEditPartAt != null && findEditPartAt.getModel() instanceof ContainerShape) {
- targetContainerShape = (ContainerShape) findEditPartAt.getModel();
- location = createRealLocation(request.getLocation(), findEditPartAt);
- } else {
- targetContainerShape = getCommonContainerShape();
- }
+ GraphicalViewer graphicalViewer = getConfigurationProvider().getDiagramContainer().getGraphicalViewer();
+ Point searchLocation = getAbsolutePosition(request.getLocation(), graphicalViewer);
+ EditPart findEditPartAt = GraphitiUiInternal.getGefService().findEditPartAt(graphicalViewer,
+ searchLocation, false);
+ if (findEditPartAt != null && findEditPartAt.getModel() instanceof ContainerShape) {
+ targetContainerShape = (ContainerShape) findEditPartAt.getModel();
+ location = createRealLocation(request.getLocation(), findEditPartAt);
+ } else {
+ targetContainerShape = getCommonContainerShape();
+ }
- IMoveShapeContext context = createMoveShapeContext(shape, oldContainer, targetContainerShape, location, connection);
- IMoveShapeFeature layoutShapeFeature = featureProvider.getMoveShapeFeature(context);
- if (layoutShapeFeature != null) {
- result = new GefCommandWrapper(new MoveShapeFeatureCommandWithContext(layoutShapeFeature, context),
- getConfigurationProvider().getDiagramBehavior().getEditingDomain());
+ IMoveShapeContext context = createMoveShapeContext(shape, oldContainer, targetContainerShape, location,
+ connection);
+ IMoveShapeFeature layoutShapeFeature = featureProvider.getMoveShapeFeature(context);
+ if (layoutShapeFeature != null) {
+ result = new GefCommandWrapper(new MoveShapeFeatureCommandWithContext(layoutShapeFeature, context),
+ getConfigurationProvider().getDiagramBehavior().getEditingDomain());
+ }
}
}