Merge "eTrice nightly feature requires complete xtext sdk"
diff --git a/plugins/org.eclipse.etrice.ui.commands/plugin.xml b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
index 850b047..2a96967 100644
--- a/plugins/org.eclipse.etrice.ui.commands/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
@@ -151,9 +151,10 @@
       </menuContribution>
   <menuContribution
         allPopups="false"
-        locationURI="popup:org.eclipse.etrice.core.room.outline?after=additions">
+        locationURI="popup:org.eclipse.etrice.core.room.outline?after=editStructure">
      <command
            commandId="org.eclipse.etrice.core.room.ui.editBehavior"
+           id="editBehavior"
            label="Edit Behavior"
            style="push">
         <visibleWhen
@@ -168,9 +169,10 @@
   </menuContribution>
   <menuContribution
         allPopups="false"
-        locationURI="popup:org.eclipse.etrice.core.room.outline?after=additions">
+        locationURI="popup:org.eclipse.etrice.core.room.outline">
      <command
            commandId="org.eclipse.etrice.core.room.ui.editStructure"
+           id="editStructure"
            label="Edit Structure"
            style="push">
         <visibleWhen
@@ -185,9 +187,10 @@
   </menuContribution>
   <menuContribution
         allPopups="false"
-        locationURI="popup:org.eclipse.etrice.core.room.outline?after=additions">
+        locationURI="popup:org.eclipse.etrice.core.room.outline?after=editBehavior">
      <command
            commandId="org.eclipse.etrice.core.room.ui.exportDiagrams"
+           id="exportDiagrams"
            label="Export Diagrams"
            style="push">
         <visibleWhen
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomContextMenuProvider.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomContextMenuProvider.java
new file mode 100644
index 0000000..5babfe0
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomContextMenuProvider.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2015 protos software gmbh (http://www.protos.de).
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * CONTRIBUTORS:
+ * 		Juergen Haug (initial contribution)
+ * 
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.base.editor;
+
+import java.util.Set;
+
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.graphiti.ui.editor.DiagramEditorContextMenuProvider;
+import org.eclipse.graphiti.ui.platform.IConfigurationProvider;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+
+import com.google.common.collect.Sets;
+
+public class CustomContextMenuProvider extends DiagramEditorContextMenuProvider {
+
+	protected Set<IContributionItem> allowedItems = Sets.newHashSet();
+	
+	public CustomContextMenuProvider(EditPartViewer viewer, ActionRegistry registry,
+			IConfigurationProvider configurationProvider) {
+		super(viewer, registry, configurationProvider);
+	}
+	
+	@Override
+	public void buildContextMenu(IMenuManager manager) {
+		super.buildContextMenu(manager);
+		
+		// remember built items
+		allowedItems = Sets.newHashSet(getItems());
+	}
+	
+	@Override
+	protected void update(boolean force, boolean recursive) {	
+		// remove external items
+		for(IContributionItem item : getItems().clone())
+			if(!allowedItems.contains(item))
+				remove(item);
+		
+		super.update(force, recursive);
+	}
+	
+	@Override
+	protected boolean allowItem(IContributionItem itemToAdd) {
+		// filtering items here does not work, Bug 93279 
+		return super.allowItem(itemToAdd);
+	}
+
+	@Override
+	protected void addDefaultMenuGroupEdit(IMenuManager manager) {
+	}
+
+	@Override
+	protected void addDefaultMenuGroupPrint(IMenuManager manager) {
+	}
+}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomDiagramBehavior.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomDiagramBehavior.java
index af2c7f3..07851e4 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomDiagramBehavior.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomDiagramBehavior.java
@@ -12,7 +12,7 @@
 
 package org.eclipse.etrice.ui.common.base.editor;
 
-import org.eclipse.etrice.ui.common.base.editor.CustomUpdateBehavior;
+import org.eclipse.gef.ContextMenuProvider;
 import org.eclipse.graphiti.ui.editor.DefaultUpdateBehavior;
 import org.eclipse.graphiti.ui.editor.DiagramBehavior;
 import org.eclipse.graphiti.ui.editor.IDiagramContainerUI;
@@ -37,4 +37,11 @@
 	protected DefaultUpdateBehavior createUpdateBehavior() {
 		return new CustomUpdateBehavior(this);
 	}
+	
+	@Override
+	protected ContextMenuProvider createContextMenuProvider() {
+		return new CustomContextMenuProvider(getDiagramContainer().getGraphicalViewer(),
+				getDiagramContainer().getActionRegistry(),
+				getConfigurationProvider());
+	}
 }
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
index f7c2204..6eeb3da 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
@@ -35,6 +35,7 @@
 import org.eclipse.etrice.core.room.StructureClass;
 import org.eclipse.etrice.core.room.SubSystemRef;
 import org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants;
+import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature;
 import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil;
@@ -79,7 +80,6 @@
 import org.eclipse.graphiti.features.impl.AbstractAddFeature;
 import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
 import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
 import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
 import org.eclipse.graphiti.features.impl.Reason;
 import org.eclipse.graphiti.mm.PropertyContainer;
@@ -886,18 +886,6 @@
 				
 		}
 		
