]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
989c5cdbc49e73c929de9e02de1bf7e40c1aab03
[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.manager.FunctionUtils;\r
12 import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
13 import org.simantics.ui.SimanticsUI;\r
14 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
15 \r
16 public class SharedFunctionsFolderNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
17 \r
18     public SharedFunctionsFolderNode(Resource resource) {\r
19         super(resource);\r
20     }\r
21 \r
22         @Override\r
23         public void delete() throws DeleteException {\r
24                 SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
25 \r
26                         @Override\r
27                         public void perform(WriteGraph graph) throws DatabaseException {\r
28                                 Layer0 l0 = Layer0.getInstance(graph);\r
29                                 \r
30                                 graph.deny(data, l0.PartOf);\r
31                                 graph.deny(data, l0.IsLinkedTo_Inverse);\r
32 \r
33                                 // TODO: remove file\r
34                         }\r
35                 });\r
36         }\r
37         \r
38         @Override\r
39         public void drop(Object data) {\r
40                 final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
41                 final Resource library = this.data;\r
42                 if(resources.length > 0) {\r
43                         SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
44                                 \r
45                                 @Override\r
46                                 public void perform(WriteGraph graph) throws DatabaseException {\r
47                                         SysdynResource sr = SysdynResource.getInstance(graph);\r
48                                         Layer0 l0 = Layer0.getInstance(graph);\r
49                                         for(Resource tobeMoved : resources) {\r
50                                                 if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
51                                                                 graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
52                                                         Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
53                                                         graph.deny(tobeMoved, l0.PartOf);\r
54                                                         graph.claim(tobeMoved, l0.PartOf, library);\r
55                                                         FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
56                                                         FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
57                                                 }\r
58                                         }\r
59                                         \r
60                                 }\r
61                         });\r
62                 }\r
63         }\r
64 \r
65 }\r