From: Marko Luukkainen Date: Thu, 23 May 2019 10:56:15 +0000 (+0000) Subject: Merge "Allow overriding Open With menu's name" X-Git-Tag: v1.43.0~136^2~152 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=1ca7c5aad9e845ca9969ea37c7d4bef54e94b9e2;hp=84bb0ec99d477592b7175a9ab995231abac82eae Merge "Allow overriding Open With menu's name" --- diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java index 8b1a928b3..26a6e68ae 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java @@ -1,6 +1,5 @@ package org.simantics.db.indexing; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -21,6 +20,7 @@ import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.exception.DatabaseException; import org.simantics.db.indexing.exception.IndexCorruptedException; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.genericrelation.IndexedRelations; import org.simantics.db.layer0.util.Layer0Utils; @@ -92,10 +92,9 @@ public class IndexUtils { Layer0 L0 = Layer0.getInstance(graph); HashSet results = new HashSet(); - String search = "Name:" + name; + String search = IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); + for(Resource resource : findResources(graph, model, search)) { if(name.equals(graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING))) results.add(resource); } return results; @@ -106,10 +105,9 @@ public class IndexUtils { HashSet results = new HashSet(); Layer0 L0 = Layer0.getInstance(graph); String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); - String search = "Types:" + IndexQueries.quoteTerm(typeName); + String search = IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); + for(Resource resource : findResources(graph, model, search)) { if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; @@ -121,10 +119,10 @@ public class IndexUtils { HashSet results = new HashSet(); String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); - String search = "Types:" + IndexQueries.quoteTerm(typeName) + " AND Name:" + IndexQueries.quoteTerm(name); + + String search = IndexQueries.and(IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName), IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name)); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); + for(Resource resource : findResources(graph, model, search)) { if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/Queries.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/Queries.java index 21a25d7d6..21b32fa1e 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/Queries.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/Queries.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.simantics.db.indexing; +import java.io.IOException; import java.io.Reader; import java.util.HashMap; import java.util.Map; @@ -20,12 +21,14 @@ import java.util.regex.Pattern; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenFilter; +import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; import org.apache.lucene.analysis.pattern.PatternReplaceFilter; import org.apache.lucene.analysis.pattern.PatternTokenizer; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.util.CharTokenizer; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; @@ -34,6 +37,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.AttributeFactory; import org.apache.lucene.util.Version; import org.simantics.databoard.util.ObjectUtils; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.utils.datastructures.Pair; public class Queries { @@ -94,14 +98,35 @@ public class Queries { } } + final static class LowercaseFilter extends TokenFilter { + private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); + + public LowercaseFilter(TokenStream in) { + super(in); + } + + @Override + public boolean incrementToken() throws IOException { + if (!input.incrementToken()) return false; + String lowercase = termAtt.toString().toLowerCase(); + termAtt.setEmpty().append(lowercase); + return true; + } + } + static final class TypeStringAnalyzer extends Analyzer { + private boolean lowercase; - @Override - protected TokenStreamComponents createComponents(String fieldName, Reader reader) { + public TypeStringAnalyzer(Boolean lowercase) { + this.lowercase = lowercase; + } + + @Override + protected TokenStreamComponents createComponents(String fieldName, Reader reader) { Tokenizer tokenizer = new PatternTokenizer(reader, Pattern.compile("(([^\\\\ ]|\\\\\\\\|\\\\ )+)( *)"), 1); TokenFilter filter = new PatternReplaceFilter(tokenizer, Pattern.compile("(\\\\(\\\\| ))"), "$2", true); - return new TokenStreamComponents(tokenizer, filter); + return new TokenStreamComponents(tokenizer, lowercase ? new LowercaseFilter(filter) : filter); } } @@ -118,7 +143,9 @@ public class Queries { analyzerPerField.put("Resource", new KeywordAnalyzer()); analyzerPerField.put("GUID", new KeywordAnalyzer()); analyzerPerField.put("Name", new KeywordAnalyzer()); - analyzerPerField.put("Types", new TypeStringAnalyzer()); + analyzerPerField.put("Types", new TypeStringAnalyzer(false)); + analyzerPerField.put(Dependencies.FIELD_NAME_SEARCH, new LowerCaseWhitespaceAnalyzer(Version.LUCENE_4_9)); + analyzerPerField.put(Dependencies.FIELD_TYPES_SEARCH, new TypeStringAnalyzer(true)); PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new LowerCaseWhitespaceAnalyzer(Version.LUCENE_4_9), analyzerPerField); return analyzer; diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java index 60ccf99cb..3ca66ce77 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Dependencies.java @@ -36,13 +36,15 @@ public class Dependencies extends FunctionImpl4 result = new ArrayList(); for (Entry entry : entries) { if(entry.name == null) continue; - result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id }); + result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id, entry.name, entry.types }); } return result; @@ -249,21 +251,21 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic @Override public List> query(RequestProcessor session, String search, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.query(null, search, session, resource, (Resource)constants[0], maxResultCount); } @Override public List queryResources(RequestProcessor session, String search, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.queryResources(null, search, session, resource, (Resource)constants[0], maxResultCount); } @Override public List> list(RequestProcessor session, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.query(null, null, session, resource, (Resource)constants[0], maxResultCount); } @@ -417,7 +419,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if(!entry.isValid(graph)) continue; Resource parent = graph.getPossibleObject(entry.component, L0.PartOf); if (parent != null) { - _additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" }); + _additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "", name, types}); } else { //LOGGER.info("resource " + entry.component + ": no parent for entry " + name + " " + types); } @@ -438,7 +440,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if(part != null) { _replacementKeys.add(ss.getRandomAccessId(entry.component)); _replacementObjects.add(new Object[] { ss.getRandomAccessId(part), - ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" }); + ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "", name, types}); } } } @@ -622,7 +624,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic ArrayList result = new ArrayList(entries.size()); for (Entry entry : entries) { - result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id }); + result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id, entry.name, entry.types }); } Layer0X L0X = Layer0X.getInstance(graph); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependencyResources.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependencyResources.java index 44175b820..1702af0f3 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependencyResources.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependencyResources.java @@ -22,20 +22,14 @@ import org.simantics.scl.runtime.function.FunctionImpl4; import org.simantics.scl.runtime.function.UnsaturatedFunction2; /** - * dependencies: - * (ReadGraph, Resource model, String query) -> List> - * (ReadGraph, Resource model, String query, Integer maxResults) -> List> + * dependencyResources: + * (ReadGraph, Resource model, String query) -> List + * (ReadGraph, Resource model, String query, Integer maxResults) -> List * * @author Antti Villberg */ public class DependencyResources extends FunctionImpl4 { - public static final String FIELD_MODEL = "Model"; - public static final String FIELD_PARENT = "Parent"; - public static final String FIELD_RESOURCE = "Resource"; - public static final String FIELD_NAME = "Name"; - public static final String FIELD_TYPES = "Types"; - protected Resource getIndexRelation(ReadGraph graph) { return Layer0X.getInstance(graph).DependenciesRelation; } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java index 212da3830..2be6bf5d0 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java @@ -159,18 +159,57 @@ public class IndexQueries { } public static String escapeTerm(String field, String term, boolean escapeWildcards) { - StringBuilder sb = new StringBuilder(); - return escapeTerm(field, term, escapeWildcards, sb).toString(); + return escapeTerm(field, term, escapeWildcards, new StringBuilder()).toString(); } - + + public static StringBuilder quoteTerm(String field, String term, StringBuilder result) { + if (field != null) + result.append(field).append(':'); + result.append("\""); + result.append(term.replaceAll("(\"|\\\\)", "\\\\$0")); + result.append("\""); + return result; + } + public static String quoteTerm(String term) { - StringBuilder sb = new StringBuilder(); - sb.append("\""); - sb.append(term.replaceAll("(\"|\\\\)", "\\\\$0")); - sb.append("\""); + return quoteTerm(null, term, new StringBuilder(term.length()*2)).toString(); + } + + public static String quoteTerm(String field, String term) { + return quoteTerm(field, term, + new StringBuilder( + term.length()*2 + + (field != null ? field.length() + 1 : 0)) + ).toString(); + } + + private static String join(String withString, String... exps) { + if (exps.length == 0) + return ""; + StringBuilder sb = new StringBuilder(128); + for (int i = 0; i < exps.length - 1; ++i) { + sb.append(exps[i]).append(withString); + } + sb.append(exps[exps.length - 1]); return sb.toString(); } + public static String and(String exp1, String exp2) { + return exp1 + " AND " + exp2; + } + + public static String and(String... exps) { + return join(" AND ", exps); + } + + public static String or(String exp1, String exp2) { + return exp1 + " OR " + exp2; + } + + public static String or(String... exps) { + return join(" OR ", exps); + } + // public static void main(String[] args) { // System.out.println("esc: " + escape("AND01", true, true)); // System.out.println("esc: " + escape("AND 01", true, true)); diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java index 8532be1ae..06710f6e2 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java @@ -13,6 +13,7 @@ package org.simantics.debug.ui; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -23,6 +24,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -56,6 +58,8 @@ import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; +import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.migration.OntologiesFromLibrary; import org.simantics.db.layer0.variable.Variables.Role; import org.simantics.db.request.Read; @@ -302,13 +306,19 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { } } } else { + String[] terms = pattern.trim().split("\\s+"); //$NON-NLS-1$ + if (terms.length == 0) return; + Resource project = Simantics.peekProjectResource(); if (project != null) { IResourceFilter rf = resourceFilter; String filter = getFilterForResourceFilter(rf); if (!filter.isEmpty()) filter += " AND "; //$NON-NLS-1$ - filter += "Name:" + pattern + "*"; //$NON-NLS-1$ //$NON-NLS-2$ + + filter += Dependencies.FIELD_NAME_SEARCH + ":("; //$NON-NLS-1$ + filter += Arrays.stream(terms).map(term -> "+" + IndexQueries.escape(term.toLowerCase(), false) + "*").collect(Collectors.joining(" ")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + filter +=")"; //$NON-NLS-1$ Layer0 L0 = Layer0.getInstance(graph); diff --git a/bundles/org.simantics.desktop.product/splash.svg b/bundles/org.simantics.desktop.product/splash.svg index ce8f4ab51..ff75c9a67 100644 --- a/bundles/org.simantics.desktop.product/splash.svg +++ b/bundles/org.simantics.desktop.product/splash.svg @@ -401,7 +401,7 @@ id="tspan6235" x="4.0821486" y="291.79337" - style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.64444447px;font-family:'The Real Font';-inkscape-font-specification:'The Real Font';fill:#ffffff;fill-opacity:1;stroke-width:0.26458335px">1.39.0 + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.64444447px;font-family:'The Real Font';-inkscape-font-specification:'The Real Font';fill:#ffffff;fill-opacity:1;stroke-width:0.26458335px">1.40.0 processed = new HashSet(); - NameComparator c = new NameComparator(query.getQuery("Name")); //$NON-NLS-1$ - + NameComparator c = new NameComparator(query.getQuery(Dependencies.FIELD_NAME_SEARCH)); + for (Resource source : results) { // Prevent index corruption from producing duplicate results. if (!processed.add(source)) diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/SearchFunction.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/SearchFunction.java index 39ae0731b..32d84eb9a 100644 --- a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/SearchFunction.java +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/SearchFunction.java @@ -27,7 +27,7 @@ public class SearchFunction extends FunctionImpl5> results = Searching.performSearch(graph, Layer0X.getInstance(graph).Dependencies, model, - query.escaped(false).getQuery("Name","Types"), maxResults); //$NON-NLS-1$ //$NON-NLS-2$ + query.escapedWithForcedCase(false, false).getQuery(Dependencies.FIELD_NAME_SEARCH, Dependencies.FIELD_TYPES_SEARCH), maxResults); return generateSearchResults(graph, results); } catch (DatabaseException e) { Logger.defaultLogError(e); diff --git a/bundles/org.simantics.event/src/org/simantics/event/writer/EventSourceResolver.java b/bundles/org.simantics.event/src/org/simantics/event/writer/EventSourceResolver.java index a382660ad..9e2b66677 100644 --- a/bundles/org.simantics.event/src/org/simantics/event/writer/EventSourceResolver.java +++ b/bundles/org.simantics.event/src/org/simantics/event/writer/EventSourceResolver.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.runtime.IProgressMonitor; @@ -35,6 +34,7 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.genericrelation.Dependencies; +import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.request.PossibleModel; import org.simantics.event.Activator; import org.simantics.event.ontology.EventResource; @@ -152,7 +152,7 @@ public class EventSourceResolver extends DatabaseJob { if (model == null) throw new CancelTransactionException(); - indexFunction = graph.adapt(L0X.Dependencies, Function.class); + indexFunction = graph.adapt(L0X.DependencyResources, Function.class); if (!initialEventsResolved) { MapList initialEventsBySource = new MapList(); @@ -201,9 +201,9 @@ public class EventSourceResolver extends DatabaseJob { monitor.subTask("Resolve events with source " + sourceName); if (DEBUG) System.out.println(EventSourceResolver.this + ": resolving source name " + sourceName); - List> results = (List>) indexFunction.apply(graph, model, "Name:" + sourceName); - for (Map result : results) { - Resource r = (Resource) result.get(Dependencies.FIELD_RESOURCE); + List results = (List) indexFunction.apply(graph, model, + IndexQueries.quoteTerm(Dependencies.FIELD_NAME, sourceName)); + for (Resource r : results) { if (eventSourceFilter != null && !eventSourceFilter.accept(graph, r)) continue; Resource rModel = graph.sync(new PossibleModel(r)); diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java index e46be60d4..0ab0ef98c 100644 --- a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java @@ -152,7 +152,7 @@ public class RunActiveValidations extends AbstractHandler { List l = ListUtils.toList(graph, list); if (l.size() > 0) { Resource mainContext = l.get(0); - if (!graph.hasStatement(mainContext)) + if (!BatchValidations.isLinkedToOtherThan(graph, mainContext, issue)) result.add(mainContext); } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java index ad48d1f2f..d5a2b92a4 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java @@ -27,6 +27,7 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.service.GraphChangeListenerSupport; import org.simantics.layer0.Layer0; @@ -45,7 +46,7 @@ import gnu.trove.set.hash.THashSet; * *

* The type of the function is expected to be: - * ReadGraph => Resource -> String -> Integer -> List<Map<String,Object>> + * ReadGraph => Resource -> String -> Integer -> List<Resource> * * @author Tuukka Lehtonen * @@ -135,7 +136,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam synchronized (this) { - String search = "Name:" + lowercaseName + "*"; + String search = IndexQueries.escapeTerm(Dependencies.FIELD_NAME_SEARCH, lowercaseName, true) + "*"; //$NON-NLS-1$ @SuppressWarnings("unchecked") List components = (List) index.apply(graph, indexRoot, search, Integer.MAX_VALUE); @@ -227,7 +228,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam synchronized (this) { - String search = "Name:" + proposition + "*"; + String search = Dependencies.FIELD_NAME_SEARCH + ":" + IndexQueries.escape(proposition.toLowerCase(), true) + "*"; //$NON-NLS-1$ //$NON-NLS-2$ Set reserved = graph.syncRequest(new ComponentsRequest(new Tuple4(indexRoot, index, search, getComparator())), TransientCacheAsyncListener.instance()); @@ -267,7 +268,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam if (propositionPreFilter != null) proposition = propositionPreFilter.apply(proposition); - String search = "Name:" + IndexQueries.quoteTerm( proposition ); + String search = IndexQueries.quoteTerm(Dependencies.FIELD_NAME_SEARCH, proposition.toLowerCase()); @SuppressWarnings("unchecked") List components = (List) index.apply(graph, indexRoot, search, Integer.MAX_VALUE); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java index 91d85aed2..0ce852403 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java @@ -14,8 +14,10 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.simantics.Simantics; import org.simantics.db.Issue; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.Statement; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; @@ -213,4 +215,39 @@ public class BatchValidations { return result; } + /** + * Checks if the specified resourceToCheckForLinks is linked to + * anything else besides itself and excludeLinksTo. + * + *

+ * This is used to if an issue context is still valid. We consider any issue + * context that is not attached to something else besides its issue context to + * be an invalid issue. Assertions and L0.InstanceOf do not count as external + * links. + * + * @param graph database access handle + * @param resourceToCheckForLinks the resource to check for "external" links + * @param excludeLinksTo exclude links to this resource from evaluation + * @return true if there are links, false otherwise + * @throws DatabaseException + */ + public static boolean isLinkedToOtherThan(ReadGraph graph, Resource resourceToCheckForLinks, + Resource excludeLinksTo) + throws DatabaseException + { + Layer0 L0 = Layer0.getInstance(graph); + for (Statement stm : graph.getStatements(resourceToCheckForLinks, L0.IsWeaklyRelatedTo)) { + if (stm.isAsserted(resourceToCheckForLinks)) + continue; + if (stm.getPredicate().equals(L0.InstanceOf)) + continue; + Resource o = stm.getObject(); + if (o.equals(excludeLinksTo) || o.equals(resourceToCheckForLinks)) + continue; + + return true; + } + return false; + } + } diff --git a/bundles/org.simantics.simulation.ui/fragment.e4xmi b/bundles/org.simantics.simulation.ui/fragment.e4xmi index 99834be78..4ca765a66 100644 --- a/bundles/org.simantics.simulation.ui/fragment.e4xmi +++ b/bundles/org.simantics.simulation.ui/fragment.e4xmi @@ -4,6 +4,7 @@ + @@ -11,6 +12,7 @@ + diff --git a/bundles/org.simantics.simulation.ui/plugin.xml b/bundles/org.simantics.simulation.ui/plugin.xml index 2bf32f153..004f7d4a7 100644 --- a/bundles/org.simantics.simulation.ui/plugin.xml +++ b/bundles/org.simantics.simulation.ui/plugin.xml @@ -74,12 +74,6 @@ categoryId="org.simantics.simulation.ui.category" id="org.simantics.simulation.ui.dispose"> - -

<#list getAllSearchParams() as param> - checked > ${param} + checked > ${param.getLabel()}
diff --git a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/DependenciesSearchFunction.java b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/DependenciesSearchFunction.java index 8a040223b..ffbfc5f62 100644 --- a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/DependenciesSearchFunction.java +++ b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/DependenciesSearchFunction.java @@ -19,6 +19,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.operation.Layer0X; import org.simantics.scl.runtime.function.FunctionImpl5; @@ -34,7 +35,9 @@ public class DependenciesSearchFunction extends FunctionImpl5> results = Searching.performSearch(graph, - Layer0X.getInstance(graph).Dependencies, model, query.getQuery("Name","Types"), maxResults); + Layer0X.getInstance(graph).Dependencies, model, + query.escapedWithForcedCase(false, false).getQuery(Dependencies.FIELD_NAME_SEARCH, Dependencies.FIELD_TYPES_SEARCH), + maxResults); return Searching.generateDependenciesSearchResult(graph, results); } catch (DatabaseException e) { diff --git a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchData.java b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchData.java index 37f7d63a7..f3783f0a0 100644 --- a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchData.java +++ b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchData.java @@ -2,8 +2,8 @@ package org.simantics.workbench.search; import java.io.File; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; +import java.util.Map; +import java.util.TreeMap; /** @@ -44,11 +44,14 @@ public class SearchData { return searchEngines; } - public Set getAllSearchParams() { - Set params = new HashSet(); - for (SearchEngine engine : searchEngines) - params.addAll(engine.getSupportedParams()); - return params; + public Collection getAllSearchParams() { + Map params = new TreeMap<>(); + for (SearchEngine engine : searchEngines) { + for (SearchParam param : engine.getSupportedParams()) { + params.put(param.getName(), param); + } + } + return params.values(); } public NamedResource getModel() { diff --git a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchEngine.java b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchEngine.java index 0c0c92c22..93fdf105c 100644 --- a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchEngine.java +++ b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchEngine.java @@ -13,7 +13,7 @@ public class SearchEngine { private String id; private String name; private Function5 searchFunction; - private Set supportedParams = new HashSet(); + private Set supportedParams = new HashSet<>(); private boolean enabledByDefault; public SearchEngine(String id, Function5 searchFunction, boolean enabledByDefault) { @@ -48,11 +48,15 @@ public class SearchEngine { return id.hashCode(); } - public void addSupportedParam(String param) { - this.supportedParams.add(param); + public void addSupportedParam(String name) { + addSupportedParam(name, name); } - public Set getSupportedParams() { + public void addSupportedParam(String name, String label) { + this.supportedParams.add(new SearchParam(name, label)); + } + + public Set getSupportedParams() { return supportedParams; } diff --git a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchParam.java b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchParam.java new file mode 100644 index 000000000..b47c1ef8d --- /dev/null +++ b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchParam.java @@ -0,0 +1,19 @@ +package org.simantics.workbench.search; + +public class SearchParam { + private String name; + private String label; + + public SearchParam(String name, String label) { + this.name = name; + this.label = label; + } + + public String getName() { + return name; + } + + public String getLabel() { + return label; + } +} \ No newline at end of file diff --git a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchQuery.java b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchQuery.java index d90a90ee9..1852316b9 100644 --- a/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchQuery.java +++ b/bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/SearchQuery.java @@ -108,6 +108,26 @@ public class SearchQuery { return withOriginalQuery( IndexQueries.escape( originalQuery, escapeWildcards ) ); } + /** + * @param uppercase true for uppercased query, false + * for lowercased query + * @return a clone of this query with the query string in lower or uppercase + */ + public SearchQuery withForcedCase(boolean uppercase) { + return withOriginalQuery(uppercase ? originalQuery.toUpperCase() : originalQuery.toLowerCase()); + } + + /** + * @param uppercase true for uppercased query, + * false for lowercased query + * @param escapeWildcards passed to {@link #escaped(boolean)} + * @return a clone of this query with the query string escaped and in lower or + * uppercase + */ + public SearchQuery escapedWithForcedCase(boolean uppercase, boolean escapeWildcards) { + return withForcedCase(uppercase).escaped(escapeWildcards); + } + public static URL encode(File file, SearchQuery query) throws IOException { URL url = file.toURI().toURL(); String s = url.toString() + "?search=" + URLEncoder.encode(query.getOriginalQuery(), "UTF-8"); diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/BrowserView.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/BrowserView.java index aa96ed13b..01d015de5 100644 --- a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/BrowserView.java +++ b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/BrowserView.java @@ -21,6 +21,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.simantics.Simantics; import org.simantics.db.Session; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.db.layer0.request.ActiveModels; import org.simantics.db.management.ISessionContext; import org.simantics.db.management.ISessionContextChangedListener; @@ -132,8 +133,8 @@ public class BrowserView extends ViewPart { protected void initializeViewContent() { SearchQuery query = new SearchQuery(""); - query.setSearchFlag("Name", "on"); - query.setSearchFlag("Types", "on"); + query.setSearchFlag(Dependencies.FIELD_NAME_SEARCH, "on"); + query.setSearchFlag(Dependencies.FIELD_TYPES_SEARCH, "on"); ISearchService searchService = (ISearchService) PlatformUI.getWorkbench().getService(ISearchService.class); if (searchService != null) searchService.performQuery(query, ResultBrowser.VIEW, false); diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchServiceImpl.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchServiceImpl.java index e0a96ed12..733bebddf 100644 --- a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchServiceImpl.java +++ b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchServiceImpl.java @@ -45,6 +45,7 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Instances; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.db.layer0.request.ActiveModels; import org.simantics.db.request.Read; import org.simantics.db.service.SerialisationSupport; @@ -567,8 +568,8 @@ public class SearchServiceImpl implements ISearchService{ @SuppressWarnings("unchecked") SearchEngine engine = new SearchEngine(id,name,(Function5)f, true); { - engine.addSupportedParam("Name"); - engine.addSupportedParam("Types"); + engine.addSupportedParam(Dependencies.FIELD_NAME_SEARCH, "Name"); + engine.addSupportedParam(Dependencies.FIELD_TYPES_SEARCH, "Types"); } searchEngines.add(engine); } @@ -661,8 +662,8 @@ public class SearchServiceImpl implements ISearchService{ @SuppressWarnings("unchecked") SearchEngine engine = new SearchEngine(id,name,(Function5)f, enabled); { - engine.addSupportedParam("Name"); - engine.addSupportedParam("Types"); + engine.addSupportedParam(Dependencies.FIELD_NAME_SEARCH, "Name"); + engine.addSupportedParam(Dependencies.FIELD_TYPES_SEARCH, "Types"); } return engine; } diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchTrim.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchTrim.java index 069e31a07..25aa1d292 100644 --- a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchTrim.java +++ b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchTrim.java @@ -28,6 +28,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.swt.IFocusService; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.utils.ui.BundleUtils; import org.simantics.workbench.search.ISearchService; import org.simantics.workbench.search.SearchQuery; @@ -151,7 +152,7 @@ public class SearchTrim extends Composite { query = filter(query); SearchQuery searchQuery = new SearchQuery(originalInput); - searchQuery.setSearchFlag("Name", "on"); + searchQuery.setSearchFlag(Dependencies.FIELD_NAME_SEARCH, "on"); performQuery(searchQuery, browserType); } @@ -166,7 +167,7 @@ public class SearchTrim extends Composite { return; SearchQuery searchQuery = new SearchQuery(originalInput); - searchQuery.setSearchFlag("Types", "on"); + searchQuery.setSearchFlag(Dependencies.FIELD_TYPES_SEARCH, "on"); performQuery(searchQuery, browserType); } @@ -181,8 +182,8 @@ public class SearchTrim extends Composite { return; SearchQuery searchQuery = new SearchQuery(originalInput); - searchQuery.setSearchFlag("Name", "on"); - searchQuery.setSearchFlag("Types", "on"); + searchQuery.setSearchFlag(Dependencies.FIELD_NAME_SEARCH, "on"); + searchQuery.setSearchFlag(Dependencies.FIELD_TYPES_SEARCH, "on"); performQuery(searchQuery, browserType); } diff --git a/features/org.simantics.sdk.feature/feature.xml b/features/org.simantics.sdk.feature/feature.xml index ccb0d4c44..c0cedff2f 100644 --- a/features/org.simantics.sdk.feature/feature.xml +++ b/features/org.simantics.sdk.feature/feature.xml @@ -13,7 +13,7 @@ diff --git a/releng/org.simantics.sdk.build.targetdefinition/simantics.target b/releng/org.simantics.sdk.build.targetdefinition/simantics.target index e3a1de5a4..745cd8dcb 100644 --- a/releng/org.simantics.sdk.build.targetdefinition/simantics.target +++ b/releng/org.simantics.sdk.build.targetdefinition/simantics.target @@ -1,7 +1,7 @@ - + diff --git a/releng/org.simantics.sdk.build.targetdefinition/simantics.tpd b/releng/org.simantics.sdk.build.targetdefinition/simantics.tpd index dc4519bf7..eeb2e54b8 100644 --- a/releng/org.simantics.sdk.build.targetdefinition/simantics.tpd +++ b/releng/org.simantics.sdk.build.targetdefinition/simantics.tpd @@ -1,4 +1,4 @@ -target "Simantics 1.39.0" +target "Simantics 1.40.0" with source allEnvironments diff --git a/releng/org.simantics.sdk.repository/pom.xml b/releng/org.simantics.sdk.repository/pom.xml index 05cf4b554..4902ca06d 100644 --- a/releng/org.simantics.sdk.repository/pom.xml +++ b/releng/org.simantics.sdk.repository/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.simantics.sdk.repository - 1.39.0-SNAPSHOT + 1.40.0-SNAPSHOT eclipse-repository diff --git a/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java b/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java index 8daf95832..700c42b0e 100644 --- a/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java +++ b/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java @@ -1,5 +1,10 @@ package org.simantics.scl.osgi.tests; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.junit.AfterClass; @@ -12,6 +17,7 @@ import org.simantics.application.arguments.Arguments; import org.simantics.application.arguments.IArgumentFactory; import org.simantics.application.arguments.IArguments; import org.simantics.application.arguments.SimanticsArguments; +import org.simantics.scl.compiler.markdown.html.GenerateAllHtmlDocumentation; import org.simantics.scl.osgi.SCLOsgi; public class TestSCLOsgi { @@ -43,4 +49,12 @@ public class TestSCLOsgi { Assert.fail(possibleError); } } + + @Test + public void exportAllSCLDocumentation() throws IOException { + // "./scldoc" evaluates to "tests/org.simantics.scl.osgi.tests/scldoc" when these tests are ran with Tycho/Maven + Path dir = Paths.get("./target/scldoc"); + Files.createDirectories(dir); + GenerateAllHtmlDocumentation.generate(SCLOsgi.MODULE_REPOSITORY, dir); + } }