From: Tuukka Lehtonen Date: Mon, 19 Sep 2016 14:09:15 +0000 (+0300) Subject: Sync git svn branch with SVN repository r33216. X-Git-Tag: v1.25.0~107^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=8e4e41fa135641b23f68e205832e0696951c5f63 Sync git svn branch with SVN repository r33216. refs #6653 refs #6699 refs #6700 --- diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/ObjectUtils.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/ObjectUtils.java index 8293f0232..f360b25ec 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/ObjectUtils.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/ObjectUtils.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.Objects; import java.util.Set; /** @@ -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; - if (o1==null || o2==null) return false; + if (o1==null || o2==null) return false; + if (o1.getClass().isArray() && o2.getClass().isArray()) + return Objects.deepEquals(o1, o2); return o1.equals(o2); } diff --git a/bundles/org.simantics.fileimport/META-INF/MANIFEST.MF b/bundles/org.simantics.fileimport/META-INF/MANIFEST.MF index d1a2f8065..bbb632778 100644 --- a/bundles/org.simantics.fileimport/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.fileimport/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ 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, diff --git a/bundles/org.simantics.fileimport/build.properties b/bundles/org.simantics.fileimport/build.properties index a26ce7b6b..f760fc222 100644 --- a/bundles/org.simantics.fileimport/build.properties +++ b/bundles/org.simantics.fileimport/build.properties @@ -1,7 +1,8 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ - OSGI-INF/, + OSGI-INF/,\ + plugin.xml OSGI-INF/FileReferenceFileImport.xml,\ OSGI-INF/LibraryFolderFileImport.xml,\ scl/ diff --git a/bundles/org.simantics.fileimport/plugin.xml b/bundles/org.simantics.fileimport/plugin.xml new file mode 100644 index 000000000..5f26dd998 --- /dev/null +++ b/bundles/org.simantics.fileimport/plugin.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java index 605e50347..4261a5171 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java @@ -27,7 +27,6 @@ public class Activator implements BundleActivator { */ public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; - FileImportDropins.watchDropinsFolder(); } /* diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java index a3a6a8c41..c65b7c7d8 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java @@ -27,6 +27,8 @@ import org.simantics.fileimport.dropins.FileImportDropins; */ public class FileImportService { + private FileImportService() {} + public static final String DB_FILE = ".simanticsdb"; private static List getFileImportServices() { 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 index 000000000..972a966a7 --- /dev/null +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsFileImportFeature.java @@ -0,0 +1,19 @@ +package org.simantics.fileimport; + +import org.simantics.fileimport.dropins.FileImportDropins; +import org.simantics.project.exception.ProjectException; +import org.simantics.project.features.AbstractProjectFeature; + +public class SimanticsFileImportFeature extends AbstractProjectFeature { + + @Override + public void configure() throws ProjectException { + FileImportDropins.watchDropinsFolder(); + } + + @Override + public void deconfigure() throws ProjectException { + FileImportDropins.unwatchDropinsFolder(); + } + +} diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java index 21a9f9ab0..5942c5deb 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/dropins/FileImportDropins.java @@ -59,6 +59,8 @@ public class FileImportDropins { * Stop watching the dropins folder */ public static void unwatchDropinsFolder() { + if (watcher == null) + return; watcher.stop(); try { watcherThread.join(500); diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java index cad451877..d3fa3d0f9 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java @@ -1,8 +1,11 @@ package org.simantics.fileimport.scl; import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.Optional; @@ -31,24 +34,47 @@ public class DropinsSCL { public static void watchDropinsFolder() { FileImportDropins.watchDropinsFolder(); } - + public static void unwatchDropinsFolder() { FileImportDropins.unwatchDropinsFolder(); } - + public static void uploadToDropinsBase64(String base64, String fileName) { // ensure that watcher is awake FileImportDropins.watchDropinsFolder(); try { Path rootFolder = Activator.getDropinsFolder(); + Path newFile = rootFolder.resolve(fileName); + if (Files.exists(newFile)) { + newFile = findFreshFileName(rootFolder, fileName); + } byte[] bytes = Base64.decode(base64); - FileUtils.writeFile(rootFolder.resolve(fileName).toFile(), bytes); - + FileUtils.writeFile(newFile.toFile(), bytes); } catch (IOException e) { e.printStackTrace(); } } - + + private static Path findFreshFileName(Path root, String fileName) throws IOException { + int ending = fileName.lastIndexOf('.'); + String glob = fileName; + String suffix = ""; + if (ending > -1) { + glob = fileName.substring(0, ending); + suffix = fileName.substring(ending); + } + int i = 0; + try (DirectoryStream stream = Files.newDirectoryStream(root, glob)) { + Iterator iter = stream.iterator(); + while (iter.hasNext()) { + iter.next(); + i++; + } + } + String newFileName = glob + "_" + i + suffix; + return root.resolve(newFileName); + } + public static Map getUploadedFiles() throws DatabaseException { Map results = FileImportService.getPathsAndResources(); Map result = Simantics.getSession().syncRequest(new UniqueRead>() { @@ -73,9 +99,9 @@ public class DropinsSCL { }); return result; } - + public static void removeFileForId(long id) { FileImportService.removeFileForResource(id, Optional.empty()); } - + } diff --git a/bundles/org.simantics.modeling/scl/Simantics/Typicals.scl b/bundles/org.simantics.modeling/scl/Simantics/Typicals.scl new file mode 100644 index 000000000..a16ea6c0a --- /dev/null +++ b/bundles/org.simantics.modeling/scl/Simantics/Typicals.scl @@ -0,0 +1,55 @@ +import "Simantics/Ontologies" +import "Simantics/Model" + +@private +toDiagrams composites = map (flip singleObject MOD.CompositeToDiagram) composites + +@private +importJava "org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances" where + syncTypicals :: Boolean -> [Resource] -> [Resource] -> () + +""" + syncAllTypicals False currentModel + +Synchronizes all typical master diagrams in the specified model with all +instances of the found typical master diagrams. + +The first argument controls whether a log of the synchronization will be +stored in the database, in the model's Documents folder. +""" +syncAllTypicals :: Boolean -> Resource -> () +syncAllTypicals log model = syncInstancesOfTypicalMasters log masterComposites + where + masterComposites = lift2Read searchByTypeShallow model MOD.MasterTypicalCompositeType + +""" + syncInstancesOfTypicalMasters False [aMasterTypicalComposite] + +Synchronizes all instances of the specified typical master diagram(s). + +The first argument controls whether a log of the synchronization will be +stored in the database, in the model's Documents folder. + +The second argument expects diagram configuration composite resources. +""" +syncInstancesOfTypicalMasters :: Boolean -> [Resource] -> () +syncInstancesOfTypicalMasters log typicalMasterComposites = syncWrite (\_ -> syncTypicals log masterDiagrams []) + where + masterDiagrams = lift1Read toDiagrams typicalMasterComposites + +""" + syncTypicalInstances False [aTypicalInstance] + +Synchronizes the specified typical instance diagram(s) with their master +diagrams. + +The first argument controls whether a log of the synchronization will be +stored in the database, in the model's Documents folder. + +The second argument expects diagram configuration composite resources. +""" +syncTypicalInstances :: Boolean -> [Resource] -> () +syncTypicalInstances log typicalInstanceComposites = let + instanceDiagrams = lift1Read toDiagrams typicalInstanceComposites + in + syncWrite (\_ -> syncTypicals log [] instanceDiagrams) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java index 55f5aef3d..cd3260513 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java @@ -11,9 +11,6 @@ *******************************************************************************/ package org.simantics.modeling.typicals; -import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; - import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collection; @@ -85,6 +82,9 @@ import org.simantics.utils.strings.AlphanumComparator; import org.simantics.utils.strings.EString; import org.simantics.utils.ui.ErrorLogger; +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; + /** * A write request that synchronizes typical master templates and their * instances as specified. @@ -210,6 +210,26 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { private boolean writeLog; + /** + * For SCL API. + * + * @param graph + * @param selectedRules + * @param templates + * @param instances + * @throws DatabaseException + */ + public static void syncTypicals(WriteGraph graph, boolean log, List templates, List instances) throws DatabaseException { + graph.syncRequest( + new SyncTypicalTemplatesToInstances( + null, + templates.toArray(Resource.NONE), + instances.toArray(Resource.NONE), + ALL, + null) + .logging(log)); + } + /** * @param templates typical diagram templates to completely synchronize with * their instances diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java index f99f679ef..9bce1aef1 100644 --- a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java @@ -28,7 +28,7 @@ public class VariablePropertyLabelRule implements LabelRule { for(Variable property : variable.getProperties(graph)) { String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN); if(column != null) { - String value = property.getValue(graph, Bindings.STRING); + String value = property.getPossibleValue(graph, Bindings.STRING); if (value != null) result.put(column, value); }