]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed compilation problems and SWTAWTComponent focus problem with Java9+ 63/1663/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 28 Mar 2018 19:44:18 +0000 (22:44 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 28 Mar 2018 19:44:18 +0000 (22:44 +0300)
refs #7848

Change-Id: If166f7864d05c67f4c58b87018b273a36f085801

bundles/org.simantics.ui/src/org/simantics/ui/dnd/LocalObjectTransfer.java
bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java
bundles/org.simantics.utils.ui/testcases/org/simantics/utils/ui/SWTAWTTest.java

index 5353ec1bb5c9b1641a7efd7c31a7c25d28e3278c..a920c82c1c13b6886216ac65553a15db451f89f2 100644 (file)
  *******************************************************************************/
 package org.simantics.ui.dnd;
 
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.FlavorTable;
 import java.awt.datatransfer.SystemFlavorMap;
-import java.util.Map;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
@@ -23,8 +20,6 @@ import org.eclipse.jface.util.Policy;
 import org.eclipse.swt.dnd.ByteArrayTransfer;
 import org.eclipse.swt.dnd.TransferData;
 
-import sun.awt.datatransfer.DataTransferer;
-
 public class LocalObjectTransfer extends ByteArrayTransfer {
 
     // First attempt to create a UUID for the type name to make sure that
@@ -32,17 +27,21 @@ public class LocalObjectTransfer extends ByteArrayTransfer {
     // <code>LocalSelectionTransfer</code>
        public static final String TYPE_NAME = SystemFlavorMap.encodeJavaMIMEType(LocalObjectTransferable.TYPE_NAME);
        
-       private static int getMapping() {
-
-               for(Map.Entry<DataFlavor, String> entry : SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).entrySet()) {
-                       for(long l : DataTransferer.getInstance().getFormatsForFlavorAsArray(entry.getKey(), (FlavorTable)SystemFlavorMap.getDefaultFlavorMap())) {
-                               return (int)l;
-                       }
-               }
-               
-               throw new Error("No mapping.");
-               
-       }
+//     private static int getMapping() {
+//
+//             for(Map.Entry<DataFlavor, String> entry : SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).entrySet()) {
+//                     for(long l : DataTransferer.getInstance().getFormatsForFlavorAsArray(entry.getKey(), (FlavorTable)SystemFlavorMap.getDefaultFlavorMap())) {
+//                             return (int)l;
+//                     }
+//             }
+//             DataFlavor[] flavors = SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).keySet().toArray(new DataFlavor[0]);
+//             for(long l : DataTransferer.getInstance().getFormatsForFlavors(flavors, (FlavorTable)SystemFlavorMap.getDefaultFlavorMap()).keySet()) {
+//                     return (int)l;
+//             }
+//             
+//             throw new Error("No mapping.");
+//             
+//     }
        // In Linux (Ubuntu 14.04) using SystemFlavorMap to get the type id gives different result than what is received with drop data (TransferData.type) 
     private static final int TYPEID = registerType(TYPE_NAME);//getMapping();
     
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);
         }
     }
 
index f0a445087c39bb9eff9fed60582756d7cade45e0..f963fe4c71e59e2b5d53a7bd93b62fa1d653cea1 100644 (file)
@@ -177,9 +177,9 @@ public class SWTAWTTest {
        private static JComponent createTable() {
                /* Creating components */
                int nrows = 1000, ncolumns = 10;
-               Vector<Object> rows = new Vector<Object>();
+               Vector<Vector<Object>> rows = new Vector<>();
                for (int i = 0; i < nrows; i++) {
-                       Vector<Object> row = new Vector<Object>();
+                       Vector<Object> row = new Vector<>();
                        for (int j = 0; j < ncolumns; j++) {
                                row.addElement("Item " + i + "-" + j);
                        }