]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7178) Validator for build.properties"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 4 May 2017 13:57:22 +0000 (16:57 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Thu, 4 May 2017 13:57:22 +0000 (16:57 +0300)
19 files changed:
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagInfoBuilder.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagInfoImpl.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagSceneGraph.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FlagClass.java
bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java
bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java
bundles/org.simantics.modeling.ui/adapters.xml
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java [deleted file]
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java [new file with mode: 0644]
bundles/org.simantics.modeling/META-INF/MANIFEST.MF
bundles/org.simantics.modeling/scl/Simantics/PGraph.scl [new file with mode: 0644]
bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java [new file with mode: 0644]
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLScriptRunnerApplication.java
bundles/org.simantics/src/org/simantics/SCLScriptRunnerApplication.java
bundles/org.simantics/src/org/simantics/Simantics.java

index d0a44984d5bd63a2ad27be6e94c3afa6f95484cb..30efa54f0301b3724f2fe0f95e88e5df56c6e202 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.diagram.adapter;
 
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
@@ -25,7 +26,6 @@ import java.util.regex.PatternSyntaxException;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;
 import org.simantics.databoard.util.Bean;
-import org.simantics.datatypes.literal.Font;
 import org.simantics.datatypes.literal.RGB;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
@@ -203,6 +203,11 @@ public class FlagClassFactory extends SyncElementFactory {
                     e.setHint(FlagClass.KEY_FLAG_TEXT, flagText);
                     flagTextIsSet = true;
                 }
