]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.event/src/org/simantics/event/util/EventExporter.java
Merge "Fix column width issues on HiDPI displays. KeyTiSelection fixes."
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / util / EventExporter.java
index 10d2dfe7f28c9505f519ea649fc777cae206f2d9..0e34770c5f988a68e8cc1d0deccfb1d2cc2a0f88 100644 (file)
@@ -26,7 +26,6 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.event.view.contribution.EventLabelRule;
 import org.simantics.event.view.contribution.ProjectEventsRule;
-import org.simantics.utils.FileUtils;
 import org.simantics.utils.strings.EString;
 
 /**
@@ -34,6 +33,28 @@ import org.simantics.utils.strings.EString;
  */
 public class EventExporter {
 
+       /**
+        * SCL API.
+        * 
+        * @param outputFile
+        * @throws DatabaseException
+        * @throws IOException
+        */
+       public static void exportCurrentEvents(String columnSeparator, String outputFile) throws DatabaseException, IOException {
+               new EventExporter().exportCsv(null, new File(outputFile), columnSeparator);
+       }
+
+       /**
+        * SCL API.
+        * 
+        * @param outputFile
+        * @throws DatabaseException
+        * @throws IOException
+        */
+       public static void exportCurrentEventsG(ReadGraph graph, String columnSeparator, String outputFile) throws DatabaseException, IOException {
+               new EventExporter().exportCsv(graph, null, new File(outputFile), columnSeparator);
+       }
+
        public EventExporter() {
        }
 
@@ -49,17 +70,33 @@ public class EventExporter {
         * @throws DatabaseException
         * @throws IOException
         */
-       public void exportCsv(final IProgressMonitor monitor, File file, final String columnSeparator) throws DatabaseException, IOException {
-               final PrintStream out = new PrintStream(file);
-               try {
+       public void exportCsv(IProgressMonitor monitor, File file, String columnSeparator) throws DatabaseException, IOException {
+               try (PrintStream out = new PrintStream(file)) {
                        Simantics.getSession().syncRequest(new ReadRequest() {
                                @Override
                                public void run(ReadGraph graph) throws DatabaseException {
                                        exportCsv(graph, monitor, out, columnSeparator);
                                }
                        });
-               } finally {
-                       FileUtils.uncheckedClose(out);
+               }
+       }
+
+       /**
+        * @param graph
+        * @param monitor
+        *            the progress monitor to use for reporting progress to the
+        *            user. It is the caller's responsibility to call done() on the
+        *            given monitor. Accepts <code>null</code>, indicating that no
+        *            progress should be reported and that the operation cannot be
+        *            cancelled.</pre>
+        * @param file
+        * @param columnSeparator
+        * @throws DatabaseException
+        * @throws IOException
+        */
+       public void exportCsv(ReadGraph graph, IProgressMonitor monitor, File file, String columnSeparator) throws DatabaseException, IOException {
+               try (PrintStream out = new PrintStream(file)) {
+                       exportCsv(graph, monitor, out, columnSeparator);
                }
        }