]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Non-constant external value configuration via procedural UCs."
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 11 Feb 2020 11:05:38 +0000 (11:05 +0000)
committerGerrit Code Review <gerrit2@simantics>
Tue, 11 Feb 2020 11:05:38 +0000 (11:05 +0000)
bundles/org.simantics.diagram/scl/Simantics/Diagram/SymbolLibrary.scl
bundles/org.simantics.diagram/src/org/simantics/diagram/scl/SymbolLibrary.java
bundles/org.simantics.document.base.ontology/graph/ConnectionPoints.pgraph
bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java
bundles/org.simantics/src/org/simantics/DatabaseBaselines.java
bundles/org.simantics/src/org/simantics/SimanticsPlatform.java

index 78be7a1dee64600f77b94ba0e5f622822ff3d225..ce97a9349b4910cc24eb6a76f47eebbd5c40a5bc 100644 (file)
@@ -44,4 +44,6 @@ importJava "org.simantics.diagram.symbolcontribution.IndexRootSymbolProviderFact
 importJava "org.simantics.diagram.scl.SymbolLibrary" where
   
   @JavaName create
-  itemToContext :: ISymbolItem -> <Proc> ICanvasContext
\ No newline at end of file
+  itemToContext :: ISymbolItem -> <Proc> ICanvasContext
+  
+  getItemResource :: ISymbolItem -> <Proc> Resource
\ No newline at end of file
index 6820cad0824d264a364c9e09c3d83d3cae6bc229..9ab2bcd6ce3497ed6ae339e485ab87531d383437 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.diagram.scl;
 
 import java.awt.Color;
 
+import org.simantics.db.Resource;
 import org.simantics.diagram.symbollibrary.ISymbolItem;
 import org.simantics.g2d.canvas.Hints;
 import org.simantics.g2d.canvas.ICanvasContext;
@@ -52,15 +53,22 @@ public class SymbolLibrary {
         ElementClass ec = item.getElementClass(diagram);
         StaticSymbol ss = ec.getSingleItem(StaticSymbol.class);
         Image source = ss == null ? DefaultImages.UNKNOWN2.get() : ss.getImage();
+        //ImageProxy proxy = new ImageProxy(source);
         
         IElement element = Element.spawnNew(ec);
         element.setHint(ElementHints.KEY_OBJECT, item);
         element.setHint(GalleryItemSGNode.KEY_IMAGE, source);
         diagram.addElement(element);
         
+        //element.getElementClass().getSingleItem(GalleryItemSGNode.class).update(element);
+        
         return ctx;
        }
        
