Fixed NPE problem from org.simantics.browsing.ui.swt.widgets.Button 73/1073/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 4 Oct 2017 10:21:21 +0000 (13:21 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 4 Oct 2017 10:21:21 +0000 (13:21 +0300)
Also fixed
org.simatnics.modeling.ui.chart.property.BooleanPropertyFactory to not
return null as Boolean selected.

refs #7527

Change-Id: I5f641141ce23ae214b775ccdf57cf55193491a61

bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Button.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/BooleanPropertyFactory.java

index 8dc5feab0b90bf5f1c9227e91f2934528cab8fe7..a3194e7b4d7fe0332b72c77bd7ea706b036e6901 100644 (file)
@@ -90,29 +90,19 @@ public class Button extends WidgetImpl {
 
                 @Override
                 public void exception(final Throwable t) {
-                    SWTUtils.asyncExec(button, new Runnable() {
-
-                        @Override
-                        public void run() {
-                            if(isDisposed()) return;
-//                            System.out.println("Button received new text: " + text);
-                            button.setText(t.toString());
-                        }
-
+                    SWTUtils.asyncExec(button, () -> {
+                        if(isDisposed()) return;
+//                        System.out.println("Button received new text: " + text);
+                        button.setText(t.toString());
                     });
                 }
 
                 @Override
                 public void execute(final String text) {
-                    SWTUtils.asyncExec(button, new Runnable() {
-
-                        @Override
-                        public void run() {
-                            if(isDisposed()) return;
-//                            System.out.println("Button received new text: " + text);
-                            button.setText(text);
-                        }
-
+                    SWTUtils.asyncExec(button, () -> {
+                        if(isDisposed()) return;
+//                        System.out.println("Button received new text: " + text);
+                        button.setText(text);
                     });
                 }
 
@@ -134,15 +124,10 @@ public class Button extends WidgetImpl {
 
                 @Override
                 public void execute(final String text) {
-                    SWTUtils.asyncExec(button, new Runnable() {
-
-                        @Override
-                        public void run() {
-                            if(isDisposed()) return;
-//                            System.out.println("Button received new tooltip: " + text);
-                            button.setToolTipText(text);
-                        }
-
+                    SWTUtils.asyncExec(button, () -> {
+                        if(isDisposed()) return;
+//                        System.out.println("Button received new tooltip: " + text);
+                        button.setToolTipText(text);
                     });
                 }
 
@@ -164,24 +149,17 @@ public class Button extends WidgetImpl {
 
                 @Override
                 public void execute(final ImageDescriptor imageDescriptor) {
-                    SWTUtils.asyncExec(button, new Runnable() {
-
-                        @Override
-                        public void run() {
-
-                            if(isDisposed()) return;
-//                            System.out.println("Button received new image");
-                            ResourceManager rm = support.getParameter(WidgetSupport.RESOURCE_MANAGER);
-                            if (rm != null) {
-                                Image image = (Image) rm.get(imageDescriptor);
-                                button.setImage(image);
-                            }
-                            // TODO: how can we resize without this knife??
-                            button.getParent().layout();
-                            button.getParent().getParent().layout();
-
+                    SWTUtils.asyncExec(button, () -> {
+                        if(isDisposed()) return;
+//                        System.out.println("Button received new image");
+                        ResourceManager rm = support.getParameter(WidgetSupport.RESOURCE_MANAGER);
+                        if (rm != null) {
+                            Image image = (Image) rm.get(imageDescriptor);
+                            button.setImage(image);
                         }
-
+                        // TODO: how can we resize without this knife??
+                        button.getParent().layout();
+                        button.getParent().getParent().layout();
                     });
                 }
 
@@ -201,12 +179,9 @@ public class Button extends WidgetImpl {
                 }
                 @Override
                 public void execute(final Boolean selected) {
-                    SWTUtils.asyncExec(button, new Runnable() {
-                        @Override
-                        public void run() {
-                            if(isDisposed()) return;
-                            button.setSelection(selected);
-                        }
+                    SWTUtils.asyncExec(button, () -> {
+                        if(isDisposed()) return;
+                        button.setSelection(Boolean.TRUE.equals(selected));
                     });
                 }
                 @Override
@@ -222,46 +197,34 @@ public class Button extends WidgetImpl {
     }
 
     public <T> void setText(final ParametrizedRead<T, String> read) {
-               
-       Simantics.getSession().async(new UniqueRead<String>() {
-
-               @Override
-               public String perform(ReadGraph graph) throws DatabaseException {
-                       T input = support.getInput(graph);
-                       return graph.syncRequest(read.get(input));
-               }
-
-       }, new Listener<String>() {
-
-               @Override
-               public void exception(Throwable t) {
-                       t.printStackTrace();
-               }
-
-               @Override
-               public void execute(final String text) {
-
-                       if(isDisposed()) return;
-
-                       button.getDisplay().asyncExec(new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       button.setText(text);
-                               }
-
-                       });
-               }
-
-               @Override
-               public boolean isDisposed() {
-                       return button.isDisposed();
-               }
+        Simantics.getSession().async(new UniqueRead<String>() {
+            @Override
+            public String perform(ReadGraph graph) throws DatabaseException {
+                T input = support.getInput(graph);
+                return graph.syncRequest(read.get(input));
+            }
+        }, new Listener<String>() {
+            @Override
+            public void exception(Throwable t) {
+                ErrorLogger.defaultLogError(t);
+            }
 
-       });
+            @Override
+            public void execute(final String text) {
+                if(isDisposed()) return;
+                button.getDisplay().asyncExec(() -> {
+                    if(isDisposed()) return;
+                    button.setText(text);
+                });
+            }
 
+            @Override
+            public boolean isDisposed() {
+                return button.isDisposed();
+            }
+        });
     }
-    
+
     public void setTooltipText(String text) {
         button.setToolTipText(text);
     }
index 14dc51c1d24d9451a31ccf6121943027127dce73..8efe2668a6980aa0bb42645597ee364836e343b8 100644 (file)
@@ -36,7 +36,7 @@ public class BooleanPropertyFactory extends ReadFactoryImpl<Resource, Boolean> {
 
     @Override
     public Boolean perform(ReadGraph graph, Resource r) throws DatabaseException {
-        return graph.getPossibleRelatedValue2(r, graph.getResource(propertyURI), Bindings.BOOLEAN);
+        return Boolean.TRUE.equals( graph.getPossibleRelatedValue2(r, graph.getResource(propertyURI), Bindings.BOOLEAN) );
     }
 
 }