]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Support L0.loadString in CompilePGraphs 61/361/2
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 13 Mar 2017 09:30:06 +0000 (11:30 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 13 Mar 2017 12:31:18 +0000 (14:31 +0200)
refs #7085

Change-Id: Ia386a6b0f654ca26708dec5b2b5b19f4a975cec3

bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java

index a84c13f5ff56375e96dfa7f9adab3ee9a8e4c2cc..525c8da5244abc27f19951b450c52d5136266dc0 100644 (file)
@@ -62,7 +62,8 @@ Require-Bundle: org.simantics.project;bundle-version="1.0.0",
  org.simantics.silk.ontology;bundle-version="1.1.0",
  org.simantics.image.ui;bundle-version="1.0.0",
  org.simantics.export.core;bundle-version="1.0.0",
- org.slf4j.api
+ org.slf4j.api,
+ org.simantics.graphfile.ontology
 Export-Package: org.simantics.modeling.ui,
  org.simantics.modeling.ui.actions,
  org.simantics.modeling.ui.chart.property,
index c13f3cb430f8bdefd525c93f9b3329338a61308a..4272b9de7f28e9277c94c29328c7546afdcbddf6 100644 (file)
@@ -35,6 +35,7 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.IndexRoot;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.UniqueRead;
@@ -58,6 +59,7 @@ import org.simantics.db.layer0.util.SimanticsKeys;
 import org.simantics.db.layer0.util.TransferableGraphConfiguration2;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.graph.compiler.CompilationResult;
+import org.simantics.graph.compiler.ExternalFileLoader;
 import org.simantics.graph.compiler.GraphCompiler;
 import org.simantics.graph.compiler.GraphCompilerPreferences;
 import org.simantics.graph.compiler.ValidationMode;
@@ -68,6 +70,7 @@ import org.simantics.graph.diff.TransferableGraphDelta1;
 import org.simantics.graph.representation.Identity;
 import org.simantics.graph.representation.Root;
 import org.simantics.graph.representation.TransferableGraph1;
+import org.simantics.graphfile.ontology.GraphFileResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.ltk.ISource;
 import org.simantics.ltk.Problem;
@@ -270,7 +273,33 @@ public class CompilePGraphs implements ActionFactory {
                                prefs.validate = true;
                                prefs.validateRelationRestrictions = ValidationMode.ERROR;
                                prefs.validateResourceHasType = ValidationMode.IGNORE;
-                               final CompilationResult result = GraphCompiler.compile("1.1", sources, dependencies, null, prefs);
+                               
+                               final CompilationResult result = Simantics.sync(new UniqueRead<CompilationResult>() {
+
+                                               @Override
+                                               public CompilationResult perform(ReadGraph graph) throws DatabaseException {
+                                                       
+                                                       final Resource root = graph.syncRequest(new IndexRoot(r));
+                                                       final String baseURI = graph.getURI(root);
+
+                                                       ExternalFileLoader fileLoader = new ExternalFileLoader() {
+                                                               @Override
+                                                               public byte[] load(String fileName) throws IOException {
+                                                                       try {
+                                                                               GraphFileResource GF = GraphFileResource.getInstance(graph);
+                                                                               Resource file = graph.getResource(baseURI + "/" + fileName);
+                                                                               return graph.getRelatedValue(file, GF.HasFiledata, Bindings.BYTE_ARRAY);
+                                                                       } catch (DatabaseException e) {
+                                                                               throw new IOException(e);
+                                                                       }
+                                                               }
+                                                       };
+
+                                                       return GraphCompiler.compile("1.1", sources, dependencies, fileLoader, prefs);
+                                                       
+                                               }
+                                       
+                               });
                                
                                for(Problem problem : result.getErrors())
                                        errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n");