]> gerrit.simantics Code Review - simantics/platform.git/blob
b4bb6acc27a5caeddfbb6c58b874279ef89796fc
[simantics/platform.git] /
1 package org.simantics.document.linking.ge;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.common.request.WriteRequest;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.adapter.ActionFactory;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.document.linking.ontology.DocumentLink;
10 import org.simantics.ui.SimanticsUI;
11
12 public class RemoveSourceAction implements ActionFactory{
13         
14         
15         @Override
16         public Runnable create(Object target) {
17                 if (!(target instanceof Variable))
18                         return null;
19                 final Variable v = (Variable)target;
20                 
21
22                 return new Runnable() {
23                         
24                         @Override
25                         public void run() {
26                                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
27                                         
28                                         @Override
29                                         public void perform(WriteGraph graph) throws DatabaseException {
30                                             graph.markUndoPoint();
31                                             
32                                                 DocumentLink sl = DocumentLink.getInstance(graph);
33                                                 Resource t = v.getPossibleRepresents(graph);
34                                                 if (!graph.isInstanceOf(t, sl.Source))
35                                                         return;
36                                                 graph.deny(t);
37                                                 
38                                         }
39                                 });
40                                 
41                         }
42                 };
43
44                 
45         }
46
47 }