Search in sources :

Example 1 with EObjectURIWrapper

use of org.osate.aadl2.modelsupport.EObjectURIWrapper in project osate2 by osate.

the class AadlElementContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    Stream<EObject> children;
    final ResourceSetImpl resourceSet = new ResourceSetImpl();
    if (parentElement instanceof IFile) {
        String path = ((IFile) parentElement).getFullPath().toString();
        URI uri = URI.createPlatformResourceURI(path, true);
        Resource resource = resourceSet.getResource(uri, true);
        children = resource.getContents().stream();
    } else if (parentElement instanceof ContributedAadlStorage) {
        URI uri = ((ContributedAadlStorage) parentElement).getUri();
        Resource resource = resourceSet.getResource(uri, true);
        children = resource.getContents().stream();
    } else {
        EObjectURIWrapper wrapper = (EObjectURIWrapper) parentElement;
        EObject eObject = resourceSet.getEObject(wrapper.getUri(), true);
        if (eObject instanceof AadlPackage || eObject instanceof PropertySet || eObject instanceof ComponentInstance) {
            children = eObject.eContents().stream().filter(element -> !(element instanceof SystemOperationMode || element instanceof PropertyAssociation));
        } else if (eObject instanceof PackageSection) {
            children = eObject.eContents().stream().filter(element -> element instanceof Classifier || element instanceof AnnexLibrary);
        } else if (eObject instanceof Classifier) {
            children = eObject.eContents().stream().filter(element -> element instanceof ClassifierFeature || element instanceof PropertyAssociation);
        } else {
            children = Stream.empty();
        }
    }
    final EObjectURIWrapper.Factory factory = new EObjectURIWrapper.Factory(UiUtil.getModelElementLabelProvider());
    // Issue 2430: limit the number of children to 150
    return children.limit(150).map(element -> factory.createWrapperFor(element)).toArray();
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) URI(org.eclipse.emf.common.util.URI) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) PropertySet(org.osate.aadl2.PropertySet) UiUtil(org.osate.ui.UiUtil) PropertyAssociation(org.osate.aadl2.PropertyAssociation) Stream(java.util.stream.Stream) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Resource(org.eclipse.emf.ecore.resource.Resource) IFile(org.eclipse.core.resources.IFile) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) AnnexLibrary(org.osate.aadl2.AnnexLibrary) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PackageSection(org.osate.aadl2.PackageSection) Resource(org.eclipse.emf.ecore.resource.Resource) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Classifier(org.osate.aadl2.Classifier) URI(org.eclipse.emf.common.util.URI) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) EObject(org.eclipse.emf.ecore.EObject) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary)

Example 2 with EObjectURIWrapper

use of org.osate.aadl2.modelsupport.EObjectURIWrapper in project osate2 by osate.

the class AadlElementLabelProvider method getDescription.

@Override
public String getDescription(Object element) {
    if (element instanceof EObjectURIWrapper) {
        EObjectURIWrapper wrapper = (EObjectURIWrapper) element;
        URI uri = wrapper.getUri();
        StringBuilder description = new StringBuilder(getText(wrapper));
        description.append(" - ");
        if (uri.isPlatformPlugin()) {
            // contributed
            String[] segments = uri.segments();
            int i = 2;
            while (segments[i].startsWith("resource") || segments[i].startsWith("package") || segments[i].startsWith("propert")) {
                i++;
            }
            description.append("Plug-in Contributions/");
            description.append(Arrays.stream(segments).skip(i).collect(Collectors.joining("/")));
        } else {
            String[] segments = uri.segments();
            description.append(Arrays.stream(segments).skip(1).collect(Collectors.joining("/")));
        }
        return description.toString();
    } else {
        return null;
    }
}
Also used : EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) URI(org.eclipse.emf.common.util.URI)

Example 3 with EObjectURIWrapper

use of org.osate.aadl2.modelsupport.EObjectURIWrapper in project osate2 by osate.

the class AadlNavigatorLinkHelper method activateEditor.

