-package org.simantics.modeling;\r
-\r
-import java.io.File;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.core.runtime.jobs.IJobManager;\r
-import org.eclipse.core.runtime.jobs.Job;\r
-import org.simantics.DatabaseJob;\r
-import org.simantics.Simantics;\r
-import org.simantics.SimanticsPlatform;\r
-import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.external.EclipsePreferencePrimitiveRead;\r
-import org.simantics.db.layer0.util.RemoverUtil;\r
-import org.simantics.db.layer0.util.SimanticsClipboard;\r
-import org.simantics.db.service.DebugSupport;\r
-import org.simantics.db.service.ServiceActivityMonitor;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class SCL {\r
- private static final Logger LOGGER = LoggerFactory.getLogger(SCL.class);\r
-\r
- public static void killPlatformWrite(WriteGraph graph) throws DatabaseException {\r
- // Currently not supported.\r
- // Would be relatively easy to support the desired functionality.\r
- // To implement this I would recommend something like:\r
- // SimanticsPlatform.INSTANCE.breakWrite();\r
- // And it's implementation with db.management.breakWrite() method.\r
- // To be clear, at the moment this method (breakWrite) does not exist.\r
- }\r
- public static void killPlatformRead(ReadGraph graph) throws DatabaseException {\r
- // See above.\r
- }\r
- public static void killPlatform() throws Exception {\r
- SimanticsPlatform.INSTANCE.shutdown(null);\r
- }\r
- public static void shutdownPlatform() throws Exception {\r
- SimanticsPlatform.INSTANCE.shutdown(null);\r
- }\r
- public static void reconnectPlatform() throws Exception {\r
- SimanticsPlatform.INSTANCE.reconnect(Simantics.getDefaultDatabaseDriver());\r
- }\r
- public static void synchronizeOntologies() throws Exception {\r
- SimanticsPlatform.INSTANCE.synchronizeOntologies(new NullProgressMonitor(), OntologyRecoveryPolicy.Merge, true);\r
- Simantics.getSession().getService(DebugSupport.class).query(Simantics.getSession(), "exec QueryControl.flush");\r
- }\r
-\r
- public static void sync() throws DatabaseException {\r
- // Multiple bugs here:\r
- // -Model performs activation in separate write transactions because API does not support changing the virtual graph\r
- // => activation & activation listener is delayed beyond this point\r
- // -This should be fixed by the following code\r
- // TransactionSupport ts = session.getService(TransactionSupport.class);\r
- // ts.waitCompletion();\r
- // but unfortunately this does not work either...\r
- // so we synchronize by a familiar write transaction\r
- // And then wait still some more\r
-// for(int i=0;i<3;i++) {\r
- Simantics.getSession().syncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "Utils sync";\r
- }\r
- });\r
-//\r
-// // And then wait still some more\r
-// Simantics.getSession().syncRequest(new ReadRequest() {\r
-// @Override\r
-// public void run(ReadGraph graph) throws DatabaseException {\r
-// }\r
-// });\r
-// }\r
- }\r
-\r
- public static void syncGraph() throws Exception {\r
- try {\r
- Simantics.getSession().getService(ServiceActivityMonitor.class).waitForCompletion();\r
- } catch (InterruptedException e) {\r
- throw new DatabaseException(e);\r
- }\r
-\r
- // OK, now the experiment activate job should be scheduled\r
- // Wait for the job to finish\r
- IJobManager job = Job.getJobManager();\r
- Job[] jobs = job.find(null);\r
- for (Job j : jobs) {\r
- if(j instanceof DatabaseJob) j.join();\r
- }\r
- sync();\r
- }\r
-\r
- public static boolean deleteMBNode(List<Resource> resources) throws DatabaseException {\r
- boolean value = false;\r
- try {\r
- value = RemoverUtil.tryCollectionRemover(resources);\r
- } catch (DatabaseException e){\r
- return value;\r
- }\r
- return value;\r
- }\r
-\r
- public static void sleep(int ms) {\r
- try {\r
- Thread.sleep(ms);\r
- } catch (InterruptedException e) {\r
- LOGGER.warn("Sleep was interrupted.", e);\r
- }\r
- }\r
-\r
- public static boolean hasSomethingToPaste(ReadGraph graph, Resource resource) throws DatabaseException {\r
-\r
- SimanticsClipboard clipboard = Simantics.getClipboard();\r
- return !clipboard.getContents().isEmpty();\r
-\r
- }\r
- \r
- public static boolean canDelete(ReadGraph graph, Resource resource) throws DatabaseException {\r
-\r
- return RemoverUtil.canRemove(graph, resource);\r
-\r
- }\r
-\r
- public static boolean canRename(ReadGraph graph, Resource resource) throws DatabaseException {\r
- return true;\r
- }\r
-\r
- public static String currentDate(String format) {\r
-\r
- SimpleDateFormat sdf = new SimpleDateFormat(format);\r
- return sdf.format(new Date(System.currentTimeMillis()));\r
-\r
- }\r
-\r
- public static File workspaceDirectory() {\r
- return new File(Platform.getInstanceLocation().getURL().getFile());\r
- }\r
- \r
- public static String queryPreference(ReadGraph graph, String pluginId, String preferenceKey) throws DatabaseException {\r
- String result = graph.syncRequest(new EclipsePreferencePrimitiveRead(pluginId, preferenceKey));\r
- if(result == null) return "";\r
- return result;\r
- }\r
-\r
- \r
-}\r
+package org.simantics.modeling;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.IJobManager;
+import org.eclipse.core.runtime.jobs.Job;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.SimanticsPlatform;
+import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.external.EclipsePreferencePrimitiveRead;
+import org.simantics.db.layer0.util.RemoverUtil;
+import org.simantics.db.layer0.util.SimanticsClipboard;
+import org.simantics.db.service.DebugSupport;
+import org.simantics.db.service.ServiceActivityMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SCL {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SCL.class);
+
+ public static void killPlatformWrite(WriteGraph graph) throws DatabaseException {
+ // Currently not supported.
+ // Would be relatively easy to support the desired functionality.
+ // To implement this I would recommend something like:
+ // SimanticsPlatform.INSTANCE.breakWrite();
+ // And it's implementation with db.management.breakWrite() method.
+ // To be clear, at the moment this method (breakWrite) does not exist.
+ }
+ public static void killPlatformRead(ReadGraph graph) throws DatabaseException {
+ // See above.
+ }
+ public static void killPlatform() throws Exception {
+ SimanticsPlatform.INSTANCE.shutdown(null);
+ }
+ public static void shutdownPlatform() throws Exception {
+ SimanticsPlatform.INSTANCE.shutdown(null);
+ }
+ public static void reconnectPlatform() throws Exception {
+ SimanticsPlatform.INSTANCE.reconnect(Simantics.getDefaultDatabaseDriver());
+ }
+ public static void synchronizeOntologies() throws Exception {
+ SimanticsPlatform.INSTANCE.synchronizeOntologies(new NullProgressMonitor(), OntologyRecoveryPolicy.Merge, true);
+ Simantics.getSession().getService(DebugSupport.class).query(Simantics.getSession(), "exec QueryControl.flush");
+ }
+
+ public static void sync() throws DatabaseException {
+ // Multiple bugs here:
+ // -Model performs activation in separate write transactions because API does not support changing the virtual graph
+ // => activation & activation listener is delayed beyond this point
+ // -This should be fixed by the following code
+ // TransactionSupport ts = session.getService(TransactionSupport.class);
+ // ts.waitCompletion();
+ // but unfortunately this does not work either...
+ // so we synchronize by a familiar write transaction
+ // And then wait still some more
+// for(int i=0;i<3;i++) {
+ Simantics.getSession().syncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ }
+
+ @Override
+ public String toString() {
+ return "Utils sync";
+ }
+ });
+//
+// // And then wait still some more
+// Simantics.getSession().syncRequest(new ReadRequest() {
+// @Override
+// public void run(ReadGraph graph) throws DatabaseException {
+// }
+// });
+// }
+ }
+
+ public static void syncGraph() throws Exception {
+ try {
+ Simantics.getSession().getService(ServiceActivityMonitor.class).waitForCompletion();
+ } catch (InterruptedException e) {
+ throw new DatabaseException(e);
+ }
+
+ // OK, now the experiment activate job should be scheduled
+ // Wait for the job to finish
+ IJobManager job = Job.getJobManager();
+ Job[] jobs = job.find(null);
+ for (Job j : jobs) {
+ if(j instanceof DatabaseJob) j.join();
+ }
+ sync();
+ }
+
+ public static boolean deleteMBNode(List<Resource> resources) throws DatabaseException {
+ boolean value = false;
+ try {
+ value = RemoverUtil.tryCollectionRemover(resources);
+ } catch (DatabaseException e){
+ return value;
+ }
+ return value;
+ }
+
+ public static void sleep(int ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ LOGGER.warn("Sleep was interrupted.", e);
+ }
+ }
+
+ public static boolean hasSomethingToPaste(ReadGraph graph, Resource resource) throws DatabaseException {
+
+ SimanticsClipboard clipboard = Simantics.getClipboard();
+ return !clipboard.getContents().isEmpty();
+
+ }
+
+ public static boolean canDelete(ReadGraph graph, Resource resource) throws DatabaseException {
+
+ return RemoverUtil.canRemove(graph, resource);
+
+ }
+
+ public static boolean canRename(ReadGraph graph, Resource resource) throws DatabaseException {
+ return true;
+ }
+
+ public static String currentDate(String format) {
+
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
+ return sdf.format(new Date(System.currentTimeMillis()));
+
+ }
+
+ public static File workspaceDirectory() {
+ return new File(Platform.getInstanceLocation().getURL().getFile());
+ }
+
+ public static String queryPreference(ReadGraph graph, String pluginId, String preferenceKey) throws DatabaseException {
+ String result = graph.syncRequest(new EclipsePreferencePrimitiveRead(pluginId, preferenceKey));
+ if(result == null) return "";
+ return result;
+ }
+
+
+}