1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 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.properties.widgets.functions;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
17 import org.simantics.browsing.ui.common.node.AbstractNode;
\r
18 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.request.ObjectsWithType;
\r
22 import org.simantics.db.common.utils.NameUtils;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.sysdyn.SysdynResource;
\r
26 import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;
\r
28 public class SharedFunctionLibraries extends ViewpointContributor<Resource> {
\r
31 public Collection<?> getContribution(ReadGraph graph, Resource input)
\r
32 throws DatabaseException {
\r
33 Layer0 l0 = Layer0.getInstance(graph);
\r
34 SysdynResource sr = SysdynResource.getInstance(graph);
\r
36 ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();
\r
38 // Find shared ontologies. graph.getPossibleResource("http://SharedOntologies") does not update if it was null for the first time.
\r
39 Resource sharedOntologies = null;
\r
40 Resource root = input;
\r
41 while(graph.getPossibleObject(root, l0.PartOf) != null)
\r
42 root = graph.getPossibleObject(root, l0.PartOf);
\r
44 for(Resource r : graph.getObjects(root, l0.ConsistsOf)) {
\r
45 if("SharedOntologies".equals(NameUtils.getSafeName(graph, r))) {
\r
46 sharedOntologies = r;
\r
51 if(sharedOntologies == null) {
\r
55 // Find all shared function ontologies.
\r
56 // (Don't know why ObjectsWithType works only the first time, then gives nothing)
\r
57 ArrayList<Resource> sharedFunctionLibraries = new ArrayList<Resource>();
\r
58 for(Resource r : graph.getObjects(sharedOntologies, l0.ConsistsOf)) {
\r
59 if(graph.isInstanceOf(r, sr.SharedFunctionOntology))
\r
60 sharedFunctionLibraries.add(r);
\r
63 // Find all shared function ontologies that have already been selected
\r
64 Collection<Resource> selectedSharedFunctionLibraries = graph.syncRequest(new ObjectsWithType(
\r
65 input, l0.IsLinkedTo, sr.SharedFunctionOntology));
\r
67 // Remove all selected ontologies from the shared function ontologies
\r
68 sharedFunctionLibraries.removeAll(selectedSharedFunctionLibraries);
\r
70 for(Resource ontology : sharedFunctionLibraries) {
\r
71 result.add(new SharedFunctionLibraryNode(ontology));
\r