Skip to content

Commit

Permalink
Fixes MagicDraw project-based scope implementation #25
Browse files Browse the repository at this point in the history
 * Fixes copy-paste error in customized NavigationHelper implementation
 * Provides an explicit manager for IProjectChangedListener instances
  • Loading branch information
ujhelyiz committed Mar 1, 2019
1 parent ca2562d commit fc3fa24
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.incquerylabs.v4md;

import com.incquerylabs.v4md.expressions.BinaryVQLExpression;
import com.incquerylabs.v4md.internal.IProjectChangedListener;
import com.nomagic.ci.persistence.IProject;
import com.nomagic.magicdraw.core.Application;
import com.nomagic.magicdraw.core.Project;
Expand All @@ -11,8 +12,9 @@
import com.nomagic.magicdraw.expressions.evaluation.ExpressionEvaluationConfigurator;

public class V4MDPlugin extends com.nomagic.magicdraw.plugins.Plugin {

private final class V4MDProjectListener extends ProjectEventListenerAdapter implements ProjectPartListener {

@Override
public void projectOpened(Project project) {
ViatraQueryAdapter.getOrCreateAdapter(project);
Expand All @@ -22,29 +24,29 @@ public void projectOpened(Project project) {
public void projectPreClosed(Project project) {
ViatraQueryAdapter.disposeAdapter(project);
}

@Override
public void projectPartLoaded(Project project, IProject storage) {
ViatraQueryAdapter.getAdapter(project).ifPresent(ViatraQueryAdapter::projectStructureUpdated);
IProjectChangedListener.MANAGER.notifyProjectListeners(project);
}

@Override
public void projectPartAttached(ModuleUsage usage) {
Project project = ProjectUtilities.getProject(usage.getUsed());
ViatraQueryAdapter.getAdapter(project).ifPresent(ViatraQueryAdapter::projectStructureUpdated);
IProjectChangedListener.MANAGER.notifyProjectListeners(project);
}

@Override
public void projectPartDetached(ModuleUsage usage) {
Project project = ProjectUtilities.getProject(usage.getUsed());
ViatraQueryAdapter.getAdapter(project).ifPresent(ViatraQueryAdapter::projectStructureUpdated);
IProjectChangedListener.MANAGER.notifyProjectListeners(project);

}

@Override
public void projectPartRemoved(IProject project) {
Project modelProject = ProjectUtilities.getProject(project);
ViatraQueryAdapter.getAdapter(modelProject).ifPresent(ViatraQueryAdapter::projectStructureUpdated);
IProjectChangedListener.MANAGER.notifyProjectListeners(modelProject);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.incquerylabs.v4md.internal;

import com.google.common.collect.ArrayListMultimap;
import com.nomagic.magicdraw.core.Project;

public interface IProjectChangedListener {
void modelSetUpdated();

public static final Manager MANAGER = new Manager();

public class Manager {
ArrayListMultimap<Project, IProjectChangedListener> listenerMap = ArrayListMultimap.create();


private Manager() {
// Private constructor for singleton class
}

public void notifyProjectListeners(Project project) {
for (IProjectChangedListener listener : listenerMap.get(project)) {
listener.modelSetUpdated();
}
}

public boolean addProjectChangeListener(Project project, IProjectChangedListener listener) {
return listenerMap.put(project, listener);
}

public boolean removeProjectChangeListener(Project project, IProjectChangedListener listener) {
return listenerMap.remove(project, listener);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;

import com.google.common.collect.Sets;
import com.incquerylabs.v4md.internal.MagicDrawProjectScope.IProjectChangedListener;

/**
* Provides a specific engine context implementation for MagicDraw projects.
Expand Down Expand Up @@ -101,7 +100,7 @@ public void removeRoot(Notifier root) {
return;

// no veto by filters
modelRoots.add(root);
modelRoots.remove(root);
// TODO contentAdapter.removeAdapter(root); removeAdapter is not visible here
Method method;
try {
Expand All @@ -120,7 +119,7 @@ public MagicDrawProjectEngineContext(MagicDrawProjectScope scope, ViatraQueryEng
this.engine = engine;
this.logger = logger;
this.taintListener = taintListener;
scope.addProjectChangeListener(scopeListener);
IProjectChangedListener.MANAGER.addProjectChangeListener(scope.getProject(), scopeListener);
}

/**
Expand Down Expand Up @@ -169,7 +168,7 @@ public void dispose() {
if (runtimeContext != null) runtimeContext.dispose();
if (navHelper != null) navHelper.dispose();

scope.removeProjectChangeListener(scopeListener);
IProjectChangedListener.MANAGER.removeProjectChangeListener(scope.getProject(), scopeListener);

this.baseIndex = null;
this.engine = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public class MagicDrawProjectScope extends EMFScope {
&& ((EReference) reference).isContainment() && reference.getName().contains("_from_"))
.withStrictNotificationMode(false);

public interface IProjectChangedListener {
void modelSetUpdated();
}
static Stream<? extends Notifier> getProjectModels(Project projectModel) {
return projectModel.getModels().stream();
}
Expand All @@ -60,14 +57,6 @@ protected IEngineContext createEngineContext(ViatraQueryEngine engine, IIndexing
Logger logger) {
return new MagicDrawProjectEngineContext(this, engine, errorListener, logger);
}

boolean addProjectChangeListener(IProjectChangedListener listener) {
return listeners.add(listener);
}

boolean removeProjectChangeListener(IProjectChangedListener listener) {
return listeners.remove(listener);
}

public void projectStructureUpdated() {
for (IProjectChangedListener listener : listeners) {
Expand Down

0 comments on commit fc3fa24

Please sign in to comment.