Search in sources :

Example 1 with AgreeActivator

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;
// }
// }
// }
// }
// });
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ComponentClassifier(org.osate.aadl2.ComponentClassifier) EmbeddedEditorFactory(org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory) AadlPackage(org.osate.aadl2.AadlPackage) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) AgreeActivator(com.rockwellcollins.atc.agree.ui.internal.AgreeActivator) Injector(com.google.inject.Injector) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) LabelProvider(org.eclipse.jface.viewers.LabelProvider) NamedElement(org.osate.aadl2.NamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with AgreeActivator

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;
}
Also used : AgreeActivator(com.rockwellcollins.atc.agree.ui.internal.AgreeActivator) GlobalURIEditorOpener(org.eclipse.xtext.ui.editor.GlobalURIEditorOpener) Injector(com.google.inject.Injector)

Aggregations

Injector (com.google.inject.Injector)2 AgreeActivator (com.rockwellcollins.atc.agree.ui.internal.AgreeActivator)2 EObject (org.eclipse.emf.ecore.EObject)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 ListViewer (org.eclipse.jface.viewers.ListViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 GlobalURIEditorOpener (org.eclipse.xtext.ui.editor.GlobalURIEditorOpener)1 EmbeddedEditorFactory (org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory)1 AadlPackage (org.osate.aadl2.AadlPackage)1 ComponentClassifier (org.osate.aadl2.ComponentClassifier)1 NamedElement (org.osate.aadl2.NamedElement)1 InstanceObject (org.osate.aadl2.instance.InstanceObject)1 BusinessObjectContext (org.osate.ge.BusinessObjectContext)1