From 9a82bf569d4173d25bb958023b3c1cdb2347dea9 Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Mon, 4 Mar 2019 14:45:07 +0100 Subject: [PATCH] Further updates related to event handling #25 * Ignore events received when event firing is disabled * Explicitly mark feature names starting with '_' as unindexable --- .../internal/MagicDrawProjectEngineContext.java | 14 +++++++++++++- .../v4md/internal/MagicDrawProjectScope.java | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectEngineContext.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectEngineContext.java index 25a4637..f95c5fa 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectEngineContext.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectEngineContext.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import org.apache.log4j.Logger; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -18,6 +19,7 @@ import org.eclipse.viatra.query.runtime.base.api.NavigationHelper; import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexObjectFilter; import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexResourceFilter; +import org.eclipse.viatra.query.runtime.base.core.NavigationHelperContentAdapter; import org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl; import org.eclipse.viatra.query.runtime.base.exception.ViatraBaseException; import org.eclipse.viatra.query.runtime.emf.DynamicEMFQueryRuntimeContext; @@ -76,6 +78,16 @@ private class MagicDrawProjectNavigationHelper extends NavigationHelperImpl { public MagicDrawProjectNavigationHelper(Notifier emfRoot, BaseIndexOptions options, Logger logger) { super(emfRoot, options, logger); + this.contentAdapter = new NavigationHelperContentAdapter(this) { + + @Override + public void notifyChanged(Notification notification) { + if (scope.getProject().getRepository().getEventSupport().isEnableEventFiring()) { + super.notifyChanged(notification); + } + } + + }; } Set getModelRoots() { @@ -113,7 +125,7 @@ public void removeRoot(Notifier root) { notifyBaseIndexChangeListeners(); } } - + public MagicDrawProjectEngineContext(MagicDrawProjectScope scope, ViatraQueryEngine engine, IIndexingErrorListener taintListener, Logger logger) { this.scope = scope; this.engine = engine; diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectScope.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectScope.java index 8a72b5e..9af2fb4 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectScope.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/internal/MagicDrawProjectScope.java @@ -30,10 +30,16 @@ public class MagicDrawProjectScope extends EMFScope { // XXX Omitting references can cause semantic errors (so far we are in the clear though) // these references are only present in UML profiles, typically their contents are equal to the original references inherited from the UML type hierarchy, however there are some cases when this might not be the case. private static final BaseIndexOptions BASE_OPTIONS = new BaseIndexOptions() - .withFeatureFilterConfiguration(reference -> reference instanceof EReference - && ((EReference) reference).isContainment() && reference.getName().contains("_from_")) + .withFeatureFilterConfiguration(reference -> reference instanceof EReference && isReferenceToBeFiltered((EReference) reference)) .withStrictNotificationMode(false); + private static boolean isReferenceToBeFiltered(EReference reference) { + String name = reference.getName(); + return (reference.isContainment() && name.contains("_from_")) + || + name.startsWith("_"); + } + static Stream getProjectModels(Project projectModel) { Package primaryModel = projectModel.getPrimaryModel(); return projectModel.getModels().stream().filter(pkg -> pkg == primaryModel || !EcoreUtil.isAncestor(primaryModel, pkg));