import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.Button;\r
import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.db.management.ISessionContext;\r
public IsOutputWidget(Composite parent, WidgetSupport support, int style) {\r
support.register(this);\r
isOutputButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+ isOutputButton.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ return graph.hasStatement(variable, sr.IsOutput);\r
+ }\r
+ });\r
isOutputButton.setText("Is Output");\r
}\r
\r
\r
if(variable == null) return;\r
\r
- try {\r
- context.getSession().syncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- final boolean isOutput = graph.hasStatement(variable, sr.IsOutput);\r
- final Button button = getWidget();\r
- button.getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- if(button.isDisposed()) return;\r
- \r
- if(isOutput)\r
- button.setSelection(true);\r
- else\r
- button.setSelection(false);\r
- }\r
- });\r
+ isOutputButton.setInput(context, input);\r
\r
- \r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- \r
isOutputButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
@Override\r
import org.eclipse.swt.events.SelectionListener;\r
import org.eclipse.swt.widgets.Button;\r
import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.utils.ui.ISelectionUtils;\r
public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) {\r
support.register(this);\r
isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+ isReplaceableButton.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ return graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable);\r
+ }\r
+ });\r
isReplaceableButton.setText("Can be replaced by parent module");\r
}\r
\r
\r
if(variable == null) return;\r
\r
- try {\r
- context.getSession().syncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable);\r
- if(replaceable != null)\r
- selected = replaceable;\r
- final Button button = getWidget();\r
- button.getDisplay().asyncExec(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- if(button.isDisposed()) return;\r
- \r
- if(replaceable)\r
- button.setSelection(true);\r
- else\r
- button.setSelection(false);\r
- }\r
- });\r
-\r
- \r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
+ isReplaceableButton.setInput(context, input);\r
\r
isReplaceableButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
graph.claimLiteral(input, sr.Enumeration_isReplaceable, true);\r
selected = true;\r
}\r
+ Layer0Utils.addCommentMetadata(graph, "Modified " + NameUtils.getSafeName(graph, input) + " can be replaced to " + selected);\r
}\r
});\r
}\r