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,9 +29,7 @@ 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
@ -40,11 +38,15 @@ public class SystemAdapterHelpers
*/ */
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) {
// object is not an adaptable itself, call the adapter manager
adapter = (ISystemViewElementAdapter)Platform.getAdapterManager().getAdapter(o, ISystemViewElementAdapter.class); adapter = (ISystemViewElementAdapter)Platform.getAdapterManager().getAdapter(o, ISystemViewElementAdapter.class);
} }
return adapter; return adapter;
} }
@ -53,8 +55,7 @@ public class SystemAdapterHelpers
* 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);
@ -66,8 +67,7 @@ public class SystemAdapterHelpers
* 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) {
@ -81,13 +81,17 @@ public class SystemAdapterHelpers
* 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); // In case the object itself is an adaptable, call the objects getAdapter() method
else if (o instanceof IAdaptable) {
adapter = (ISystemRemoteElementAdapter)((IAdaptable)o).getAdapter(ISystemRemoteElementAdapter.class); 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; return adapter;
} }
@ -96,8 +100,7 @@ public class SystemAdapterHelpers
* 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 ISystemRemoteElementAdapter getRemoteAdapter(Object o, Viewer viewer) public static ISystemRemoteElementAdapter getRemoteAdapter(Object o, Viewer viewer) {
{
ISystemRemoteElementAdapter adapter = getRemoteAdapter(o); ISystemRemoteElementAdapter adapter = getRemoteAdapter(o);
if ((adapter != null) && (adapter instanceof ISystemViewElementAdapter)) if ((adapter != null) && (adapter instanceof ISystemViewElementAdapter))
((ISystemViewElementAdapter)adapter).setViewer(viewer); ((ISystemViewElementAdapter)adapter).setViewer(viewer);
@ -107,9 +110,7 @@ public class SystemAdapterHelpers
/** /**
* 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();
} }
} }