Bug 519089:[Java 9] Automatic window tabbing should be disallowed

In macOS 10.12, a new system preference "prefer tabs when opening
documents" has been added which causes automatic tabbing of windows in
Eclipse. This is by default enabled to work when application is in
fullscreen mode and can be modified to work always.

Disable automatic window tabbing, by setting the
NSWindow.allowsAutomaticWindowTabbing property to false.

Change-Id: I7f22249d92dabe2597147b9089c42f79b68ac6c4
(cherry picked from commit 36dd297e30a6bf8d2609cf34092c1b40b3cee4fc)
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/180992
Tested-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
Reviewed-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
index 2f534a2..81733e5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
@@ -175,6 +175,9 @@
 	public static final int NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7;
 	public static final int NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8;
 
+	/** 10.12 selector */
+	public static final long /*int*/ sel_setAllowsAutomaticWindowTabbing_ = sel_registerName("setAllowsAutomaticWindowTabbing:");
+
 	/* AWT application delegate. Remove these when JavaRuntimeSupport.framework has bridgesupport generated for it. */
 	public static final long /*int*/ class_JRSAppKitAWT = objc_getClass("JRSAppKitAWT");
 	public static final long /*int*/ sel_awtAppDelegate = sel_registerName("awtAppDelegate");
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
index 57f6d2f..5330bf0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
@@ -707,6 +707,15 @@
 				OS.objc_msgSend(window.id, OS.sel_setMovable_, 0);
 			}
 		}
+		if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 12, 0)) {
+			/*
+			 * In macOS 10.12, a new system preference "prefer tabs when opening documents"
+			 * has been added which causes automatic tabbing of windows in Eclipse.
+			 * Disable automatic window tabbing, by setting the NSWindow.allowsAutomaticWindowTabbing
+			 * property to false.
+			 */
+			OS.objc_msgSend(OS.class_NSWindow, OS.sel_setAllowsAutomaticWindowTabbing_, false);
+		}
 		display.cascadeWindow(window, screen);
 		NSRect screenFrame = screen.frame();
 		double /*float*/ width = screenFrame.width * 5 / 8, height = screenFrame.height * 5 / 8;;