1 package org.simantics.sysdyn.ui.wizards.functions;
\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
16 public class SharedFunctionsFolderNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {
\r
18 public SharedFunctionsFolderNode(Resource resource) {
\r
23 public void delete() throws DeleteException {
\r
24 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
27 public void perform(WriteGraph graph) throws DatabaseException {
\r
28 Layer0 l0 = Layer0.getInstance(graph);
\r
30 graph.deny(data, l0.PartOf);
\r
31 graph.deny(data, l0.IsLinkedTo_Inverse);
\r
33 // TODO: remove file
\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
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