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.SysdynResource;
\r
11 import org.simantics.sysdyn.manager.SysdynModel;
\r
12 import org.simantics.sysdyn.manager.SysdynModelManager;
\r
15 * Name validator for function libraries.
\r
16 * @author Tuomas Miettinen
\r
19 public class FunctionLibraryNameValidator extends NameValidator {
\r
22 protected boolean nameIsTaken(ReadGraph graph, Resource functionLibrary, String name) throws DatabaseException {
\r
23 Layer0 l0 = Layer0.getInstance(graph);
\r
24 SysdynResource sr = SysdynResource.getInstance(graph);
\r
25 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
27 if(functionLibrary == null)
\r
30 Resource containingLibrary = graph.getPossibleObject(functionLibrary, l0.PartOf);
\r
31 if(containingLibrary == null)
\r
34 // Check if the function is right under the model.
\r
35 if (graph.isInstanceOf(containingLibrary, sr.SysdynModel)) {
\r
36 Resource configurationResource = graph.getPossibleObject(containingLibrary, SIMU.HasConfiguration);
\r
37 if(configurationResource == null)
\r
39 SysdynModel sysdynModel = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configurationResource);
\r
40 sysdynModel.update(graph);
\r
42 if (nameTakenByTopLevelVariableOrModule(graph, sysdynModel, null, name)) return true;
\r
44 // Check that the functioLibrary name != model name (== containingLibrary name)
\r
45 if (NameUtils.getSafeName(graph, containingLibrary).equals(name)) return true;
\r
47 if (nameTakenByBuiltInFunction(graph, name)) return true;
\r
49 if (nameTakenBySharedFunctionLibrary(graph, containingLibrary, null, name)) return true;
\r
51 if (nameTakenBySheet(sysdynModel, name)) return true;
\r
54 // Containing library may also be the model
\r
55 if (nameTakenByItemUnderLibrary(graph, containingLibrary, functionLibrary, name)) return true;
\r
61 public void renameInEquations(WriteGraph graph, Resource variable, String originalName, String newName)
\r
62 throws DatabaseException {
\r
63 // TODO Auto-generated method stub
\r
68 public void renameInAllEquations(WriteGraph graph, Resource configuration, String originalName, String newName)
\r
69 throws DatabaseException {
\r
70 // TODO Auto-generated method stub
\r