@Override
protected ItemsFilter createFilter() {
// NOTE: filter must be created here.
- return new ItemsFilter() {
- @Override
- public boolean matchItem(Object item) {
- //return matches(item.toString());
- return true;
- }
+ return new ItemsFilterWithSearchResults();
+ }
- // If this method returns true, it means fillContentProvider will
- // not be called again, but the existing results are just re-filtered.
- @Override
- public boolean isSubFilter(ItemsFilter filter) {
- //System.out.println(getPattern() + " vs. " + filter.getPattern());
- return false;
- }
+ private class ItemsFilterWithSearchResults extends ItemsFilter {
+ private Set<Object> searchResults = new HashSet<Object>();
- @Override
- public boolean isConsistentItem(Object item) {
- return true;
- }
+ public ItemsFilterWithSearchResults() {
+
+ final String pattern = getPattern();
+ final boolean findUris = pattern.trim().startsWith("http:/");
+ final long referencedResourceId = referencedResourceId(pattern);
+ final boolean findIds = referencedResourceId != 0;
- @Override
- public boolean equalsFilter(ItemsFilter filter) {
- return false;
- }
- };
- }
+ searchResults.clear();
+ if (pattern.isEmpty()) return;
+ //progressMonitor.beginTask("Searching", IProgressMonitor.UNKNOWN);
- @Override
- protected void fillContentProvider(final AbstractContentProvider contentProvider,
- final ItemsFilter itemsFilter, final IProgressMonitor progressMonitor)
- throws CoreException {
- final String pattern = itemsFilter.getPattern();
- final boolean findUris = pattern.trim().startsWith("http:/");
- final long referencedResourceId = referencedResourceId(pattern);
- final boolean findIds = referencedResourceId != 0;
-
- //progressMonitor.beginTask("Searching", IProgressMonitor.UNKNOWN);
-
- try {
- session.syncRequest(new ReadRequest() {
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- // Find by ID first.
- if (findIds) {
- try {
- Resource r = graph.getService(SerialisationSupport.class).getResource(referencedResourceId);
- contentProvider.add(new LabeledResource(DebugUtils.getSafeLabel(graph, r), r), itemsFilter);
- //contentProvider.add(new LabeledResource(pattern, r), itemsFilter);
- } catch (DatabaseException e) {
- // No resource for specified id.
- }
- }
- if (findUris) {
- String uri = pattern;
- if (uri.endsWith(Role.CHILD.getIdentifier())) {
- uri = uri.substring(0, uri.length() - 1);
+ try {
+ session.syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ // Find by ID first.
+ if (findIds) {
+ try {
+ Resource r = graph.getService(SerialisationSupport.class).getResource(referencedResourceId);
+ searchResults.add(new LabeledResource(DebugUtils.getSafeLabel(graph, r), r));
+ } catch (DatabaseException e) {
+ // No resource for specified id.
+ }
}
- Resource r = graph.getPossibleResource(uri);
- if (r != null) {
- contentProvider.add(new LabeledResource(DebugUtils.getSafeURI(graph, r), r), itemsFilter );
+ if (findUris) {
+ String uri = pattern;
+ if (uri.endsWith(Role.CHILD.getIdentifier())) {
+ uri = uri.substring(0, uri.length() - 1);
+ }
+ Resource r = graph.getPossibleResource(uri);
+ if (r != null) {
+ searchResults.add(new LabeledResource(DebugUtils.getSafeURI(graph, r), r));
- Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(r));
- for (Resource child : children.values()) {
- contentProvider.add(new LabeledResource(DebugUtils.getSafeURI(graph, child), child), itemsFilter );
+ Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(r));
+ for (Resource child : children.values()) {
+ searchResults.add(new LabeledResource(DebugUtils.getSafeURI(graph, child), child));
+ }
}
- }
- } else {
- Resource project = Simantics.peekProjectResource();
- if (project != null) {
- IResourceFilter rf = resourceFilter;
- String filter = getFilterForResourceFilter(rf);
- if (!filter.isEmpty())
- filter += " AND ";
- filter += "Name:" + pattern + "*";
-
- Layer0 L0 = Layer0.getInstance(graph);
-
- Set<Resource> indexRoots = new HashSet<>();
- indexRoots.addAll(graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, L0.IndexRoot)));
- indexRoots.addAll(graph.syncRequest(new OntologiesFromLibrary(graph.getRootLibrary())));
- for (Resource indexRoot : indexRoots) {
- Collection<Resource> hits = find(graph, indexRoot, filter);
- for (Resource r : hits) {
- if (rf != null && !rf.acceptResource(graph, r))
- continue;
- contentProvider.add(new LabeledResource(DebugUtils.getSafeLabel(graph, r), r), itemsFilter);
+ } else {
+ Resource project = Simantics.peekProjectResource();
+ if (project != null) {
+ IResourceFilter rf = resourceFilter;
+ String filter = getFilterForResourceFilter(rf);
+ if (!filter.isEmpty())
+ filter += " AND ";
+ filter += "Name:" + pattern + "*";
+
+ Layer0 L0 = Layer0.getInstance(graph);
+
+ Set<Resource> indexRoots = new HashSet<>();
+ indexRoots.addAll(graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, L0.IndexRoot)));
+ indexRoots.addAll(graph.syncRequest(new OntologiesFromLibrary(graph.getRootLibrary())));
+ for (Resource indexRoot : indexRoots) {
+ Collection<Resource> hits = find(graph, indexRoot, filter);
+ for (Resource r : hits) {
+ if (rf != null && !rf.acceptResource(graph, r))
+ continue;
+ searchResults.add(new LabeledResource(DebugUtils.getSafeLabel(graph, r), r));
+ }
}
}
}
}
- }
- public Collection<Resource> find(ReadGraph graph, Resource index, String filter) throws DatabaseException {
- //TimeLogger.resetTimeAndLog("find(" + graph.getURI(index) + ", " + filter + ")");
- Collection<Resource> indexResult = graph.syncRequest(new QueryIndex(index, filter), TransientCacheListener.<Collection<Resource>>instance());
- //TimeLogger.log("found " + indexResult.size());
- return indexResult;
- }
+ public Collection<Resource> find(ReadGraph graph, Resource index, String filter) throws DatabaseException {
+ //TimeLogger.resetTimeAndLog("find(" + graph.getURI(index) + ", " + filter + ")");
+ Collection<Resource> indexResult = graph.syncRequest(new QueryIndex(index, filter), TransientCacheListener.<Collection<Resource>>instance());
+ //TimeLogger.log("found " + indexResult.size());
+ return indexResult;
+ }
+
+ });
+ } catch (DatabaseException ex) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex));
+ }
- });
- } catch (DatabaseException ex) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex));
}
+ @Override
+ public boolean matchItem(Object item) {
+ return searchResults.contains(item);
+ }
+
+ @Override
+ public boolean isSubFilter(ItemsFilter filter) {
+ return false;
+ }
+
+ @Override
+ public boolean isConsistentItem(Object item) {
+ return true;
+ }
+
+ @Override
+ public boolean equalsFilter(ItemsFilter filter) {
+ return false;
+ }
+
+ public void fillContentProvider(final AbstractContentProvider contentProvider) {
+ for (Object item : searchResults) {
+ contentProvider.add(item, this);
+ }
+ }
+ }
+
+ @Override
+ protected void fillContentProvider(final AbstractContentProvider contentProvider,
+ final ItemsFilter itemsFilter, final IProgressMonitor progressMonitor)
+ throws CoreException {
+ ((ItemsFilterWithSearchResults) itemsFilter).fillContentProvider(contentProvider);
progressMonitor.done();
}
@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> ()
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;
/**
*/
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() {
}
* @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);
}
}
g.setStroke(DASHED);
else if(styleName.equals("dotted"))
g.setStroke(DOTTED);
+ else if(styleName.startsWith("setlinewidth(")) {
+ double w = Double.parseDouble(styleName.substring(13, styleName.length()-1));
+ g.setStroke(new BasicStroke((float)w, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, ((BasicStroke)g.getStroke()).getDashArray(), 0.0f));
+ }
else
System.out.println("Unknown style: " + styleName);
}
return -1;
}
+ public SCLValue resolveSCLValue(long location, Namespace namespace, String name) throws AmbiguousNameException {
+ SCLValue value = namespace.getValue(name);
+ if(value == null)
+ return null;
+ String deprecatedDescription = value.isDeprecated();
+ if(deprecatedDescription != null)
+ errorLog.logWarning(location, "Deprecated value " + value.getName().name + "." + (deprecatedDescription.isEmpty() ? "" : " " + deprecatedDescription));
+ if(moduleDebugInfo != null)
+ moduleDebugInfo.symbolReferences.add(new SymbolReference(value.getName(), Name.create(compilationContext.module.getName(), definitionName), location));
+ return value;
+ }
+
public Expression resolveValue(long location, Namespace namespace, String name) {
try {
- SCLValue value = namespace.getValue(name);
+ SCLValue value = resolveSCLValue(location, namespace, name);
if(value == null)
return null;
- String deprecatedDescription = value.isDeprecated();
- if(deprecatedDescription != null)
- errorLog.logWarning(location, "Deprecated value " + value.getName().name + "." + (deprecatedDescription.isEmpty() ? "" : " " + deprecatedDescription));
- if(moduleDebugInfo != null)
- moduleDebugInfo.symbolReferences.add(new SymbolReference(value.getName(), Name.create(compilationContext.module.getName(), definitionName), location));
return new EConstant(location, value);
} catch (AmbiguousNameException e) {
if(SCLCompilerConfiguration.ALLOW_OVERLOADING)
return new EError(location);
}
+ public SCLValue resolveRecordConstructor(long location, String name) throws AmbiguousNameException {
+ return resolveRecordConstructor(location, getEnvironment().getLocalNamespace(), name, 0);
+ }
+
+ public SCLValue resolveRecordConstructor(long location, Namespace namespace, String name, int begin) throws AmbiguousNameException {
+ int end = findSeparator(name, begin);
+ String part = end == -1 ? (begin == 0 ? name : name.substring(begin)) : name.substring(begin, end);
+
+ if(end != -1 && name.charAt(end) == '.') {
+ Namespace childNamespace = namespace.getNamespace(part);
+ if(childNamespace == null)
+ return null;
+ else
+ return resolveRecordConstructor(location, childNamespace, name, end+1);
+ }
+ else
+ return resolveSCLValue(location, namespace, part);
+ }
+
private void reportResolveFailure(long location, Namespace namespace, String name) {
StringBuilder message = new StringBuilder();
message.append("Couldn't resolve ").append(name).append(".");
public Expression resolve(TranslationContext context, boolean asPattern) {
SCLValue constructorValue;
try {
- constructorValue = context.getEnvironment().getLocalNamespace().getValue(constructor.name);
+ constructorValue = context.resolveRecordConstructor(location, constructor.name);
} catch (AmbiguousNameException e) {
context.getErrorLog().log(constructor.location, e.getMessage());
return new EError(constructor.location);
@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();
/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2010, 2018 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.common.primitiverequest.Adapter;
*
* @return a valid ISessionContextProvider
*/
+ @Deprecated
public static ISessionContextProvider getSessionContextProvider() {
- return getProviderSource().getActive();
+ return Simantics.getSessionContextProvider();
}
/**
* workbench window or <code>null</code> if the active window has no
* session context
*/
+ @Deprecated
public static ISessionContext getSessionContext() {
- ISessionContextProvider provider = getSessionContextProvider();
- return provider != null ? provider.getSessionContext() : null;
+ return Simantics.getSessionContext();
}
/**
* @return the Session bound to the currently active workbench window
* @throws IllegalStateException if no Session was available
*/
+ @Deprecated
public static Session getSession() {
- ISessionContext ctx = getSessionContext();
- if (ctx == null)
- throw new IllegalStateException("Session unavailable, no database session open");
- return ctx.getSession();
+ return Simantics.getSession();
}
/**
* @return the Session bound to the currently active workbench window or
* <code>null</code>
*/
+ @Deprecated
public static Session peekSession() {
- ISessionContext ctx = getSessionContext();
- return ctx == null ? null : ctx.peekSession();
+ return Simantics.peekSession();
}
/**
* @return the currently open and active project as an IProject or
* <code>null</code> if there is no active session or project
*/
+ @Deprecated
public static IProject peekProject() {
- ISessionContext ctx = getSessionContext();
- return ctx == null ? null : (org.simantics.project.IProject) ctx.getHint(ProjectKeys.KEY_PROJECT);
+ return Simantics.peekProject();
}
/**
* @return the currently open and active project for the specified database
* session or <code>null</code> if there is no current project
*/
+ @Deprecated
public static IProject peekProject(ISessionContext ctx) {
if (ctx == null)
return null;
* session, which also means there is no active project at the
* moment
*/
+ @Deprecated
public static IProject getProject() {
- ISessionContext ctx = getSessionContext();
- if (ctx == null)
- throw new IllegalStateException("No current database session");
- return ctx.getHint(ProjectKeys.KEY_PROJECT);
+ return Simantics.getProject();
}
/**
@Test public void Record1() { test(); }
@Test public void Record2() { test(); }
@Test public void Record3() { test(); }
+ @Test public void Record4() { test(); }
@Test public void RecordShorthand() { test(); }
@Test public void RecordWildcards() { test(); }
@Test public void RecursionBug() { test(); }
--- /dev/null
+// module Module
+data Foo = Foo { x :: Integer }
+--
+import "Prelude"
+import "Module" as M
+
+f = M.Foo { x = 3 }
+main = match f with
+ M.Foo { x } -> x
+--
+3
\ No newline at end of file