Commit c6db1b89 authored by Liana Soima's avatar Liana Soima
Browse files

Set as developed/instantiated



Automatic set as developed/undeveloped and instantiated/uninstantiated
entity.
Signed-off-by: Liana Soima's avatarLiana Soima <soima@fortiss.org>
Issue-Ref: 3979
parent d24a688b
......@@ -15,21 +15,31 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safetycases.listener;
import static org.fortiss.tooling.common.util.LambdaUtils.filter;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.safetyargumentationpackage.model.SafetyArgumentationPackage;
import org.fortiss.af3.safetycases.AF3SafetyCasesActivator;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.ExitConnector;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.Strategy;
import org.fortiss.tooling.base.model.base.HierarchicElementBase;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
* Listener that installs a {@link AutomaticSetListener} to {@link ITopLevelElement}s that are
* loaded
* at startup or during runtime.
* loaded at startup or during runtime.
*
* @author soima
*/
......@@ -62,14 +72,18 @@ public class AutomaticSetListener extends EContentAdapter {
"listeners. This could indicate a model corruption.");
return;
}
FileProject fileProject = (FileProject)rootElement;
List<SafetyArgumentationPackage> safetyPackages =
pickInstanceOf(SafetyArgumentationPackage.class, fileProject.getRootElements());
filter(safetyPackages, argEl -> !argEl.eAdapters().contains(getInstance()))
.forEach(argEl -> argEl.eAdapters().add(getInstance()));
}
/** {@inheritDoc} */
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
// Automatic set as instantiated/uninstantiated ArgumentElement.
if(notification.getNotifier() instanceof ArgumentElement &&
notification.getEventType() == Notification.SET) {
// Input checks.
......@@ -78,9 +92,49 @@ public class AutomaticSetListener extends EContentAdapter {
}
EAttribute attribute = (EAttribute)notification.getFeature();
if(!attribute.getName().equals("name")) {
// Only act upon renaming, not other modifications.
return;
if(attribute.getName().equals("textualInformation")) {
ArgumentElement argElement = ((ArgumentElement)notification.getNotifier());
String textualInformation = argElement.getTextualInformation();
// Check if a text is written between curly brackets. Example: {Claim}.
if(!Pattern.matches("^\\{((.|\\n)*)}$", textualInformation) &&
!textualInformation.isEmpty()) {
argElement.setToBeInstantiated(false);
} else {
argElement.setToBeInstantiated(true);
}
}
return;
}
// Automatic set as developed/undeveloped entity.
notification.getEventType();
if((notification.getNotifier() instanceof ExitConnector) &&
(notification.getEventType() == Notification.ADD ||
notification.getEventType() == Notification.REMOVE)) {
HierarchicElementBase element =
((ExitConnector)notification.getNotifier()).getGSNElement();
if(notification.getEventType() == Notification.ADD) {
if(element instanceof Goal) {
((Goal)element).setToBeDeveloped(false);
}
if(element instanceof Strategy) {
((Strategy)element).setToBeDeveloped(false);
}
} else if(notification.getEventType() == Notification.REMOVE) {
if(element instanceof Goal) {
List<ExitConnector> connectors = ((Goal)element).getExitConnectors().stream()
.filter(e -> !e.getOutgoing().isEmpty()).collect(Collectors.toList());
if(connectors.isEmpty()) {
((Goal)element).setToBeDeveloped(true);
}
}
if(element instanceof Strategy) {
List<ExitConnector> connectors = ((Strategy)element).getExitConnectors()
.stream().filter(e -> !e.getOutgoing().isEmpty())
.collect(Collectors.toList());
if(connectors.isEmpty()) {
((Strategy)element).setToBeDeveloped(true);
}
}
}
}
}
......
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