use of com.rockwellcollins.atc.agree.ui.internal.AgreeActivator in project AGREE by loonwerks.
the class GenericPropertySection method createControls.
@Override
public void createControls(final Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
final Composite composite = getWidgetFactory().createPlainComposite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
// Create Statement List Viewer
listViewer = new ListViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
listViewer.setContentProvider(ArrayContentProvider.getInstance());
listViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
final String name = getName(element);
String suffix = "";
final NamedElement container = getContainingPackageOrComponentClassifier(element);
if (container != null) {
suffix = " (" + container.getQualifiedName() + ")";
}
return name + suffix;
}
private NamedElement getContainingPackageOrComponentClassifier(final Object obj) {
if (obj instanceof ComponentClassifier) {
return (ComponentClassifier) obj;
} else if (obj instanceof AadlPackage) {
return (AadlPackage) obj;
} else if (obj instanceof EObject) {
return getContainingPackageOrComponentClassifier(((EObject) obj).eContainer());
} else if (obj instanceof BusinessObjectContext) {
return getContainingPackageOrComponentClassifier(((BusinessObjectContext) obj).getBusinessObject());
} else if (obj != null) {
return getContainingPackageOrComponentClassifier(Adapters.adapt(obj, BusinessObjectContext.class));
} else {
return null;
}
}
});
listViewer.addDoubleClickListener(event -> {
onOpenSource();
});
listViewer.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).create());
// Create viewer for the selected element
final AgreeActivator agreeActivator = AgreeActivator.getInstance();
final Injector injector = agreeActivator.getInjector(AgreeActivator.COM_ROCKWELLCOLLINS_ATC_AGREE_AGREE);
final EmbeddedEditorResourceProvider resourceProvider = injector.getInstance(EmbeddedEditorResourceProvider.class);
final EmbeddedEditorFactory editorFactory = injector.getInstance(EmbeddedEditorFactory.class);
editor = editorFactory.newEditor(resourceProvider).readOnly().withParent(composite);
model = editor.createPartialEditor();
// Register handler for when selected element changes
listViewer.addSelectionChangedListener(event -> {
onSelectionChanged();
});
// Add Buttons
final Composite buttons = getWidgetFactory().createPlainComposite(composite, SWT.NONE);
buttons.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).create());
buttons.setLayout(RowLayoutFactory.fillDefaults().wrap(false).create());
addBtn = getWidgetFactory().createButton(buttons, "Add", SWT.PUSH);
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onAdd();
}
});
deleteBtn = getWidgetFactory().createButton(buttons, "Delete", SWT.PUSH);
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onDelete();
}
});
openSourceBtn = getWidgetFactory().createButton(buttons, "Open AADL Source", SWT.PUSH);
openSourceBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onOpenSource();
}
});
// TODO: Experimental focus listener that allows updating the model with changes. However, issues regarding proper handling of errors when the viewer
// loses focus needs to be handled. See comments in the code.
// When using this listener, the editor should not be configured as read-only.
// editor.getViewer().getControl().addFocusListener(new FocusListener() {
// private EObject elementBeingEdited = null;
//
// @Override
// public void focusGained(final FocusEvent e) {
// final IStructuredSelection elementSelection = listViewer.getStructuredSelection();
// if (elementSelection.size() == 1) {
// elementBeingEdited = (EObject) elementSelection.getFirstElement();
// }
// }
//
// @Override
// public void focusLost(final FocusEvent e) {
// if (elementBeingEdited != null) {
// // TODO: Check if a change was actually made?
//
// final EObject originalElementBeingEdited = elementBeingEdited;
//
// try {
// try {
// editor.getDocument().readOnly(res -> {
// final EObject newObj = res.getContents().get(0);
//
// // Test serialization
// res.getSerializer().serialize(newObj);
//
// PropertySectionUtil.execute(Operation.create(op -> {
// final IStructuredSelection selection = listViewer.getStructuredSelection();
// final EObject obj = (EObject) selection.getFirstElement();
// op.map((tag) -> StepResultBuilder.create(obj).build()).modifyPreviousResult(o -> {
// EcoreUtil.replace(o, newObj);
// return StepResultBuilder.create().build();
// });
// }));
//
// return null;
// });
// } finally {
// elementBeingEdited = null;
// }
//
// } catch (final RuntimeException ex) {
// // TODO: Message wording
// switch (MessageDialog.open(MessageDialog.ERROR, null, "Error Updating Model",
// "Error updating model.",
// SWT.NONE, "Edit", "Revert")) {
// // Edit
// case 0:
// // TODO: Selecting edit can result in the same message appearing because if the selection in the diagram has changed, the entire
// // property section will lose focus.
// editor.getViewer().getControl().setFocus();
// elementBeingEdited = originalElementBeingEdited;
// break;
//
// // Revert
// case 1:
// updateSourceViewer();
// break;
// }
// }
// }
// }
// });
}
use of com.rockwellcollins.atc.agree.ui.internal.AgreeActivator in project AGREE by loonwerks.
the class AgreeUtils method getGlobalURIEditorOpener.
public static GlobalURIEditorOpener getGlobalURIEditorOpener() {
if (globalURIEditorOpener == null) {
AgreeActivator activator = AgreeActivator.getInstance();
String language = AgreeActivator.COM_ROCKWELLCOLLINS_ATC_AGREE_AGREE;
Injector injector = activator.getInjector(language);
globalURIEditorOpener = injector.getInstance(GlobalURIEditorOpener.class);
}
return globalURIEditorOpener;
}
Aggregations