]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java
Fixed compilation problems and SWTAWTComponent focus problem with Java9+
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / SWTAWTComponent.java
index 8031a93abb4f6728feb6a1afbfee586feece68ea..2f2f604ec038e79b32112e153789bff1ee8f2981 100644 (file)
@@ -60,6 +60,8 @@ import org.simantics.utils.ui.internal.awt.AwtFocusHandler;
 import org.simantics.utils.ui.internal.awt.CleanResizeListener;
 import org.simantics.utils.ui.internal.awt.EmbeddedChildFocusTraversalPolicy;
 import org.simantics.utils.ui.internal.awt.SwtFocusHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -99,6 +101,8 @@ import org.simantics.utils.ui.internal.awt.SwtFocusHandler;
  */
 public abstract class SWTAWTComponent extends Composite {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SWTAWTComponent.class);
+
     private static class AwtContext {
         private Frame frame;
         private Component swingComponent;
@@ -342,14 +346,27 @@ public abstract class SWTAWTComponent extends Composite {
 
     private void workaroundJava7FocusProblem(Frame frame) {
         String ver = System.getProperty("java.version");
-        if (ver.startsWith("1.7") || ver.startsWith("1.8")) {
-            try {
-                frame.addWindowListener(new Java7FocusFixListener(this, frame));
-            } catch (SecurityException e) {
-                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
-            } catch (NoSuchMethodException e) {
-                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+        String[] split = ver.split(".");
+
+        if (split.length < 2) {
+            LOGGER.warn("Focus fix listener: unrecognized Java version: " + ver);
+            return;
+        }
+
+        try {
+            int major = Integer.parseInt(split[0]);
+            int minor = Integer.parseInt(split[1]);
+            if ((major == 1 && (minor == 7 || minor == 8)) || major >= 9) {
+                try {
+                    frame.addWindowListener(new Java7FocusFixListener(this, frame));
+                } catch (SecurityException e) {
+                    Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+                } catch (NoSuchMethodException e) {
+                    Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+                }
             }
+        } catch (NumberFormatException e) {
+            LOGGER.error("Focus fix listener: unrecognized Java version: " + ver);
         }
     }