Commit c27875b2 authored by Johannes Roith's avatar Johannes Roith

Cleanup notification calls in model.

parent 7d36e247
package de.tum.in.www2.cupplugin.model;
public interface ICupGraphModelObserver {
public void modelChanged(Model model);
public interface ICupGraphModelObserver extends ICupModelObserverBase {
}
package de.tum.in.www2.cupplugin.model;
public interface ICupModelObserverBase {
void modelChanged(Model model);
}
package de.tum.in.www2.cupplugin.model;
public interface ICupParserASTChangeObserver {
public void modelChanged(Model model);
public interface ICupParserASTChangeObserver extends ICupModelObserverBase {
}
package de.tum.in.www2.cupplugin.model;
public interface ICupParserLaLrChangeObserver {
public void modelChanged(Model model);
public interface ICupParserLaLrChangeObserver extends ICupModelObserverBase {
}
package de.tum.in.www2.cupplugin.model;
public interface ICupStatisticsChangeObserver {
public interface ICupStatisticsChangeObserver extends ICupModelObserverBase {
public void modelChanged(Model model);
}
......@@ -29,7 +29,7 @@ public class Model {
private ControllerStatistics controllerStats;
private final Object observerLock = new Object();
private List<Object> modelObservers;
private List<ICupModelObserverBase> modelObservers;
public static void deleteForDocument(IDocument document) {
if (document == null)
......@@ -65,10 +65,16 @@ public class Model {
}
private Model() {
this.modelObservers = new ArrayList<Object>();
this.modelObservers = new ArrayList<ICupModelObserverBase>();
}
public void registerModelObserver(Object modelObserver) {
private <T> void notifyObservers (Class<T> cls) {
for(ICupModelObserverBase observer : modelObservers)
if(cls.isAssignableFrom(observer.getClass()))
observer.modelChanged(this);
}
public void registerModelObserver(ICupModelObserverBase modelObserver) {
if (modelObserver == null)
return;
synchronized (observerLock) {
......@@ -78,7 +84,7 @@ public class Model {
}
}
public boolean unregisterModelObserver(Object modelObserver) {
public boolean unregisterModelObserver(ICupModelObserverBase modelObserver) {
if (modelObserver == null)
return false;
synchronized (observerLock) {
......@@ -108,9 +114,7 @@ public class Model {
public void setStatistics(Statistics statistics, long revisionNumber) {
ensureUIThread();
this.statistics = statistics;
for(Object observer : modelObservers)
if(observer instanceof ICupStatisticsChangeObserver)
((ICupStatisticsChangeObserver) observer).modelChanged(this);
notifyObservers(ICupStatisticsChangeObserver.class);
}
public void setControllerStatistics(ControllerStatistics stats) {
......@@ -128,9 +132,7 @@ public class Model {
this.astModel = result;
this.astContext = context;
this.astModelRevisionNumber = revisionNumber;
for(Object observer : modelObservers)
if(observer instanceof ICupParserASTChangeObserver)
((ICupParserASTChangeObserver) observer).modelChanged(this);
notifyObservers(ICupParserASTChangeObserver.class);
}
public void setAstModelRevisionNumber(long revisionNumber) {
......@@ -158,9 +160,7 @@ public class Model {
this.lalrModel = result;
this.lalrModelRevisionNumber = revisionNumber;
this.lalrContext = lalrContext;
for(Object observer : modelObservers)
if (observer instanceof ICupParserLaLrChangeObserver)
((ICupParserLaLrChangeObserver) observer).modelChanged(this);
notifyObservers(ICupParserLaLrChangeObserver.class);
}
public CupContext getLaLrContext() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment