use of org.geotoolkit.sml.xml.v101.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);
}
use of org.geotoolkit.sml.xml.v101.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);
}
use of org.geotoolkit.sml.xml.v101.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();
}
}
use of org.geotoolkit.sml.xml.v101.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);
}
use of org.geotoolkit.sml.xml.v101.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;
}
Aggregations