]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Add shadow profiles for imported models (refs #4154)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 22 Apr 2013 06:44:45 +0000 (06:44 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 22 Apr 2013 06:44:45 +0000 (06:44 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27291 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java

index c576dd7c9244baeb843d0d3984594f340d0df096..eee9b25d7b3848ff01d758aff41ee9097d3cade6 100644 (file)
@@ -18,6 +18,7 @@ import java.util.ArrayList;
 import java.util.Collection;\r
 import java.util.Collections;\r
 import java.util.HashMap;\r
+import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 \r
@@ -36,8 +37,10 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.common.utils.ListUtils;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ResourceNotFoundException;\r
@@ -47,6 +50,7 @@ import org.simantics.db.layer0.migration.MigrationStateKeys;
 import org.simantics.db.layer0.migration.MigrationUtils;\r
 import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.issues.common.AllBatchIssueSources;\r
 import org.simantics.issues.common.BatchIssueSource;\r
 import org.simantics.issues.ontology.IssueResource;\r
@@ -139,7 +143,7 @@ public class ImportUtils {
         final Resource project = SimanticsUI.getProject().get();\r
         if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null);\r
 \r
-        beginTask(monitor, "Import model", 7);\r
+        beginTask(monitor, "Import model", 8);\r
 \r
         Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent());\r
 \r
@@ -188,6 +192,9 @@ public class ImportUtils {
                             subTask(monitor, "Add enumeration issue source");\r
                             addEnumerationIssueSource(graph, ModelRoot);\r
                             worked(monitor, 1);\r
+                            subTask(monitor, "Add shadow profile");\r
+                            addShadowProfile(graph, ModelRoot);\r
+                            worked(monitor, 1);                            \r
                             subTask(monitor, "Activate model");\r
                             activateModel(graph, ModelRoot);\r
                             worked(monitor, 1);\r
@@ -318,7 +325,24 @@ public class ImportUtils {
                     L0X.IsActivatedBy, modelRoot,\r
                     L0.PartOf, modelRoot\r
                     );  \r
-        }   }\r
+        }   \r
+    }\r
+    \r
+    private static void addShadowProfile(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
+        DiagramResource DIA = DiagramResource.getInstance(graph);\r
+        SysdynResource SR = SysdynResource.getInstance(graph);\r
+        Resource defaultProfile = graph.syncRequest(new PossibleObjectWithType(modelRoot, Layer0.getInstance(graph).ConsistsOf, SR.DefaultProfile));\r
+        if(defaultProfile != null) {\r
+            Resource entryList = graph.getPossibleObject(defaultProfile, DIA.HasEntries);\r
+            if(entryList != null) {\r
+                List<Resource> entries = ListUtils.toList(graph, entryList);\r
+                if(entries != null && !entries.contains(SR.Profiles_ShadowVisualizations)) {\r
+                    ListUtils.insertBack(graph, entryList, Collections.singletonList(SR.Profiles_ShadowVisualizations));\r
+                }\r
+            }\r
+            \r
+        }\r
+    }\r
 \r
     private static Collection<Resource> findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException {\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r