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.diagram.Logger;
12 import org.simantics.scl.runtime.function.Function3;
14 public class SCLDropAction implements DropActionFactory {
16 final private Resource rule;
18 public SCLDropAction(ReadGraph graph, Resource rule) throws DatabaseException {
22 static class RuleFunctionRequest extends ResourceRead<Function3<Resource,Object,Integer,Object>> {
24 protected RuleFunctionRequest(Resource rule) {
29 public Function3<Resource, Object, Integer, Object> perform(ReadGraph graph) throws DatabaseException {
30 Variable ruleVariable = Variables.getVariable(graph, resource);
31 ModelingResources MOD = ModelingResources.getInstance(graph);
32 return ruleVariable.getPossiblePropertyValue(graph, MOD.SCLDropAction_action);
37 public static class SCLDropActionRunnable implements Runnable {
40 public Resource target;
44 public SCLDropActionRunnable(Resource rule, Resource target, Object source, int operation) {
48 this.operation = operation;
53 Simantics.getSession().markUndoPoint();
55 Function3<Resource, Object, Integer, Object> function = Simantics.getSession().syncRequest(new RuleFunctionRequest(rule));
56 function.apply(target, source, operation);
57 } catch (DatabaseException e) {
58 Logger.defaultLogError(e);
65 public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {
66 return new SCLDropActionRunnable(rule, (Resource)target, source, operation);