Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Explain ItemProviderAdapter.getTypeText implementation
Explain ItemProviderAdapter.getTypeText implementation [message #1743167] Mon, 12 September 2016 20:40 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
So you don't have to look it up:

/**
   * This looks up the name of the type of the specified object.
   */
  protected String getTypeText(Object object)
  {
    if (object instanceof EObject)
    {
      EObject eObject = ((EObject)object);
      String typeKey = eObject.eClass().getName();
      List<Adapter> originalAdapters = new ArrayList<Adapter>(eObject.eAdapters());
      try
      {
        return getResourceLocator(object).getString("_UI_" + typeKey + "_type");
      }
      catch (MissingResourceException e)
      {
        return typeKey;
      }
      finally
      {
        eObject.eAdapters().retainAll(originalAdapters);
      }
    }
    return getString("_UI_Unknown_type");
  }


I am just curious about the finally {} block? Is there some hidden adapter attachment that needs to be undone before completion?
Re: Explain ItemProviderAdapter.getTypeText implementation [message #1743179 is a reply to message #1743167] Tue, 13 September 2016 05:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31917
Registered: July 2009
Senior Member
Felix,

Yes, the resource locator might attach a new adapter, potentially one from a different factory.

  protected ResourceLocator getResourceLocator(Object anyObject)
  {
    if (adapterFactory instanceof ComposeableAdapterFactory)
    {
      Object adapter = ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory().adapt(anyObject, IItemLabelProvider.class);
      if (adapter instanceof ResourceLocator)
      {
        return (ResourceLocator)adapter;
      }
    }

    return getResourceLocator();
  }

The getTypeText method is called on new children in org.eclipse.emf.edit.provider.ItemProviderAdapter.getCreateChildDescription(Object, Object, Object, Collection<?>) so all children ever created for each create child command (and that happens each time the selection is changed) would tend to leak until the editor itself is disposed. The code as written avoids that problem.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Updating package registry
Next Topic:Attribute vs Containment Reference Relationship
Goto Forum:
  


Current Time: Wed Jun 23 05:12:34 GMT 2021

Powered by FUDForum. Page generated in 0.01375 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top