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;
}
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();
}
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);
}
}
}
}
}
}
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);
}
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;
}
Aggregations