-		private class RemoveFeature extends DefaultRemoveFeature {
-
-			public RemoveFeature(IFeatureProvider fp) {
-				super(fp);
-			}
-
-			@Override
-			public boolean canRemove(IRemoveContext context) {
-				return false;
-			}
-		}
-		
 		private class DeleteFeature extends DeleteWithoutConfirmFeature {
 
 			public DeleteFeature(IFeatureProvider fp) {
@@ -1067,7 +1055,7 @@
 		
 		@Override
 		public IRemoveFeature getRemoveFeature(IRemoveContext context) {
-			return new RemoveFeature(fp);
+			return new CantRemoveFeature(fp);
 		}
 		
 		@Override
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
index db2235b..db8d4b7 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
@@ -22,6 +22,7 @@
 import org.eclipse.etrice.core.room.Port;
 import org.eclipse.etrice.core.room.RoomFactory;
 import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateConnectionFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature;
 import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature;
@@ -54,7 +55,6 @@
 import org.eclipse.graphiti.features.custom.ICustomFeature;
 import org.eclipse.graphiti.features.impl.AbstractAddFeature;
 import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
 import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
 import org.eclipse.graphiti.mm.algorithms.Polyline;
 import org.eclipse.graphiti.mm.pictograms.Anchor;
@@ -412,18 +412,6 @@
 			}
 		}
 		
-		private class RemoveFeature extends DefaultRemoveFeature {
-
-			public RemoveFeature(IFeatureProvider fp) {
-				super(fp);
-			}
-			
-			@Override
-			public boolean canRemove(IRemoveContext context) {
-				return false;
-			}
-		}
-		
 		private class DeleteFeature extends DeleteWithoutConfirmFeature {
 
 			public DeleteFeature(IFeatureProvider fp) {
@@ -521,7 +509,7 @@
 		
 		@Override
 		public IRemoveFeature getRemoveFeature(IRemoveContext context) {
-			return new RemoveFeature(fp);
+			return new CantRemoveFeature(fp);
 		}
 		
 		@Override
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
index 8fdc2f7..fabba7a 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
@@ -21,6 +21,7 @@
 import org.eclipse.etrice.core.room.Port;
 import org.eclipse.etrice.core.room.SPP;
 import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature;
 import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature;
@@ -49,7 +50,6 @@
 import org.eclipse.graphiti.features.impl.AbstractAddFeature;
 import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
 import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
 import org.eclipse.graphiti.features.impl.Reason;
 import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
 import org.eclipse.graphiti.mm.algorithms.Rectangle;
@@ -414,17 +414,6 @@
 			}
 		}
 		
-		protected static class RemoveFeature extends DefaultRemoveFeature {
-
-			public RemoveFeature(IFeatureProvider fp) {
-				super(fp);
-			}
-
-			public boolean canRemove(IRemoveContext context) {
-				return false;
-			}
-		}
-		
 		protected static class DeleteFeature extends DeleteWithoutConfirmFeature {
 
 			public DeleteFeature(IFeatureProvider fp) {
@@ -645,7 +634,7 @@
 		
 		@Override
 		public IRemoveFeature getRemoveFeature(IRemoveContext context) {
-			return new RemoveFeature(fp);
+			return new CantRemoveFeature(fp);
 		}
 		
 		@Override
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
index ea58062..4982b94 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
@@ -23,6 +23,7 @@
 import org.eclipse.etrice.core.room.SPP;
 import org.eclipse.etrice.core.room.SPPoint;
 import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
 import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateConnectionFeature;
 import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature;
 import org.eclipse.etrice.ui.structure.ImageProvider;
@@ -49,7 +50,6 @@
 import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
 import org.eclipse.graphiti.features.impl.AbstractAddFeature;
 import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
 import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
 import org.eclipse.graphiti.mm.algorithms.Polyline;
 import org.eclipse.graphiti.mm.pictograms.Anchor;
@@ -216,18 +216,6 @@
 
 		}
 		
-		private class RemoveFeature extends DefaultRemoveFeature {
-
-			public RemoveFeature(IFeatureProvider fp) {
-				super(fp);
-			}
-			
-			@Override
-			public boolean canRemove(IRemoveContext context) {
-				return false;
-			}
-		}
-		
 		private class DeleteFeature extends DeleteWithoutConfirmFeature {
 
 			public DeleteFeature(IFeatureProvider fp) {
@@ -374,7 +362,7 @@
 		
 		@Override
 		public IRemoveFeature getRemoveFeature(IRemoveContext context) {
-			return new RemoveFeature(fp);
+			return new CantRemoveFeature(fp);
 		}
 		
 		@Override
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
index 33d5333..729a3d3 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
@@ -20,6 +20,7 @@
 import org.eclipse.etrice.core.room.Port;
 import org.eclipse.etrice.core.room.StructureClass;
 import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase;
+import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
 import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature;
 import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob;
 import org.eclipse.graphiti.dt.IDiagramTypeProvider;
@@ -44,7 +45,6 @@
 import org.eclipse.graphiti.features.custom.ICustomFeature;
 import org.eclipse.graphiti.features.impl.AbstractAddFeature;
 import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
 import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
 import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
 import org.eclipse.graphiti.mm.algorithms.Rectangle;
@@ -375,18 +375,6 @@
 			}
 		}
 		
-		private class RemoveFeature extends DefaultRemoveFeature {
-
-			public RemoveFeature(IFeatureProvider fp) {
-				super(fp);
-			}
-			
-			@Override
-			public boolean canRemove(IRemoveContext context) {
-				return false;
-			}
-		}
-		
 		private class DeleteFeature extends DeleteWithoutConfirmFeature {
 
 			public DeleteFeature(IFeatureProvider fp) {
@@ -435,7 +423,7 @@
 		
 		@Override
 		public IRemoveFeature getRemoveFeature(IRemoveContext context) {
-			return new RemoveFeature(fp);
+			return new CantRemoveFeature(fp);
 		}
 		
 		@Override