Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » addColumnsIndexesToGroup
addColumnsIndexesToGroup [message #902214] Thu, 16 August 2012 07:54 Go to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
Hi,

I found when I add a column indexes to group the name of the column group name must be unique. In my
case the group name displayed in the table has the same name more then once.

How can I resolve this?

The wanted table layout

+-----------------------+
| A | B | C |
+-----------------------+
| a | b | a | b | a | b |
+-----------------------+
| | | | | | |
+-----------------------+
| | | | | | |
+-----------------------+
| | | | | | |
+-----------------------+


Martin
Re: addColumnsIndexesToGroup [message #902225 is a reply to message #902214] Thu, 16 August 2012 08:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1066
Registered: July 2012
Senior Member
Hi,

looking at your table layout, what you want to do is create column groups with the name A, B and C that contain columns with that have same names. This is working fine with NatTable. So I don't understand what is not working for you?

Greez,
Dirk
Re: addColumnsIndexesToGroup [message #902230 is a reply to message #902225] Thu, 16 August 2012 08:55 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
Yes you are right. I missed one group level to simplify the example. Actually I need 4 header rows
using groups. The final design is.

One problem I found is to give unique names to the column group and the other is the number of group
layers. There is the class ColumnGroupGroupHeaderLayer which need a ColumnGroupHeaderLayer as
constructor argument but cant handle ColumnGroupGroupHeaderLayer as argument to construct multi
level groups.

+-----------------------------------------------+
| AAA | BBB |
+-----------------------------------------------+
| AA | BB | AA |
+-----------------------------------------------+
| A | B | C | C | C | C |
+-----------------------------------------------+
| a | b | a | b | a | b | a | b | a | b | a | b |
+-----------------------------------------------+
| | | | | | | | | | | | |
+-----------------------------------------------+
| | | | | | | | | | | | |
+-----------------------------------------------+
| | | | | | | | | | | | |
+-----------------------------------------------+


What I did so fare:

IDataProvider dataProvider = new BodyDataProvider();
IDataProvider colHeaderDataProvider = new ColHeaderDataProvider();
IDataProvider rowHeaderDataProvider = new RowHeaderDataProvider();
BodyLayerStack bodyLayer = new BodyLayerStack(dataProvider);
ColumnHeaderLayerStack columnHeaderLayer = new ColumnHeaderLayerStack(colHeaderDataProvider, bodyLayer);
RowHeaderLayerStack rowHeaderLayer = new RowHeaderLayerStack(rowHeaderDataProvider, bodyLayer);
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(colHeaderDataProvider,
rowHeaderDataProvider);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(cornerDataProvider), rowHeaderLayer,
columnGroupHeaderLayerNetwork);
GridLayer gridLayer = new GridLayer(bodyLayer, columnGroupHeaderLayerNetwork, rowHeaderLayer,
cornerLayer);
natTable = new NatTable(parent, gridLayer);


public class ColumnHeaderLayerStack extends AbstractLayerTransform {
public ColumnHeaderLayerStack(IDataProvider dataProvider, BodyLayerStack pBodyLayer) {
DataLayer dataLayer = new DataLayer(dataProvider);
ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer, pBodyLayer,
pBodyLayer.getSelectionLayer());

ColumnGroupModel columnGroupModelTrack = new ColumnGroupModel();
columnGroupHeaderLayerTrack = new ColumnGroupHeaderLayer(colHeaderLayer,
pBodyLayer.getSelectionLayer(), columnGroupModelTrack);
columnGroupHeaderLayerTrack.addColumnsIndexesToGroup("", 0, 1);

ColumnGroupModel columnGroupModelLine = new ColumnGroupModel();
ColumnGroupHeaderLayer columnGroupHeaderLayerLine = new
ColumnGroupHeaderLayer(columnGroupHeaderLayerTrack, pBodyLayer.getSelectionLayer(),
columnGroupModelLine);
columnGroupHeaderLayerLine.addColumnsIndexesToGroup("", 0, 1);

ColumnGroupModel columnGroupModelNetwork = new ColumnGroupModel();
columnGroupHeaderLayerNetwork = new ColumnGroupGroupHeaderLayer(columnGroupHeaderLayerLine,
pBodyLayer.getSelectionLayer(), columnGroupModelNetwork);
columnGroupHeaderLayerNetwork.addColumnsIndexesToGroup("", 0, 1);

....
addColumnsIndexesToGroup to all 3 group level
....

setUnderlyingLayer(colHeaderLayer);
}
}



Dirk Fauth wrote, On 16.08.2012 14:32:
> Hi,
>
> looking at your table layout, what you want to do is create column groups with the name A, B and C
> that contain columns with that have same names. This is working fine with NatTable. So I don't
> understand what is not working for you?
>
> Greez,
> Dirk
Re: addColumnsIndexesToGroup [message #902232 is a reply to message #902230] Thu, 16 August 2012 09:16 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1066
Registered: July 2012
Senior Member
Hi,

I'm sorry to say that, but what you are trying to do is currently not supported by NatTable out of the box. We're aware of this, but currently only two grouping levels are supported. So you can have a ColumnHeaderLayer, ColumnGroupHeaderLayer and a ColumnGroupGroupHeaderLayer. The last one is quite old and in fact should be removed with some more generic ColumnGroupHeaderLayer that supports n levels of grouping. But we didn't had time yet to look at this.

There is already a Bugzilla item for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=379940

At the moment the only thing you can do is to create your own ColumnGroupGroupGroupHeaderLayer (yes, not a really good solution) like the ColumnGroupGroupHeaderLayer that fits your needs. Alternatively you can create some generic ColumnGroupHeaderLayer that supports n levels of grouping (and contribute if you like to).

Regarding the grouping by name, I'm not sure how to solve this at the moment. I guess we have to rethink the whole grouping mechanism there.

Greez,
Dirk
Re: addColumnsIndexesToGroup [message #902236 is a reply to message #902232] Thu, 16 August 2012 09:27 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
Thanks for ur quick answer.
I have to get more familiar with NatTable before starting to do changes or extensions. Re the
grouping by name I could give the group a unique name internally but want to display not unique
names. Is there a concept of label providers for that?

Martin

Dirk Fauth wrote, On 16.08.2012 15:16:
> Hi,
>
> I'm sorry to say that, but what you are trying to do is currently not supported by NatTable out of
> the box. We're aware of this, but currently only two grouping levels are supported. So you can have
> a ColumnHeaderLayer, ColumnGroupHeaderLayer and a ColumnGroupGroupHeaderLayer. The last one is quite
> old and in fact should be removed with some more generic ColumnGroupHeaderLayer that supports n
> levels of grouping. But we didn't had time yet to look at this.
>
> There is already a Bugzilla item for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=379940
>
> At the moment the only thing you can do is to create your own ColumnGroupGroupGroupHeaderLayer (yes,
> not a really good solution) like the ColumnGroupGroupHeaderLayer that fits your needs. Alternatively
> you can create some generic ColumnGroupHeaderLayer that supports n levels of grouping (and
> contribute if you like to).
>
> Regarding the grouping by name, I'm not sure how to solve this at the moment. I guess we have to
> rethink the whole grouping mechanism there.
>
> Greez,
> Dirk
Re: addColumnsIndexesToGroup [message #902237 is a reply to message #902236] Thu, 16 August 2012 09:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1066
Registered: July 2012
Senior Member
Something like that. You can configure your own CellPainter for the column groups. You have to set another configuration to your instance of ColumnGroupHeaderLayer. The default is DefaultColumnGroupHeaderLayerConfiguration where the ColumnGroupHeaderTextPainter is configured as cell painter. You can either create your own configuration and set this instead of the default, or override the cell painter configuration for the ColumnGroupHeaderLayer by registering your own painter. In your own painter you can then interprete your unique key to the value you want to show.

Writing this there might be another more easy solution. You can write a DisplayConverter which you have to attach to the GridRegion.COLUMN_GROUP_HEADER. And your DisplayConverter is than responsible for converting your keys to the display values you want to show.

Hope this helps.

Greez,
Dirk
Re: addColumnsIndexesToGroup [message #902644 is a reply to message #902237] Thu, 16 August 2012 10:06 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
I try the DisplayConverter but not sure how to register. I try:
natTable.getConfigRegistry().registerConfigAttribute(GridRegion.COLUMN_GROUP_HEADER, new
DisplayConverter(){
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
return "canonicalValue";
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return "displayValue";
}});

but this does not compile.

Where and how should I register my own display converter?

Martin

Dirk Fauth wrote, On 16.08.2012 15:37:
> Something like that. You can configure your own CellPainter for the column groups. You have to set
> another configuration to your instance of ColumnGroupHeaderLayer. The default is
> DefaultColumnGroupHeaderLayerConfiguration where the ColumnGroupHeaderTextPainter is configured as
> cell painter. You can either create your own configuration and set this instead of the default, or
> override the cell painter configuration for the ColumnGroupHeaderLayer by registering your own
> painter. In your own painter you can then interprete your unique key to the value you want to show.
>
> Writing this there might be another more easy solution. You can write a DisplayConverter which you
> have to attach to the GridRegion.COLUMN_GROUP_HEADER. And your DisplayConverter is than responsible
> for converting your keys to the display values you want to show.
>
> Hope this helps.
>
> Greez,
> Dirk
Re: addColumnsIndexesToGroup [message #902645 is a reply to message #902644] Thu, 16 August 2012 10:19 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
OK got it how to satisfy the linker:
natTable = new NatTable(sashForm_1, gridLayer);
natTable.getConfigRegistry().registerConfigAttribute(new ConfigAttribute<DisplayConverter>(),
new DisplayConverter() {
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
return "canonicalValue";
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return "displayValue";
}
}, GridRegion.COLUMN_GROUP_HEADER);


but the above specified DisplayConverter get never called. What to do to get it work?

Martin

Martin Jacob wrote, On 16.08.2012 16:06:
> I try the DisplayConverter but not sure how to register. I try:
> natTable.getConfigRegistry().registerConfigAttribute(GridRegion.COLUMN_GROUP_HEADER, new
> DisplayConverter(){
> @Override
> public Object canonicalToDisplayValue(Object canonicalValue) {
> return "canonicalValue";
> }
> @Override
> public Object displayToCanonicalValue(Object displayValue) {
> return "displayValue";
> }});
>
> but this does not compile.
>
> Where and how should I register my own display converter?
>
> Martin
>
> Dirk Fauth wrote, On 16.08.2012 15:37:
>> Something like that. You can configure your own CellPainter for the column groups. You have to set
>> another configuration to your instance of ColumnGroupHeaderLayer. The default is
>> DefaultColumnGroupHeaderLayerConfiguration where the ColumnGroupHeaderTextPainter is configured as
>> cell painter. You can either create your own configuration and set this instead of the default, or
>> override the cell painter configuration for the ColumnGroupHeaderLayer by registering your own
>> painter. In your own painter you can then interprete your unique key to the value you want to show.
>>
>> Writing this there might be another more easy solution. You can write a DisplayConverter which you
>> have to attach to the GridRegion.COLUMN_GROUP_HEADER. And your DisplayConverter is than responsible
>> for converting your keys to the display values you want to show.
>>
>> Hope this helps.
>>
>> Greez,
>> Dirk
Re: addColumnsIndexesToGroup [message #902646 is a reply to message #902645] Thu, 16 August 2012 11:43 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
The DisplayConverter works now, see the picture and coresponding code below:

natTable = new NatTable(sashForm_1, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER,
new DisplayConverter() {

@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
if (canonicalValue instanceof String) {
String[] lStrings = ((String) canonicalValue).split("/");
if (lStrings.length > 2) {
return lStrings[lStrings.length - 1];
}
}
return canonicalValue;
}

@Override
public Object displayToCanonicalValue(Object displayValue) {
return displayValue;
}
}, DisplayMode.NORMAL, GridRegion.COLUMN_GROUP_HEADER);
natTable.configure();



Martin

Martin Jacob wrote, On 16.08.2012 16:19:
> OK got it how to satisfy the linker:
> natTable = new NatTable(sashForm_1, gridLayer);
> natTable.getConfigRegistry().registerConfigAttribute(new ConfigAttribute<DisplayConverter>(),
> new DisplayConverter() {
> @Override
> public Object canonicalToDisplayValue(Object canonicalValue) {
> return "canonicalValue";
> }
> @Override
> public Object displayToCanonicalValue(Object displayValue) {
> return "displayValue";
> }
> }, GridRegion.COLUMN_GROUP_HEADER);
>
>
> but the above specified DisplayConverter get never called. What to do to get it work?
>
> Martin
>
> Martin Jacob wrote, On 16.08.2012 16:06:
>> I try the DisplayConverter but not sure how to register. I try:
>> natTable.getConfigRegistry().registerConfigAttribute(GridRegion.COLUMN_GROUP_HEADER, new
>> DisplayConverter(){
>> @Override
>> public Object canonicalToDisplayValue(Object canonicalValue) {
>> return "canonicalValue";
>> }
>> @Override
>> public Object displayToCanonicalValue(Object displayValue) {
>> return "displayValue";
>> }});
>>
>> but this does not compile.
>>
>> Where and how should I register my own display converter?
>>
>> Martin
>>
>> Dirk Fauth wrote, On 16.08.2012 15:37:
>>> Something like that. You can configure your own CellPainter for the column groups. You have to set
>>> another configuration to your instance of ColumnGroupHeaderLayer. The default is
>>> DefaultColumnGroupHeaderLayerConfiguration where the ColumnGroupHeaderTextPainter is configured as
>>> cell painter. You can either create your own configuration and set this instead of the default, or
>>> override the cell painter configuration for the ColumnGroupHeaderLayer by registering your own
>>> painter. In your own painter you can then interprete your unique key to the value you want to show.
>>>
>>> Writing this there might be another more easy solution. You can write a DisplayConverter which you
>>> have to attach to the GridRegion.COLUMN_GROUP_HEADER. And your DisplayConverter is than responsible
>>> for converting your keys to the display values you want to show.
>>>
>>> Hope this helps.
>>>
>>> Greez,
>>> Dirk
Re: addColumnsIndexesToGroup [message #902650 is a reply to message #902237] Fri, 17 August 2012 01:41 Go to previous messageGo to next message
Martin Jacob is currently offline Martin Jacob
Messages: 116
Registered: July 2009
Senior Member
Hi Dirk,

may be its possible to use Object as the key for the column group in ColumnGroupModel instead of the
column group name? Do you see any problem with this?

Martin

Dirk Fauth wrote, On 16.08.2012 15:37:
> Something like that. You can configure your own CellPainter for the column groups. You have to set
> another configuration to your instance of ColumnGroupHeaderLayer. The default is
> DefaultColumnGroupHeaderLayerConfiguration where the ColumnGroupHeaderTextPainter is configured as
> cell painter. You can either create your own configuration and set this instead of the default, or
> override the cell painter configuration for the ColumnGroupHeaderLayer by registering your own
> painter. In your own painter you can then interprete your unique key to the value you want to show.
>
> Writing this there might be another more easy solution. You can write a DisplayConverter which you
> have to attach to the GridRegion.COLUMN_GROUP_HEADER. And your DisplayConverter is than responsible
> for converting your keys to the display values you want to show.
>
> Hope this helps.
>
> Greez,
> Dirk
Re: addColumnsIndexesToGroup [message #902731 is a reply to message #902650] Mon, 20 August 2012 03:44 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1066
Registered: July 2012
Senior Member
Hi,

I will have a look at this after my vacation. For the moment just a hint on configurations. Every layer has its own configuration. Therefore it's more NatTable Style to override the ColumnGroupHeaderLayer configuration (think it is the DefaultColumnGroupHeaderConfiguration) instead of registering directly on the NatTable. But this is just a hint, your way also works.

Greez,
Dirk
Previous Topic:IDataProvider
Next Topic:collapse column groups
Goto Forum:
  


Current Time: Sat Apr 19 18:34:15 EDT 2014

Powered by FUDForum. Page generated in 0.01972 seconds