Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-02-28 10:13:20 -0500
committerHenrik Rentz-Reichert2012-02-28 10:13:20 -0500
commit5e0f00753039cb447cd9c96f65b80c631a6014df (patch)
tree7bab722e0e075cf0d09a149b0eadf2e760d05a0e /plugins/org.eclipse.etrice.ui.structure
parent687c8945f63693ccb1d0120d8096e84c4a5fb9b2 (diff)
downloadorg.eclipse.etrice-5e0f00753039cb447cd9c96f65b80c631a6014df.tar.gz
org.eclipse.etrice-5e0f00753039cb447cd9c96f65b80c631a6014df.tar.xz
org.eclipse.etrice-5e0f00753039cb447cd9c96f65b80c631a6014df.zip
[ui.structure] bug 371992: Deleting a connected port should delete all associated bindings
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371992
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.structure')
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java107
1 files changed, 97 insertions, 10 deletions
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
index 294ad9bda..d56390f7a 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
@@ -12,7 +12,26 @@
package org.eclipse.etrice.ui.structure.support;
+import java.util.ArrayList;
+import java.util.Collection;
+
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.ExternalPort;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.MessageFromIf;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
import org.eclipse.etrice.ui.structure.ImageProvider;
@@ -32,6 +51,8 @@ import org.eclipse.graphiti.features.context.IDoubleClickContext;
import org.eclipse.graphiti.features.context.IPictogramElementContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.DeleteContext;
+import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.mm.algorithms.Ellipse;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
@@ -49,22 +70,13 @@ import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.ContextButtonEntry;
import org.eclipse.graphiti.tb.IContextButtonPadData;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.IScopeProvider;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ExternalPort;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.SubSystemClass;
-
public class PortSupport extends InterfaceItemSupport {
private static final int REPL_OFFSET = ITEM_SIZE/8;
@@ -244,10 +256,85 @@ public class PortSupport extends InterfaceItemSupport {
private static class DeleteFeature extends InterfaceItemSupport.FeatureProvider.DeleteFeature {
+ private ArrayList<Binding> external = new ArrayList<Binding>();
+ private ArrayList<Binding> internal = new ArrayList<Binding>();
+
public DeleteFeature(IFeatureProvider fp) {
super(fp);
}
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ if (!super.canDelete(context))
+ return false;
+
+ ContainerShape shape = (ContainerShape) context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ if (!(bo instanceof Port))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public void delete(IDeleteContext context) {
+ // check for bindings first
+ external.clear();
+ internal.clear();
+ Port port = (Port) getBusinessObjectForPictogramElement(context.getPictogramElement());
+ StructureClass sc = (StructureClass) port.eContainer();
+ Collection<Setting> refs = EcoreUtil.UsageCrossReferencer.find(port, port.eResource().getResourceSet());
+ for (Setting ref : refs) {
+ if (ref.getEObject() instanceof BindingEndPoint) {
+ if (ref.getEObject().eContainer().eContainer() instanceof StructureClass
+ && ref.getEObject().eContainer().eContainer()==sc)
+ internal.add((Binding) ref.getEObject().eContainer());
+ else
+ external.add((Binding) ref.getEObject().eContainer());
+ }
+ else if (ref.getEObject() instanceof MessageFromIf) {
+ MessageDialog.openInformation(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete Port",
+ "This port cannot be deleted since it is referenced from the state machine.");
+ return;
+ }
+ }
+ if (!external.isEmpty()) {
+ boolean proceed = MessageDialog.openQuestion(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete Port",
+ "This port is connected externally.\n"
+ +"It can only be deleted if the external bindings are also deleted.\n\n"
+ +"Proceed?");
+ if (!proceed)
+ return;
+ }
+
+ super.delete(context);
+ }
+
+ @Override
+ public void preDelete(IDeleteContext context) {
+ // delete all bindings
+ for (Binding bind: internal) {
+ PictogramElement connection = getFeatureProvider().getPictogramElementForBusinessObject(bind);
+ DeleteContext ctx = new DeleteContext(connection);
+ ctx.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1));
+ IDeleteFeature deleteFeature = getFeatureProvider().getDeleteFeature(ctx);
+ if (deleteFeature!=null)
+ deleteFeature.delete(ctx);
+ }
+ for (Binding bind: external) {
+ EcoreUtil.delete(bind);
+ }
+
+ super.preDelete(context);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.graphiti.ui.features.DefaultDeleteFeature#deleteBusinessObject(java.lang.Object)
*/

Back to the top