1 package org.simantics.sysdyn.ui.utils;
\r
3 import org.simantics.db.ReadGraph;
\r
4 import org.simantics.db.Resource;
\r
5 import org.simantics.db.WriteGraph;
\r
6 import org.simantics.db.common.utils.NameUtils;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.layer0.Layer0;
\r
9 import org.simantics.simulation.ontology.SimulationResource;
\r
10 import org.simantics.sysdyn.manager.SysdynModel;
\r
11 import org.simantics.sysdyn.manager.SysdynModelManager;
\r
14 * Name validator for shared function libraries.
\r
15 * @author Tuomas Miettinen
\r
18 public class SharedFunctionLibraryNameValidator extends NameValidator {
\r
21 protected boolean nameIsTaken(ReadGraph graph, Resource functionLibrary, String name) throws DatabaseException {
\r
22 Layer0 l0 = Layer0.getInstance(graph);
\r
23 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
25 if(functionLibrary == null)
\r
28 // Do the checking for all models that are linked to that shared function library
\r
29 for (Resource model : graph.getObjects(functionLibrary, l0.IsLinkedTo_Inverse)) {
\r
33 Resource configurationResource = graph.getPossibleObject(model, SIMU.HasConfiguration);
\r
34 if(configurationResource == null)
\r
36 SysdynModel sysdynModel = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configurationResource);
\r
37 sysdynModel.update(graph);
\r
39 if (nameTakenByTopLevelVariableOrModule(graph, sysdynModel, null, name)) return true;
\r
41 // Check that the functionLibrary name != model name
\r
42 if (NameUtils.getSafeName(graph, model).equals(name)) return true;
\r
44 if (nameTakenByBuiltInFunction(graph, name)) return true;
\r
46 if (nameTakenBySharedFunctionLibrary(graph, model, functionLibrary, name)) return true;
\r
48 if (nameTakenBySheet(sysdynModel, name)) return true;
\r
50 if (nameTakenByItemUnderLibrary(graph, model, null, name)) return true;
\r
57 public void renameInEquations(WriteGraph graph, Resource variable, String originalName, String newName)
\r
58 throws DatabaseException {
\r
59 // TODO Auto-generated method stub
\r
64 public void renameInAllEquations(WriteGraph graph, Resource configuration, String originalName, String newName)
\r
65 throws DatabaseException {
\r
66 // TODO Auto-generated method stub
\r