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
/**
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);
}
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,
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
--- /dev/null
+<?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
*/\r
public void start(BundleContext bundleContext) throws Exception {\r
Activator.context = bundleContext;\r
- FileImportDropins.watchDropinsFolder();\r
}\r
\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
--- /dev/null
+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
* 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
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.util.Iterator;\r
import java.util.Map;\r
import java.util.Optional;\r
\r
public static void watchDropinsFolder() {\r
FileImportDropins.watchDropinsFolder();\r
}\r
- \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
+ Path newFile = rootFolder.resolve(fileName);\r
+ if (Files.exists(newFile)) {\r
+ newFile = findFreshFileName(rootFolder, fileName);\r
+ }\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
- \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
});\r
return result;\r
}\r
- \r
+\r
public static void removeFileForId(long id) {\r
FileImportService.removeFileForResource(id, Optional.empty());\r
}\r
- \r
+\r
}\r
--- /dev/null
+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
*******************************************************************************/\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 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
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
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