use of org.sireum.awas.awasfacade.Collector in project osate-plugin by sireum.
the class ReachBackwardHandler method execute.
@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Boolean isImplDiagram = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
List<DiagramElement> des = SelectionUtil.getSelectedDiagramElements(SelectionHelper.getDiagramSelection(), // getSelectedDiagramElem(event)
true);
List<InstanceObject> ios = des.stream().flatMap(de -> {
Object bo = de.getBusinessObject();
List<InstanceObject> io = new ArrayList<InstanceObject>();
if (bo != null && bo instanceof InstanceObject) {
io.add(((InstanceObject) bo));
}
return io.stream();
}).collect(Collectors.toList());
List<String> criterions = ios.stream().map(io -> io.getInstanceObjectPath()).collect(Collectors.toList());
if (!ios.isEmpty()) {
MessageConsole console = displayConsole("Awas Console");
try {
Aadl model = Util.getAir(ios.get(0).getSystemInstance(), true, console);
Model awasModel = org.sireum.awas.slang.Aadl2Awas$.MODULE$.apply(model);
SymbolTable st = org.sireum.awas.symbol.SymbolTable$.MODULE$.apply(awasModel, new ConsoleTagReporter());
FlowGraph<FlowNode, FlowEdge<FlowNode>> graph = org.sireum.awas.flow.FlowGraph$.MODULE$.apply(awasModel, st, false);
AwasGraph awasgraph = new AwasGraphImpl(graph, st);
String query = "t = reach backward " + "{" + String.join(",", criterions) + "}";
Map<String, Collector> qres = awasgraph.queryEvaluator(query);
if (qres.isEmpty()) {
MessageDialog.openError(window.getShell(), "Sireum", "Empty result");
} else {
final DiagramService diagramService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
SystemInstance si = ios.get(0).getSystemInstance();
Resource resource = si.eResource();
List<Collector> lc = new ArrayList<Collector>(qres.values());
Set<AgeEditor> ads = AwasUtil.awasGraphUri2AgeDiagramEditor(lc.get(0).getGraph(), isImplDiagram, st, resource, diagramService);
AwasUtil.highlightDiagrams(ads, lc.get(0), isImplDiagram, st, resource);
}
} catch (URISyntaxException e1) {
// // TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e3) {
e3.printStackTrace();
String m2 = "Could not invoke visualizer. Please make sure Awas is configured correctly.\n\n" + e3.getLocalizedMessage();
MessageDialog.openError(window.getShell(), "Sireum", m2);
}
} else {
String m3 = "Please select a component or port from the instance diagram";
MessageDialog.openError(window.getShell(), "Sireum", m3);
}
return null;
}
use of org.sireum.awas.awasfacade.Collector in project osate-plugin by sireum.
the class ReachForwardHandler method execute.
@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Boolean isImplDiagram = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
List<DiagramElement> des = SelectionUtil.getSelectedDiagramElements(SelectionHelper.getDiagramSelection(), // getSelectedDiagramElem(event)
true);
List<InstanceObject> ios = des.stream().flatMap(de -> {
Object bo = de.getBusinessObject();
List<InstanceObject> io = new ArrayList();
if (bo != null && bo instanceof InstanceObject) {
io.add(((InstanceObject) bo));
}
return io.stream();
}).collect(Collectors.toList());
List<String> criterions = ios.stream().map(io -> io.getInstanceObjectPath()).collect(Collectors.toList());
if (!ios.isEmpty()) {
MessageConsole console = displayConsole("Awas Console");
try {
Aadl model = Util.getAir(ios.get(0).getSystemInstance(), true, console);
Model awasModel = org.sireum.awas.slang.Aadl2Awas$.MODULE$.apply(model);
SymbolTable st = org.sireum.awas.symbol.SymbolTable$.MODULE$.apply(awasModel, new ConsoleTagReporter());
FlowGraph<FlowNode, FlowEdge<FlowNode>> graph = org.sireum.awas.flow.FlowGraph$.MODULE$.apply(awasModel, st, false);
AwasGraph awasgraph = new AwasGraphImpl(graph, st);
String query = "t = reach forward " + "{" + String.join(",", criterions) + "}";
Map<String, Collector> qres = awasgraph.queryEvaluator(query);
if (qres.isEmpty()) {
MessageDialog.openError(window.getShell(), "Sireum", "Empty result");
} else {
final DiagramService diagramService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
SystemInstance si = ios.get(0).getSystemInstance();
Resource resource = si.eResource();
ComponentImplementation cii = InstanceUtil.getComponentImplementation(si, 0, null);
// cii.eResource().getResourceSet().get
List<Collector> lc = new ArrayList<Collector>(qres.values());
Set<AgeEditor> ads = AwasUtil.awasGraphUri2AgeDiagramEditor(lc.get(0).getGraph(), isImplDiagram, st, resource, diagramService);
AwasUtil.highlightDiagrams(ads, lc.get(0), isImplDiagram, st, resource);
}
} catch (URISyntaxException e1) {
// // TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e3) {
e3.printStackTrace();
String m2 = "Could not invoke visualizer. Please make sure Awas is configured correctly.\n\n" + e3.getLocalizedMessage();
MessageDialog.openError(window.getShell(), "Sireum", m2);
}
} else {
String m3 = "Please select a component or port from the instance diagram";
MessageDialog.openError(window.getShell(), "Sireum", m3);
}
return null;
}
use of org.sireum.awas.awasfacade.Collector in project osate-plugin by sireum.
the class AwasUtil method highlightDiagrams.
@SuppressWarnings("restriction")
public static void highlightDiagrams(Set<AgeEditor> ads, Collector qres, Boolean isImpleDiagram, SymbolTable st, Resource resource) {
// AtomicBoolean isNode = new AtomicBoolean(true);
Set<String> uris = new HashSet<String>();
if (qres.getResultType().isPresent()) {
if (qres.getResultType().get() == ResultType.Node()) {
uris.addAll(qres.getNodes().stream().map(it -> it.getUri()).collect(Collectors.toSet()));
} else {
uris.addAll(qres.getPorts());
uris.addAll(qres.getFlows());
uris.addAll(qres.getNodes().stream().filter(it -> it.getResourceType() == NodeType.CONNECTION()).map(it -> it.getUri()).collect(Collectors.toSet()));
// isNode.getAndSet(false);
}
} else if (!qres.getNodes().isEmpty()) {
uris.addAll(qres.getNodes().stream().map(it -> it.getUri()).collect(Collectors.toSet()));
}
Set<InstanceObject> ios = awasUri2AadlInstObj(uris, st, resource);
Set<URI> aadlUris = new HashSet<URI>();
if (isImpleDiagram) {
Set<Element> elems = instObjs2Elements(ios);
aadlUris.addAll(elems.stream().map(it -> new EObjectURIWrapper(it).getUri()).collect(Collectors.toSet()));
} else {
aadlUris.addAll(ios.stream().map(it -> new EObjectURIWrapper(it).getUri()).collect(Collectors.toSet()));
}
Set<DiagramElement> des = new HashSet<DiagramElement>();
ads.forEach(ad -> {
// getDiagram()));
des.addAll(getAllDiagramElements(ad.getDiagram()));
});
des.forEach(de -> {
if (de.getBusinessObject() instanceof EObject && aadlUris.contains(new EObjectURIWrapper((EObject) de.getBusinessObject()).getUri())) {
de.setStyle(StyleBuilder.create(de.getStyle()).backgroundColor(org.osate.ge.graphics.Color.ORANGE).outlineColor(org.osate.ge.graphics.Color.MAGENTA).build());
}
});
ads.forEach(ad -> {
ad.getActionExecutor().execute("highlight diagram", ExecutionMode.NORMAL, () -> {
ad.updateNowIfModelHasChanged();
ad.updateDiagram();
ad.getGefDiagram().refreshDiagramStyles();
ad.doSave(new NullProgressMonitor());
return null;
});
});
}
Aggregations