From: lempinen Date: Thu, 21 Apr 2011 11:04:51 +0000 (+0000) Subject: Improved shared function library handling X-Git-Tag: simantics-1.4RC1~40 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=37c19eb77047a408be00d2de04f9a2dbf81e7333;p=simantics%2Fsysdyn.git Improved shared function library handling git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20567 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index c64518a6..83a652e3 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -366,7 +366,7 @@ @@ -893,6 +893,10 @@ class="org.simantics.sysdyn.ui.browser.contributions.LibraryFunctions" preference="2.0"> + + @@ -941,6 +945,20 @@ preference="2.0"> + + + + + + + + @@ -994,6 +1012,10 @@ class="org.simantics.sysdyn.ui.browser.contributions.FunctionLibraryLabeler" preference="2.0"> + + @@ -1034,6 +1056,20 @@ preference="2.0"> + + + + + + + + @@ -1059,6 +1095,20 @@ preference="2.0"> + + + + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java index d00e9e96..6b447f4d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -29,6 +29,7 @@ import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode; import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; import org.simantics.sysdyn.ui.browser.nodes.VariableNode; public class AbstractNodeImager extends ImagerContributor> { @@ -37,12 +38,13 @@ public class AbstractNodeImager extends ImagerContributor public ImageDescriptor getDescriptor(ReadGraph graph, AbstractNode node) throws DatabaseException { String image = null; - if (node instanceof SharedFunctionLibraryNode) + if (node instanceof SharedFunctionsFolder) image = "icons/folder_link.png"; else if (node instanceof ExperimentsFolder || node instanceof ModulesNode || node instanceof FunctionsFolder || - node instanceof FunctionLibraryNode) + node instanceof FunctionLibraryNode || + node instanceof SharedFunctionLibraryNode) image = "icons/folder.png"; else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode) image = "icons/bricks.png"; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java index a0a250c3..6bebe335 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java @@ -28,7 +28,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; import org.simantics.sysdyn.ui.browser.nodes.FunctionNode; import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; -import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; public class FunctionLibraries extends ViewpointContributor { @@ -47,20 +47,9 @@ public class FunctionLibraries extends ViewpointContributor { result.add(new FunctionNode(function)); } - // Find shared libraries - Function index = graph.adapt(L0.Dependencies, Function.class); - Collection> results = (Collection>)index.apply(graph, functionsFolder.data, "Types:SharedFunctionOntology"); - HashSet sharedLibraries = new HashSet(); - for(Map r : results) { - Resource sharedLibrary = (Resource)r.get("Resource"); - if(sharedLibrary == null) - continue; - sharedLibraries.add(sharedLibrary); - } - // Find function libraries in model and sysdyn ontology - index = graph.adapt(L0.Dependencies, Function.class); - results = (Collection>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary"); + Function index = graph.adapt(L0.Dependencies, Function.class); + Collection> results = (Collection>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary"); HashSet modelLibraries = new HashSet(); for(Map r : results) { Resource library = (Resource)r.get("Resource"); @@ -73,23 +62,16 @@ public class FunctionLibraries extends ViewpointContributor { } // If the root is not a shared library (it is the model or sysdyn ontology) - if(!sharedLibraries.contains(root)) + if(graph.isInstanceOf(root, sr.SysdynModel)) modelLibraries.add(library); } for(Resource modelLibrary : modelLibraries) { - Resource partOf = graph.getPossibleObject(modelLibrary, l0.PartOf); - if(graph.isInstanceOf(partOf, sr.SysdynModel)) - // From the model - result.add(new FunctionLibraryNode(modelLibrary)); - else - // From sysdyn ontology, this is read only - result.add(new FunctionLibraryNode(modelLibrary)); + result.add(new FunctionLibraryNode(modelLibrary)); } - for(Resource sharedLibrary : sharedLibraries) - result.add(new SharedFunctionLibraryNode(sharedLibrary)); + result.add(new SharedFunctionsFolder(functionsFolder.data)); return result; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java new file mode 100644 index 00000000..7d5c736a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java @@ -0,0 +1,36 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; + +public class SharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, + SharedFunctionsFolder sharedFunctionsFolder) throws DatabaseException { + + ArrayList> result = new ArrayList>(); + + + for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType( + sharedFunctionsFolder.data, + Layer0.getInstance(graph).IsLinkedTo, + SysdynResource.getInstance(graph).SharedFunctionOntology))) + { + result.add(new SharedFunctionLibraryNode(sharedLibrary)); + } + + return result; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java new file mode 100644 index 00000000..c1c8c0a8 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; + +public class SharedFunctionsLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, SharedFunctionsFolder input) throws DatabaseException { + return "Shared Functions"; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java new file mode 100644 index 00000000..0531fd92 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class SharedFunctionsFolder extends AbstractNode { + + public SharedFunctionsFolder(Resource data) { + super(data); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java index 9cee6cb4..96caea96 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -22,7 +22,6 @@ import java.util.Collection; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.variable.Variable; @@ -125,9 +124,6 @@ public class InputFactory extends SysdynElementFactory { } } else { Resource runtime = diagram.getHint((DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE)); - for(Resource r : graph.getPredicates(runtime)) { - System.out.println(NameUtils.getSafeName(graph, r) + " " + graph.getPossibleRelatedValue(runtime, r)); - } DiagramResource dr = DiagramResource.getInstance(graph); String variable = (String)graph.getPossibleRelatedValue(runtime, dr.HasVariable); if(variable == null) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 499ea6e5..cf417b6f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -30,6 +30,7 @@ import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; import org.simantics.ui.utils.AdaptionUtils; public class ResourceSelectionProcessor implements SelectionProcessor { @@ -70,8 +71,19 @@ public class ResourceSelectionProcessor implements SelectionProcessor iterator = iss.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if(o instanceof IAdaptable) { + IAdaptable a = (IAdaptable)o; + final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class); + if(node != null) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(getModel() != null && node.data != null) + graph.deny(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); + } + }); + } + } + } + } + }; + + availableSharedFunctionLibraries + .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/AvailableSharedFunctionLibraries"); + availableSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + availableSharedFunctionLibraries.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + availableSharedFunctionLibraries); + + Composite middleButtons = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(middleButtons); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, true).applyTo(middleButtons); + + Button add = new Button(middleButtons, support, SWT.NONE); + add.setText(" -> "); + + add.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + List selectedLibraries = getSelectedResources(availableSharedFunctionLibraries); + for(Resource library : selectedLibraries) { + graph.claim(input, l0.IsLinkedTo, library); + } + } + }); + + Button remove = new Button(middleButtons, support, SWT.NONE); + remove.setText(" <- "); + + remove.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + List selectedLibraries = getSelectedResources(usedSharedFunctionLibraries); + for(Resource library : selectedLibraries) { + graph.deny(input, l0.IsLinkedTo, library); + } + } + }); + + + Composite used = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(used); + GridDataFactory.fillDefaults().grab(true, true).applyTo(used); + label = new Label(used, SWT.None); + label.setText("Selected Shared Function Libraries"); + + usedSharedFunctionLibraries = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI) { + + @Override + protected void handleDrop(Object data, NodeContext target) { + if (!(data instanceof IStructuredSelection)) + return; + + IStructuredSelection iss = (IStructuredSelection)data; + if (iss == null || iss.isEmpty()) + return; + + for (Iterator iterator = iss.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if(o instanceof IAdaptable) { + IAdaptable a = (IAdaptable)o; + final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class); + if(node != null) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(getModel() != null && node.data != null) + graph.claim(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); + } + }); + } + } + } + } + }; + + usedSharedFunctionLibraries + .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/SelectedSharedFunctionLibraries"); + usedSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + usedSharedFunctionLibraries.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + usedSharedFunctionLibraries); + } + + + private List getSelectedResources(GraphExplorerComposite explorer) { + List result = new ArrayList(); + + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return result; + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + for(AdaptableHintContext ahc : selections) { + Resource resource = (Resource) ahc.getAdapter(Resource.class); + result.add(resource); + } + return result; + } + + private Resource getModel() { + return model; + } + + @Override + public void setInput(ISessionContext context, Object input) { + availableSharedFunctionLibraries.setInput(context, input); + usedSharedFunctionLibraries.setInput(context, input); + this.model = AdaptionUtils.adaptToSingle(input, Resource.class); + } + +} + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java new file mode 100644 index 00000000..255555b9 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class SelectedSharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + ArrayList> result = new ArrayList>(); + + + for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType( + input, + Layer0.getInstance(graph).IsLinkedTo, + SysdynResource.getInstance(graph).SharedFunctionOntology))) + { + result.add(new SharedFunctionLibraryNode(sharedLibrary)); + } + + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java new file mode 100644 index 00000000..70dbb6f7 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class SharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + ArrayList> result = new ArrayList>(); + + // Find shared ontologies. graph.getPossibleResource("http://SharedOntologies") does not update if it was null for the first time. + Resource sharedOntologies = null; + Resource root = input; + while(graph.getPossibleObject(root, l0.PartOf) != null) + root = graph.getPossibleObject(root, l0.PartOf); + + for(Resource r : graph.getObjects(root, l0.ConsistsOf)) { + if("SharedOntologies".equals(NameUtils.getSafeName(graph, r))) { + sharedOntologies = r; + break; + } + } + + if(sharedOntologies == null) { + return result; + } + + // Find all shared function ontologies. + // (Don't know why ObjectsWithType works only the first time, then gives nothing) + ArrayList sharedFunctionLibraries = new ArrayList(); + for(Resource r : graph.getObjects(sharedOntologies, l0.ConsistsOf)) { + if(graph.isInstanceOf(r, sr.SharedFunctionOntology)) + sharedFunctionLibraries.add(r); + } + + // Find all shared function ontologies that have already been selected + Collection selectedSharedFunctionLibraries = graph.syncRequest(new ObjectsWithType( + input, l0.IsLinkedTo, sr.SharedFunctionOntology)); + + // Remove all selected ontologies from the shared function ontologies + sharedFunctionLibraries.removeAll(selectedSharedFunctionLibraries); + + for(Resource ontology : sharedFunctionLibraries) { + result.add(new SharedFunctionLibraryNode(ontology)); + } + + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index a26c3121..b650cd89 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -102,7 +102,6 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen HashSet models = new HashSet(); for(Variable variable : variables) { Resource model = Variables.getModel(graph, variable); - System.out.println("MODEL: " + model); if(model != null) { models.add(getSysdynModel(graph, model)); } @@ -148,7 +147,9 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen ArrayList dataSets = new ArrayList(); HashMap rvis = new HashMap(); - String rvi = Variables.getRVI(g, variable).substring(1).replace("/", "."); + String rvi = Variables.getRVI(g, variable).replace("/", "."); + if(rvi.length() > 1) + rvi = rvi.substring(1); Resource r = variable.getPropertyValue(g, Variables.REPRESENTS); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java index def1fcbb..585601dd 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import org.simantics.databoard.Bindings; @@ -21,7 +20,6 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Simantics; import org.simantics.layer0.Layer0; -import org.simantics.scl.runtime.function.Function; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.Activator; import org.simantics.sysdyn.SysdynResource; @@ -63,80 +61,18 @@ public class FunctionUtils { private static Set getParents(ReadGraph graph, SysdynModel model) throws DatabaseException{ HashSet parents = new HashSet(); - HashSet checked = new HashSet(); - ArrayList toCheck = new ArrayList(); Layer0 l0 = Layer0.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); SimulationResource simu = SimulationResource.getInstance(graph); Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf); + parents.add(modelResource); - // add model to parents and all the model libraries to checked - if(!graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() || - !graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty()) { - parents.add(modelResource); - toCheck.clear(); - toCheck.add(modelResource); - while(!toCheck.isEmpty()){ - Resource checkedLibrary = toCheck.get(0); - checked.add(checkedLibrary); - toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))); - toCheck.remove(checkedLibrary); - } - } - - // add all linked function ontologies to parents and their children ontologies to checked - Function index = graph.adapt(l0.Dependencies, Function.class); - Collection> results = (Collection>)index.apply(graph, modelResource, "Types:SharedFunctionOntology"); - for(Map r : results) { - Resource sharedLibrary = (Resource)r.get("Resource"); - if(sharedLibrary == null) - continue; - if(graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() && - graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty()) - continue; - - parents.add(sharedLibrary); - toCheck.clear(); - toCheck.add(sharedLibrary); - while(!toCheck.isEmpty()){ - Resource checkedLibrary = toCheck.get(0); - checked.add(checkedLibrary); - toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))); - toCheck.remove(checkedLibrary); - } - } + Collection sharedOntologies = graph.syncRequest(new ObjectsWithType( + modelResource, l0.IsLinkedTo, sr.SharedFunctionOntology)); + parents.addAll(sharedOntologies); - // it is assumed that only built-in function libraries remain - if(modelResource != null) { - index = graph.adapt(l0.Dependencies, Function.class); - results = (Collection>)index.apply(graph, modelResource, "Types:SysdynModelicaFunctionLibrary"); - for(Map r : results) { - Resource library = (Resource)r.get("Resource"); - if(library != null && !checked.contains(library)) { - - while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) { - library = graph.getPossibleObject(library, l0.PartOf); - } - - if(graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() && - graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty()) - continue; - - parents.add(library); - - toCheck.clear(); - toCheck.add(library); - while(!toCheck.isEmpty()){ - Resource checkedLibrary = toCheck.get(0); - checked.add(checkedLibrary); - toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))); - toCheck.remove(checkedLibrary); - } - } - } - } return parents; }