]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Synchronize ModelingUtils.fileDialog() to UI thread. 27/2827/2
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 1 Apr 2019 12:57:59 +0000 (15:57 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 4 Apr 2019 18:24:12 +0000 (18:24 +0000)
gitlab #284

Change-Id: Ie76ba4cd255eb2371745ac9162d2a619527f7ad0

bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java

index f7ab55fdd3715e742f4a4450c3dba9c0cd274afa..ea960c1d0de2fe97dfae468331b0521f69219ccd 100644 (file)
@@ -2400,31 +2400,45 @@ public class ModelingUtils {
        }
        
        public static File fileDialog(String title, List<Tuple> namesAndExtensions) {
-               
-               Display display = Display.getCurrent();
-               Shell shell = display.getActiveShell();
-               
-        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
-        dialog.setText(title);
-        
-        String[] extensions = new String[namesAndExtensions.size()];
-        String[] filterNames = new String[namesAndExtensions.size()];
-        int index = 0;
-        for(Tuple t : namesAndExtensions) {
-               String filterName = (String)t.get(0);
-               String extension = (String)t.get(1);
-               filterNames[index] = filterName;
-               extensions[index] = extension;
-               index++;
-        }
-        
-        dialog.setFilterExtensions(extensions);
-        dialog.setFilterNames(filterNames);
-        final String fileName = dialog.open();
-        if (fileName == null) return null;
-        
-        return new File(fileName);
+               return new Runnable() {
+                       private File result;
+                       
+                       File getFile() {
+                               Display.getDefault().syncExec(this);
+                               return result;
+                       }
+                       
+                       @Override
+                       public void run() {
+                               result = showDialog();
+                       }
 
+                       private File showDialog() {
+                               Display display = Display.getCurrent();
+                               Shell shell = display.getActiveShell();
+                               
+                       FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+                       dialog.setText(title);
+                       
+                       String[] extensions = new String[namesAndExtensions.size()];
+                       String[] filterNames = new String[namesAndExtensions.size()];
+                       int index = 0;
+                       for(Tuple t : namesAndExtensions) {
+                               String filterName = (String)t.get(0);
+                               String extension = (String)t.get(1);
+                               filterNames[index] = filterName;
+                               extensions[index] = extension;
+                               index++;
+                       }
+                       
+                       dialog.setFilterExtensions(extensions);
+                       dialog.setFilterNames(filterNames);
+                       final String fileName = dialog.open();
+                       if (fileName == null) return null;
+                       
+                       return new File(fileName);
+                       }
+               }.getFile();
        }
        
        public static Resource createLibrary(WriteGraph graph, Resource parent) throws DatabaseException {