Skip to main content



      Home
Home » Modeling » EMF » Explain ItemProviderAdapter.getTypeText implementation
Explain ItemProviderAdapter.getTypeText implementation [message #1743167] Mon, 12 September 2016 16:40 Go to next message
Eclipse UserFriend
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 01:30 Go to previous message
Eclipse UserFriend
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.
Previous Topic:[CDO] Updating package registry
Next Topic:Attribute vs Containment Reference Relationship
Goto Forum:
  


Current Time: Wed Jul 23 14:38:54 EDT 2025

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

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

Back to the top