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.modeling.ModelingResources;
\r
10 import org.simantics.simulation.ontology.SimulationResource;
\r
11 import org.simantics.sysdyn.SysdynResource;
\r
12 import org.simantics.sysdyn.manager.SysdynModel;
\r
13 import org.simantics.sysdyn.manager.SysdynModelManager;
\r
16 * Name validator for module types.
\r
17 * @author Tuomas Miettinen
\r
20 public class ModuleTypeNameValidator extends NameValidator {
\r
23 protected boolean nameIsTaken(ReadGraph graph, Resource moduleTypeSymbol, String name) throws DatabaseException {
\r
24 Layer0 l0 = Layer0.getInstance(graph);
\r
25 SimulationResource SIMU = SimulationResource.getInstance(graph);
\r
26 ModelingResources mr = ModelingResources.getInstance(graph);
\r
27 SysdynResource sr = SysdynResource.getInstance(graph);
\r
29 if(moduleTypeSymbol == null)
\r
32 Resource moduleType;
\r
33 if (graph.isInheritedFrom(moduleTypeSymbol, sr.Module)) {
\r
34 // Renamed in model browser
\r
35 moduleType = moduleTypeSymbol;
\r
37 // Renamed in ModuleTypeTab
\r
38 moduleType = graph.getPossibleObject(moduleTypeSymbol, mr.SymbolToComponentType);
\r
40 if(moduleType == null)
\r
43 // All ModuleTypes are under the top level model
\r
44 Resource model = graph.getPossibleObject(moduleType, l0.PartOf);
\r
48 Resource configurationResource = graph.getPossibleObject(model, SIMU.HasConfiguration);
\r
49 if(configurationResource == null)
\r
51 SysdynModel sysdynModel = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configurationResource);
\r
52 sysdynModel.update(graph);
\r
54 if (nameTakenByTopLevelVariableOrModule(graph, sysdynModel, null, name)) return true;
\r
56 // Check that the module name != model name
\r
57 if (NameUtils.getSafeName(graph, model).equals(name)) return true;
\r
59 if (nameTakenByBuiltInFunction(graph, name)) return true;
\r
61 if (nameTakenBySharedFunctionLibrary(graph, model, null, name)) return true;
\r
63 if (nameTakenBySheet(sysdynModel, name)) return true;
\r
65 if (nameTakenByItemUnderLibrary(graph, model, moduleType, name)) return true;
\r
71 public void renameInEquations(WriteGraph graph, Resource variable, String originalName, String newName)
\r
72 throws DatabaseException {
\r
73 // TODO Auto-generated method stub
\r
78 public void renameInAllEquations(WriteGraph graph, Resource configuration, String originalName, String newName)
\r
79 throws DatabaseException {
\r
80 // TODO Auto-generated method stub
\r