1 package org.simantics.issues.ui.contribution;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.Session;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.SelectionHints;
12 import org.simantics.db.layer0.adapter.DropActionFactory;
13 import org.simantics.issues.ontology.IssueResource;
14 import org.simantics.modeling.PropertyVariables;
15 import org.simantics.utils.datastructures.Callback;
16 import org.simantics.utils.ui.ErrorLogger;
17 import org.simantics.utils.ui.ISelectionUtils;
20 * @author Tuukka Lehtonen
22 public class IssueContextDropAction implements DropActionFactory {
25 public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {
26 //System.out.println("DROP: " + source + " -> " + target);
28 final Resource issue= ISelectionUtils.getSinglePossibleKey(target, SelectionHints.KEY_MAIN, Resource.class);
32 final List<PropertyVariables> vars = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, PropertyVariables.class);
33 if (!vars.isEmpty()) {
34 //System.out.println("TODO: add property container to context");
36 List<Resource> ctx = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, Resource.class);
38 addToIssueContext(g.getSession(), issue, ctx);
44 private void addToIssueContext(Session session, final Resource issue, final List<Resource> contexts) {
45 session.asyncRequest(new WriteRequest() {
47 public void perform(WriteGraph graph) throws DatabaseException {
48 final IssueResource ISSUE = IssueResource.getInstance(graph);
49 for (Resource ctx : contexts) {
50 graph.claim(issue, ISSUE.Issue_HasContext, ISSUE.Issue_HasContext, ctx);
53 }, new Callback<DatabaseException>() {
55 public void run(DatabaseException e) {
57 ErrorLogger.defaultLogError(e);