use of org.osate.aadl2.impl.SystemTypeImpl in project VERDICT by ge-high-assurance.
the class StatementEditor method checkIfSystem.
// check if a component is "top-level" system
private boolean checkIfSystem(SystemTypeImpl sys) {
boolean sysLevel = false;
String systemName;
TreeIterator<EObject> tree = sys.eResource().getAllContents();
while (tree.hasNext()) {
EObject tmp = tree.next();
if (tmp instanceof SystemImplementationImpl) {
systemName = ((SystemImplementationImpl) tmp).getTypeName();
if (sys.getName().equals(systemName)) {
sysLevel = true;
break;
}
}
}
return sysLevel;
}
use of org.osate.aadl2.impl.SystemTypeImpl in project VERDICT by ge-high-assurance.
the class WzrdHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (isRunningNow) {
MessageDialog.openError(window.getShell(), "VERDICT Wizard Launcher", "Cannot launch multiple sessions of Wizard simultaneously. Aborting..");
return null;
} else {
isRunningNow = true;
}
try {
// set auto-refresh of eclipse editor "ON"
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
try {
prefs.flush();
} catch (Exception e) {
System.out.println("Error in setting auto-refresh");
System.out.println(e.getStackTrace());
}
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// save the invoking .aadl editor if it has unsaved content
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart openEditor = page.getActiveEditor();
if (openEditor != null) {
boolean response = page.saveEditor(openEditor, true);
if (!response) {
isRunningNow = false;
return null;
} else if (openEditor.isDirty()) {
MessageDialog.openError(window.getShell(), "VERDICT Wizard Launcher", "Cannot launch Wizard with unsaved content on the editor. Aborting..");
isRunningNow = false;
return null;
}
}
// Skip the dashboard when Wizard is invoked from a valid text selection
if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection) {
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
TextSelection ts = (TextSelection) xtextEditor.getSelectionProvider().getSelection();
xtextEditor.getDocument().readOnly(resource -> {
EObject e = new EObjectAtOffsetHelper().resolveContainedElementAt(resource, ts.getOffset());
if (e instanceof SystemTypeImpl) {
SystemTypeImpl selectedSys = (SystemTypeImpl) e;
setModelPath(e);
StatementEditor editor = new StatementEditor(selectedSys, fileModel.getFullPath(), shell, window.getShell().getBounds(), "osate");
if (editor.isValid()) {
editor.run();
}
} else {
MessageDialog.openError(window.getShell(), "VERDICT Wizard Launcher", "Selected object must be a SystemTypeImpl to launch cyber-property editor Wizard.");
}
return EcoreUtil.getURI(e);
});
isRunningNow = false;
return null;
}
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
// Launch dashboard when invoked from a valid .aadl file
if (selection.getFirstElement() instanceof IOutlineNode) {
IOutlineNode node = (IOutlineNode) selection.getFirstElement();
node.readOnly(state -> {
EObject selectedObject = state;
setModelPath(selectedObject);
if (selectedObject instanceof SystemTypeImpl) {
SystemTypeImpl selectedSys = (SystemTypeImpl) selectedObject;
setModelPath(selectedObject);
StatementEditor editor = new StatementEditor(selectedSys, fileModel.getFullPath(), shell, window.getShell().getBounds(), "osate");
if (editor.isValid()) {
editor.run();
}
} else {
MessageDialog.openError(window.getShell(), "VERDICT Wizard Launcher", "Selected object must be a SystemTypeImpl to launch Cyber Requirement Wizard. The currently selected element is:" + selectedObject.getClass().toString());
}
isRunningNow = false;
return null;
});
} else if (selection.getFirstElement() instanceof IFile) {
fileModel = (IFile) selection.getFirstElement();
if (!fileModel.getFileExtension().equals("aadl")) {
MessageDialog.openError(window.getShell(), "VERDICT Wizard Launcher", "Wizard can be launched from files only with .aadl extension.");
return null;
}
IFile file = (IFile) selection.getFirstElement();
URI uri = URI.createPlatformResourceURI(file.getFullPath().toPortableString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource resource = rs.getResource(uri, true);
try {
resource.load(null);
} catch (Exception e) {
e.printStackTrace();
}
// the following code loads all the cross-referred .aadl resources in the project
// IFile fileRoot = WorkspaceSynchronizer.getFile(resource);
// IResource parent = fileRoot.getParent();
// IResource[] children = parent.getProject().members();
//
// for (int i = 0; i < children.length; i++) {
// if (children[i].getFileExtension().equals("aadl") && children[i] != file) {
// URI uriXRefered = URI.createPlatformResourceURI(children[i].getFullPath().toPortableString(),
// true);
// Resource resourceXRefered = rs.getResource(uriXRefered, true);
// System.out.println(
// resourceXRefered.toString() + "----loading status: " + resourceXRefered.isLoaded());
// }
// }
WzrdDashboard dashboard = new WzrdDashboard(resource, shell, fileModel.getFullPath());
if (dashboard.isValid()) {
dashboard.run();
}
}
isRunningNow = false;
} catch (Exception e) {
System.out.println("Error in Wizard!!");
e.printStackTrace();
}
return null;
}
use of org.osate.aadl2.impl.SystemTypeImpl in project VERDICT by ge-high-assurance.
the class StatementEditor method reloadSystem.
private SystemTypeImpl reloadSystem(SystemTypeImpl sys) {
Resource oldResource = sys.eResource();
ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry();
Resource resource = resourceSet.createResource(oldResource.getURI());
try {
resource.load(null);
} catch (Exception e) {
System.out.println("Error in reloading resource while saving content by Wizard.");
e.printStackTrace();
}
TreeIterator<EObject> tree = resource.getAllContents();
while (tree.hasNext()) {
EObject anObject = tree.next();
if (anObject instanceof SystemTypeImpl) {
if (((SystemTypeImpl) anObject).getFullName().equals(sys.getFullName())) {
sys = (SystemTypeImpl) anObject;
}
}
// extract the existing set of IDs that are already used------------------------------------------------------
if (anObject instanceof DefaultAnnexSubclauseImpl) {
if (!((DefaultAnnexSubclauseImpl) anObject).getName().equals("verdict")) {
continue;
}
Verdict vd = ((VerdictContractSubclause) ((DefaultAnnexSubclauseImpl) anObject).getParsedAnnexSubclause()).getContract();
List<Statement> stmts = vd.getElements();
for (int i = 0; i < stmts.size(); i++) {
if (stmts.get(i) instanceof CyberMissionImpl) {
idSet.add(((CyberMissionImpl) stmts.get(i)).getId());
} else if (stmts.get(i) instanceof CyberRelImpl) {
idSet.add(((CyberRelImpl) stmts.get(i)).getId());
} else if (stmts.get(i) instanceof CyberReqImpl) {
idSet.add(((CyberReqImpl) stmts.get(i)).getId());
}
}
}
// ------------------------------------------------------------------------------------------------------------
}
return sys;
}
use of org.osate.aadl2.impl.SystemTypeImpl in project VERDICT by ge-high-assurance.
the class WzrdClosure method reloadSystem.
private SystemTypeImpl reloadSystem(SystemTypeImpl sys) {
Resource oldResource = sys.eResource();
ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry();
Resource resource = resourceSet.createResource(oldResource.getURI());
try {
resource.load(null);
} catch (Exception e) {
System.out.println("Error in reloading resource while saving content by Wizard.");
e.printStackTrace();
}
TreeIterator<EObject> tree = resource.getAllContents();
while (tree.hasNext()) {
EObject anObject = tree.next();
if (anObject instanceof SystemTypeImpl) {
if (((SystemTypeImpl) anObject).getFullName().equals(sys.getFullName())) {
sys = (SystemTypeImpl) anObject;
break;
}
}
}
return sys;
}
use of org.osate.aadl2.impl.SystemTypeImpl in project VERDICT by ge-high-assurance.
the class WzrdDashboard method composeToolTip.
// Dynamically updates tooltiptext of the buttons
private String composeToolTip(int i) {
String str = "";
SystemTypeImpl sys = systems.get(i);
List<DataPort> dpList = sys.getOwnedDataPorts();
str = str + "IN ports:\n";
String inLine = "";
// wrap the string into multi-line if its lengthy-------------------------
int inLength = 0;
for (int j = 0; j < dpList.size(); j++) {
if (dpList.get(j).isIn()) {
inLength = inLength + (dpList.get(j).getFullName() + ",").length();
inLine = inLine + dpList.get(j).getFullName() + ",";
if (inLength > 30) {
inLength = 0;
inLine = inLine + "\n";
}
}
}
// -------------------------------------------------------------------------
str = str + inLine + "\n\n";
str = str + "OUT ports:\n";
String outLine = "";
int outLength = 0;
// wrap the string into multi-line if its lengthy-------------------------
int outCount = 0;
for (int j = 0; j < dpList.size(); j++) {
if (dpList.get(j).isOut()) {
outCount++;
outLength = outLength + (dpList.get(j).getFullName() + ",").length();
outLine = outLine + dpList.get(j).getFullName() + ",";
if (outLength > 30) {
outLength = 0;
outLine = outLine + "\n";
}
}
}
// ------------------------------------------------------------------------
List<EObject> objs = sys.eContents();
List<Statement> stmts = new ArrayList<Statement>();
for (int k = 0; k < objs.size(); k++) {
if (objs.get(k) instanceof DefaultAnnexSubclauseImpl) {
if (!((DefaultAnnexSubclauseImpl) objs.get(k)).getName().equals("verdict")) {
continue;
}
Verdict vd = ((VerdictContractSubclause) ((DefaultAnnexSubclauseImpl) objs.get(k)).getParsedAnnexSubclause()).getContract();
stmts = vd.getElements();
break;
}
}
str = str + outLine + "\n\n";
if (!checkIfSystem(sys)) {
if (stmts.size() > 0) {
str = str + "Cyber-relations:\n";
if (stmts.size() == outCount) {
colorTag = 0;
} else {
colorTag = 0;
}
} else {
str = str + "No cyber-relation defined.";
colorTag = 2;
}
} else {
if (stmts.size() > 0) {
str = str + "Cyber-requirements:\n";
} else {
str = str + "No cyber-requirement defined.";
}
}
for (int m = 0; m < stmts.size(); m++) {
str = str + stmts.get(m).getId() + "\n";
}
return str;
}
Aggregations