Search in sources :

Example 21 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class ClassifierInfoView method createAncestorTreeNode.

private AncestorTreeNode createAncestorTreeNode(final Classifier classifier, final String prefix, final IProgressMonitor progressMonitor) throws InterruptedException {
    if (progressMonitor.isCanceled()) {
        throw new InterruptedException();
    }
    AncestorTreeNode[] children = new AncestorTreeNode[0];
    if (classifier instanceof ComponentType) {
        final ComponentType extended = ((ComponentType) classifier.getExtended());
        if (extended != null) {
            children = new AncestorTreeNode[] { createAncestorTreeNode(extended, EXTENDS, progressMonitor) };
        }
    } else if (classifier instanceof ComponentImplementation) {
        final ComponentImplementation asCompImpl = (ComponentImplementation) classifier;
        final ComponentType implemented = asCompImpl.getType();
        final ComponentImplementation extended = asCompImpl.getExtended();
        if (extended == null) {
            children = new AncestorTreeNode[] { createAncestorTreeNode(implemented, IMPLEMENTS, progressMonitor) };
        } else {
            children = new AncestorTreeNode[] { createAncestorTreeNode(implemented, IMPLEMENTS, progressMonitor), createAncestorTreeNode(extended, EXTENDS, progressMonitor) };
        }
    } else if (classifier instanceof FeatureGroupType) {
        final FeatureGroupType asFeatureGroup = (FeatureGroupType) classifier;
        final FeatureGroupType inverseOf = asFeatureGroup.getInverse();
        final FeatureGroupType extended = asFeatureGroup.getExtended();
        final List<AncestorTreeNode> childrenList = new ArrayList<>(2);
        if (inverseOf != null) {
            childrenList.add(createAncestorTreeNode(inverseOf, INVERSE_OF, progressMonitor));
        }
        if (extended != null) {
            childrenList.add(createAncestorTreeNode(extended, EXTENDS, progressMonitor));
        }
        children = childrenList.toArray(children);
    }
    return new AncestorTreeNode(classifier, prefix, children);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ArrayList(java.util.ArrayList)

Example 22 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class ClassifierInfoView method updateDisplay.

// Synchronized to make manipulation of the currentRefreshJob atomic
private synchronized void updateDisplay(final Classifier inputHierarchy, final Classifier inputMember) {
    // Stop any current refresh job
    if (currentRefreshJob != null) {
        currentRefreshJob.cancel();
    }
    final Job waitForJob = currentRefreshJob;
    // Compute the tree in a separate job and then update the view on the display thread.
    final IWorkbenchSiteProgressService service = getSite().getService(IWorkbenchSiteProgressService.class);
    final Job refreshJob = new Job("Classifier Info View Refresh") {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            // Wait for the current refresh to finish (it should have been cancelled)
            if (waitForJob != null) {
                try {
                    waitForJob.join();
                } catch (final OperationCanceledException | InterruptedException e) {
                    /*
						 * We were interrupted while waiting. Not sure this should be possible, but
						 * if it happens, we clear the display.
						 */
                    clearDisplay(false);
                    return Status.CANCEL_STATUS;
                }
            }
            boolean needsRefresh = false;
            boolean skipMember = false;
            final SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
            if (inputHierarchy != null) {
                subMonitor.subTask("Buidling classifier hiearchy");
                final Set<IProject> projects = getDependantProjects(inputHierarchy);
                projectDependancies.addAll(projects);
                try {
                    final AncestorTree ancestorTreeModel = createAncestorTree(inputHierarchy, subMonitor);
                    subMonitor.worked(1);
                    final DescendantTree descendantTreeModel = createDescendantTree(inputHierarchy, projects, subMonitor.split(1));
                    // Update the view contents in the UI thread
                    getViewSite().getShell().getDisplay().asyncExec(() -> {
                        ancestorTreeViewer.setInput(ancestorTreeModel);
                        ancestorTreeViewer.expandToLevel(2);
                        ancestorTreeViewer.setSelection(new TreeSelection(new TreePath(ancestorTreeModel.getChildren())));
                        descendantTreeViewer.setInput(descendantTreeModel);
                        descendantTreeViewer.expandToLevel(2);
                        descendantTreeViewer.setSelection(new TreeSelection(new TreePath(descendantTreeModel.getChildren())));
                    });
                } catch (final OperationCanceledException | InterruptedException e) {
                    /*
						 * Hierarchy build cancelled-- clear both panes. Originally we just cleared the
						 * hierarchy pane, but then it is confusing what is being shown in the member pane.
						 * Set the 'skip' flag so we don't readd the member pane below.
						 */
                    clearDisplay(false);
                    // Update incomplete, so we still need to refresh later
                    needsRefresh = true;
                    skipMember = true;
                }
                subMonitor.done();
            } else {
                subMonitor.worked(2);
            }
            if (inputMember != null && !skipMember) {
                final MemberTree memberTree;
                if (inputMember instanceof ComponentType) {
                    memberTree = createMemberTree((ComponentType) inputMember);
                } else if (inputMember instanceof ComponentImplementation) {
                    memberTree = createMemberTree((ComponentImplementation) inputMember);
                } else if (inputMember instanceof FeatureGroupType) {
                    memberTree = createMemberTree((FeatureGroupType) inputMember);
                } else {
                    // Shouldn't get here
                    memberTree = null;
                }
                if (memberTree != null) {
                    // Update the view contents in the UI thread
                    getViewSite().getShell().getDisplay().asyncExec(() -> {
                        memberTreeViewer.setInput(memberTree);
                        memberTreeViewer.expandToLevel(2);
                    });
                } else {
                    clearMembers(false);
                }
            }
            setNeedsRefresh(needsRefresh);
            // Mark the view as changed (should show up with a bold title)
            service.warnOfContentChange();
            return Status.OK_STATUS;
        }
    };
    // doesn't write resources
    refreshJob.setRule(null);
    refreshJob.setUser(true);
    refreshJob.setSystem(false);
    // Run the job using the progress service so that the view is marked as busy (italics)
    currentRefreshJob = refreshJob;
    service.schedule(refreshJob, 0, true);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) FeatureGroupType(org.osate.aadl2.FeatureGroupType) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Job(org.eclipse.core.runtime.jobs.Job)

