Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using e3x property view with e4 Selection service from EMF Model

I built a small e4 RCP application containing both an "e4 xmi" tree view populated by emf generated model code (using ComposedAdapterFactory) and an "e3 properties view".

Tried following "dirksmetric tutorial" to display property view in application.e4xmi (shared elements) with an empty property view.

To get a tree's selected element displayed in my property sheet (IItemPropertySource), I did the following things :

  • On my e4 treeviewer side, I use the e4 selection service in #createComposite:

    // Register the viewer as a selection provider (to be consumed by the property view...) viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); // set the selection to the service selectionService.setSelection( selection.size() == 1? selection.getFirstElement(): selection.toArray()); } });

  • On the e3 "classical" property sheet side, I defined a couple of things :

    1. I called IDE.registerAdapters in my ApplicationWorkbenchAdvisor#initialize.
    2. I declared my property source adapter as follow in my plugin.xml :

    extension point="org.eclipse.core.runtime.adapters"> factory adaptableType="org.eclipse.emf.ecore.EObject" class="myappmodeler.properties.ModelPropertiesAdapter"> adapter type="org.eclipse.ui.views.properties.IPropertySource">

    1. My ModelPropertiesAdapter#getAdapter returns a property source :

    public Object getAdapter(Object adaptableObject, Class adapterType) { if (adapterType== IPropertySource.class && adaptableObject instanceof EObject){ emfGlobalFactory = new ComposedAdapterFactory(); emfGlobalFactory.addAdapterFactory(new RepositorystructureItemProviderAdapterFactory()); emfGlobalFactory.addAdapterFactory(new ApplicationItemProviderAdapterFactory()); emfGlobalFactory.addAdapterFactory(new ServiceItemProviderAdapterFactory()); return new AdapterFactoryContentProvider(emfGlobalFactory).getPropertySource(adaptableObject); } return null; }

My problem is this adapter is not even executed.

Currently using Eclipse neon (it was recently updated to synchronise E3 and E4 selection service) https://bugs.eclipse.org/bugs/show_bug.cgi?id=403930

like image 957
WattoWatto Avatar asked Aug 25 '16 09:08

WattoWatto


1 Answers

There are different ways to fix this problem, but for my case, these are the steps

I took to these steps to solve mine

  1. Take control of the base model - create an interface which extends EObject
  2. Create custom property provider, source and descriptor - extends org.eclipse.emf.edit.ui.provider.*
    • at runtime we need IItemPropertySource
  3. Create a content provider class (extends AdapterFactoryContentProvider) and override createPropertySource with custom property source
  4. Note; I also developed a table layout which means implementing custom ItemProvider (implement ITableItemLabelProvider) for individual elements in the model

Worked perfectly with ESelectionService

Hope these notes helps somebody

like image 104
WattoWatto Avatar answered Oct 24 '22 11:10

WattoWatto