From 8d15309b77e1c97bf6fa59f15ffe786553b33fb1 Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Sun, 10 Dec 2017 12:08:39 +0100 Subject: [PATCH] [528378] Updated query result view model with match counts The models of matchers could maintain the known match count on the model level, allowing to calculate labels and existence of children without directly accessing the underlying matcher. This seemingly fixes various concurrency issues noticed with the attached RCPTT test. Change-Id: Ia45215a8ec0b6705a18b7d19bbe87521689f599d Signed-off-by: Zoltan Ujhelyi (cherry picked from commit da1174d5abbcdee54542509d1816c66354b8bc0b) --- .../QueryResultTreeContentProvider.xtend | 11 ++++++-- .../ui/queryresult/QueryResultTreeInput.xtend | 26 +++++++++++++++---- .../QueryResultTreeLabelProvider.xtend | 2 +- .../ui/queryresult/QueryResultViewModel.java | 2 +- .../matcher/PatternMatcherContent.java | 16 ++++++++++++ .../ui/util/IFilteredMatcherContent.java | 24 +++++++++++++++-- 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeContentProvider.xtend b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeContentProvider.xtend index 6d0e743e83..b413c3506a 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeContentProvider.xtend +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeContentProvider.xtend @@ -68,7 +68,7 @@ package class QueryResultTreeContentProvider implements ITreeContentProvider, IQ if(inputElement.exception !== null) { return null } - return inputElement.matcher.getAllMatches(inputElement.filterMatch) + return inputElement.filteredMatches } def dispatch Object[] getChildrenInternal(IPatternMatch inputElement) { @@ -114,7 +114,7 @@ package class QueryResultTreeContentProvider implements ITreeContentProvider, IQ if(inputElement.exception !== null) { return false } - return inputElement.matcher.countMatches(inputElement.filterMatch) > 0 + return inputElement.matchCount > 0 } def dispatch boolean hasChildrenInternal(IPatternMatch inputElement) { @@ -138,6 +138,7 @@ package class QueryResultTreeContentProvider implements ITreeContentProvider, IQ } override matcherFilterUpdated(QueryResultTreeMatcher matcher) { + matcher.matchCount = matcher.countFilteredMatches viewer.tree.display.asyncExec[ if(!viewer.tree.isDisposed){ viewer.refresh(matcher) @@ -154,6 +155,9 @@ package class QueryResultTreeContentProvider implements ITreeContentProvider, IQ } override matchAdded(QueryResultTreeMatcher matcher, IPatternMatch match) { + if (matcher.filterMatch.isCompatibleWith(match)) { + matcher.matchCount = matcher.matchCount + 1 + } viewer.tree.display.asyncExec[ if(!viewer.tree.isDisposed){ viewer.add(matcher, match) @@ -172,6 +176,9 @@ package class QueryResultTreeContentProvider implements ITreeContentProvider, IQ } override matchRemoved(QueryResultTreeMatcher matcher, IPatternMatch match) { + if (matcher.filterMatch.isCompatibleWith(match)) { + matcher.matchCount = matcher.matchCount - 1 + } viewer.tree.display.asyncExec[ if(!viewer.tree.isDisposed){ viewer.remove(match) diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeInput.xtend b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeInput.xtend index 044fd18aec..e9a7342737 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeInput.xtend +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeInput.xtend @@ -391,16 +391,16 @@ class QueryResultTreeInput implements IFilteredMatcherCollection { * @author Abel Hegedus */ @FinalFieldsConstructor -class QueryResultTreeMatcher implements IFilteredMatcherContent { +class QueryResultTreeMatcher implements IFilteredMatcherContent { @Accessors(PUBLIC_GETTER) final QueryResultTreeInput parent @Accessors(PUBLIC_GETTER) - final ViatraQueryMatcher matcher + final ViatraQueryMatcher matcher @Accessors(PROTECTED_SETTER) - IPatternMatch filterMatch + MATCH filterMatch @Accessors(PUBLIC_GETTER, PROTECTED_SETTER) QueryEvaluationHint hint @@ -412,7 +412,10 @@ class QueryResultTreeMatcher implements IFilteredMatcherContent { RuleSpecification ruleSpec @Accessors(PUBLIC_GETTER, PROTECTED_SETTER) - Exception exception; + Exception exception + + @Accessors(PUBLIC_GETTER, PROTECTED_SETTER) + int matchCount override def getFilterMatch() { if(filterMatch === null) { @@ -426,7 +429,7 @@ class QueryResultTreeMatcher implements IFilteredMatcherContent { filterMatch.filterUpdated } - def filterUpdated(IPatternMatch filterMatch) { + def filterUpdated(MATCH filterMatch) { if(filterMatch !== this.filterMatch){ this.filterMatch = filterMatch } @@ -440,6 +443,19 @@ class QueryResultTreeMatcher implements IFilteredMatcherContent { def remove() { parent.removeMatcher(this) } + + override countFilteredMatches() { + matcher.countMatches(filterMatch) + } + + override getFilteredMatches() { + matcher.getAllMatches(filterMatch) + } + + override hasFilteredMatch() { + matcher.hasMatch(filterMatch) + } + } /** diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeLabelProvider.xtend b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeLabelProvider.xtend index 716a81e928..453d78f49c 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeLabelProvider.xtend +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultTreeLabelProvider.xtend @@ -68,7 +68,7 @@ package class QueryResultTreeLabelProvider extends ColumnLabelProvider { return '''«element.entry?.fullyQualifiedName» - «element.exception.message»''' } val matcher = element.matcher - val count = matcher.countMatches(element.filterMatch) + val count = element.matchCount val countMsg = switch count { case 0 : "No matches" case 1 : "1 match" diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultViewModel.java b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultViewModel.java index 2814334bd5..612de73f1d 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultViewModel.java +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui.browser/src/org/eclipse/viatra/query/tooling/ui/queryresult/QueryResultViewModel.java @@ -82,7 +82,7 @@ protected boolean removeInput(QueryResultTreeInput input) { if(removed) { AdvancedViatraQueryEngine engine = input.getEngine(); input.dispose(); - if(!input.isReadOnlyEngine()) { + if(engine != null && !input.isReadOnlyEngine()) { engine.dispose(); } } diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/queryexplorer/content/matcher/PatternMatcherContent.java b/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/queryexplorer/content/matcher/PatternMatcherContent.java index cf7feef5bd..d57372bb8a 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/queryexplorer/content/matcher/PatternMatcherContent.java +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/queryexplorer/content/matcher/PatternMatcherContent.java @@ -11,6 +11,7 @@ package org.eclipse.viatra.query.tooling.ui.queryexplorer.content.matcher; +import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; @@ -284,4 +285,19 @@ public Iterator getChildrenIterator() { */ return children.iterator(); } + + @Override + public Collection getFilteredMatches() { + return getMatcher().getAllMatches(getFilterMatch()); + } + + @Override + public int countFilteredMatches() { + return getMatcher().countMatches(getFilterMatch()); + } + + @Override + public boolean hasFilteredMatch() { + return getMatcher().hasMatch(getFilterMatch()); + } } diff --git a/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/util/IFilteredMatcherContent.java b/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/util/IFilteredMatcherContent.java index 4b85fa3512..e42e6f9791 100644 --- a/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/util/IFilteredMatcherContent.java +++ b/query/plugins/org.eclipse.viatra.query.tooling.ui/src/org/eclipse/viatra/query/tooling/ui/util/IFilteredMatcherContent.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.viatra.query.tooling.ui.util; +import java.util.Collection; + import org.eclipse.viatra.query.runtime.api.IPatternMatch; import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; @@ -21,11 +23,29 @@ * @since 1.4 * */ -public interface IFilteredMatcherContent { +public interface IFilteredMatcherContent { - ViatraQueryMatcher getMatcher(); + ViatraQueryMatcher getMatcher(); IPatternMatch getFilterMatch(); IFilteredMatcherCollection getParent(); + + /** + * Collects the filtered matches defined by the {@link #getFilterMatch()} + * @since 1.7.1 + */ + Collection getFilteredMatches(); + + /** + * Counts the number of filtered matches defined by {@link #getFilterMatch()} + * @since 1.7.1 + */ + int countFilteredMatches(); + + /** + * Returns whethere there is a filtered match defined by {@link #getFilterMatch()} + * @since 1.7.1 + */ + boolean hasFilteredMatch(); }