1 package org.simantics.modeling;
3 import org.simantics.Simantics;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.common.request.ResourceRead;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.adapter.DropActionFactory;
9 import org.simantics.db.layer0.variable.Variable;
10 import org.simantics.db.layer0.variable.Variables;
11 import org.simantics.scl.runtime.function.Function3;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public class SCLDropAction implements DropActionFactory {
17 private static final Logger LOGGER = LoggerFactory.getLogger(SCLDropAction.class);
19 final private Resource rule;
21 public SCLDropAction(ReadGraph graph, Resource rule) throws DatabaseException {
25 static class RuleFunctionRequest extends ResourceRead<Function3<Resource,Object,Integer,Object>> {
27 protected RuleFunctionRequest(Resource rule) {
32 public Function3<Resource, Object, Integer, Object> perform(ReadGraph graph) throws DatabaseException {
33 Variable ruleVariable = Variables.getVariable(graph, resource);
34 ModelingResources MOD = ModelingResources.getInstance(graph);
35 return ruleVariable.getPossiblePropertyValue(graph, MOD.SCLDropAction_action);
40 public static class SCLDropActionRunnable implements Runnable {
43 public Resource target;
47 public SCLDropActionRunnable(Resource rule, Resource target, Object source, int operation) {
51 this.operation = operation;
56 Simantics.getSession().markUndoPoint();
58 Function3<Resource, Object, Integer, Object> function = Simantics.getSession().syncRequest(new RuleFunctionRequest(rule));
59 function.apply(target, source, operation);
60 } catch (DatabaseException e) {
61 LOGGER.error("SCLDropActionRunnable failed to request/apply RuleFunction {}", rule, e);
68 public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {
69 return new SCLDropActionRunnable(rule, (Resource)target, source, operation);