From eda658d9efc9dc16839734f9c55913761579eea9 Mon Sep 17 00:00:00 2001 From: lehtonen Date: Tue, 15 Jun 2010 19:05:39 +0000 Subject: [PATCH] Added a component naming strategy to SysdynProject. The naming is defined to be %s%d, i.e. Stock1, Stock2, etc. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16164 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/project/SysdynProject.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index aeeaa4a5..9634c86e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -21,6 +21,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.Queries; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.GraphChangeListenerSupport; import org.simantics.db.service.LifecycleSupport; import org.simantics.diagram.DiagramConstants; import org.simantics.diagram.synchronization.graph.layer.GraphLayer; @@ -28,6 +29,8 @@ import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ModelingResources; import org.simantics.modeling.ModelingUtils; +import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2; +import org.simantics.modeling.services.ComponentNamingStrategy; import org.simantics.project.ProjectElementType; import org.simantics.project.ProjectElements; import org.simantics.project.ProjectKeys; @@ -75,13 +78,14 @@ public class SysdynProject extends AbstractProjectFeature { } private final WriteRunnable CREATE_MODEL = new WriteRunnable() { + @Override public void run(WriteGraph g, Resource library, Callback callback, Callback errorCallback) { try { Builtins b = g.getBuiltins(); SysdynResource sr = SysdynResource.getInstance(g); ModelingResources mr = ModelingResources.getInstance(g); ModelingUtils mu = new ModelingUtils(g); - + Resource model = g.newResource(); g.claimValue(model, b.HasName, "Model1"); g.claimValue(model, b.HasLabel, "Model1"); @@ -92,21 +96,21 @@ public class SysdynProject extends AbstractProjectFeature { GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true); g.claim(diagram, mu.dr.HasLayer, l.getLayer()); g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE); - + Resource conf = g.newResource(); g.claimValue(conf, b.HasName, "Configuration"); g.claim(conf, b.InstanceOf, sr.Configuration); g.claimValue(conf, sr.HasStartTime, 0.0); g.claimValue(conf, sr.HasStopTime, 10.0); - + g.claim(conf, mr.CompositeToDiagram, diagram); g.claim(model, b.HasConfiguration, conf); - + Resource mapping = g.newResource(); g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping); g.claim(diagram, b.HasTrigger, mapping); - + Resource report = GraphUtils.create2(g, mu.b.Report, mu.b.HasDocumentation, "===Report==="); Resource experiment = GraphUtils.create2(g, mu.b.Experiment, @@ -114,7 +118,7 @@ public class SysdynProject extends AbstractProjectFeature { mu.b.HasLabel, "Experiment", mu.b.HasReportFactory, report, mu.b.PartOf, model); - + callback.run(model); } catch(Exception e) { errorCallback.run(e); @@ -132,6 +136,13 @@ public class SysdynProject extends AbstractProjectFeature { mm = new ModelManager(); getProjectElement().setHint(UIModelManager.KEY_MODEL_MANAGER, mm); + + // Install naming strategy for model components. + Session session = getProject().getSession(); + GraphChangeListenerSupport changeSupport = session.peekService(GraphChangeListenerSupport.class); + if (changeSupport != null) { + getProjectElement().setHint(ComponentNamingStrategy.PROJECT_KEY, new CaseInsensitiveComponentNamingStrategy2(changeSupport, "%s%d")); + } } @Override @@ -139,6 +150,8 @@ public class SysdynProject extends AbstractProjectFeature { if (getProjectElement().getHint(UIModelManager.KEY_MODEL_MANAGER) == mm) getProjectElement().removeHint(UIModelManager.KEY_MODEL_MANAGER); mm = null; + + getProjectElement().removeHint(ComponentNamingStrategy.PROJECT_KEY); } } -- 2.47.1