Search in sources :

Example 1 with ContributedAadlStorage

use of org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage in project osate2 by osate.

the class AadlContributionLabelProvider method getText.

@Override
public String getText(Object element) {
    String text = null;
    if (element instanceof VirtualPluginResources) {
        text = ((VirtualPluginResources) element).getLabel();
    } else if (element instanceof ContributedDirectory) {
        List<String> directoryPath = ((ContributedDirectory) element).getPath();
        text = directoryPath.get(directoryPath.size() - 1);
    } else if (element instanceof ContributedAadlStorage) {
        final URI uri = ((ContributedAadlStorage) element).getUri();
        final URI overridesURI = PredeclaredProperties.getOverridesURI(uri);
        if (overridesURI != null) {
            text = overridesURI.lastSegment() + " (overridden)";
        } else {
            text = ((ContributedAadlStorage) element).getName();
        }
    }
    return text;
}
Also used : ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) List(java.util.List) URI(org.eclipse.emf.common.util.URI)

Example 2 with ContributedAadlStorage

use of org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage 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 3 with ContributedAadlStorage

use of org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage 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 ContributedAadlStorage

use of org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage in project osate2 by osate.

the class AadlContributionContentProvider method getChildren.

@Override
public Object[] getChildren(Object element) {
    if (element instanceof IProject) {
        IProject project = (IProject) element;
        try {
            if (project.getNature(AadlNature.ID) != null) {
                // Assume there are always plug-in contributions
                return new Object[] { new VirtualPluginResources(project) };
            }
        } catch (CoreException e) {
        // couldn't retrieve AADL nature from project
        }
        return new Object[0];
    } else if (element instanceof VirtualPluginResources) {
        List<URI> disabled = PredeclaredProperties.getDisabledContributions();
        return PredeclaredProperties.getContributedResources().stream().map(uri -> {
            OptionalInt firstSignificantIndex = PluginSupportUtil.getFirstSignificantIndex(uri);
            if (!firstSignificantIndex.isPresent() || firstSignificantIndex.getAsInt() == uri.segmentCount() - 1) {
                final URI replacedBy = PredeclaredProperties.getOverriddenResources().getOrDefault(uri, uri);
                return new ContributedAadlStorage((VirtualPluginResources) element, replacedBy, disabled.contains(replacedBy));
            } else {
                return new ContributedDirectory((VirtualPluginResources) element, Collections.singletonList(uri.segment(firstSignificantIndex.getAsInt())));
            }
        }).distinct().toArray();
    } else if (element instanceof ContributedDirectory) {
        List<String> directoryPath = ((ContributedDirectory) element).getPath();
        Stream<URI> inDirectory = PredeclaredProperties.getContributedResources().stream().filter(uri -> {
            OptionalInt firstSignificantIndex = PluginSupportUtil.getFirstSignificantIndex(uri);
            if (firstSignificantIndex.isPresent() && firstSignificantIndex.getAsInt() < uri.segmentCount() - 1) {
                List<String> uriDirectory = uri.segmentsList().subList(firstSignificantIndex.getAsInt(), uri.segmentCount() - 1);
                return isPrefix(directoryPath, uriDirectory);
            } else {
                return false;
            }
        });
        return inDirectory.map(uri -> {
            int nextSignificantIndex = PluginSupportUtil.getFirstSignificantIndex(uri).getAsInt() + directoryPath.size();
            List<URI> disabled = PredeclaredProperties.getDisabledContributions();
            if (nextSignificantIndex == uri.segmentCount() - 1) {
                final URI replacedBy = PredeclaredProperties.getOverriddenResources().getOrDefault(uri, uri);
                return new ContributedAadlStorage((ContributedDirectory) element, replacedBy, disabled.contains(replacedBy));
            } else {
                ArrayList<String> newPath = new ArrayList<>(directoryPath);
                newPath.add(uri.segment(nextSignificantIndex));
                return new ContributedDirectory((ContributedDirectory) element, newPath);
            }
        }).distinct().toArray();
    }
    return super.getChildren(element);
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) List(java.util.List) AadlNature(org.osate.core.AadlNature) Stream(java.util.stream.Stream) PredeclaredProperties(org.osate.pluginsupport.PredeclaredProperties) IProject(org.eclipse.core.resources.IProject) Collections(java.util.Collections) PluginSupportUtil(org.osate.pluginsupport.PluginSupportUtil) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) ArrayList(java.util.ArrayList) OptionalInt(java.util.OptionalInt) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ContributedAadlStorage

use of org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage in project osate2 by osate.

the class AadlContributionLabelProvider method getDescription.

@Override
public String getDescription(Object element) {
    String description = null;
    if (element instanceof VirtualPluginResources) {
        description = "Plug-in Contributions";
    } else if (element instanceof ContributedDirectory) {
        List<String> directoryPath = ((ContributedDirectory) element).getPath();
        description = "Plug-in Contributions/" + String.join("/", directoryPath);
    } else if (element instanceof ContributedAadlStorage) {
        final URI uri = ((ContributedAadlStorage) element).getUri();
        final URI overridesURI = PredeclaredProperties.getOverridesURI(uri);
        if (overridesURI != null) {
            description = uriToNavigatorPath(overridesURI) + " (contributed by " + overridesURI.segment(1) + ") (Overridden by " + uriToWorkspacePath(uri) + ")";
        } else {
            description = uriToNavigatorPath(uri) + " (contributed by " + uri.segment(1) + ")";
        }
    }
    return description;
}
Also used : ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) List(java.util.List) URI(org.eclipse.emf.common.util.URI)

Aggregations

URI (org.eclipse.emf.common.util.URI)6 ContributedAadlStorage (org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage)6 List (java.util.List)3 Stream (java.util.stream.Stream)3 IFile (org.eclipse.core.resources.IFile)3 EObjectURIWrapper (org.osate.aadl2.modelsupport.EObjectURIWrapper)3 CoreException (org.eclipse.core.runtime.CoreException)2 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 AadlPackage (org.osate.aadl2.AadlPackage)2 AnnexLibrary (org.osate.aadl2.AnnexLibrary)2 Classifier (org.osate.aadl2.Classifier)2 ClassifierFeature (org.osate.aadl2.ClassifierFeature)2 PackageSection (org.osate.aadl2.PackageSection)2 PropertyAssociation (org.osate.aadl2.PropertyAssociation)2 PropertySet (org.osate.aadl2.PropertySet)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)2