]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added a component naming strategy to SysdynProject.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 19:05:39 +0000 (19:05 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 19:05:39 +0000 (19:05 +0000)
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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java

index aeeaa4a598ad8cfd53e5fe9cad0da1dd177f25cd..9634c86e2e7803ad97fe984c819b32c7164a10ba 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.db.WriteGraph;
 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
@@ -28,6 +29,8 @@ import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;
 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
@@ -75,13 +78,14 @@ public class SysdynProject extends AbstractProjectFeature {
     }\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
@@ -92,21 +96,21 @@ public class SysdynProject extends AbstractProjectFeature {
                 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
@@ -114,7 +118,7 @@ public class SysdynProject extends AbstractProjectFeature {
                         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
@@ -132,6 +136,13 @@ public class SysdynProject extends AbstractProjectFeature {
 \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
@@ -139,6 +150,8 @@ public class SysdynProject extends AbstractProjectFeature {
         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