1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.utils.imports;
\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
26 * Import advisor for importing function libraries to SysDyn
\r
28 * @author Teemu Lempinen
\r
31 public class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor {
\r
33 public SysdynFunctionLibraryImportAdvisor(Resource library) {
\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
42 library = graph.getResource("http://SharedOntologies");
\r
43 } catch (ResourceNotFoundException e) {
\r
44 e.printStackTrace();
\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