Wednesday, December 29, 2010

Activating the EMF Edit ItemProvider AdapterFactory-s (with CDO)

I used to have a problem with CDO Editor UI: it does not use my EMF Edit models' ItemProvider implementation (like label formatting, image/icon, and so on).

Today I found the reason, I changed the model's nsURI and did not change all references to it.

The relevant portion is plugin.xml for your.model.edit plugin :

   <extension point="org.eclipse.emf.edit.itemProviderAdapterFactories">
      <factory
            uri="http://www.abispulsa.com/model/1.0"
            class="com.abispulsa.provider.AbispulsaItemProviderAdapterFactory"
            supportedTypes=
              "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
               org.eclipse.emf.edit.provider.IStructuredItemContentProvider
               org.eclipse.emf.edit.provider.ITreeItemContentProvider
               org.eclipse.emf.edit.provider.IItemLabelProvider
               org.eclipse.emf.edit.provider.IItemPropertySource"/>
   </extension>

The way to get ComposedAdapterFactory I previously blogged turned out to be incorrect:

public class AbispulsaContentProvider extends AdapterFactoryContentProvider {

private static AdapterFactory adapterFactory;

static {
adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
new ResourceItemProviderAdapterFactory(),
new AbispulsaItemProviderAdapterFactory(),
new ReflectiveItemProviderAdapterFactory()
});
}

public AbispulsaContentProvider() {
super(adapterFactory);
}

}

The correct way is like this:

public class AbispulsaContentProvider extends AdapterFactoryContentProvider {

private static ComposedAdapterFactory adapterFactory;

static {
Registry registry = EMFEditPlugin.getComposedAdapterFactoryDescriptorRegistry();
adapterFactory = new ComposedAdapterFactory(registry);
adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
}

public AbispulsaContentProvider() {
super(adapterFactory);
}

}

Although then you should move the ComposedAdapterFactory creation to another singleton class so it can be reused from both ContentProvider and LabelProvider.

Note that for above to work, the extension org.eclipse.emf.edit.itemProviderAdapterFactories must also be set properly.

This is actually not CDO specific, but applies to all EMF Edit / Editor UI in general.
But it highlights a very important CDO feature: it reuses your EMF Edit ItemProvider implementations! :-)

2 comments:

  1. Sure it was a wonderful weekend!, I'm happy for you!, your outfit is georgeous!
    Cheapest WOW Gold


    buy Crystal Saga Gold

    ReplyDelete
  2. Buy Diablo 3 Gold parent and also players My partner and i reach for about 2k+. But sometimes buy your figures direct as well as attempt jumping Guild Wars 2 Gems straight into Ds lite with an increase of Life Pressure.

    ReplyDelete