Skip to content
Snippets Groups Projects
Commit ac9b2ad6 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

adds addMissingConstraints

refs 2334
parent 0267a33c
No related branches found
No related tags found
No related merge requests found
......@@ -7,16 +7,20 @@ import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.loadClass;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
......@@ -53,7 +57,7 @@ import org.osgi.framework.Bundle;
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 5FB1D1BA3A20C0560809BA04FE487D4E
* @ConQAT.Rating YELLOW Hash: 7DB8A6A2739AB60295A69BCC9774AB3B
*/
public final class ConstraintVerificationUIService implements IConstraintVerificationUIService,
IIntrospectiveKernelService {
......@@ -335,7 +339,7 @@ public final class ConstraintVerificationUIService implements IConstraintVerific
return "Constraint Verification UI Service";
}
/** Activated constraints per top loevel element. */
/** Activated constraints per top level element. */
private static Map<ITopLevelElement, Set<String>> activatedConstraints = new HashMap<>();
/** {@inheritDoc} */
......@@ -360,6 +364,13 @@ public final class ConstraintVerificationUIService implements IConstraintVerific
return handlerMap.keySet();
}
/** {@inheritDoc} */
@Override
public Set<String> getActivatedConstraintTypes(ITopLevelElement top) {
Set<String> res = activatedConstraints.get(top);
return res != null ? res : new HashSet<>();
}
/** {@inheritDoc} */
@Override
public void activate(String id, IConstraintContainer cstrContainer) {
......@@ -369,18 +380,53 @@ public final class ConstraintVerificationUIService implements IConstraintVerific
activatedConstraints.put(top, new HashSet<>());
}
activatedConstraints.get(top).add(id);
IConstraintVerifierUI verifier = getFirstVerifier(id);
verifier.onActivate(cstrContainer);
for(Constraint c : cstrContainer.getConstraints()) {
if(id.equals(c.getConstraintTypeID())) {
if(!IConstraintVerificationService.getInstance().isUpToDate(c) ||
c.getVerificationStatus() == null ||
c.getVerificationStatus() instanceof OutdatedVerificationStatus) {
verifier.onOutdate(c);
}
List<Constraint> addeds =
IConstraintVerificationService.getInstance().addMissingConstraints(top, id);
if(!addeds.isEmpty()) {
ConstraintsUIUtils.displayTimeConsumptionWarning(id);
}
// Install notifiers for newly added constraints
for(Constraint added : addeds) {
IConstraintVerificationUIService.getInstance().install(added);
}
EList<Constraint> cstrs = cstrContainer.getConstraints();
Predicate<Constraint> isID = c -> id.equals(c.getConstraintTypeID());
List<Constraint> idCstrs = cstrs.stream().filter(isID).collect(Collectors.toList());
update(idCstrs);
}
/** {@inheritDoc} */
@Override
public void addMissingConstraints(IConstraintContainer cstrContainer) {
ITopLevelElement top =
IPersistencyService.getInstance().getTopLevelElementFor(cstrContainer);
List<Constraint> addeds = new ArrayList<Constraint>();
for(String id : getActivatedConstraintTypes(top)) {
addeds.addAll(IConstraintVerificationService.getInstance().addMissingConstraints(top,
id));
IConstraintVerificationService.getInstance().addMissingConstraints(top, id);
}
// Install notifiers for newly added constraints
for(Constraint added : addeds) {
IConstraintVerificationUIService.getInstance().install(added);
}
update(addeds);
}
/** Checks the constraints of type <code>id</code> among the given list of constraints. */
private void update(List<Constraint> constraints) {
// Checks all the constraints: the newly added and the already existing ones which are now
// activated.
for(Constraint c : constraints) {
// No need to check if it turns out the status is already known from a previous
// activation.
if(!IConstraintVerificationService.getInstance().isUpToDate(c) ||
c.getVerificationStatus() == null ||
c.getVerificationStatus() instanceof OutdatedVerificationStatus) {
getFirstVerifier(c).onOutdate(c);
}
}
ConstraintsUIUtils.triggerMarkerRefresh(id, cstrContainer);
ConstraintsUIUtils.triggerMarkerRefresh(constraints);
}
/** {@inheritDoc} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment