From 42542a731384c850346a58e580770011ee3d4ba2 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Mon, 1 Apr 2019 15:57:59 +0300 Subject: [PATCH] Synchronize ModelingUtils.fileDialog() to UI thread. gitlab #284 Change-Id: Ie76ba4cd255eb2371745ac9162d2a619527f7ad0 --- .../org/simantics/modeling/ModelingUtils.java | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index f7ab55fdd..ea960c1d0 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -2400,31 +2400,45 @@ public class ModelingUtils { } public static File fileDialog(String title, List 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 { -- 2.47.1