]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Fixed record constructor resolving from namespaces"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 14 May 2018 10:06:03 +0000 (10:06 +0000)
committerGerrit Code Review <gerrit2@simantics>
Mon, 14 May 2018 10:06:03 +0000 (10:06 +0000)
bundles/org.simantics.event/scl/Simantics/Event.scl
bundles/org.simantics.event/src/org/simantics/event/util/EventExporter.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionProposal.java

index 01a520d52e71c2e8a57967db4aa69c0ad4c95fb5..6839c964c33d0a74c760ba3d675942e0d3c7727b 100644 (file)
@@ -20,4 +20,25 @@ findEventSlices log = do
 @private
 findEventsFromSlice :: Resource -> <ReadGraph, Proc> [Resource]
 findEventsFromSlice slice = do
-    collectionToList (objects_ slice L0.ConsistsOf)
\ No newline at end of file
+    collectionToList (objects_ slice L0.ConsistsOf)
+
+importJava "org.simantics.event.util.EventExporter" where
+    """
+        exportCurrentEvents "\t" "X:/events.txt"
+    
+    exports the currently visible events into the specified
+    text file using the specified column separator string.
+    This function should be used when invoking outside of
+    a database transaction.
+    """
+    exportCurrentEvents :: String -> String -> ()
+
+    """
+        exportCurrentEventsG "\t" "X:/events.txt"
+    
+    exports the currently visible events into the specified
+    text file using the specified column separator string.
+    This variant must be used when invoking the method with
+    DB transaction.
+    """
+    exportCurrentEventsG :: String -> String -> <ReadGraph> ()
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);
                }
        }
 
index 11749a4b2b24eef1c717eec74e9129731da58ce6..3734513cb6c3588b054e13a03b7cc15d9d4de1b6 100644 (file)
@@ -166,14 +166,15 @@ public class SCLCompletionProposal implements ICompletionProposal, ICompletionPr
     @Override
     public boolean validate(IDocument document, int offset, DocumentEvent event) {
         try {
-//            System.out.println("replacementOffset : " + replacementOffset);
-//            System.out.println("offset : " + offset);
+            String n = getName();
+            //System.out.println(n + " (" + n.length() + ") " + replacementOffset + " " + offset);
             boolean a = offset >= replacementOffset;
-            boolean b = offset < replacementOffset + getName().length();
+            boolean b = offset <= replacementOffset + n.length();
             String s = document.get(replacementOffset, offset - replacementOffset);
             prefix = s;
-            String d = getName();//.substring(0, offset - prefixStart);
-            boolean c = d.toLowerCase().startsWith(s.toLowerCase());
+            //System.out.println("prefix: " + s + " - " + prefix);
+            boolean c = n.toLowerCase().startsWith(s.toLowerCase());
+            //System.out.println("matches: " + a + " " + b + " " + c);
             return a && b && c;
         } catch (BadLocationException x) {
             //x.printStackTrace();