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

Bug 97780

Summary: [Model] Make BaseWorkbenchContentProvider and LabelProvider adapter manager friendly
Product: [Eclipse Project] Platform Reporter: Jean-Michel Lemieux <jean-michel_lemieux>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P5 CC: bokowski, charles, eclipse, gunnar, jeffmcaffer, michaelvanmeekeren, paulk, Tod_Creasey
Version: 3.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug
Bug Depends on: 118560    
Bug Blocks:    
Attachments:
Description Flags
patch to BaseWorkbenchContentProvider and LabelProvider
none
Modified patch none

Description Jean-Michel Lemieux CLA 2005-05-31 23:34:55 EDT
I'm sorry I missed this way back in M5, but I just realized that I hadn't
submitted patches to enable the Workbench's default content and label providers
to use the adapter factory. Actually, the example we are using in the RCP book
shows how to use adapters and was reminded that this example is still broken.

I've attached a patch that you can apply against v20050526-1200 that fixed both
these classes and allows you to put objects into viewers that *don't* have to
implement IAdaptable directly, instead you can register an adapter for them.
This is very useful when you are adding objects into a viewer from a 3rd party
library and you can't change their code. See Bug 86362 for more discussions
about other places in the Workbench that have been changed to do this same kind
of check. I actually submitted the patch for this a long time ago and just
forgot about this case. 

So why do I think this should be put into 3.1? Well, for starters it's really
part of the improved action contribution plan item and was just plain forgotten.
It's a low risk fix because the IAdaptable check is still done in the same
order, which in case of existing viewers would mean that this is the code that
will still run. If the object is not adaptable, then the adapter manager is
checked. There is a small performance hit if the objects don't adapt to
IAdaptable but since this was enforced, it won't affect any existing plug-ins. 

The only contraversal issue in the patch is that IAdapterManager.loadAdapter()
is called instead of getAdapter(). This is for the same reason as stated in Bug
86362.
Comment 1 Jean-Michel Lemieux CLA 2005-05-31 23:35:26 EDT
Created attachment 22119 [details]
patch to BaseWorkbenchContentProvider and LabelProvider
Comment 2 Nick Edgar CLA 2005-06-01 10:11:15 EDT
I'm willing to consider this, but only if the performance impact is negligible.
 We use these in many of the views.
Do you have any feeling (or preferably measurements) showing the performance impact?
Comment 3 Jean-Michel Lemieux CLA 2005-06-01 13:11:00 EDT
I didn't re-run the Workbench performance tests, but they should catch any
performance issues. But for the record, let's have a look at the proposed
changes and compare them with the old code:

protected IWorkbenchAdapter getAdapter(Object element) {
  IWorkbenchAdapter adapter = null;
  if (element instanceof IAdaptable)
    adapter = (IWorkbenchAdapter) ((IAdaptable) element)
      .getAdapter(IWorkbenchAdapter.class);
  if (adapter == null)
    adapter = (IWorkbenchAdapter) Platform.getAdapterManager()
      .loadAdapter(element, IWorkbenchAdapter.class.getName());
  return adapter;
}

And compare it to the previous code:

protected IWorkbenchAdapter getAdapter(Object element) {  
  if (!(element instanceof IAdaptable)) {
    return null;
  }
  return (IWorkbenchAdapter) ((IAdaptable) element)
    .getAdapter(IWorkbenchAdapter.class);
}

For all existing views the first IAdaptable check would succeed and as it did
before. The failure case, which means that the adapters were broken, would mean
looking up in the adapter manager. What I think then is that this won't have a
performance impact on any existing viewers, but any new viewers that show
objects that don't implement IAdaptable would be a bit slower because of the
extra adapter manager call. But there is a catch, some implementations of
IAdaptable already called the adapter manager already, so this won't affect them
either.
Comment 4 Nick Edgar CLA 2005-06-01 13:30:21 EDT
> some implementations of IAdaptable already called the adapter manager already,
so this won't affect them either.

The typical case is for getAdapter to call
Platform.getAdapterManager().getAdapter(...), which doesn't activate plug-ins,
so it's still possible for the loadAdapter case to cause activation.

But I agree with your assessment for the existing resource-based viewers, so I'm
OK with this going in for RC2.
Comment 5 Jean-Michel Lemieux CLA 2005-06-01 16:23:01 EDT
thanks 
Comment 6 Nick Edgar CLA 2005-06-06 22:25:22 EDT
MvM: +1?
Comment 7 Michael Van Meekeren CLA 2005-06-07 08:07:39 EDT
+1, but I'd like to see the before + after performance test results first just
to make sure.
Comment 8 Nick Edgar CLA 2005-06-07 16:23:34 EDT
I've decided not to add this in 3.2 due to performance concenrs.  The
loadAdapter case happens more frequently than anticipated due to getFont always
looking for an IWorkbenchAdapter2, which resources don't adapt to.
Comment 9 Nick Edgar CLA 2005-06-07 16:25:58 EDT
Created attachment 22564 [details]
Modified patch 

This patch has the following changes to the one provided by JM:
- getAdapter2 is private (didn't want to introduce new API at this stage)
- added null check, since loadAdapter doesn't handle a null element, and the
Navigator's frame source was trying to get the label for null (previously did
not fail due to the instanceof check)
- various other Javadoc cleanup
Comment 10 Nick Edgar CLA 2005-06-07 16:28:45 EDT
Re "allows you to put objects into viewers that *don't* have to implement
IAdaptable directly", note that this can be accomplished via the regular label-
and content-provider mechanism.  It's not required that they use
BaseWorkbenchContentProvider and WorkbenchLabelProvider, and go through the
IWorkbenchAdapter redirection.

Will reassess in 3.2.

Comment 11 Nick Edgar CLA 2005-12-22 10:28:20 EST
*** Bug 120965 has been marked as a duplicate of this bug. ***
Comment 12 Nick Edgar CLA 2006-03-15 11:19:26 EST
Reassigning bugs in component areas that are changing ownership.
Comment 13 Tod Creasey CLA 2006-03-15 14:29:30 EST
Not for 3.2
Comment 14 Boris Bokowski CLA 2006-09-12 15:18:00 EDT
Tod, as part of the fix for bug 156581, BaseWorkbenchContentProvider and LabelProvider should now be adapter manager friendly.  However, getAdapter() is called instead of loadAdapter().  We can leave this bug open to discuss whether in this case, loadAdapter() is the better choice, like it was for bug 86362.
Comment 15 Susan McCourt CLA 2009-07-09 19:19:59 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 16 Eclipse Webmaster CLA 2019-09-06 16:16:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 17 Eclipse Genie CLA 2022-02-20 17:16:01 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.