From: lempinen Date: Mon, 22 Apr 2013 06:44:45 +0000 (+0000) Subject: Add shadow profiles for imported models (refs #4154) X-Git-Tag: 1.8.1~321 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6827f786270ebb197fb0ef30d2e676e7ea82fe4f;p=simantics%2Fsysdyn.git Add shadow profiles for imported models (refs #4154) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27291 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java index c576dd7c..eee9b25d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -36,8 +37,10 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ResourceNotFoundException; @@ -47,6 +50,7 @@ import org.simantics.db.layer0.migration.MigrationStateKeys; import org.simantics.db.layer0.migration.MigrationUtils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.request.Read; +import org.simantics.diagram.stubs.DiagramResource; import org.simantics.issues.common.AllBatchIssueSources; import org.simantics.issues.common.BatchIssueSource; import org.simantics.issues.ontology.IssueResource; @@ -139,7 +143,7 @@ public class ImportUtils { final Resource project = SimanticsUI.getProject().get(); if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null); - beginTask(monitor, "Import model", 7); + beginTask(monitor, "Import model", 8); Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent()); @@ -188,6 +192,9 @@ public class ImportUtils { subTask(monitor, "Add enumeration issue source"); addEnumerationIssueSource(graph, ModelRoot); worked(monitor, 1); + subTask(monitor, "Add shadow profile"); + addShadowProfile(graph, ModelRoot); + worked(monitor, 1); subTask(monitor, "Activate model"); activateModel(graph, ModelRoot); worked(monitor, 1); @@ -318,7 +325,24 @@ public class ImportUtils { L0X.IsActivatedBy, modelRoot, L0.PartOf, modelRoot ); - } } + } + } + + private static void addShadowProfile(WriteGraph graph, Resource modelRoot) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + SysdynResource SR = SysdynResource.getInstance(graph); + Resource defaultProfile = graph.syncRequest(new PossibleObjectWithType(modelRoot, Layer0.getInstance(graph).ConsistsOf, SR.DefaultProfile)); + if(defaultProfile != null) { + Resource entryList = graph.getPossibleObject(defaultProfile, DIA.HasEntries); + if(entryList != null) { + List entries = ListUtils.toList(graph, entryList); + if(entries != null && !entries.contains(SR.Profiles_ShadowVisualizations)) { + ListUtils.insertBack(graph, entryList, Collections.singletonList(SR.Profiles_ShadowVisualizations)); + } + } + + } + } private static Collection findAllConfigurations(ReadGraph graph, Resource modelRoot) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph);