Bug 533726 - Allow to detach a view part via the tab menu as in Eclipse
3.x

Move position of new menu entry to top and creates a separator if
necessary

Change-Id: I7c436921b154408dcd2beb8b106a1e7c55ba23f5
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
index 2ddebbd..4243d8b 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
@@ -1408,14 +1408,17 @@
 	/**
 	 * Populate the tab's context menu for the given part.
 	 *
-	 * @param menu
-	 *            the menu to be populated
-	 * @param part
-	 *            the relevant part
+	 * @param menu the menu to be populated
+	 * @param part the relevant part
 	 */
 	protected void populateTabMenu(final Menu menu, MPart part) {
+
+		createMenuItem(menu, SWTRenderersMessages.menuDetach, e -> detachActivePart(menu));
+		boolean needSeparatorAfterDetach = true;
+
 		int closeableElements = 0;
 		if (isClosable(part)) {
+			needSeparatorAfterDetach = createSeparator(menu, needSeparatorAfterDetach);
 			createMenuItem(menu, SWTRenderersMessages.menuClose, e -> closePart(menu));
 			closeableElements++;
 		}
@@ -1425,6 +1428,7 @@
 			closeableElements += getCloseableSiblingParts(part).size();
 
 			if (closeableElements >= 2) {
+				needSeparatorAfterDetach = createSeparator(menu, needSeparatorAfterDetach);
 				createMenuItem(menu, SWTRenderersMessages.menuCloseOthers, e -> closeSiblingParts(menu, true));
 
 				// create menu for parts on the left
@@ -1443,7 +1447,18 @@
 
 			}
 		}
-		createMenuItem(menu, SWTRenderersMessages.menuDetach, e -> detachActivePart(menu));
+
+	}
+
+	/**
+	 * @param needSeparator
+	 */
+	private boolean createSeparator(Menu menu, boolean needSeparator) {
+		if (needSeparator) {
+			new MenuItem(menu, SWT.SEPARATOR);
+			return false;
+		}
+		return true;
 
 	}