Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [CNF] Selection, switching model & IElementComparer
[CNF] Selection, switching model & IElementComparer [message #670342] Fri, 13 May 2011 11:16
Eclipse UserFriend
Hello all,

I've been struggling with a strange behaviour of the CommonViewer for the past days, I hope someone here could explain to me what is going on.

Here's the pitch :
* I am using the CommonViewer (and lovin' it Wink )
* Elements represented in the tree of my viewer are mapped to regular Java beans
* Now here is the tough part : some user actions may switch the model beans with other beans. Let's say we got a bean A, provided by a content provider, mapped to an item in the tree. This bean could be switched by bean A1 on a specific user action.

The code of my application works "mostly" ok : events are intercepted, refresh is properly invoked on the common viewer.

The very important thing here is :
A IElementComparer is defined on the common viewer so that bean A and bean A1 are EQUALS : same hashCode and equals return true.


So far it works fine : when the model is switched, the display refreshes OK, tree expand / collapse state remains the same, etc.

The problem is the current selection of the common viewer. If I do nothing, the selection is not updated and the previous model (bean instance A) was still provided by the selection. That makes sense.

Now, when I explicitly set a selection containing the new model, through a call like :
final ISelectionProvider provider = 
         PlatformUI.getWorkbench().getActiveWorkbenchWindow()
         .getActivePage().getActivePart().getSite()
         .getSelectionProvider();
provider.setSelection(sel);


a very weird thing happens : setting a new selection with new elements does not set the selection. Therefore, I cannot make the selection with new model instances... It seems to come from the code TreeViewer:347 :
if(isSameSelection(items, current)) {
  return;
}


Therefore, calling getSelection from the currently active selection provider result in providing the old selection with the old beans. It also makes the commands wrongly enabled / disabled because they consider old objects.

The other weird thing is that I would have suspected that clicking on the exact same selection as the current one would not fix the problem since I thought it would have call the setSelection() on the same items, therefore falling in the same piece of code which would not adjust the selection... but it does work and switch to the proper selection.

I could also override the "isSameSelection" method to always return false but the javadoc says not to override.

So my question is : what is the best way to do this? Am I doing something risky with the framework ? Is there other parts that I should know which could work badly with what I am doing ?

Thanks,
Christophe
http://www.nextep-softwares.com
Previous Topic:Multipage editor
Next Topic:Mark specific table cell during selecting the whole row.
Goto Forum:
  


Current Time: Sat Jul 05 22:57:44 EDT 2025

Powered by FUDForum. Page generated in 0.02791 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top