]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
2658fb650c2e903dbf974a4b0e33e3a8bba028fc
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.wizards.functions;\r
2 \r
3 import org.simantics.browsing.ui.common.node.DeleteException;\r
4 import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
5 import org.simantics.db.Resource;\r
6 import org.simantics.db.WriteGraph;\r
7 import org.simantics.db.common.request.WriteRequest;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.layer0.Layer0;\r
10 import org.simantics.sysdyn.SysdynResource;\r
11 import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
12 import org.simantics.ui.SimanticsUI;\r
13 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
14 \r
15 public class SharedFunctionsFolderNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
16 \r
17     public SharedFunctionsFolderNode(Resource resource) {\r
18         super(resource);\r
19     }\r
20 \r
21         @Override\r
22         public void delete() throws DeleteException {\r
23                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
24 \r
25                         @Override\r
26                         public void perform(WriteGraph graph) throws DatabaseException {\r
27                                 Layer0 l0 = Layer0.getInstance(graph);\r
28                                 \r
29                                 graph.deny(data, l0.PartOf);\r
30                                 graph.deny(data, l0.IsLinkedTo_Inverse);\r
31 \r
32                                 // TODO: remove file\r
33                         }\r
34                 });\r
35         }\r
36         \r
37         @Override\r
38         public void drop(Object data) {\r
39                 final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
40                 final Resource library = this.data;\r
41                 if(resources.length > 0) {\r
42                         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
43                                 \r
44                                 @Override\r
45                                 public void perform(WriteGraph graph) throws DatabaseException {\r
46                                         SysdynResource sr = SysdynResource.getInstance(graph);\r
47                                         Layer0 l0 = Layer0.getInstance(graph);\r
48                                         for(Resource tobeMoved : resources) {\r
49                                                 if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
50                                                                 graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
51                                                         graph.deny(tobeMoved, l0.PartOf);\r
52                                                         graph.claim(tobeMoved, l0.PartOf, library);\r
53                                                 }\r
54                                         }\r
55                                 }\r
56                         });\r
57                 }\r
58         }\r
59 \r
60 }\r