X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FButton.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FButton.java;h=a3194e7b4d7fe0332b72c77bd7ea706b036e6901;hp=8dc5feab0b90bf5f1c9227e91f2934528cab8fe7;hb=0a8153231a20d3de2950a9558b5becdca38ed477;hpb=17a42ca754147cfd5d101ae120697fbb172b3411 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); }