]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
b23385af215b0ec089b37bdc32e44e7db95b611b
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.utils.imports;\r
13 \r
14 import org.simantics.databoard.Bindings;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.WriteOnlyGraph;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.db.exception.ResourceNotFoundException;\r
20 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
21 import org.simantics.graph.representation.Root;\r
22 import org.simantics.layer0.Layer0;\r
23 import org.simantics.sysdyn.SysdynResource;\r
24 \r
25 /**\r
26  * Import advisor for importing function libraries to SysDyn\r
27  * \r
28  * @author Teemu Lempinen\r
29  *\r
30  */\r
31 public class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor {\r
32     \r
33     public SysdynFunctionLibraryImportAdvisor(Resource library) {\r
34         super(library);\r
35     }\r
36     \r
37     @Override\r
38     public void analyzeType(ReadGraph graph, Root root) throws DatabaseException {\r
39         // Change the library to http://SharedOntologies, if the imported library is of type SharedFunctionOntology\r
40         if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) {\r
41             try {\r
42                 library = graph.getResource("http://SharedOntologies");\r
43             } catch (ResourceNotFoundException e) {\r
44                 e.printStackTrace();\r
45             }\r
46         }\r
47     }\r
48     \r
49     @Override\r
50     public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException {\r
51         Layer0 l0 = graph.getService(Layer0.class);\r
52         this.root = graph.newResource();\r
53         graph.claim(library, l0.ConsistsOf, l0.PartOf, this.root);\r
54         String name = root.name;\r
55         String newName = nameMappings.get(name);\r
56         graph.addLiteral(this.root, l0.HasName, l0.NameOf, l0.String, newName, Bindings.STRING);\r
57         return this.root;\r
58 \r
59     }\r
60         \r
61 }