+       public static Resource getItemResource(ISymbolItem item) {
+               return item.getAdapter(Resource.class);
+       }
+       
         private static void initializeCanvasContext(final CanvasContext canvasContext) {
                // Create canvas context and a layer of interactors
                final IHintContext h = canvasContext.getDefaultHintContext();
index d069d127aafd17ce55b3eaa2517abd6b06459d3f..73b795343d9c5d9b65acbf9643263a0948314690 100644 (file)
@@ -282,6 +282,387 @@ RELATIONS.sequence9 : RELATIONS.commandRelation
 RELATIONS.sequence10 : RELATIONS.commandRelation
     @defCommandConnectionPoint "10"
 
+RELATIONS.sequence11 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "11"
+RELATIONS.sequence12 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "12"   
+RELATIONS.sequence13 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "13"
+RELATIONS.sequence14 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "14"
+RELATIONS.sequence15 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "15"
+RELATIONS.sequence16 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "16"
+RELATIONS.sequence17 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "17"
+RELATIONS.sequence18 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "18"
+RELATIONS.sequence19 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "19"
+RELATIONS.sequence20 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "20"
+RELATIONS.sequence21 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "21"
+RELATIONS.sequence22 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "22"
+RELATIONS.sequence23 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "23"
+RELATIONS.sequence24 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "24"
+RELATIONS.sequence25 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "25"
+RELATIONS.sequence26 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "26"
+RELATIONS.sequence27 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "27"
+RELATIONS.sequence28 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "28"
+RELATIONS.sequence29 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "29"
+RELATIONS.sequence30 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "30"
+RELATIONS.sequence31 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "31"
+RELATIONS.sequence32 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "32"
+RELATIONS.sequence33 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "33"
+RELATIONS.sequence34 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "34"
+RELATIONS.sequence35 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "35"
+RELATIONS.sequence36 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "36"
+RELATIONS.sequence37 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "37"
+RELATIONS.sequence38 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "38"
+RELATIONS.sequence39 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "39"
+RELATIONS.sequence40 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "40"
+RELATIONS.sequence41 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "41"
+RELATIONS.sequence42 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "42"
+RELATIONS.sequence43 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "43"
+RELATIONS.sequence44 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "44"
+RELATIONS.sequence45 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "45"
+RELATIONS.sequence46 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "46"
+RELATIONS.sequence47 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "47"
+RELATIONS.sequence48 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "48"
+RELATIONS.sequence49 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "49"
+RELATIONS.sequence50 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "50"
+RELATIONS.sequence51 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "51"
+RELATIONS.sequence52 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "52"
+RELATIONS.sequence53 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "53"
+RELATIONS.sequence54 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "54"
+RELATIONS.sequence55 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "55"
+RELATIONS.sequence56 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "56"
+RELATIONS.sequence57 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "57"
+RELATIONS.sequence58 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "58"
+RELATIONS.sequence59 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "59"
+RELATIONS.sequence60 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "60"
+RELATIONS.sequence61 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "61"
+RELATIONS.sequence62 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "62"
+RELATIONS.sequence63 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "63"
+RELATIONS.sequence64 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "64"
+RELATIONS.sequence65 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "65"
+RELATIONS.sequence66 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "66"
+RELATIONS.sequence67 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "67"
+RELATIONS.sequence68 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "68"
+RELATIONS.sequence69 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "69"
+RELATIONS.sequence70 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "70"
+RELATIONS.sequence71 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "71"
+RELATIONS.sequence72 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "72"
+RELATIONS.sequence73 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "73"
+RELATIONS.sequence74 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "74"
+RELATIONS.sequence75 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "75"
+RELATIONS.sequence76 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "76"
+RELATIONS.sequence77 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "77"
+RELATIONS.sequence78 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "78"
+RELATIONS.sequence79 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "79"
+RELATIONS.sequence80 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "80"
+RELATIONS.sequence81 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "81"
+RELATIONS.sequence82 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "82"
+RELATIONS.sequence83 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "83"
+RELATIONS.sequence84 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "84"
+RELATIONS.sequence85 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "85"
+RELATIONS.sequence86 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "86"
+RELATIONS.sequence87 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "87"
+RELATIONS.sequence88 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "88"
+RELATIONS.sequence89 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "89"
+RELATIONS.sequence90 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "90"
+RELATIONS.sequence91 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "91"
+RELATIONS.sequence92 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "92"
+RELATIONS.sequence93 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "93"
+RELATIONS.sequence94 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "94"
+RELATIONS.sequence95 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "95"
+RELATIONS.sequence96 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "96"
+RELATIONS.sequence97 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "97"
+RELATIONS.sequence98 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "98"
+RELATIONS.sequence99 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "99"
+RELATIONS.sequence100 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "100"
+RELATIONS.sequence101 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "101"
+RELATIONS.sequence102 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "102"
+RELATIONS.sequence103 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "103"
+RELATIONS.sequence104 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "104"
+RELATIONS.sequence105 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "105"
+RELATIONS.sequence106 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "106"
+RELATIONS.sequence107 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "107"
+RELATIONS.sequence108 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "108"
+RELATIONS.sequence109 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "109"
+RELATIONS.sequence110 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "110"
+RELATIONS.sequence111 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "111"
+RELATIONS.sequence112 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "112"
+RELATIONS.sequence113 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "113"
+RELATIONS.sequence114 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "114"
+RELATIONS.sequence115 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "115"
+RELATIONS.sequence116 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "116"
+RELATIONS.sequence117 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "117"
+RELATIONS.sequence118 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "118"
+RELATIONS.sequence119 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "119"
+RELATIONS.sequence120 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "120"
+RELATIONS.sequence121 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "121"
+RELATIONS.sequence122 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "122"
+RELATIONS.sequence123 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "123"
+RELATIONS.sequence124 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "124"
+RELATIONS.sequence125 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "125"
+RELATIONS.sequence126 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "126"
+RELATIONS.sequence127 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "127"
+RELATIONS.sequence128 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "128"
+RELATIONS.sequence129 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "129"
+RELATIONS.sequence130 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "130"
+RELATIONS.sequence131 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "131"
+RELATIONS.sequence132 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "132"
+RELATIONS.sequence133 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "133"
+RELATIONS.sequence134 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "134"
+RELATIONS.sequence135 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "135"
+RELATIONS.sequence136 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "136"
+RELATIONS.sequence137 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "137"
+RELATIONS.sequence138 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "138"
+RELATIONS.sequence139 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "139"
+RELATIONS.sequence140 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "140"
+RELATIONS.sequence141 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "141"
+RELATIONS.sequence142 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "142"
+RELATIONS.sequence143 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "143"
+RELATIONS.sequence144 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "144"
+RELATIONS.sequence145 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "145"
+RELATIONS.sequence146 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "146"
+RELATIONS.sequence147 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "147"
+RELATIONS.sequence148 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "148"
+RELATIONS.sequence149 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "149"
+RELATIONS.sequence150 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "150"
+RELATIONS.sequence151 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "151"
+RELATIONS.sequence152 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "152"
+RELATIONS.sequence153 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "153"
+RELATIONS.sequence154 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "154"
+RELATIONS.sequence155 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "155"
+RELATIONS.sequence156 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "156"
+RELATIONS.sequence157 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "157"
+RELATIONS.sequence158 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "158"
+RELATIONS.sequence159 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "159"
+RELATIONS.sequence160 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "160"
+RELATIONS.sequence161 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "161"
+RELATIONS.sequence162 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "162"
+RELATIONS.sequence163 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "163"
+RELATIONS.sequence164 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "164"
+RELATIONS.sequence165 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "165"
+RELATIONS.sequence166 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "166"
+RELATIONS.sequence167 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "167"
+RELATIONS.sequence168 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "168"
+RELATIONS.sequence169 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "169"
+RELATIONS.sequence170 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "170"
+RELATIONS.sequence171 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "171"
+RELATIONS.sequence172 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "172"
+RELATIONS.sequence173 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "173"
+RELATIONS.sequence174 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "174"
+RELATIONS.sequence175 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "175"
+RELATIONS.sequence176 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "176"
+RELATIONS.sequence177 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "177"
+RELATIONS.sequence178 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "178"
+RELATIONS.sequence179 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "179"
+RELATIONS.sequence180 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "180"
+RELATIONS.sequence181 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "181"
+RELATIONS.sequence182 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "182"
+RELATIONS.sequence183 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "183"
+RELATIONS.sequence184 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "184"
+RELATIONS.sequence185 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "185"
+RELATIONS.sequence186 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "186"
+RELATIONS.sequence187 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "187"
+RELATIONS.sequence188 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "188"
+RELATIONS.sequence189 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "189"
+RELATIONS.sequence190 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "190"
+RELATIONS.sequence191 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "191"
+RELATIONS.sequence192 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "192"
+RELATIONS.sequence193 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "193"
+RELATIONS.sequence194 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "194"
+RELATIONS.sequence195 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "195"
+RELATIONS.sequence196 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "196"
+RELATIONS.sequence197 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "197"
+RELATIONS.sequence198 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "198"
+RELATIONS.sequence199 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "199"
+RELATIONS.sequence200 : RELATIONS.commandRelation
+   @defCommandConnectionPoint "200"
+    
 RELATIONS.broadcasted : RELATIONS.commandRelation
     @defCommandConnectionPoint "1"
 
index f5bda18b0a137816c209b12972bfeb346605eb2e..8a8b493753e3be04b14156483ba9f4df63dba9a8 100644 (file)
@@ -88,6 +88,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.simantics.CancelStartupException;
+import org.simantics.DatabaseBaselines;
 import org.simantics.PlatformException;
 import org.simantics.Simantics;
 import org.simantics.SimanticsPlatform;
@@ -105,7 +106,6 @@ import org.simantics.ui.SimanticsUI;
 import org.simantics.ui.jobs.SessionGarbageCollectorJob;
 import org.simantics.ui.workbench.PerspectiveBarsActivator;
 import org.simantics.ui.workbench.PerspectiveContextActivator;
-import org.simantics.ui.workbench.WorkbenchShutdownService;
 import org.simantics.utils.logging.TimeLogger;
 import org.simantics.utils.ui.dialogs.ShowError;
 import org.simantics.utils.ui.dialogs.ShowMessage;
@@ -432,6 +432,11 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
             if (PROFILE_PLATFORM_STARTUP)
                 mon = new TimingProgressMonitor();
             SimanticsPlatform.INSTANCE.startUp(databaseDriverId, mon, workspacePolicy, ontologyPolicy, requireSynchronize, new JFaceUserAgent());
+            if(DatabaseBaselines.shouldCreateAutomaticBaseline(SimanticsPlatform.INSTANCE.databaseExists() != null)) {
+                SimanticsPlatform.INSTANCE.shutdown(null);
+                DatabaseBaselines.createAutomaticBaseline(SimanticsPlatform.INSTANCE.dbLocation());
+                SimanticsPlatform.INSTANCE.reconnect(Simantics.getDefaultDatabaseDriver());
+            }
 
             // Make sure that the default perspective comes from the project if
             // the project has set ProjectKeys#DEFAULT_PERSPECTIVE.
index fe3393a2c0afd6f7abb7eb522eb22086b9ed4d51..c58cb508623026fbf5f054cc67645e6d87d1db1a 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics;
 
+import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -13,6 +14,7 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
+import org.eclipse.core.runtime.Platform;
 import org.simantics.utils.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,8 +34,114 @@ public class DatabaseBaselines {
 
        private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter.ofPattern("d. MMM yyyy HH:mm:ss");
 
-       public static Path packageBaseline(Path fromWorkspace, Path packageFile) throws IOException {
-               return compressZip(fromWorkspace, collectBaselinePaths(fromWorkspace), packageFile);
+    public static boolean handleBaselineDatabase(Path installLocation, boolean databaseExists) throws PlatformException {
+        Path workspaceLocation = Platform.getLocation().toFile().toPath();
+        Path baselineIndicatorFile = workspaceLocation.resolve(".baselined");
+        if (Files.isRegularFile(baselineIndicatorFile)) {
+            // This means that the workspace has already been initialized from
+            // a database baseline and further initialization is not necessary.
+            return true;
+        }
+
+        Path baseline = resolveBaselineFile(installLocation);
+        if (baseline == null) {
+            baseline = getAutomaticBaselinePath();
+            if(baseline == null)
+                return false;
+            if(databaseExists)
+                return false;
+            if(!existsAutomaticBaseline())
+                return false;
+        }
+        
+        DatabaseBaselines.validateBaselineFile(baseline);
+        DatabaseBaselines.validateWorkspaceForBaselineInitialization(workspaceLocation);
+        DatabaseBaselines.initializeWorkspaceWithBaseline(baseline, workspaceLocation, baselineIndicatorFile);
+        return true;
+        
+    }
+
+    private static Path resolveBaselineFile(Path installLocation) throws PlatformException {
+        String dbBaselineArchive = System.getProperty("org.simantics.db.baseline", null);
+        if (dbBaselineArchive == null)
+            return null;
+
+        Path baseline = Paths.get(dbBaselineArchive);
+        if (baseline.isAbsolute()) {
+            if (!Files.isRegularFile(baseline))
+                throw new PlatformException("Specified database baseline archive " + baseline
+                        + " does not exist. Cannot initialize workspace database from baseline.");
+            return baseline;
+        }
+
+        // Relative path resolution order:
+        // 1. from the platform "install location"
+        // 2. from working directory
+        //Path installLocation = tryGetInstallLocation();
+        if (installLocation != null) {
+            Path installedBaseline = installLocation.resolve(dbBaselineArchive);
+            if (Files.isRegularFile(installedBaseline))
+                return installedBaseline;
+        }
+        if (!Files.isRegularFile(baseline))
+            throw new PlatformException("Specified database baseline archive " + baseline
+                    + " does not exist in either the install location (" + installLocation
+                    + ") or the working directory (" + Paths.get(".").toAbsolutePath()
+                    + "). Cannot initialize workspace database.");
+        return null;
+    }
+
+    private static boolean useAutomaticBaseline() {
+        return getAutomaticBaselinePath() != null;
+    }
+
+    private static Path getAutomaticBaselinePath() {
+        if("true".equals(System.getProperty("org.simantics.db.baseline.automatic")))
+            return Paths.get("automatic_baseline", "baseline.zip");
+        else
+            return null;
+    }
+    
+    private static boolean existsAutomaticBaseline() {
+        Path baselineFile = getAutomaticBaselinePath();
+        if(baselineFile == null)
+            return false;
+        return Files.exists(baselineFile);
+    }
+
+    public static boolean shouldCreateAutomaticBaseline(boolean existsDatabase) throws PlatformException {
+        if(!useAutomaticBaseline()) {
+            // Are we using this feature? 
+            return false;
+        }
+        if(existsDatabase) {
+            // Baseline can only be created after db initialization
+            return false;
+        }
+        if(existsAutomaticBaseline()) {
+            // Existing baselines should not be automatically overridden
+            return false;
+        }
+        return true;
+    }
+
+    public static void createAutomaticBaseline(Path dbLocation) throws PlatformException {
+
+        if(existsAutomaticBaseline())
+            return;
+
+        try {
+            DatabaseBaselines.packageBaseline(dbLocation.getParent(), getAutomaticBaselinePath());
+        } catch (IOException e) {
+            LOGGER.error("Error while creating automatic baseline", e);
+        }
+
+    }
+
+    public static Path packageBaseline(Path fromWorkspace, Path packageFilePath) throws IOException {
+           File packageFile = packageFilePath.toFile();
+           packageFile.getParentFile().mkdirs();
+               return compressZip(fromWorkspace, collectBaselinePaths(fromWorkspace), packageFilePath);
        }
 
        private static List<Path> collectBaselinePaths(Path workspace) throws IOException {
index c0a85cd1ac1c06343b7a9bfb516b2efb84eb80fc..730e4e8877470439c8fd88cc8b47050db3bcfb66 100644 (file)
@@ -239,7 +239,7 @@ public class SimanticsPlatform implements LifecycleListener {
         if (progressMonitor == null)
             progressMonitor = new NullProgressMonitor();
         Path workspaceLocation = Platform.getLocation().toFile().toPath();
-        Path dbLocation = workspaceLocation.resolve("db");
+        Path dbLocation = dbLocation();
         Path dbIniPath = workspaceLocation.resolve("db.ini");
         // The driver file overrides any command line arguments to prevent
         // using the wrong driver for an existing database directory.
@@ -679,8 +679,9 @@ public class SimanticsPlatform implements LifecycleListener {
 
     public void resetDatabase(IProgressMonitor monitor) throws PlatformException {
         // TODO: fix this to use Path APIs
-        File dbLocation = Platform.getLocation().append("db").toFile();
-        if(!dbLocation.exists()) return;
+        File dbLocation = dbLocation().toFile();
+        if(!dbLocation.exists())
+            return;
         try { // Load driver
             Driver driver = Manager.getDriver("acorn");
             Management management = driver.getManagement(dbLocation.getAbsolutePath(), null);
@@ -721,53 +722,16 @@ public class SimanticsPlatform implements LifecycleListener {
         return l == null ? null : new File(l.getURL().getPath()).toPath();
     }
 
-    private Path resolveBaselineFile() throws PlatformException {
-        String dbBaselineArchive = System.getProperty("org.simantics.db.baseline", null);
-        if (dbBaselineArchive == null)
-            return null;
-
-        Path baseline = Paths.get(dbBaselineArchive);
-        if (baseline.isAbsolute()) {
-            if (!Files.isRegularFile(baseline))
-                throw new PlatformException("Specified database baseline archive " + baseline
-                        + " does not exist. Cannot initialize workspace database from baseline.");
-            return baseline;
-        }
-
-        // Relative path resolution order:
-        // 1. from the platform "install location"
-        // 2. from working directory
-        Path installLocation = tryGetInstallLocation();
-        if (installLocation != null) {
-            Path installedBaseline = installLocation.resolve(dbBaselineArchive);
-            if (Files.isRegularFile(installedBaseline))
-                return installedBaseline;
-        }
-        if (!Files.isRegularFile(baseline))
-            throw new PlatformException("Specified database baseline archive " + baseline
-                    + " does not exist in either the install location (" + installLocation
-                    + ") or the working directory (" + Paths.get(".").toAbsolutePath()
-                    + "). Cannot initialize workspace database.");
+    public Path databaseExists() {
+        Path dbLocation = dbLocation();
+        if(Files.exists(dbLocation))
+            return dbLocation;
         return null;
     }
-
-    private boolean handleBaselineDatabase() throws PlatformException {
+    
+    public Path dbLocation() {
         Path workspaceLocation = Platform.getLocation().toFile().toPath();
-        Path baselineIndicatorFile = workspaceLocation.resolve(".baselined");
-        if (Files.isRegularFile(baselineIndicatorFile)) {
-            // This means that the workspace has already been initialized from
-            // a database baseline and further initialization is not necessary.
-            return true;
-        }
-
-        Path baseline = resolveBaselineFile();
-        if (baseline == null)
-            return false;
-
-        DatabaseBaselines.validateBaselineFile(baseline);
-        DatabaseBaselines.validateWorkspaceForBaselineInitialization(workspaceLocation);
-        DatabaseBaselines.initializeWorkspaceWithBaseline(baseline, workspaceLocation, baselineIndicatorFile);
-        return true;
+        return workspaceLocation.resolve("db");
     }
 
     /**
@@ -827,7 +791,7 @@ public class SimanticsPlatform implements LifecycleListener {
 
         // 0.3 Handle baseline database before opening db
         @SuppressWarnings("unused")
-        boolean usingBaseline = handleBaselineDatabase();
+        boolean usingBaseline = DatabaseBaselines.handleBaselineDatabase(tryGetInstallLocation(), databaseExists() != null);
 
         // 1. Assert there is a database at <workspace>/db
         SessionDescriptor sessionDescriptor = setupDatabase(databaseDriverId, monitor.newChild(200, SubMonitor.SUPPRESS_NONE), workspacePolicy, userAgent);