@Override
public void activateEditor(IWorkbenchPage page, IStructuredSelection structuredSelection) {
    if (structuredSelection == null || structuredSelection.isEmpty()) {
        return;
    }
    Object selected = structuredSelection.getFirstElement();
    if (selected instanceof IFile) {
        IEditorPart editor = page.findEditor(new FileEditorInput((IFile) selected));
        if (editor != null) {
            page.bringToTop(editor);
        }
    } else if (selected instanceof ContributedAadlStorage) {
        ContributedAadlStorage storage = (ContributedAadlStorage) selected;
        IEditorPart editor = page.findEditor(new ContributedAadlEditorInput(storage));
        if (editor != null) {
            page.bringToTop(editor);
        }
    } else if (selected instanceof EObjectURIWrapper) {
        EObjectURIWrapper navigatorNode = (EObjectURIWrapper) selected;
        URI resourceURI = navigatorNode.getUri().trimFragment();
        IEditorPart editor = null;
        if (resourceURI.isPlatformResource()) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IFile file = root.getFile(new Path(null, resourceURI.toPlatformString(true)));
            editor = page.findEditor(new FileEditorInput(file));
        } else if (resourceURI.isPlatformPlugin()) {
            ContributedAadlStorage storage = new ContributedAadlStorage(null, resourceURI);
            editor = page.findEditor(new ContributedAadlEditorInput(storage));
        }
        if (editor != null) {
            page.bringToTop(editor);
            if (editor instanceof XtextEditor) {
                editorOpener.open(navigatorNode.getUri(), true);
            } else {
                IGotoMarker gotoMarkerAdapter = Adapters.adapt(editor, IGotoMarker.class);
                if (gotoMarkerAdapter != null) {
                    try {
                        IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IMarker.MARKER);
                        marker.setAttribute("uri", navigatorNode.getUri().toString());
                        gotoMarkerAdapter.gotoMarker(marker);
                        marker.delete();
                    } catch (CoreException e) {
                        OsateCorePlugin.log(e);
                    }
                }
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IGotoMarker(org.eclipse.ui.ide.IGotoMarker) IEditorPart(org.eclipse.ui.IEditorPart) URI(org.eclipse.emf.common.util.URI) ContributedAadlEditorInput(org.osate.xtext.aadl2.ui.editor.ContributedAadlEditorInput) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) IMarker(org.eclipse.core.resources.IMarker)

Example 4 with EObjectURIWrapper

use of org.osate.aadl2.modelsupport.EObjectURIWrapper in project osate2 by osate.

the class FTAHandler method getTarget.

private InstanceObject getTarget(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            Object obj = iss.getFirstElement();
            if (obj instanceof InstanceObject) {
                return (InstanceObject) obj;
            }
            if (obj instanceof EObjectURIWrapper) {
                EObject eObject = new ResourceSetImpl().getEObject(((EObjectURIWrapper) obj).getUri(), true);
                if (eObject instanceof InstanceObject) {
                    return (InstanceObject) eObject;
                }
            }
            if (obj instanceof IFile) {
                URI uri = OsateResourceUtil.toResourceURI((IFile) obj);
                Resource res = new ResourceSetImpl().getResource(uri, true);
                EList<EObject> rl = res.getContents();
                if (!rl.isEmpty()) {
                    return (InstanceObject) rl.get(0);
                }
            }
        }
    }
    return null;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(org.eclipse.emf.common.util.URI)

Example 5 with EObjectURIWrapper

use of org.osate.aadl2.modelsupport.EObjectURIWrapper in project osate2 by osate.

the class InstantiationEngine method getInputsFromSelection.

