import org.simantics.db.common.request.Queries;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.GraphChangeListenerSupport;\r
import org.simantics.db.service.LifecycleSupport;\r
import org.simantics.diagram.DiagramConstants;\r
import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2;\r
+import org.simantics.modeling.services.ComponentNamingStrategy;\r
import org.simantics.project.ProjectElementType;\r
import org.simantics.project.ProjectElements;\r
import org.simantics.project.ProjectKeys;\r
}\r
\r
private final WriteRunnable CREATE_MODEL = new WriteRunnable() {\r
+ @Override\r
public void run(WriteGraph g, Resource library, Callback<Resource> callback, Callback<Throwable> errorCallback) {\r
try {\r
Builtins b = g.getBuiltins();\r
SysdynResource sr = SysdynResource.getInstance(g);\r
ModelingResources mr = ModelingResources.getInstance(g);\r
ModelingUtils mu = new ModelingUtils(g);\r
- \r
+\r
Resource model = g.newResource();\r
g.claimValue(model, b.HasName, "Model1");\r
g.claimValue(model, b.HasLabel, "Model1");\r
GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
- \r
+\r
\r
Resource conf = g.newResource();\r
g.claimValue(conf, b.HasName, "Configuration");\r
g.claim(conf, b.InstanceOf, sr.Configuration);\r
g.claimValue(conf, sr.HasStartTime, 0.0);\r
g.claimValue(conf, sr.HasStopTime, 10.0);\r
- \r
+\r
g.claim(conf, mr.CompositeToDiagram, diagram);\r
g.claim(model, b.HasConfiguration, conf);\r
- \r
+\r
Resource mapping = g.newResource();\r
g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
g.claim(diagram, b.HasTrigger, mapping);\r
- \r
+\r
Resource report = GraphUtils.create2(g, mu.b.Report, mu.b.HasDocumentation, "===Report===");\r
\r
Resource experiment = GraphUtils.create2(g, mu.b.Experiment,\r
mu.b.HasLabel, "Experiment",\r
mu.b.HasReportFactory, report,\r
mu.b.PartOf, model);\r
- \r
+\r
callback.run(model);\r
} catch(Exception e) {\r
errorCallback.run(e);\r
\r
mm = new ModelManager();\r
getProjectElement().setHint(UIModelManager.KEY_MODEL_MANAGER, mm);\r
+\r
+ // Install naming strategy for model components.\r
+ Session session = getProject().getSession();\r
+ GraphChangeListenerSupport changeSupport = session.peekService(GraphChangeListenerSupport.class);\r
+ if (changeSupport != null) {\r
+ getProjectElement().setHint(ComponentNamingStrategy.PROJECT_KEY, new CaseInsensitiveComponentNamingStrategy2(changeSupport, "%s%d"));\r
+ }\r
}\r
\r
@Override\r
if (getProjectElement().getHint(UIModelManager.KEY_MODEL_MANAGER) == mm)\r
getProjectElement().removeHint(UIModelManager.KEY_MODEL_MANAGER);\r
mm = null;\r
+\r
+ getProjectElement().removeHint(ComponentNamingStrategy.PROJECT_KEY);\r
}\r
\r
}\r