use of com.ge.research.osate.verdict.gui.WzrdDashboard 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;
}
Aggregations