Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Is it possible to use RowSelectionModel in combination with GroupByLayer ?(There seem to be problems when Group-By is active with casts from GroupByObject to "MyRowBean")
Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1770286] Wed, 09 August 2017 16:05 Go to next message
Chris Lewold is currently offline Chris LewoldFriend
Messages: 13
Registered: July 2017
Junior Member
What I basically want to achieve is, that the user can select only rows, not single cells - so I wanted to use the RowSelectionModel.

However I also need the group-by feature.

As long as I do no grouping everything works fine. Once I drag a column to the "group by header area" I get ClassCastExceptions because GroupByObject cannot be cast to "MyRowBean".

The problem sounds obvious to me - RowSelectionModel likely expects just beans of a given type, and GroupByLayer suddenly introduces completely different beans for the GroupBy tree.

Did anyone ever mix these two features successfully ?

[Updated on: Wed, 09 August 2017 16:07]

Report message to a moderator

Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1770746 is a reply to message #1770286] Wed, 16 August 2017 17:12 Go to previous messageGo to next message
Didier Bolf is currently offline Didier BolfFriend
Messages: 3
Registered: August 2011
Junior Member
Hi Chris

we wrote some code based on this nattable example : "example _6051_GroupByExample"

and we added the following code to select rows rather that cells

SelectionLayer selectionLayer = bodyLayerStack.getSelectionLayer();
		
		selectionLayer.setSelectionModel(new RowSelectionModel<Object>(selectionLayer, 
				(IRowDataProvider) bodyLayerStack.getBodyDataLayer().getDataProvider(), 
        		new IRowIdAccessor<Object>() {
		        	public Serializable getRowId(Object rowObject)  {
		        		return rowObject.hashCode();
		        	}
				}, 
        		false
			));





that works well in our case
best regards

Didier
Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1771004 is a reply to message #1770746] Mon, 21 August 2017 05:50 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
The question is "where do you get ClassCastExceptions"? In NatTable code or in your own code? Typically there should only be a CCE when you are trying to cast in your IRowIdAccessor, and that should be solvable by your own.
Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1771374 is a reply to message #1771004] Thu, 24 August 2017 12:28 Go to previous messageGo to next message
Chris Lewold is currently offline Chris LewoldFriend
Messages: 13
Registered: July 2017
Junior Member
Uhm, well .....

IRowIdAccessor is a teplated class, with my "row data bean" as template argument.
I do not get the CCE - it happens before getRowId is invoked. I also cannot use e.g. Object as template argument, as then I cannot instantiate the RowSelectionModel, which itself is templated.

But ..... both you and Didier are of course correct. What I can do is
* not to use template arguments for both the IRowIdAccessor and the RowSelectionModel
* check the type of the passed class in getRowId
* return the proper id in case it is "MyDataBean" and hashcode otherwise. (basically I want to avoid hashCode as it is not necessarily unique).

Imho still a little bit hackish ;-) - but it seems to work ....

[Updated on: Thu, 24 August 2017 13:22]

Report message to a moderator

Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1771425 is a reply to message #1771374] Fri, 25 August 2017 05:05 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
Well, I'm not sure what you mean with "templated class", but it sounds like you are using some custom framework on top of NatTable. And therefore it is not a NatTable issue.
Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1771431 is a reply to message #1771425] Fri, 25 August 2017 05:50 Go to previous messageGo to next message
Chris Lewold is currently offline Chris LewoldFriend
Messages: 13
Registered: July 2017
Junior Member
package org.eclipse.nebula.widgets.nattable.data;

import java.io.Serializable;

public interface IRowIdAccessor<R> {

    public Serializable getRowId(R rowObject);

}



isn't R a template argument? Shouldn't this be the same as in the RowSelectionModel and shouldn't the "RowDataBean" class be used there?
... well maybe there is my misunderstanding - but if it is used like this, then you get the CCE I described (when activating grouping) .... so no, there is no other framework, this is native NatTable

Either way - if I use Object instead, and do the downcast in getRowId, then I'm able to handle the exception. Possibly it's not exactly as intended, but it works quite well.

[Updated on: Fri, 25 August 2017 05:51]

Report message to a moderator

Re: Is it possible to use RowSelectionModel in combination with GroupByLayer ? [message #1771435 is a reply to message #1771431] Fri, 25 August 2017 05:59 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
It is not a template, it is a generic. And yes if you use the GroupBy feature, than the objects in the list are not all of the same type and you need to use Object as generic type and perform the cast.

If you want to use the GroupBy feature, this is the way to go because we need to introduce objects of other types to the list to make it work. I don't know another way to make the grouping work with GlazedLists.
Previous Topic:How to use static filters
Next Topic:Best Practice about uncommon table layout
Goto Forum:
  


Current Time: Fri Sep 21 13:24:14 GMT 2018

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

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

Back to the top