1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-20 22:55:51 +02:00

[fix] 174418 SystemAdapterHelpers.getAdapter(Object) try to find adapter twice

This commit is contained in:
Uwe Stieber 2007-02-16 10:26:08 +00:00
parent 881441ad83
commit 084a3ce496

View file

@ -29,87 +29,88 @@ import org.eclipse.rse.ui.view.SystemViewAdapterFactory;
/** /**
* This class has static helper methods that will get an adapter given an object. * This class has static helper methods that will get an adapter given an object.
*/ */
public class SystemAdapterHelpers public class SystemAdapterHelpers {
{
/**
/**
* Returns the implementation of ISystemViewElement for the given * Returns the implementation of ISystemViewElement for the given
* object. Returns null if the adapter is not defined or the * object. Returns null if the adapter is not defined or the
* object is not adaptable. * object is not adaptable.
*/ */
public static ISystemViewElementAdapter getAdapter(Object o) { public static ISystemViewElementAdapter getAdapter(Object o) {
ISystemViewElementAdapter adapter = null; ISystemViewElementAdapter adapter = null;
// In case the object itself is an adaptable, call the objects getAdapter() method
if (o instanceof IAdaptable) { if (o instanceof IAdaptable) {
adapter = (ISystemViewElementAdapter) ((IAdaptable) o).getAdapter(ISystemViewElementAdapter.class); adapter = (ISystemViewElementAdapter)((IAdaptable)o).getAdapter(ISystemViewElementAdapter.class);
} if (o != null) { } else if (o != null) {
adapter = (ISystemViewElementAdapter) Platform.getAdapterManager().getAdapter(o, ISystemViewElementAdapter.class); // object is not an adaptable itself, call the adapter manager
adapter = (ISystemViewElementAdapter)Platform.getAdapterManager().getAdapter(o, ISystemViewElementAdapter.class);
} }
return adapter; return adapter;
} }
/** /**
* Overload to use when calling from a viewer. This not only finds and returns * Overload to use when calling from a viewer. This not only finds and returns
* the adapter, but also sets its viewer to the given viewer. Many actions rely * the adapter, but also sets its viewer to the given viewer. Many actions rely
* on this being set. * on this being set.
*/ */
public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer) public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer) {
{ ISystemViewElementAdapter adapter = getAdapter(o);
ISystemViewElementAdapter adapter = getAdapter(o); if (adapter != null)
if (adapter != null) adapter.setViewer(viewer);
adapter.setViewer(viewer); return adapter;
return adapter; }
}
/** /**
* Overload to use when calling from a viewer. This not only finds and returns * Overload to use when calling from a viewer. This not only finds and returns
* the adapter, but also sets its viewer and input provider to the given viewer. * the adapter, but also sets its viewer and input provider to the given viewer.
* Many actions rely on this being set. * Many actions rely on this being set.
*/ */
public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer, ISystemViewInputProvider inputProvider) public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer, ISystemViewInputProvider inputProvider) {
{ ISystemViewElementAdapter adapter = getAdapter(o, viewer);
ISystemViewElementAdapter adapter = getAdapter(o, viewer);
if (adapter != null) { if (adapter != null) {
adapter.setInput(inputProvider); adapter.setInput(inputProvider);
} }
return adapter; return adapter;
} }
/** /**
* Returns the implementation of ISystemRemoteElementAdapter for the given * Returns the implementation of ISystemRemoteElementAdapter for the given
* remote object. Returns null if this object does not adaptable to this. * remote object. Returns null if this object does not adaptable to this.
*/ */
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o) public static ISystemRemoteElementAdapter getRemoteAdapter(Object o) {
{ ISystemRemoteElementAdapter adapter = null;
ISystemRemoteElementAdapter adapter = null;
if (!(o instanceof IAdaptable))
adapter = (ISystemRemoteElementAdapter)Platform.getAdapterManager().getAdapter(o,ISystemRemoteElementAdapter.class);
else
adapter = (ISystemRemoteElementAdapter)((IAdaptable)o).getAdapter(ISystemRemoteElementAdapter.class);
return adapter;
}
/** // In case the object itself is an adaptable, call the objects getAdapter() method
* Overload to use when calling from a viewer. This not only finds and returns if (o instanceof IAdaptable) {
* the adapter, but also sets its viewer to the given viewer. Many actions rely adapter = (ISystemRemoteElementAdapter)((IAdaptable)o).getAdapter(ISystemRemoteElementAdapter.class);
* on this being set. } else if (o != null) {
*/ // object is not an adaptable itself, call the adapter manager
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o, Viewer viewer) adapter = (ISystemRemoteElementAdapter)Platform.getAdapterManager().getAdapter(o, ISystemRemoteElementAdapter.class);
{ }
ISystemRemoteElementAdapter adapter = getRemoteAdapter(o);
if ((adapter != null) && (adapter instanceof ISystemViewElementAdapter)) return adapter;
((ISystemViewElementAdapter)adapter).setViewer(viewer); }
return adapter;
} /**
* Overload to use when calling from a viewer. This not only finds and returns
* the adapter, but also sets its viewer to the given viewer. Many actions rely
* on this being set.
*/
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o, Viewer viewer) {
ISystemRemoteElementAdapter adapter = getRemoteAdapter(o);
if ((adapter != null) && (adapter instanceof ISystemViewElementAdapter))
((ISystemViewElementAdapter)adapter).setViewer(viewer);
return adapter;
}
/** /**
* For pathpath access to our adapters for non-local objects in our model. Exploits the knowledge we use singleton adapters. * For pathpath access to our adapters for non-local objects in our model. Exploits the knowledge we use singleton adapters.
*/ */
public SystemViewAdapterFactory getSystemViewAdapterFactory() public SystemViewAdapterFactory getSystemViewAdapterFactory() {
{
return RSEUIPlugin.getDefault().getSystemViewAdapterFactory(); return RSEUIPlugin.getDefault().getSystemViewAdapterFactory();
} }
} }