Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 189298

Summary: Improve PropertySourceAdapterFactory
Product: [Tools] GEF Reporter: Patrick Sodre <psodre>
Component: GEF-Legacy GEF (MVC)Assignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: evan38109, hudsonr, nyssen
Version: unspecified   
Target Milestone: 3.8.0 (Juno)   
Hardware: All   
OS: All   
Whiteboard:

Description Patrick Sodre CLA 2007-05-26 19:39:46 EDT
Build ID: I20070517-1700

Steps To Reproduce:
This is an enhancement and there is a reasonable workaround.

I would like that org.eclipse.gef.internal.PropertySourceAdapter also checked with the Platform.getAdapterManager() to see if the model can be adapted to an IPropertySource.

More information:

I faced this "requirement" when coding a GEF editor for a "eclipse adverse" third-party model that cannot be modified. I imagine this would be useful for anyone trying to extend/reuse 3rd-party models.
Comment 1 Evan Cowden CLA 2009-03-12 15:49:23 EDT
The purpose of the org.eclipse.gef.internal.PropertySourceAdapter seems to be to redirect the creation of a IPropertySource from an AbstractEditPart to the edit part's model.  However, it does this by examining the model and either: 1. If it is an IPropertySource, return the model directly; or, 2. If it is IAdaptable,  calling it's getAdapter() method.  The platform adapter manager is never queried.

This means that in order to be an IPropertySource, GEF models must directly implement IAdaptable; registering an IAdapterFactory will not work.

A proposed fix would be: change org.eclipse.gef.internal.PropertySourceAdapter, line 28 from:

  return ((IAdaptable)model).getAdapter(adapterType);

to:

  Platform.getAdapterManager().getAdapter(model, adapterType);
Comment 2 Alexander Nyßen CLA 2011-09-27 18:06:00 EDT
Re-scheduling to 3.8, as this is an enhancement that changes the current behavior, even if it is not API-visible.
Comment 3 Alexander Nyßen CLA 2011-09-27 18:08:25 EDT
Changed implementation of getAdapter() within PropertySourceAdapterFactory to fall back to platform's adapter manager as follows:

public Object getAdapter(Object adaptableObject, Class adapterType) {
		AbstractEditPart part = (AbstractEditPart) adaptableObject;
		Object model = part.getModel();
		// check if model is already of the desired adapter type
		if (adapterType.isInstance(model)) {
			return model;
		}
		// check if model is adaptable and does provide an adapter of the
		// desired type
		if (model instanceof IAdaptable) {
			Object adapter = ((IAdaptable) model).getAdapter(adapterType);
			if (adapter != null) {
				return adapter;
			}
		}
		// fall back to platform's adapter manager
		return Platform.getAdapterManager().getAdapter(model, adapterType);
	}

Committed changes to cvs HEAD (3.8). Resolving as fixed.