blob: 1f1b1f77566a096e4300d15d092e36f0c3a8ff4e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.modelChecker.impl;
import java.util.Collection;
import java.util.TreeSet;
import org.eclipse.viatra2.core.ICoreNotificationListener;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.core.notification.ICoreNotificationObject;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectTransactionEnd;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectUndoEnd;
public class ConsistencyListener implements ICoreNotificationListener {
ProblemCounter pc;
ModelChecker checker;
public ConsistencyListener(ProblemCounter pc) {
this.pc = pc;
checker = new ModelChecker();
}
TreeSet<IModelElement> noted = new TreeSet<IModelElement>();
public void actionPerformed(ICoreNotificationObject notification) {
Collection<IModelElement> newNoted = notification.getNotifiedObjects();
noted.addAll(newNoted);
if (notification instanceof ICoreNotificationObjectTransactionEnd ||
notification instanceof ICoreNotificationObjectUndoEnd)
{
checkChanges();
}
}
private void checkChanges() {
for (IModelElement me : noted)
{
pc.pm.tm.clearTags(me);
checkME(me);
if (me instanceof IRelation) {
IRelation rel = (IRelation) me;
if (!noted.contains(rel.getFrom())) {
checkME(rel.getFrom());
}
if (!noted.contains(rel.getTo())) {
checkME(rel.getTo());
}
}
}
noted = new TreeSet<IModelElement>();
}
private void checkME(IModelElement me) {
pc.setProblems(me, checker.checkModelElement(me));
}
public int getListenerCategory() {
return 0;
}
}