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! :-)

6 comments:

  1. Anytime you come to our site to buy Cheapest WOW Gold , you can contact with our live help. Just click the “Live Help” on the World Of Warcraft Gold page, our professional customer server will reply you. Through this way, you can ask anything about our site about World of Warcraft, we will try our best to let you satisfied to Gold WOW.

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


    buy Crystal Saga Gold

    ReplyDelete
  3. 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
  4. With a dramatically improved user experience and intelligent drawing tools and templates, Microsoft Project Standard 2010 Download makes every step in creating diagrams easier.
    Project 2010 Download contains enhanced functionality for basic copying and pasting project information while retaining formatting and column heading information.
    Visio 2010 Download helps business and creative professionals communicate and collaborate more effectively and securely with virtually anyone, anywhere. Unify a wide range of content in a single organized PDF Portfolio. Collaborate through electronic document reviews. Create and manage dynamic forms. And help protect sensitive information.

    ReplyDelete