]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Sync git svn branch with SVN repository r33216.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 19 Sep 2016 14:09:15 +0000 (17:09 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 19 Sep 2016 14:09:15 +0000 (17:09 +0300)
refs #6653
refs #6699
refs #6700

12 files changed:
bundles/org.simantics.databoard/src/org/simantics/databoard/util/ObjectUtils.java
bundles/org.simantics.fileimport/META-INF/MANIFEST.MF
bundles/org.simantics.fileimport/build.properties
bundles/org.simantics.fileimport/plugin.xml [new file with mode: 0644]
bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsFileImportFeature.java [new file with mode: 0644]
bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java
bundles/org.simantics.modeling/scl/Simantics/Typicals.scl [new file with mode: 0644]
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java

index 8293f0232b06df41ccec386019c77c50fccf53ef..f360b25ecaa321ae5be8253fe77e1df0eaabbc81 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Arrays;
 import java.util.Collection;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
 import java.util.Collection;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
+import java.util.Objects;\r
 import java.util.Set;\r
 
 /**
 import java.util.Set;\r
 
 /**
@@ -37,7 +38,9 @@ public class ObjectUtils {
     public static boolean objectEquals(Object o1, Object o2) {
         if (o1==o2) return true;
         if (o1==null && o2==null) return true;
     public static boolean objectEquals(Object o1, Object o2) {
         if (o1==o2) return true;
         if (o1==null && o2==null) return true;
-        if (o1==null || o2==null) return false;
+        if (o1==null || o2==null) return false;\r
+        if (o1.getClass().isArray() && o2.getClass().isArray())\r
+            return Objects.deepEquals(o1, o2);
         return o1.equals(o2);
     }
     
         return o1.equals(o2);
     }
     
index d1a2f8065749b20373e856fa3c6354dceb595d69..bbb632778cee2fbd035dbab3e06afaf990d0d12a 100644 (file)
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Simantics Fileimport Interface and base classes
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Simantics Fileimport Interface and base classes
-Bundle-SymbolicName: org.simantics.fileimport
+Bundle-SymbolicName: org.simantics.fileimport;singleton:=true
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.simantics.fileimport.Activator
 Require-Bundle: org.eclipse.core.runtime,
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.simantics.fileimport.Activator
 Require-Bundle: org.eclipse.core.runtime,
index a26ce7b6b2a5e0189f176ee2c720b1a89222252d..f760fc2225ebde0b1e2ace2a65f970598c0264c3 100644 (file)
@@ -1,7 +1,8 @@
 output.. = bin/\r
 bin.includes = META-INF/,\\r
                .,\\r
 output.. = bin/\r
 bin.includes = META-INF/,\\r
                .,\\r
-               OSGI-INF/,\r
+               OSGI-INF/,\\r
+               plugin.xml\r
                OSGI-INF/FileReferenceFileImport.xml,\\r
                OSGI-INF/LibraryFolderFileImport.xml,\\r
                scl/\r
                OSGI-INF/FileReferenceFileImport.xml,\\r
                OSGI-INF/LibraryFolderFileImport.xml,\\r
                scl/\r
diff --git a/bundles/org.simantics.fileimport/plugin.xml b/bundles/org.simantics.fileimport/plugin.xml
new file mode 100644 (file)
index 0000000..5f26dd9
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<?eclipse version="3.4"?>\r
+<plugin>\r
+   <extension\r
+         point="org.simantics.project.feature">\r
+      <feature\r
+            class="org.simantics.fileimport.SimanticsFileImportFeature"\r
+            id="org.simantics.fileimport.simanticsFileImport"\r
+            label="Simantics File Import Feature">\r
+        <installGroup id="omnipresent" version="[1.0.0,2.0.0)"/>\r
+      </feature>\r
+   </extension>\r
+\r
+</plugin>\r
index 605e50347babec4e4fd0c29fd6a0344b0c7c9613..4261a51718e617d72b2531f5c922cbd38457d35d 100644 (file)
@@ -27,7 +27,6 @@ public class Activator implements BundleActivator {
         */\r
        public void start(BundleContext bundleContext) throws Exception {\r
                Activator.context = bundleContext;\r
         */\r
        public void start(BundleContext bundleContext) throws Exception {\r
                Activator.context = bundleContext;\r
-               FileImportDropins.watchDropinsFolder();\r
        }\r
 \r
        /*\r
        }\r
 \r
        /*\r
index a3a6a8c41efe415f37b6c5e102d376e7bbd311d3..c65b7c7d835114de7d971e5d7b5fe90d110761f0 100644 (file)
@@ -27,6 +27,8 @@ import org.simantics.fileimport.dropins.FileImportDropins;
  */\r
 public class FileImportService {\r
 \r
  */\r
 public class FileImportService {\r
 \r
+    private FileImportService() {}\r
+    \r
     public static final String DB_FILE = ".simanticsdb";\r
 \r
     private static List<IGenericFileImport> getFileImportServices() {\r
     public static final String DB_FILE = ".simanticsdb";\r
 \r
     private static List<IGenericFileImport> getFileImportServices() {\r
diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsFileImportFeature.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsFileImportFeature.java
new file mode 100644 (file)
index 0000000..972a966
--- /dev/null
@@ -0,0 +1,19 @@
+package org.simantics.fileimport;\r
+\r
+import org.simantics.fileimport.dropins.FileImportDropins;\r
+import org.simantics.project.exception.ProjectException;\r
+import org.simantics.project.features.AbstractProjectFeature;\r
+\r
+public class SimanticsFileImportFeature extends AbstractProjectFeature {\r
+\r
+    @Override\r
+    public void configure() throws ProjectException {\r
+        FileImportDropins.watchDropinsFolder();\r
+    }\r
+\r
+    @Override\r
+    public void deconfigure() throws ProjectException {\r
+        FileImportDropins.unwatchDropinsFolder();\r
+    }\r
+\r
+}\r
index 21a9f9ab0152fd5fab5d5a6d84d50e553d2a047f..5942c5deb299956e871f034c86efe78bcd07f358 100644 (file)
@@ -59,6 +59,8 @@ public class FileImportDropins {
      * Stop watching the dropins folder\r
      */\r
     public static void unwatchDropinsFolder() {\r
      * Stop watching the dropins folder\r
      */\r
     public static void unwatchDropinsFolder() {\r
+        if (watcher == null)\r
+            return;\r
         watcher.stop();\r
         try {\r
             watcherThread.join(500);\r
         watcher.stop();\r
         try {\r
             watcherThread.join(500);\r
index cad45187721a8caef5345cea807c426d4a9c9f1a..d3fa3d0f9b6b14302e37ee4bef804d174a57e06e 100644 (file)
@@ -1,8 +1,11 @@
 package org.simantics.fileimport.scl;\r
 \r
 import java.io.IOException;\r
 package org.simantics.fileimport.scl;\r
 \r
 import java.io.IOException;\r
+import java.nio.file.DirectoryStream;\r
+import java.nio.file.Files;\r
 import java.nio.file.Path;\r
 import java.util.HashMap;\r
 import java.nio.file.Path;\r
 import java.util.HashMap;\r
+import java.util.Iterator;\r
 import java.util.Map;\r
 import java.util.Optional;\r
 \r
 import java.util.Map;\r
 import java.util.Optional;\r
 \r
@@ -31,24 +34,47 @@ public class DropinsSCL {
     public static void watchDropinsFolder() {\r
         FileImportDropins.watchDropinsFolder();\r
     }\r
     public static void watchDropinsFolder() {\r
         FileImportDropins.watchDropinsFolder();\r
     }\r
-    \r
+\r
     public static void unwatchDropinsFolder() {\r
         FileImportDropins.unwatchDropinsFolder();\r
     }\r
     public static void unwatchDropinsFolder() {\r
         FileImportDropins.unwatchDropinsFolder();\r
     }\r
-    \r
+\r
     public static void uploadToDropinsBase64(String base64, String fileName) {\r
         // ensure that watcher is awake\r
         FileImportDropins.watchDropinsFolder();\r
         try {\r
             Path rootFolder = Activator.getDropinsFolder();\r
     public static void uploadToDropinsBase64(String base64, String fileName) {\r
         // ensure that watcher is awake\r
         FileImportDropins.watchDropinsFolder();\r
         try {\r
             Path rootFolder = Activator.getDropinsFolder();\r
+            Path newFile = rootFolder.resolve(fileName);\r
+            if (Files.exists(newFile)) {\r
+                newFile = findFreshFileName(rootFolder, fileName);\r
+            }\r
             byte[] bytes = Base64.decode(base64);\r
             byte[] bytes = Base64.decode(base64);\r
-            FileUtils.writeFile(rootFolder.resolve(fileName).toFile(), bytes);\r
-            \r
+            FileUtils.writeFile(newFile.toFile(), bytes);\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
         }\r
     }\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
         }\r
     }\r
-    \r
+\r
+    private static Path findFreshFileName(Path root, String fileName) throws IOException {\r
+        int ending = fileName.lastIndexOf('.');\r
+        String glob = fileName;\r
+        String suffix = "";\r
+        if (ending > -1) {\r
+            glob = fileName.substring(0, ending);\r
+            suffix = fileName.substring(ending);\r
+        }\r
+        int i = 0;\r
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(root, glob)) {\r
+            Iterator<Path> iter = stream.iterator();\r
+            while (iter.hasNext()) {\r
+                iter.next();\r
+                i++;\r
+            }\r
+        }\r
+        String newFileName = glob + "_" + i + suffix;\r
+        return root.resolve(newFileName);\r
+    }\r
+\r
     public static Map<String, Long> getUploadedFiles() throws DatabaseException {\r
         Map<String, String> results = FileImportService.getPathsAndResources();\r
         Map<String, Long> result = Simantics.getSession().syncRequest(new UniqueRead<Map<String, Long>>() {\r
     public static Map<String, Long> getUploadedFiles() throws DatabaseException {\r
         Map<String, String> results = FileImportService.getPathsAndResources();\r
         Map<String, Long> result = Simantics.getSession().syncRequest(new UniqueRead<Map<String, Long>>() {\r
@@ -73,9 +99,9 @@ public class DropinsSCL {
         });\r
         return result;\r
     }\r
         });\r
         return result;\r
     }\r
-    \r
+\r
     public static void removeFileForId(long id) {\r
         FileImportService.removeFileForResource(id, Optional.empty());\r
     }\r
     public static void removeFileForId(long id) {\r
         FileImportService.removeFileForResource(id, Optional.empty());\r
     }\r
-    \r
+\r
 }\r
 }\r
diff --git a/bundles/org.simantics.modeling/scl/Simantics/Typicals.scl b/bundles/org.simantics.modeling/scl/Simantics/Typicals.scl
new file mode 100644 (file)
index 0000000..a16ea6c
--- /dev/null
@@ -0,0 +1,55 @@
+import "Simantics/Ontologies"\r
+import "Simantics/Model"\r
+\r
+@private\r
+toDiagrams composites = map (flip singleObject MOD.CompositeToDiagram) composites\r
+\r
+@private\r
+importJava "org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances" where\r
+    syncTypicals :: Boolean -> [Resource] -> [Resource] -> <WriteGraph> ()\r
+\r
+"""\r
+    syncAllTypicals False currentModel\r
+\r
+Synchronizes all typical master diagrams in the specified model with all\r
+instances of the found typical master diagrams.\r
+\r
+The first argument controls whether a log of the synchronization will be\r
+stored in the database, in the model's Documents folder.\r
+"""\r
+syncAllTypicals :: Boolean -> Resource -> <Proc> ()\r
+syncAllTypicals log model = syncInstancesOfTypicalMasters log masterComposites\r
+    where\r
+        masterComposites = lift2Read searchByTypeShallow model MOD.MasterTypicalCompositeType\r
+\r
+"""\r
+    syncInstancesOfTypicalMasters False [aMasterTypicalComposite]\r
+\r
+Synchronizes all instances of the specified typical master diagram(s).\r
+\r
+The first argument controls whether a log of the synchronization will be\r
+stored in the database, in the model's Documents folder.\r
+\r
+The second argument expects diagram configuration composite resources.\r
+"""\r
+syncInstancesOfTypicalMasters :: Boolean -> [Resource] -> <Proc> ()\r
+syncInstancesOfTypicalMasters log typicalMasterComposites = syncWrite (\_ -> syncTypicals log masterDiagrams [])\r
+    where\r
+        masterDiagrams = lift1Read toDiagrams typicalMasterComposites\r
+\r
+"""\r
+    syncTypicalInstances False [aTypicalInstance]\r
+\r
+Synchronizes the specified typical instance diagram(s) with their master\r
+diagrams.\r
+\r
+The first argument controls whether a log of the synchronization will be\r
+stored in the database, in the model's Documents folder.\r
+\r
+The second argument expects diagram configuration composite resources.\r
+"""\r
+syncTypicalInstances :: Boolean -> [Resource] -> <Proc> ()\r
+syncTypicalInstances log typicalInstanceComposites = let\r
+        instanceDiagrams = lift1Read toDiagrams typicalInstanceComposites\r
+    in\r
+        syncWrite (\_ -> syncTypicals log [] instanceDiagrams)\r
index 55f5aef3dabf1869b305b5376d14633abbcf9850..cd326051371169ad70b442b8b986300c336cbce2 100644 (file)
@@ -11,9 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.modeling.typicals;\r
 \r
  *******************************************************************************/\r
 package org.simantics.modeling.typicals;\r
 \r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
 import java.awt.geom.Point2D;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.awt.geom.Point2D;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
@@ -85,6 +82,9 @@ import org.simantics.utils.strings.AlphanumComparator;
 import org.simantics.utils.strings.EString;\r
 import org.simantics.utils.ui.ErrorLogger;\r
 \r
 import org.simantics.utils.strings.EString;\r
 import org.simantics.utils.ui.ErrorLogger;\r
 \r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
 /**\r
  * A write request that synchronizes typical master templates and their\r
  * instances as specified.\r
 /**\r
  * A write request that synchronizes typical master templates and their\r
  * instances as specified.\r
@@ -210,6 +210,26 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
 \r
        private boolean writeLog;\r
 \r
 \r
        private boolean writeLog;\r
 \r
+    /**\r
+     * For SCL API.\r
+     * \r
+     * @param graph\r
+     * @param selectedRules\r
+     * @param templates\r
+     * @param instances\r
+     * @throws DatabaseException\r
+     */\r
+    public static void syncTypicals(WriteGraph graph, boolean log, List<Resource> templates, List<Resource> instances) throws DatabaseException {\r
+        graph.syncRequest(\r
+                new SyncTypicalTemplatesToInstances(\r
+                        null,\r
+                        templates.toArray(Resource.NONE),\r
+                        instances.toArray(Resource.NONE),\r
+                        ALL,\r
+                        null)\r
+                .logging(log));\r
+    }\r
+\r
     /**\r
      * @param templates typical diagram templates to completely synchronize with\r
      *        their instances\r
     /**\r
      * @param templates typical diagram templates to completely synchronize with\r
      *        their instances\r
index f99f679efe4859813bdd8186605afeacb08c22af..9bce1aef1f27f0cad00f9f6b6d6212a0322da778 100644 (file)
@@ -28,7 +28,7 @@ public class VariablePropertyLabelRule implements LabelRule {
        for(Variable property : variable.getProperties(graph)) {\r
                String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN);\r
                if(column != null) {\r
        for(Variable property : variable.getProperties(graph)) {\r
                String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN);\r
                if(column != null) {\r
-                       String value = property.getValue(graph, Bindings.STRING);\r
+                       String value = property.getPossibleValue(graph, Bindings.STRING);\r
                        if (value != null)\r
                                result.put(column, value);\r
                }\r
                        if (value != null)\r
                                result.put(column, value);\r
                }\r