Example 23 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class Aadl2OccurrenceComputer method createAnnotationMap.

@Override
public Map<Annotation, Position> createAnnotationMap(XtextEditor editor, final ITextSelection selection, final SubMonitor monitor) {
    final IXtextDocument document = editor.getDocument();
    if (document != null) {
        return document.tryReadOnly(new CancelableUnitOfWork<Map<Annotation, Position>, XtextResource>() {

            @Override
            public Map<Annotation, Position> exec(XtextResource resource, final CancelIndicator cancelIndicator) throws Exception {
                EObject target = eObjectAtOffsetHelper.resolveElementAt(resource, selection.getOffset());
                if (target != null && !target.eIsProxy()) {
                    final List<EObjectReferenceAndIndex> references = newArrayList();
                    IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() {

                        @Override
                        public void accept(IReferenceDescription reference) {
                            throw new UnsupportedOperationException("Local references are announced per object");
                        }

                        @Override
                        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) {
                            EObjectReferenceAndIndex acceptMe = new EObjectReferenceAndIndex();
                            acceptMe.source = source;
                            acceptMe.reference = eReference;
                            acceptMe.idx = index;
                            references.add(acceptMe);
                        }
                    };
                    Iterable<URI> targetURIs = getTargetURIs(target);
                    if (!(targetURIs instanceof TargetURIs)) {
                        TargetURIs result = targetURIsProvider.get();
                        result.addAllURIs(targetURIs);
                        targetURIs = result;
                    }
                    IProgressMonitor localMonitor = new NullProgressMonitor() {

                        @Override
                        public boolean isCanceled() {
                            return monitor.isCanceled() || cancelIndicator.isCanceled();
                        }
                    };
                    referenceFinder.findReferences((TargetURIs) targetURIs, resource, acceptor, localMonitor);
                    operationCanceledManager.checkCanceled(cancelIndicator);
                    Map<Annotation, Position> result = newHashMapWithExpectedSize(references.size() + 1);
                    if (target.eResource() == resource) {
                        if (!references.isEmpty() || canBeReferencedLocally(target)) {
                            ITextRegion declarationRegion = locationInFileProvider.getSignificantTextRegion(target);
                            addOccurrenceAnnotation(DECLARATION_ANNOTATION_TYPE, document, declarationRegion, result);
                            declarationRegion = ((Aadl2LocationInFile) locationInFileProvider).getSecondaryTextRegion(target, !(target instanceof ComponentImplementation));
                            if (declarationRegion != null) {
                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, declarationRegion, result);
                                if (target instanceof ComponentType) {
                                    ModelUnit pkg = EcoreUtil2.getContainerOfType(target, ModelUnit.class);
                                    for (ComponentImplementation impl : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
                                        if (impl.getType() == target) {
                                            declarationRegion = ((Aadl2LocationInFile) locationInFileProvider).getSecondaryTextRegion(impl, true);
                                            if (declarationRegion != null) {
                                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, declarationRegion, result);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    for (EObjectReferenceAndIndex highlightMe : references) {
                        try {
                            if (localMonitor.isCanceled()) {
                                return emptyMap();
                            }
                            ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(highlightMe.source, highlightMe.reference, highlightMe.idx);
                            if (target instanceof ComponentImplementation) {
                                ComponentImplementation impl = (ComponentImplementation) target;
                                textRegion = getAdjustedRegion(document, textRegion, impl.getImplementationName(), textRegion);
                            } else if (target instanceof ComponentType || target instanceof Property || target instanceof PropertyType || target instanceof PropertyConstant) {
                                NamedElement named = (NamedElement) target;
                                textRegion = getAdjustedRegion(document, textRegion, named.getName(), textRegion);
                            } else if (target instanceof ModelUnit) {
                                NamedElement named = (NamedElement) target;
                                textRegion = getAdjustedRegion(document, textRegion, named.getName(), null);
                            }
                            if (textRegion != null) {
                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, textRegion, result);
                            }
                        } catch (Exception exc) {
                        // outdated index information. Ignore
                        }
                    }
                    return result;
                }
                return emptyMap();
            }
        }, () -> emptyMap());
    } else {
        return emptyMap();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextResource(org.eclipse.xtext.resource.XtextResource) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) PropertyType(org.osate.aadl2.PropertyType) URI(org.eclipse.emf.common.util.URI) Aadl2LocationInFile(org.osate.xtext.aadl2.util.Aadl2LocationInFile) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Property(org.osate.aadl2.Property) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) ComponentType(org.osate.aadl2.ComponentType) BadLocationException(org.eclipse.jface.text.BadLocationException) PropertyConstant(org.osate.aadl2.PropertyConstant) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) ITextRegion(org.eclipse.xtext.util.ITextRegion) ModelUnit(org.osate.aadl2.ModelUnit) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) NamedElement(org.osate.aadl2.NamedElement) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 24 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class Aadl2RenameStrategy method applyDeclarationChange.

@Override
public void applyDeclarationChange(String newName, ResourceSet resourceSet) {
    // rename component implementations
    EObject targetElement = resourceSet.getEObject(getTargetElementOriginalURI(), false);
    if (targetElement instanceof ComponentType) {
        AadlPackage pkg = EcoreUtil2.getContainerOfType(targetElement, AadlPackage.class);
        for (ComponentImplementation impl : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
            if (impl.getType() == targetElement) {
                impl.setName(newName + "." + impl.getImplementationName());
            }
        }
    }
    super.applyDeclarationChange(newName, resourceSet);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject)

Example 25 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class Aadl2RenameStrategy method setName.

@Override
protected EObject setName(URI targetElementURI, String newName, ResourceSet resourceSet) {
    EObject targetElement = super.setName(targetElementURI, newName, resourceSet);
    if (targetElement == null) {
        throw new RefactoringException("Target element not loaded.");
    }
    if (targetElement instanceof ComponentImplementation && !newName.contains(".")) {
        ComponentImplementation ci = (ComponentImplementation) targetElement;
        ComponentType ct = ci.getType();
        newName = ct.getName() + "." + newName;
        ci.setName(newName);
    }
    return targetElement;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) EObject(org.eclipse.emf.ecore.EObject) RefactoringException(org.eclipse.xtext.ui.refactoring.impl.RefactoringException)

Aggregations

ComponentType (org.osate.aadl2.ComponentType)73 ComponentImplementation (org.osate.aadl2.ComponentImplementation)42 Classifier (org.osate.aadl2.Classifier)33 ComponentClassifier (org.osate.aadl2.ComponentClassifier)21 ArrayList (java.util.ArrayList)18 EObject (org.eclipse.emf.ecore.EObject)16 NamedElement (org.osate.aadl2.NamedElement)15 AnnexSubclause (org.osate.aadl2.AnnexSubclause)13 Feature (org.osate.aadl2.Feature)13 BasicEList (org.eclipse.emf.common.util.BasicEList)11 AadlPackage (org.osate.aadl2.AadlPackage)11 HashSet (java.util.HashSet)10 FeatureGroupType (org.osate.aadl2.FeatureGroupType)10 List (java.util.List)9 Subcomponent (org.osate.aadl2.Subcomponent)8 FeatureGroup (org.osate.aadl2.FeatureGroup)7 EList (org.eclipse.emf.common.util.EList)6 Property (org.osate.aadl2.Property)6 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)6 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)5