From d68b21f05cd0fbcccdc9a9c05a8dee9c133a8ba0 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 22 Aug 2014 08:11:29 +0000 Subject: [PATCH] refs #5207 Fixing IsOutputWidget and ReplaceableIndexes to use WidgetImpl.setInput instead of own custom input handling git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30117 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/properties/widgets/IsOutputWidget.java | 38 +++++----------- .../arrays/ReplaceableIndexesWidget.java | 43 ++++++------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java index db9a513f..40fe24cb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java @@ -16,6 +16,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; @@ -23,7 +24,6 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; @@ -39,6 +39,14 @@ public class IsOutputWidget implements Widget{ public IsOutputWidget(Composite parent, WidgetSupport support, int style) { support.register(this); isOutputButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK); + isOutputButton.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + return graph.hasStatement(variable, sr.IsOutput); + } + }); isOutputButton.setText("Is Output"); } @@ -56,34 +64,8 @@ public class IsOutputWidget implements Widget{ if(variable == null) return; - try { - context.getSession().syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - final boolean isOutput = graph.hasStatement(variable, sr.IsOutput); - final Button button = getWidget(); - button.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(button.isDisposed()) return; - - if(isOutput) - button.setSelection(true); - else - button.setSelection(false); - } - }); + isOutputButton.setInput(context, input); - - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - isOutputButton.addSelectionListener(new SelectionListenerImpl(context) { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java index 0dd0a49a..d5403ac9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java @@ -17,14 +17,16 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.ui.ISelectionUtils; @@ -38,6 +40,14 @@ public class ReplaceableIndexesWidget implements Widget { public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) { support.register(this); isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK); + isReplaceableButton.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + return graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable); + } + }); isReplaceableButton.setText("Can be replaced by parent module"); } @@ -55,35 +65,7 @@ public class ReplaceableIndexesWidget implements Widget { if(variable == null) return; - try { - context.getSession().syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable); - if(replaceable != null) - selected = replaceable; - final Button button = getWidget(); - button.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(button.isDisposed()) return; - - if(replaceable) - button.setSelection(true); - else - button.setSelection(false); - } - }); - - - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } + isReplaceableButton.setInput(context, input); isReplaceableButton.addSelectionListener(new SelectionListenerImpl(context) { @@ -98,6 +80,7 @@ public class ReplaceableIndexesWidget implements Widget { graph.claimLiteral(input, sr.Enumeration_isReplaceable, true); selected = true; } + Layer0Utils.addCommentMetadata(graph, "Modified " + NameUtils.getSafeName(graph, input) + " can be replaced to " + selected); } }); } -- 2.47.1