1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-20 06:35:50 +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
* the adapter, but also sets its viewer to the given viewer. Many actions rely
* on this being set.
*/
public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer)
{
ISystemViewElementAdapter adapter = getAdapter(o);
if (adapter != null)
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 and input provider to the given viewer.
* Many actions rely on this being set.
*/
public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer, ISystemViewInputProvider inputProvider)
{
ISystemViewElementAdapter adapter = getAdapter(o, viewer);
if (adapter != null) {
adapter.setInput(inputProvider);
}
return adapter;
}
/** /**
* Returns the implementation of ISystemRemoteElementAdapter for the given * Overload to use when calling from a viewer. This not only finds and returns
* remote object. Returns null if this object does not adaptable to this. * the adapter, but also sets its viewer to the given viewer. Many actions rely
*/ * on this being set.
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o) */
{ public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer) {
ISystemRemoteElementAdapter adapter = null; ISystemViewElementAdapter adapter = getAdapter(o);
if (!(o instanceof IAdaptable)) if (adapter != null)
adapter = (ISystemRemoteElementAdapter)Platform.getAdapterManager().getAdapter(o,ISystemRemoteElementAdapter.class); adapter.setViewer(viewer);
else return adapter;
adapter = (ISystemRemoteElementAdapter)((IAdaptable)o).getAdapter(ISystemRemoteElementAdapter.class); }
return adapter;
} /**
* 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.
* Overload to use when calling from a viewer. This not only finds and returns * Many actions rely on this being set.
* the adapter, but also sets its viewer to the given viewer. Many actions rely */
* on this being set. public static ISystemViewElementAdapter getAdapter(Object o, Viewer viewer, ISystemViewInputProvider inputProvider) {
*/ ISystemViewElementAdapter adapter = getAdapter(o, viewer);
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o, Viewer viewer)
{ if (adapter != null) {
ISystemRemoteElementAdapter adapter = getRemoteAdapter(o); adapter.setInput(inputProvider);
if ((adapter != null) && (adapter instanceof ISystemViewElementAdapter)) }
((ISystemViewElementAdapter)adapter).setViewer(viewer);
return adapter; return adapter;
} }
/**
* Returns the implementation of ISystemRemoteElementAdapter for the given
* remote object. Returns null if this object does not adaptable to this.
*/
public static ISystemRemoteElementAdapter getRemoteAdapter(Object o) {
ISystemRemoteElementAdapter adapter = null;
// In case the object itself is an adaptable, call the objects getAdapter() method
if (o instanceof IAdaptable) {
adapter = (ISystemRemoteElementAdapter)((IAdaptable)o).getAdapter(ISystemRemoteElementAdapter.class);
} else if (o != null) {
// object is not an adaptable itself, call the adapter manager
adapter = (ISystemRemoteElementAdapter)Platform.getAdapterManager().getAdapter(o, ISystemRemoteElementAdapter.class);
}
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();
} }
} }