]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
bf67e477c5569671e81474cbc31b0a64a8807aa1
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.utils;\r
2 \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
13 \r
14 /**\r
15  * Name validator for function libraries.\r
16  * @author Tuomas Miettinen\r
17  * \r
18  */\r
19 public class FunctionLibraryNameValidator extends NameValidator {\r
20 \r
21     @Override\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
26         \r
27         if(functionLibrary == null)\r
28             return false;\r
29         \r
30         Resource containingLibrary = graph.getPossibleObject(functionLibrary, l0.PartOf);\r
31         if(containingLibrary == null)\r
32             return true;\r
33         \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
38                 return true;\r
39             SysdynModel sysdynModel = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configurationResource);\r
40             sysdynModel.update(graph);\r
41             \r
42             if (nameTakenByTopLevelVariableOrModule(graph, sysdynModel, null, name)) return true;\r
43             \r
44             // Check that the functioLibrary name != model name (== containingLibrary name)\r
45             if (NameUtils.getSafeName(graph, containingLibrary).equals(name)) return true;\r
46             \r
47             if (nameTakenByBuiltInFunction(graph, name)) return true;\r
48 \r
49             if (nameTakenBySharedFunctionLibrary(graph, containingLibrary, null, name)) return true;\r
50             \r
51             if (nameTakenBySheet(sysdynModel, name)) return true;\r
52         }\r
53 \r
54         // Containing library may also be the model\r
55         if (nameTakenByItemUnderLibrary(graph, containingLibrary, functionLibrary, name)) return true;\r
56 \r
57         return false;\r
58     }\r
59 \r
60     @Override\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
64 \r
65     }\r
66 \r
67     @Override\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
71 \r
72     }\r
73 \r
74 }\r