Fixed CompilePGraphsAction that gave a NullPointerException 14/1314/1
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Mon, 11 Dec 2017 12:39:35 +0000 (14:39 +0200)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Mon, 11 Dec 2017 12:39:35 +0000 (14:39 +0200)
A worker thread with a null displayed tried to compile the pgraph for
ontology definition files. Ensuring that a default display is used in
such cases fixed the issues.

An error message mentioned missing dependencies if the ontology file
containers syntax errors. Thie message now mentioned problems in the
ontology file instead.

refs #7679

Change-Id: Icd483835462ec3cd27c16ca751eaee3d7b3dbdd2

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java

index eda0228f9049d08ab1fba7e8ea0e5983d603de48..d71d1e83729a297eb15c5806c069fe5e587da930 100644 (file)
@@ -52,34 +52,43 @@ public class CompilePGraphsAction implements ActionFactory {
     }
 
     public static class CompileUserAgent implements CompilePGraphs.UserAgent {
+       
         @Override
         public void reportProblems(CompilationResult result) {
-            class ErrorMessageDialog extends MessageDialog {
-                public ErrorMessageDialog(Shell shell) {
-                    super(shell, 
-                            "Unsatisfied dependencies", null, 
-                            "The following dependencies were missing. Please import the dependencies and try again.", 
-                            MessageDialog.ERROR, new String[] { "Continue" }, 0);
-                }
+               Runnable runnable = () -> {
+                       class ErrorMessageDialog extends MessageDialog {
+                               public ErrorMessageDialog(Shell shell) {
+                                       super(shell, 
+                                                       "Problems in the Ontology Definition File", null, 
+                                                       "The following issues were found:", 
+                                                       MessageDialog.ERROR, new String[] { "Continue" }, 0);
+                               }
 
-                @Override
-                protected Control createCustomArea(Composite composite) {
-                    GridLayoutFactory.fillDefaults().applyTo(composite);
+                               @Override
+                               protected Control createCustomArea(Composite composite) {
+                                       GridLayoutFactory.fillDefaults().applyTo(composite);
 
-                    org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
-                    GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
-                    for (Problem problem : result.getErrors())
-                        list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
-                    for (Problem problem : result.getWarnings())
-                        list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
+                                       org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
+                                       GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
+                                       for (Problem problem : result.getErrors())
+                                               list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
+                                       for (Problem problem : result.getWarnings())
+                                               list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
 
-                    return composite;
-                }
-            }
+                                       return composite;
+                               }
+                       }
 
-            ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
-            md.open();
+                       ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
+                       md.open();
+               };              
+               
+               Display display = Display.getCurrent();
+               if (display == null)
+                       display = Display.getDefault();
+               display.asyncExec(runnable);
         }
+
     }
 
 }