@Override
protected Set<ComponentImplementation> getInputsFromSelection(final Collection<?> selectionAsList) {
    final Set<ComponentImplementation> ciSet = new HashSet<>();
    final List<ComponentImplementation> fromAadl = new ArrayList<>();
    for (final Object selection : selectionAsList) {
        if (selection instanceof IFile) {
            final URI uri = OsateResourceUtil.toResourceURI((IFile) selection);
            final EList<EObject> contents = new ResourceSetImpl().getResource(uri, true).getContents();
            if (null != contents && !contents.isEmpty()) {
                final EObject root = contents.get(0);
                if (!(root instanceof AadlPackage)) {
                    throw new AssertionError("Unexpected selection: " + selection + " is not an AADL package file");
                }
                getComponentImplsFromPackage((AadlPackage) root, fromAadl);
            }
        } else {
            URI uri = null;
            if (selection instanceof EObjectNode) {
                uri = ((EObjectNode) selection).getEObjectURI();
            } else if (selection instanceof EObjectURIWrapper) {
                uri = ((EObjectURIWrapper) selection).getUri();
            } else {
                throw new AssertionError("Unexpected selection: " + selection);
            }
            final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.segment(1));
            final ResourceSet resourceSet = resourceSetProvider.get(project);
            final ComponentImplementation impl = (ComponentImplementation) resourceSet.getEObject(uri, true);
            ciSet.add(impl);
        }
    }
    if (!fromAadl.isEmpty()) {
        final boolean showDialog = OsateCorePlugin.getDefault().getAlwaysShowInstantiationAadlDialog();
        final boolean systemsOnly = OsateCorePlugin.getDefault().getOnlyInstantiateSystemImpls();
        final List<SystemImplementation> systems = new ArrayList<>();
        for (final ComponentImplementation ci : fromAadl) {
            if (ci instanceof SystemImplementation) {
                systems.add((SystemImplementation) ci);
            }
        }
        if (!showDialog) {
            ciSet.addAll(systemsOnly ? systems : fromAadl);
        } else {
            /*
				 * THe label provider is sloppy, as I'm replacing the text portion of the delegate and just using
				 * the image portion of the delegate, but I don't know how else to get the images.
				 */
            PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
                final ElementListSelectionDialog d = new ElementListSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new AbstractLabelProvider(UiUtil.getModelElementLabelProvider()) {

                    @Override
                    public String getText(final Object element) {
                        return ((ComponentImplementation) element).getQualifiedName();
                    }
                }) {

                    private Button dontShowButton;

                    private Button systemsOnlyButton;

                    @Override
                    protected Control createDialogArea(final Composite parent) {
                        Composite contents = (Composite) super.createDialogArea(parent);
                        dontShowButton = new Button(contents, SWT.CHECK);
                        dontShowButton.setText("Don't show this dialog again");
                        GridData data = new GridData();
                        data.grabExcessVerticalSpace = false;
                        data.grabExcessHorizontalSpace = true;
                        data.horizontalAlignment = GridData.FILL;
                        data.verticalAlignment = GridData.BEGINNING;
                        dontShowButton.setLayoutData(data);
                        dontShowButton.setFont(parent.getFont());
                        systemsOnlyButton = new Button(contents, SWT.CHECK);
                        systemsOnlyButton.setText("Only systems by default");
                        GridData data2 = new GridData();
                        data2.grabExcessVerticalSpace = false;
                        data2.grabExcessHorizontalSpace = true;
                        data2.horizontalAlignment = GridData.FILL;
                        data2.verticalAlignment = GridData.BEGINNING;
                        systemsOnlyButton.setLayoutData(data2);
                        systemsOnlyButton.setFont(parent.getFont());
                        systemsOnlyButton.setSelection(systemsOnly);
                        return contents;
                    }

                    @Override
                    protected void okPressed() {
                        final IPreferenceStore prefs = OsateCorePlugin.getDefault().getPreferenceStore();
                        if (dontShowButton.getSelection()) {
                            // User just toggled the "don't show option"
                            if (MessageDialog.openQuestion(getShell(), "Confirm change", "This results dialog will be hidden in the future.  " + "You can restore it by going to the \"OSATE > Instantiation\" preference pane.  " + "Do you wish to make this change?")) {
                                prefs.setValue(OsateCorePlugin.ALWAYS_SHOW_INSTANTIATION_AADL_DIALOG, false);
                            }
                        }
                        prefs.setValue(OsateCorePlugin.ONLY_INSTANTIATE_SYSTEM_IMPLS, systemsOnlyButton.getSelection());
                        if (prefs.needsSaving()) {
                            final Job saveJob = Job.create("Save preferences", monitor -> {
                                try {
                                    ((IPersistentPreferenceStore) prefs).save();
                                } catch (final IOException e) {
                                    Display.getDefault().asyncExec(() -> {
                                        MessageDialog.openError(getShell(), "Error", "There was a problem saving the preferences: " + e.getMessage());
                                    });
                                }
                            });
                            saveJob.schedule();
                        }
                        super.okPressed();
                    }
                };
                d.setTitle("Select Component Implementations");
                d.setMessage("Select the component implementations from the selected .aadl files to instantiate.");
                d.setElements(fromAadl.toArray());
                d.setMultipleSelection(true);
                d.setInitialElementSelections(systemsOnly ? systems : fromAadl);
                d.setBlockOnOpen(true);
                if (d.open() == IStatus.OK) {
                    final Object[] result = d.getResult();
                    for (final Object ci : result) {
                        ciSet.add((ComponentImplementation) ci);
                    }
                }
            });
        }
    }
    return ciSet;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode) URI(org.eclipse.emf.common.util.URI) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) EObject(org.eclipse.emf.ecore.EObject) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) AadlPackage(org.osate.aadl2.AadlPackage) Composite(org.eclipse.swt.widgets.Composite) AbstractLabelProvider(org.eclipse.xtext.ui.label.AbstractLabelProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) SystemImplementation(org.osate.aadl2.SystemImplementation) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) GridData(org.eclipse.swt.layout.GridData) EObject(org.eclipse.emf.ecore.EObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

EObjectURIWrapper (org.osate.aadl2.modelsupport.EObjectURIWrapper)10 URI (org.eclipse.emf.common.util.URI)9 IFile (org.eclipse.core.resources.IFile)7 EObject (org.eclipse.emf.ecore.EObject)7 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)7 Resource (org.eclipse.emf.ecore.resource.Resource)4 AadlPackage (org.osate.aadl2.AadlPackage)4 Classifier (org.osate.aadl2.Classifier)4 Stream (java.util.stream.Stream)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 EObjectNode (org.eclipse.xtext.ui.editor.outline.impl.EObjectNode)2 AnnexLibrary (org.osate.aadl2.AnnexLibrary)2 ClassifierFeature (org.osate.aadl2.ClassifierFeature)2 Element (org.osate.aadl2.Element)2 PackageSection (org.osate.aadl2.PackageSection)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 ContributedAadlStorage (org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1