Search in sources :

Example 6 with SystemTypeImpl

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;
}
Also used : SystemImplementationImpl(org.osate.aadl2.impl.SystemImplementationImpl) EObject(org.eclipse.emf.ecore.EObject)

Example 7 with SystemTypeImpl

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Resource(org.eclipse.emf.ecore.resource.Resource) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) WzrdDashboard(com.ge.research.osate.verdict.gui.WzrdDashboard) URI(org.eclipse.emf.common.util.URI) ExecutionException(org.eclipse.core.commands.ExecutionException) SystemTypeImpl(org.osate.aadl2.impl.SystemTypeImpl) Shell(org.eclipse.swt.widgets.Shell) EObject(org.eclipse.emf.ecore.EObject) EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) StatementEditor(com.ge.research.osate.verdict.gui.StatementEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 8 with SystemTypeImpl

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;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DefaultAnnexSubclauseImpl(org.osate.aadl2.impl.DefaultAnnexSubclauseImpl) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) CyberRelImpl(com.ge.research.osate.verdict.dsl.verdict.impl.CyberRelImpl) Resource(org.eclipse.emf.ecore.resource.Resource) CyberReqImpl(com.ge.research.osate.verdict.dsl.verdict.impl.CyberReqImpl) SystemTypeImpl(org.osate.aadl2.impl.SystemTypeImpl) VerdictContractSubclause(com.ge.research.osate.verdict.dsl.verdict.VerdictContractSubclause) EObject(org.eclipse.emf.ecore.EObject) CyberMissionImpl(com.ge.research.osate.verdict.dsl.verdict.impl.CyberMissionImpl) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict)

Example 9 with SystemTypeImpl

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;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) SystemTypeImpl(org.osate.aadl2.impl.SystemTypeImpl)

Example 10 with SystemTypeImpl

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;
}
Also used : DefaultAnnexSubclauseImpl(org.osate.aadl2.impl.DefaultAnnexSubclauseImpl) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) ArrayList(java.util.ArrayList) SystemTypeImpl(org.osate.aadl2.impl.SystemTypeImpl) VerdictContractSubclause(com.ge.research.osate.verdict.dsl.verdict.VerdictContractSubclause) DataPort(org.osate.aadl2.DataPort) EObject(org.eclipse.emf.ecore.EObject) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)10 DefaultAnnexSubclauseImpl (org.osate.aadl2.impl.DefaultAnnexSubclauseImpl)6 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)5 Verdict (com.ge.research.osate.verdict.dsl.verdict.Verdict)5 VerdictContractSubclause (com.ge.research.osate.verdict.dsl.verdict.VerdictContractSubclause)5 ArrayList (java.util.ArrayList)5 SystemTypeImpl (org.osate.aadl2.impl.SystemTypeImpl)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 CyberMissionImpl (com.ge.research.osate.verdict.dsl.verdict.impl.CyberMissionImpl)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 SystemImplementationImpl (org.osate.aadl2.impl.SystemImplementationImpl)2 CyberRelImpl (com.ge.research.osate.verdict.dsl.verdict.impl.CyberRelImpl)1 CyberReqImpl (com.ge.research.osate.verdict.dsl.verdict.impl.CyberReqImpl)1 StatementEditor (com.ge.research.osate.verdict.gui.StatementEditor)1 WzrdDashboard (com.ge.research.osate.verdict.gui.WzrdDashboard)1 IOException (java.io.IOException)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1