From: Tuukka Lehtonen Date: Wed, 4 Oct 2017 10:21:21 +0000 (+0300) Subject: Fixed NPE problem from org.simantics.browsing.ui.swt.widgets.Button X-Git-Tag: v1.31.0~146 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0a8153231a20d3de2950a9558b5becdca38ed477;p=simantics%2Fplatform.git Fixed NPE problem from org.simantics.browsing.ui.swt.widgets.Button Also fixed org.simatnics.modeling.ui.chart.property.BooleanPropertyFactory to not return null as Boolean selected. refs #7527 Change-Id: I5f641141ce23ae214b775ccdf57cf55193491a61 --- diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Button.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Button.java index 8dc5feab0..a3194e7b4 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Button.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Button.java @@ -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 void setText(final ParametrizedRead read) { - - Simantics.getSession().async(new UniqueRead() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - T input = support.getInput(graph); - return graph.syncRequest(read.get(input)); - } - - }, new Listener() { - - @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() { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + T input = support.getInput(graph); + return graph.syncRequest(read.get(input)); + } + }, new Listener() { + @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); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/BooleanPropertyFactory.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/BooleanPropertyFactory.java index 14dc51c1d..8efe2668a 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/BooleanPropertyFactory.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/BooleanPropertyFactory.java @@ -36,7 +36,7 @@ public class BooleanPropertyFactory extends ReadFactoryImpl { @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) ); } }