+                
+                Font flagFont = info.getFont();
+                if(flagFont != null) {
+                    e.setHint(FlagClass.KEY_FLAG_FONT, flagFont);
+                }
 
                 if (info.getTextArea() != null) {
                     e.setHint(FlagClass.KEY_FLAG_TEXT_AREA, info.getTextArea());
index 6372267a4b9c94f5ce8cbf81874d5552e03645d5..080ca9df192bd0f46fe30443029645e608f227b7 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.diagram.flag;
 
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
@@ -33,6 +34,7 @@ public class FlagInfoBuilder {
     private Rectangle2D textArea;
     private Alignment   horizontalAlignment = Alignment.LEADING;
     private Alignment   verticalAlignment = Alignment.CENTER;
+    private Font        font;
 
     public static FlagInfoBuilder fill(Type type) {
         return new FlagInfoBuilder().type(type);
@@ -42,7 +44,7 @@ public class FlagInfoBuilder {
     }
 
     public FlagInfo create() {
-        return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment);
+        return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment, font);
     }
 
     public Shape shape() {
@@ -53,6 +55,10 @@ public class FlagInfoBuilder {
         return text;
     }
 
+    public Font font() {
+        return font;
+    }
+    
     public Type type() {
         return type;
     }
@@ -78,6 +84,11 @@ public class FlagInfoBuilder {
         this.text = text;
         return this;
     }
+    
+    public FlagInfoBuilder font(Font font) {
+        this.font = font;
+        return this;
+    }
 
     public FlagInfoBuilder type(Type type) {
         this.type = type;
index bad06dbbdaafa7d927213e202d329a0c9017722f..53db4209d2372dc859bc5886fc8e479fef2b23da 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.diagram.flag;
 
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
@@ -29,15 +30,17 @@ public class FlagInfoImpl implements FlagInfo {
     private final Rectangle2D textArea;
     private final Alignment   horizontalAlignment;
     private final Alignment   verticalAlignment;
+    private final Font        font;
 
     public FlagInfoImpl(Shape shape, String[] text, Type type, Rectangle2D textArea,
-            Alignment horizontalAlignment, Alignment verticalAlignment) {
+            Alignment horizontalAlignment, Alignment verticalAlignment, Font font) {
         this.shape = shape;
         this.text = text;
         this.type = type;
         this.textArea = textArea;
         this.horizontalAlignment = horizontalAlignment;
         this.verticalAlignment = verticalAlignment;
+        this.font = font;
     }
 
     @Override
@@ -70,4 +73,8 @@ public class FlagInfoImpl implements FlagInfo {
         return verticalAlignment;
     }
 
+    @Override
+    public Font getFont() {
+        return font;
+    }
 }
index cd8661350bc14318003cf1683d196be64145f631..9895dd39f018c90e277a3c543e39efbb2775f9f4 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.diagram.flag;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
@@ -90,6 +91,8 @@ public class FlagSceneGraph implements SceneGraph {
             Alignment horizAlign = ElementUtils.getHintOrDefault(e, FlagClass.KEY_TEXT_HORIZONTAL_ALIGN, Alignment.LEADING);
             Alignment vertAlign = ElementUtils.getHintOrDefault(e, FlagClass.KEY_TEXT_VERTICAL_ALIGN, Alignment.CENTER);
 
+            Font font  = ElementUtils.getHintOrDefault(e, FlagClass.KEY_FLAG_FONT, FlagNode.DEFAULT_FONT);
+
             ElementUtils.removePossibleNode(e, KEY_VISUAL_SG_NODE);
             e.removeHint(KEY_VISUAL_SG_NODE);
 
@@ -106,7 +109,8 @@ public class FlagSceneGraph implements SceneGraph {
                     (float) beakAngle,
                     textArea,
                     horizAlign.ordinal(),
-                    vertAlign.ordinal());
+                    vertAlign.ordinal(),
+                    font);
             AffineTransform at = ElementUtils.getTransform(e);
             if(at != null) flag.setTransform(at);
 
index 8ee0ff93dcc6712a5ebde1f5b9baa1fa5208d93d..8176d1e7931081fdc66665ff1cb1065b2d4731c0 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.diagram.flag;
 
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
@@ -35,6 +36,7 @@ public interface IFlagType {
         FlagClass.Type getType();
         Alignment getHorizontalAlignment();
         Alignment getVerticalAlignment();
+        Font getFont();
     }
 
     /**
index 98a63269978b01597d1d5ea7fb14628f39fec688..fa83a224acfc2d7076af4417e2f2e181680e93e7 100644 (file)
@@ -150,15 +150,3 @@ consoleLog state message = do
 
 contextDocument :: CommandContext -> <Proc> IDocument
 contextDocument ctx = justValue ctx "__document__"
-
-importJava "org.simantics.document.server.io.IRequest" where
-    @private
-    data IRequest
-    
-    @private
-    getParameter :: IRequest -> String -> <Proc> Maybe String
-
-possibleQueryParameterFromContext :: CommandContext -> String -> <Proc> Maybe String
-possibleQueryParameterFromContext context parameter = do
-    request = fromJust $ possibleValue context "__request__"
-    getParameter request parameter
index 604fa15a58e04b1714c58e4f15b0d50295e56e79..7c60894bc9a9c85ec3ffd685c6ec3b32db8fb7d6 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.g2d.elementclass;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Path2D;
@@ -101,6 +102,7 @@ public class FlagClass {
     public static final Key           KEY_SHAPE                    = new KeyOf(Shape.class, "SHAPE");
     public static final Key           KEY_TEXT_HORIZONTAL_ALIGN    = new KeyOf(Alignment.class, "TEXT_HORIZONTAL_ALIGN");
     public static final Key           KEY_TEXT_VERTICAL_ALIGN      = new KeyOf(Alignment.class, "TEXT_VERTICAL_ALIGN");
+    public static final Key           KEY_FLAG_FONT                = new KeyOf(Font.class, "FLAG_FONT");
 
     public static final Key          KEY_SG_NODE                  = new SceneGraphNodeKey(Node.class, "FLAG_SG_NODE");
 
@@ -631,6 +633,8 @@ public class FlagClass {
             Alignment horizAlign = ElementUtils.getHintOrDefault(e, KEY_TEXT_HORIZONTAL_ALIGN, Alignment.LEADING);
             Alignment vertAlign = ElementUtils.getHintOrDefault(e, KEY_TEXT_VERTICAL_ALIGN, Alignment.CENTER);
 
+            Font font  = ElementUtils.getHintOrDefault(e, KEY_FLAG_FONT, FlagNode.DEFAULT_FONT); 
+            
             FlagNode flag = ElementUtils.getOrCreateNode(e, parent, KEY_SG_NODE, ElementUtils.generateNodeId(e), FlagNode.class);
             flag.init(shape,
                     flagText,
@@ -644,7 +648,8 @@ public class FlagClass {
                     (float) beakAngle,
                     textArea,
                     horizAlign.ordinal(),
-                    vertAlign.ordinal());
+                    vertAlign.ordinal(),
+                    font);
             AffineTransform at = ElementUtils.getTransform(e);
             if(at != null) flag.setTransform(at);
 
index 524885f5d57a71ba291579c0942f1e0cdff3945f..06abd615fd5df6ffb65d393d498b4a84a458100d 100644 (file)
@@ -221,7 +221,7 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                                }
                        }
                        else if(definition instanceof Internal) {
-                               String uri = TransferableGraphUtils.getURI(resourceCount, identityMap, identity.resource);
+                               String uri = TransferableGraphUtils.getTrueURI(resourceCount, identityMap, identity.resource);
                                Resource existing = graph.getPossibleResource(uri);
                                if(existing != null) {
                                        existingInternalMap.put(identity.resource, existing);
@@ -334,7 +334,9 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
 
                                Resource parent = resolvedParents.get(parts[0]);
                                // TODO: proper exception message
-                               if(parent == null) throw new IllegalStateException("!!");
+                               if(parent == null) {
+                                       throw new IllegalStateException("!!");
+                               }
 
                                Resource childResource = graph.newResource();
                                graph.claim(childResource, InstanceOf, null, ExternalEntity);
index 4646116dc37d784255466ad55f1914e94c545596..4b113fa499b6bc1208d64b62e2be5be66713cc10 100644 (file)
@@ -8,6 +8,7 @@ import java.util.TreeMap;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.util.URIStringUtils;
 
 import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.TIntObjectMap;
@@ -266,5 +267,27 @@ public class TransferableGraphUtils {
                }
                return "<internal reference " + id + ">:";
        }
+       
+       public static String getTrueURI(int resourceCount, TIntObjectMap<Identity> identities, int id) {
+               Identity identity = identities.get(id);
+               if(identity != null) {
+                       IdentityDefinition definition = identity.definition;
+                       if(definition instanceof External) {
+                               External def = (External)definition;
+                               if(def.parent == -1) return "http:/";
+                               else return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+                       } else if(definition instanceof Root) {
+                               Root def = (Root)definition;
+                               if(def.name.isEmpty()) return "http:/";
+                               return def.name;
+                       } else if (definition instanceof Internal) {
+                               Internal def = (Internal)definition;
+                               return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+                       } else {
+                               return "";
+                       }
+               }
+               return "<internal reference " + id + ">:";
+       }
 
 }
index 274db7a09e54c6aa686f24f3e317fd4eadbe5156..891ac0d46ba1cdbb77e37e8ce9803c1708068dc7 100644 (file)
 <!--                   class="org.simantics.modeling.ui.actions.MigrateMasterTypical" /> -->
                <resource
                        uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/CompilePGraphs"
-                       class="org.simantics.modeling.ui.actions.CompilePGraphs" />
+                       class="org.simantics.modeling.ui.actions.CompilePGraphsAction" />
                <resource
                        uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Delete"
                        class="org.simantics.modeling.ui.actions.Delete" />
diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphs.java
deleted file mode 100644 (file)
index 4272b9d..0000000
+++ /dev/null
@@ -1,420 +0,0 @@
-package org.simantics.modeling.ui.actions;
-
-import static org.simantics.db.common.utils.Transaction.endTransaction;
-
-import java.io.ByteArrayInputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.osgi.framework.Bundle;
-import org.simantics.PlatformException;
-import org.simantics.Simantics;
-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;
-import org.simantics.db.common.request.WriteRequest;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.adapter.ActionFactory;
-import org.simantics.db.layer0.adapter.CopyHandler;
-import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
-import org.simantics.db.layer0.adapter.impl.DefaultCopyHandler;
-import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
-import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
-import org.simantics.db.layer0.util.ClipboardUtils;
-import org.simantics.db.layer0.util.DomainProcessorState;
-import org.simantics.db.layer0.util.Layer0Utils;
-import org.simantics.db.layer0.util.ModelTransferableGraphSource;
-import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
-import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
-import org.simantics.db.layer0.util.SimanticsClipboardImpl;
-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;
-import org.simantics.graph.db.TransferableGraphSource;
-import org.simantics.graph.db.TransferableGraphs;
-import org.simantics.graph.diff.Diff;
-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;
-import org.simantics.modeling.ui.Activator;
-import org.simantics.utils.datastructures.Pair;
-
-/**
- * @author Antti Villberg
- */
-public class CompilePGraphs implements ActionFactory {
-
-    @Override
-    public Runnable create(Object target) {
-       
-        if (!(target instanceof Resource))
-            return null;
-        
-        final Resource r = (Resource)target;
-
-        return new Runnable() {
-               
-            private void uncheckedClose(Closeable closeable) {
-                try {
-                    if (closeable != null)
-                        closeable.close();
-                } catch (IOException e) {
-                    //ignore
-                }
-            }
-               
-            private File copyResource(URL url, File targetFile) throws IOException, FileNotFoundException {
-                FileOutputStream os = null;
-                InputStream is = null;
-                try {
-                    if (targetFile.exists())
-                        targetFile.delete();
-
-                    is = url.openStream();
-                    int read;
-                    byte [] buffer = new byte [16384];
-                    os = new FileOutputStream (targetFile);
-                    while ((read = is.read (buffer)) != -1) {
-                        os.write(buffer, 0, read);
-                    }
-                    os.close ();
-                    is.close ();
-
-                    return targetFile;
-                } finally {
-                    uncheckedClose(os);
-                    uncheckedClose(is);
-                }
-            }
-               
-            private File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {
-                String tmpDirStr = System.getProperty("java.io.tmpdir");
-                if (tmpDirStr == null)
-                    throw new NullPointerException("java.io.tmpdir property is null");
-                File tmpDir = new File(tmpDirStr);
-                File libFile = new File(tmpDir, libName);
-                return copyResource(libURL, libFile);
-            }
-               
-               private File url2file(URL url, String fileName) {
-                       if ("file".equals(url.getProtocol())) {
-                               try {
-                                       File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
-                                       return path;
-                               } catch (UnsupportedEncodingException e) {
-                                       Logger.defaultLogError(e);
-                               }
-                       } else if ("jar".equals(url.getProtocol())) {
-                               try {
-                                       File libFile = extractLib(url, fileName);
-                                       return libFile;
-                               } catch (FileNotFoundException e) {
-                                       Logger.defaultLogError(e);
-                               } catch (IOException e) {
-                                       Logger.defaultLogError(e);
-                               }
-                       } else {
-                               System.err.println("Unsupported URL protocol '" + url + "' for FastLZ native library file '" + fileName);
-                       }       
-                       return null;
-               }
-                       @Override
-                       public void run() {
-                               
-                               try {
-                                       
-                               final Collection<ISource> sources = new ArrayList<ISource>();
-                               Collection<TransferableGraph1> dependencies = new ArrayList<TransferableGraph1>();
-
-                               for(Bundle b : Activator.getContext().getBundles()) {
-                                       URL tg = b.getEntry("/graph.tg");
-                                       if(tg == null) continue;
-                                       File f = url2file(FileLocator.resolve(tg), b.getSymbolicName());
-                                       dependencies.add(GraphCompiler.read(f));
-                               }
-
-                               final TransferableGraph1 thisOntology = Simantics.sync(new UniqueRead<TransferableGraph1>() {
-
-                                               @Override
-                                               public TransferableGraph1 perform(ReadGraph graph) throws DatabaseException {
-                                                       
-                                                       Layer0 L0 = Layer0.getInstance(graph);
-                                                       Resource parent = graph.getSingleObject(r, L0.PartOf);
-                                                       
-                                   CopyHandler ch = new DefaultCopyHandler(r) {
-                                       
-                                       protected TransferableGraphConfiguration2 createConfiguration(ReadGraph graph, boolean cut) throws DatabaseException {
-
-                                               Map<Resource, ExtentStatus> preStatus = new HashMap<Resource, ExtentStatus>();
-                                               preStatus.put(r, ExtentStatus.EXTERNAL);
-                                               if(!parent.equals(graph.getRootLibrary()))
-                                                       preStatus.put(parent, ExtentStatus.EXTERNAL);
-                                               
-                                               return new TransferableGraphConfiguration2(null, Collections.emptyList(), preStatus, true, true);
-                                               
-                                       }
-
-                                       protected TransferableGraphSource computeSource(ReadGraph graph, TransferableGraphConfiguration2 conf) throws DatabaseException {
-                                               return graph.syncRequest(new ModelTransferableGraphSourceRequest(conf) {
-
-                                                       protected ModelTransferableGraphSource getSource(ReadGraph graph, TransferableGraphConfiguration2 configuration, DomainProcessorState state, File otherStatementsFile, File valueFile) throws DatabaseException {
-                                                       return new ModelTransferableGraphSource(graph, configuration, state, otherStatementsFile, valueFile) {
-
-                                                                       @Override
-                                                                       protected Identity getRootIdentity(DomainProcessorState state, SerialisationSupport support, Resource rootLibrary) throws DatabaseException {
-                                                                               return new Identity(state.ids.get(support.getTransientId(rootLibrary)), new Root("", ""));
-                                                                       }
-
-                                                       };
-                                                       }
-
-                                               });
-                                       }
-                                       
-                                   };
-                                   SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                                   ch.copyToClipboard(graph, clipboard);
-                                   for (Set<Representation> object : clipboard.getContents()) {
-                                       TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
-                                       if(tg != null) return tg;
-                                   }
-                                                       return null;
-                                               }
-                                       
-                               });
-
-                               dependencies.add(thisOntology);
-                               
-                                       Simantics.sync(new ReadRequest() {
-
-                                               @Override
-                                               public void run(ReadGraph graph) throws DatabaseException {
-                                                       Layer0 L0 = Layer0.getInstance(graph);
-                                                       for(Resource file : graph.syncRequest(new ObjectsWithType(r, L0.ConsistsOf, L0.PGraph))) {
-                                                               
-                                                               final String src = graph.getRelatedValue(file, L0.PGraph_definition, Bindings.STRING);
-
-                                                               final ByteArrayInputStream baos = new ByteArrayInputStream(src.getBytes()); 
-                                                       
-                                                       sources.add(new ISource() {
-                                                                       
-                                                                       @Override
-                                                                       public int startPos() {
-                                                                               return 0;
-                                                                       }
-                                                                       
-                                                                       @Override
-                                                                       public int startLine() {
-                                                                               return 0;
-                                                                       }
-                                                                       
-                                                                       @Override
-                                                                       public InputStream open() throws IOException {
-                                                                               return baos;
-                                                                       }
-                                                                       
-                                                                       @Override
-                                                                       public int length() throws IOException {
-                                                                               return src.length();
-                                                                       }
-                                                                       
-                                                                       @Override
-                                                                       public String getName() {
-                                                                               return "Source";
-                                                                       }
-                                                                       
-                                                               });
-                                                               
-                                                       }
-                                               }
-                                               
-                                       });
-                               
-                               final StringBuilder errorStringBuilder = new StringBuilder();
-                               GraphCompilerPreferences prefs = new GraphCompilerPreferences();
-                               prefs.validate = true;
-                               prefs.validateRelationRestrictions = ValidationMode.ERROR;
-                               prefs.validateResourceHasType = ValidationMode.IGNORE;
-                               
-                               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");
-                               for(Problem problem : result.getWarnings())
-                                       errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
-                               
-                               if(!result.getErrors().isEmpty() || !result.getWarnings().isEmpty()) {
-
-                                       class ErrorMessageDialog extends MessageDialog {
-
-                                               public ErrorMessageDialog(Shell shell) {
-                                                       super(shell, 
-                                                                       "Unsatisfied dependencies", null, 
-                                                                       "The following dependencies were missing. Please import the dependencies and try again.", 
-                                                                       MessageDialog.ERROR, new String[] { "Continue" }, 0);
-                                               }
-
-                                               @Override
-                                               protected Control createCustomArea(Composite composite) {
-                                                       
-                                                       GridLayoutFactory.fillDefaults().applyTo(composite);
-                                                       
-                                                       org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
-                                                       GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
-                                               for(Problem problem : result.getErrors())
-                                                       list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
-                                               for(Problem problem : result.getWarnings())
-                                                       list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
-
-                                                       return composite;
-                                                       
-                                               }
-
-                                       }
-
-                                       ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
-                                       md.open();
-
-                                       return;
-                               }
-                               
-                               
-                               final Pair<TransferableGraph1, long[]> existing = Simantics.sync(new UniqueRead<Pair<TransferableGraph1, long[]>>() {
-
-                                               @Override
-                                               public Pair<TransferableGraph1, long[]> perform(ReadGraph graph) throws DatabaseException {
-                                                       Layer0 L0 = Layer0.getInstance(graph);
-                                                       TransferableGraph1 tg = graph.getPossibleRelatedValue(r, L0.SharedOntology_tg, Bindings.getBindingUnchecked( TransferableGraph1.class ));
-                                                       if(tg == null) return null;
-                                                       long[] tgResources = graph.getPossibleRelatedValue(r, L0.SharedOntology_tgResources, Bindings.LONG_ARRAY);
-                                                       if(tgResources == null) return null;
-                                                       return Pair.make(tg,  tgResources);
-                                               }
-                                       
-                               });
-                               
-                               if(existing != null) {
-                                       
-                           try {
-                               
-                                                       Simantics.sync(new WriteRequest() {
-                                                               
-                                                               @Override
-                                                               public void perform(WriteGraph graph) throws DatabaseException {
-
-                                                   TransferableGraphDelta1 delta = new Diff(existing.first, result.getGraph()).diff();
-                                               long[] resourceArray = TransferableGraphs.applyDelta(graph, existing.second, delta);
-
-                                                                       Layer0 L0 = Layer0.getInstance(graph);
-                                                                       graph.claimLiteral(r, L0.SharedOntology_tg, result.getGraph(), Bindings.getBindingUnchecked( TransferableGraph1.class ));
-                                                                       graph.claimLiteral(r, L0.SharedOntology_tgResources, L0.ResourceIdArray, resourceArray, Bindings.LONG_ARRAY);
-                                                                       
-                                                       Layer0Utils.addCommentMetadata(graph, "Compiled ontology " + graph.getURI(r));
-
-                                                               }
-                                                               
-                                                       });
-
-                           } catch (Throwable t) {
-                               throw new PlatformException(t);
-                           } finally {
-                               endTransaction();
-                           }
-                                       
-                               } else {
-                               
-                                       final DefaultPasteImportAdvisor advisor = new DefaultPasteImportAdvisor(r);
-                                       
-                                       DefaultPasteHandler.defaultExecute(result.getGraph(), r, advisor);
-                                       
-                                               Simantics.sync(new WriteRequest() {
-       
-                                                       @Override
-                                                       public void perform(WriteGraph graph) throws DatabaseException {
-       
-                                                               Layer0 L0 = Layer0.getInstance(graph);
-                                                               graph.claimLiteral(r, L0.SharedOntology_tg, result.getGraph(), Bindings.getBindingUnchecked( TransferableGraph1.class ));
-                                                               graph.claimLiteral(r, L0.SharedOntology_tgResources, L0.ResourceIdArray, advisor.getResourceIds(), Bindings.LONG_ARRAY);
-
-                                               Layer0Utils.addCommentMetadata(graph, "Compiled ontology " + graph.getURI(r));
-
-                                                       }
-                                                       
-                                               });
-                                               
-                               }
-                                       
-                               } catch (Exception e) {
-                                       Logger.defaultLogError(e);
-                               }
-                               
-                       }
-               
-        };
-        
-    }
-
-}
diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java
new file mode 100644 (file)
index 0000000..783244a
--- /dev/null
@@ -0,0 +1,70 @@
+package org.simantics.modeling.ui.actions;
+
+import java.io.IOException;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.graph.compiler.CompilationResult;
+import org.simantics.ltk.Problem;
+import org.simantics.modeling.CompilePGraphs;
+import org.simantics.utils.ui.ExceptionUtils;
+
+/**
+ * @author Antti Villberg
+ */
+public class CompilePGraphsAction implements ActionFactory {
+
+    @Override
+    public Runnable create(Object target) {
+        if (!(target instanceof Resource))
+            return null;
+        return () -> {
+            try {
+                CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent());
+            } catch (IOException | DatabaseException e) {
+                ExceptionUtils.logAndShowError(e);
+            }
+        };
+    }
+
+    public static class CompileUserAgent implements CompilePGraphs.UserAgent {
+        @Override
+        public void reportProblems(CompilationResult result) {
+            class ErrorMessageDialog extends MessageDialog {
+                public ErrorMessageDialog(Shell shell) {
+                    super(shell, 
+                            "Unsatisfied dependencies", null, 
+                            "The following dependencies were missing. Please import the dependencies and try again.", 
+                            MessageDialog.ERROR, new String[] { "Continue" }, 0);
+                }
+
+                @Override
+                protected Control createCustomArea(Composite composite) {
+                    GridLayoutFactory.fillDefaults().applyTo(composite);
+
+                    org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
+                    GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
+                    for (Problem problem : result.getErrors())
+                        list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
+                    for (Problem problem : result.getWarnings())
+                        list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
+
+                    return composite;
+                }
+            }
+
+            ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
+            md.open();
+        }
+    }
+
+}
index 7f81e56f2300bc0511473436e2494932e4b8af15..bcdf142191365b0176b90d0d110c872d69c426e1 100644 (file)
@@ -38,7 +38,10 @@ Require-Bundle: org.simantics.simulation;bundle-version="1.0.0",
  org.simantics.selectionview.ontology;bundle-version="1.2.0",
  org.simantics.scl.ui;bundle-version="0.5.0",
  org.slf4j.api,
- org.apache.batik
+ org.simantics.graphfile.ontology,
+ org.apache.batik,
+ org.simantics.ltk,
+ org.simantics.graph.compiler
 Export-Package: org.simantics.modeling,
  org.simantics.modeling.actions,
  org.simantics.modeling.adapters,
diff --git a/bundles/org.simantics.modeling/scl/Simantics/PGraph.scl b/bundles/org.simantics.modeling/scl/Simantics/PGraph.scl
new file mode 100644 (file)
index 0000000..31afde3
--- /dev/null
@@ -0,0 +1,4 @@
+import "Simantics/DB"
+
+importJava "org.simantics.modeling.CompilePGraphs" where
+    compilePGraphs :: Resource -> <Proc> ()
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java
new file mode 100644 (file)
index 0000000..9b620c2
--- /dev/null
@@ -0,0 +1,314 @@
+package org.simantics.modeling;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.osgi.framework.Bundle;
+import org.simantics.Simantics;
+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;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.CopyHandler;
+import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
+import org.simantics.db.layer0.adapter.impl.DefaultCopyHandler;
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
+import org.simantics.db.layer0.util.ClipboardUtils;
+import org.simantics.db.layer0.util.DomainProcessorState;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.db.layer0.util.ModelTransferableGraphSource;
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
+import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
+import org.simantics.db.layer0.util.SimanticsClipboardImpl;
+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;
+import org.simantics.graph.db.TransferableGraphException;
+import org.simantics.graph.db.TransferableGraphSource;
+import org.simantics.graph.db.TransferableGraphs;
+import org.simantics.graph.diff.Diff;
+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;
+import org.simantics.modeling.internal.Activator;
+import org.simantics.utils.FileUtils;
+import org.simantics.utils.datastructures.Pair;
+
+/**
+ * @author Antti Villberg
+ */
+public class CompilePGraphs {
+
+    public static interface UserAgent {
+        void reportProblems(CompilationResult result);
+    }
+
+    /**
+     * <code>Simantics/PGraph#compilePGraphs</code> SCL API.
+     * 
+     * @param r
+     * @throws IOException
+     * @throws DatabaseException
+     */
+    public static void compilePGraphs(Resource r) throws IOException, DatabaseException {
+        compilePGraphs(r, null);
+    }
+
+    public static void compilePGraphs(Resource r, UserAgent userAgent) throws IOException, DatabaseException {
+        final Collection<ISource> sources = new ArrayList<>();
+        Collection<TransferableGraph1> dependencies = new ArrayList<>();
+
+        for (Bundle b : Activator.getContext().getBundles()) {
+            URL tg = b.getEntry("/graph.tg");
+            if (tg == null) continue;
+            File f = url2file(FileLocator.resolve(tg), b.getSymbolicName());
+            try {
+                dependencies.add(GraphCompiler.read(f));
+            } catch (Exception e) {
+                throw new IOException("Failed to read compiled transferable graph as dependency: " + f, e);
+            }
+        }
+
+        final TransferableGraph1 thisOntology = Simantics.sync(new UniqueRead<TransferableGraph1>() {
+
+            @Override
+            public TransferableGraph1 perform(ReadGraph graph) throws DatabaseException {
+                Layer0 L0 = Layer0.getInstance(graph);
+                Resource parent = graph.getSingleObject(r, L0.PartOf);
+
+                CopyHandler ch = new DefaultCopyHandler(r) {
+                    protected TransferableGraphConfiguration2 createConfiguration(ReadGraph graph, boolean cut) throws DatabaseException {
+                        Map<Resource, ExtentStatus> preStatus = new HashMap<>();
+                        preStatus.put(r, ExtentStatus.EXTERNAL);
+                        if (!parent.equals(graph.getRootLibrary()))
+                            preStatus.put(parent, ExtentStatus.EXTERNAL);
+                        return new TransferableGraphConfiguration2(null, Collections.emptyList(), preStatus, true, true);
+                    }
+
+                    protected TransferableGraphSource computeSource(ReadGraph graph, TransferableGraphConfiguration2 conf) throws DatabaseException {
+                        return graph.syncRequest(new ModelTransferableGraphSourceRequest(conf) {
+                            protected ModelTransferableGraphSource getSource(ReadGraph graph, TransferableGraphConfiguration2 configuration, DomainProcessorState state, File otherStatementsFile, File valueFile) throws DatabaseException {
+                                return new ModelTransferableGraphSource(graph, configuration, state, otherStatementsFile, valueFile) {
+                                    @Override
+                                    protected Identity getRootIdentity(DomainProcessorState state, SerialisationSupport support, Resource rootLibrary) throws DatabaseException {
+                                        return new Identity(state.ids.get(support.getTransientId(rootLibrary)), new Root("", ""));
+                                    }
+                                };
+                            }
+                        });
+                    }
+                };
+
+                SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
+                ch.copyToClipboard(graph, clipboard);
+                for (Set<Representation> object : clipboard.getContents()) {
+                    TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
+                    if (tg != null)
+                        return tg;
+                }
+
+                return null;
+            }
+        });
+
+        if (thisOntology == null)      
+            throw new DatabaseException("Failed to dump the containing ontology of " + r + " into TransferableGraph1");
+
+        dependencies.add(thisOntology);
+
+        Simantics.sync(new ReadRequest() {
+            @Override
+            public void run(ReadGraph graph) throws DatabaseException {
+                Layer0 L0 = Layer0.getInstance(graph);
+                for (Resource file : graph.syncRequest(new ObjectsWithType(r, L0.ConsistsOf, L0.PGraph))) {
+                    String src = graph.getRelatedValue(file, L0.PGraph_definition, Bindings.STRING);
+                    sources.add(new StringSource(src));
+                }
+            }
+        });
+
+        GraphCompilerPreferences prefs = new GraphCompilerPreferences();
+        prefs.validate = true;
+        prefs.validateRelationRestrictions = ValidationMode.ERROR;
+        prefs.validateResourceHasType = ValidationMode.IGNORE;
+        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);
+
+                GraphFileResource GF = GraphFileResource.getInstance(graph);
+                ExternalFileLoader fileLoader = fileName -> {
+                    try {
+                        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);
+            }
+        });
+
+        if (!result.getErrors().isEmpty() || !result.getWarnings().isEmpty()) {
+            if (userAgent != null) {
+                userAgent.reportProblems(result);
+                return;
+            } else {
+                StringBuilder error = new StringBuilder();
+                for (Problem problem : result.getErrors())
+                    error.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
+                for (Problem problem : result.getWarnings())
+                    error.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
+                throw new DatabaseException(error.toString());
+            }
+        }
+
+        final Pair<TransferableGraph1, long[]> existing = Simantics.sync(new UniqueRead<Pair<TransferableGraph1, long[]>>() {
+            @Override
+            public Pair<TransferableGraph1, long[]> perform(ReadGraph graph) throws DatabaseException {
+                Layer0 L0 = Layer0.getInstance(graph);
+                TransferableGraph1 tg = graph.getPossibleRelatedValue(r, L0.SharedOntology_tg, Bindings.getBindingUnchecked( TransferableGraph1.class ));
+                if(tg == null) return null;
+                long[] tgResources = graph.getPossibleRelatedValue(r, L0.SharedOntology_tgResources, Bindings.LONG_ARRAY);
+                if(tgResources == null) return null;
+                return Pair.make(tg,  tgResources);
+            }
+        });
+
+        if (existing != null) {
+            Simantics.sync(new WriteRequest() {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    TransferableGraphDelta1 delta = new Diff(existing.first, result.getGraph()).diff();
+                    long[] resourceArray = TransferableGraphs.applyDelta(graph, existing.second, delta);
+
+                    Layer0 L0 = Layer0.getInstance(graph);
+                    graph.claimLiteral(r, L0.SharedOntology_tg, result.getGraph(), Bindings.getBindingUnchecked( TransferableGraph1.class ));
+                    graph.claimLiteral(r, L0.SharedOntology_tgResources, L0.ResourceIdArray, resourceArray, Bindings.LONG_ARRAY);
+
+                    Layer0Utils.addCommentMetadata(graph, "Compiled ontology " + graph.getURI(r));
+                }
+            });
+        } else {
+            final DefaultPasteImportAdvisor advisor = new DefaultPasteImportAdvisor(r);
+            try {
+                DefaultPasteHandler.defaultExecute(result.getGraph(), r, advisor);
+            } catch (TransferableGraphException e) {
+                // TODO: defaultExecute never actually throws this exception!
+                throw new DatabaseException(e);
+            }
+
+            Simantics.sync(new WriteRequest() {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    Layer0 L0 = Layer0.getInstance(graph);
+                    graph.claimLiteral(r, L0.SharedOntology_tg, result.getGraph(), Bindings.getBindingUnchecked( TransferableGraph1.class ));
+                    graph.claimLiteral(r, L0.SharedOntology_tgResources, L0.ResourceIdArray, advisor.getResourceIds(), Bindings.LONG_ARRAY);
+
+                    Layer0Utils.addCommentMetadata(graph, "Compiled ontology " + graph.getURI(r));
+                }
+            });
+        }
+    }
+
+    private static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {
+        String tmpDirStr = System.getProperty("java.io.tmpdir");
+        if (tmpDirStr == null)
+            throw new NullPointerException("java.io.tmpdir property is null");
+        File tmpDir = new File(tmpDirStr);
+        File libFile = new File(tmpDir, libName);
+        return FileUtils.copyResource(libURL, libFile, false);
+    }
+
+    private static File url2file(URL url, String fileName) {
+        if ("file".equals(url.getProtocol())) {
+            try {
+                File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
+                return path;
+            } catch (UnsupportedEncodingException e) {
+                Logger.defaultLogError(e);
+            }
+        } else if ("jar".equals(url.getProtocol())) {
+            try {
+                File libFile = extractLib(url, fileName);
+                return libFile;
+            } catch (FileNotFoundException e) {
+                Logger.defaultLogError(e);
+            } catch (IOException e) {
+                Logger.defaultLogError(e);
+            }
+        } else {
+            System.err.println("Unsupported URL protocol '" + url + "' for FastLZ native library file '" + fileName);
+        }   
+        return null;
+    }
+
+    private static class StringSource implements ISource {
+        private String src;
+        private ByteArrayInputStream baos;
+
+        public StringSource(String s) {
+            this.src = s;
+            this.baos = new ByteArrayInputStream(src.getBytes());
+        }
+
+        @Override
+        public int startPos() {
+            return 0;
+        }
+
+        @Override
+        public int startLine() {
+            return 0;
+        }
+
+        @Override
+        public InputStream open() throws IOException {
+            return baos;
+        }
+
+        @Override
+        public int length() throws IOException {
+            return src.length();
+        }
+
+        @Override
+        public String getName() {
+            return "Source";
+        }
+    }
+
+}
index 4468996fb81d57e995bcc0c34162feb94e672cd8..598e130091391303febf5b14cbe039e4bda3ef2e 100644 (file)
@@ -49,7 +49,7 @@ public class FlagNode extends G2DNode {
     static transient final BasicStroke   STROKE           = new BasicStroke(0.25f, BasicStroke.CAP_BUTT,
                                                                   BasicStroke.JOIN_MITER);
 
-    final transient Font                 FONT             = Font.decode("Arial 12");
+    public final static Font             DEFAULT_FONT     = Font.decode("Arial 12");
 
     protected boolean visible;
 
@@ -66,6 +66,7 @@ public class FlagNode extends G2DNode {
     protected Rectangle2D textArea;
     protected byte hAlign;
     protected byte vAlign;
+    protected Font font = DEFAULT_FONT;
 
     private transient final Point2D      origin           = new Point2D.Double();
     private transient final Point2D      xa               = new Point2D.Double();
@@ -85,8 +86,8 @@ public class FlagNode extends G2DNode {
         return visible;
     }
 
-    @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign"})
-    public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign) {
+    @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign", "font"})
+    public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign, Font font) {
         this.visible = true;
         this.flagShape = flagShape;
         this.flagText = flagText;
@@ -101,6 +102,7 @@ public class FlagNode extends G2DNode {
         this.textArea = textArea;
         this.hAlign =  (byte) hAlign;
         this.vAlign = (byte) vAlign;
+        this.font = font;
 
         resetCaches();
     }
@@ -165,8 +167,7 @@ public class FlagNode extends G2DNode {
             }
 
             // Paint flag text
-            Font f = FONT;
-            g.setFont(f);
+            g.setFont(font);
             g.setColor(textColor);
 
             AffineTransform orig = g.getTransform();
@@ -240,7 +241,7 @@ public class FlagNode extends G2DNode {
                 System.out.println("transform: " + g.getTransform());
             }
 
-            FontMetrics fm = g.getFontMetrics(f);
+            FontMetrics fm = g.getFontMetrics(font);
             double fontHeight = fm.getHeight();
 
             if (textLayout == null || (float) scale != lastViewScale)
@@ -254,7 +255,7 @@ public class FlagNode extends G2DNode {
                 textHeight = 0;
                 for (int i = 0; i < flagText.length; ++i) {
                     String txt = flagText[i].isEmpty() ? " " : flagText[i]; 
-                    textLayout[i] = new TextLayout(txt, f, frc);
+                    textLayout[i] = new TextLayout(txt, font, frc);
                     rects[i] = textLayout[i].getBounds();
 
                     // If the bb height is not overridden with the font height
index acfce7de990adc16a50aa66384b99d608263051e..5e53808a2b30f039b49d19282c0ad0f1531b5dfa 100644 (file)
@@ -60,6 +60,8 @@ public class SCLScriptRunnerApplication implements IApplication {
                                SimanticsArguments.ONTOLOGY_RECOVERY_POLICY_REINSTALL,
                                SimanticsArguments.SERVER,
                                SimanticsArguments.LOCAL_SERVER_PORT,
+                               SimanticsArguments.DISABLE_INDEX,
+                               SimanticsArguments.DATABASE_ID,
                };
                IArguments result = Arguments.parse(args, accepted);
                return result;
index 977d1c527ce081d6f81ef140c3bafbe654a9d2eb..7919710ff1fcdc2595a937e82e3dbf738d295a6d 100644 (file)
@@ -59,6 +59,7 @@ public class SCLScriptRunnerApplication implements IApplication {
                                SimanticsArguments.ONTOLOGY_RECOVERY_POLICY_REINSTALL,
                                SimanticsArguments.SERVER,
                                SimanticsArguments.LOCAL_SERVER_PORT,
+                               SimanticsArguments.DISABLE_INDEX,
                                SimanticsArguments.DATABASE_ID,
                };
                IArguments result = Arguments.parse(args, accepted);
index 9529628eaee3bab8dc38bec39cd1ee15a6db3e7f..9a1a354f17131b35e1fbfd7bfcc0565645b95616 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.Indexing;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
@@ -125,6 +126,16 @@ public class Simantics {
             ontologyPolicy = OntologyRecoveryPolicy.ReinstallDatabase;
         }
 
+        if (args.contains(SimanticsArguments.DISABLE_INDEX)) {
+            Indexing.setDefaultDependenciesIndexingEnabled(false);
+        }
+
+        String databaseDriverId = defaultDatabaseDriverId;
+        if (args.contains(SimanticsArguments.DATABASE_ID)) {
+            databaseDriverId = args.get(SimanticsArguments.DATABASE_ID);
+            Simantics.setDefaultDatabaseDriver(databaseDriverId);
+        }
+
         int localPort = 0;
         if (args.contains(SimanticsArguments.LOCAL_SERVER_PORT)) {
             try {
@@ -144,7 +155,7 @@ public class Simantics {
 //            }
 //        }
 
-        return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort /*, remoteDatabase*/);
+        return startUpHeadless(progress, workspacePolicy, ontologyPolicy, localPort, databaseDriverId /*, remoteDatabase*/);
     }
 
     /**
@@ -156,7 +167,7 @@ public class Simantics {
      * @return
      * @throws PlatformException
      */
-    public static ISessionContext startUpHeadless(IProgressMonitor progress, RecoveryPolicy workspacePolicy, OntologyRecoveryPolicy ontologyPolicy, int localPort) throws PlatformException {
+    public static ISessionContext startUpHeadless(IProgressMonitor progress, RecoveryPolicy workspacePolicy, OntologyRecoveryPolicy ontologyPolicy, int localPort, String databaseDriverId) throws PlatformException {
         if (SimanticsPlatform.INSTANCE.sessionContext != null) {
             throw new RuntimeDatabaseException("Simantics is already up and running.");
         }
@@ -169,7 +180,7 @@ public class Simantics {
 
         if (progress == null)
             progress = new NullProgressMonitor();
-        return SimanticsPlatform.INSTANCE.startUp(defaultDatabaseDriverId, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent());
+        return SimanticsPlatform.INSTANCE.startUp(databaseDriverId, progress, workspacePolicy, ontologyPolicy, true, new ConsoleUserAgent());
     }
 
     /**