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