Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Best way to apply dynamic styling in 1.1
Best way to apply dynamic styling in 1.1 [message #1401503] Tue, 15 July 2014 18:12 Go to next message
Evan O\'Connell is currently offline Evan O\'ConnellFriend
Messages: 13
Registered: August 2013
Junior Member
To summarize, I need to apply a particular style to cell based on its data value at runtime.

For example, displaying negative numbers in red and positive in black.

The approach I took in 1.0 was to inspect the IDataLayer from a ColumnLabelAccumulator -- not the most performant solution but it worked. After upgrading to 1.1, I am experiencing a StackOverflowException. It turns out the new features added to the GroupByDataLayer require the #getDataValueByPosition method to invoke the ColumnLabelAcumulator. Thus, my solution creates an endless loop.


It looks like there are two examples releated to this: _001_Custom_styling_of_specific_cells and _002_Using_a_custom_cell_painter

- 001's solution uses a ColumnLabelAccumulator but assumes knoweledge of the cell's position ahead of time.

- 002's solution uses CellPainters to dynamically change the cell's background based on the cell's value.


Using 002 as an example, I created a new CellPainterWrapper that adds a "negative_number" label to the LabelStack if the cell's value is less than zero.

Would you recommend doing it this way?

[Updated on: Tue, 15 July 2014 18:30]

Report message to a moderator

Re: Best way to apply dynamic styling in 1.1 [message #1401514 is a reply to message #1401503] Tue, 15 July 2014 18:33 Go to previous messageGo to next message
Evan O\'Connell is currently offline Evan O\'ConnellFriend
Messages: 13
Registered: August 2013
Junior Member
<deleted duplicate>

[Updated on: Tue, 15 July 2014 21:45]

Report message to a moderator

Re: Best way to apply dynamic styling in 1.1 [message #1401609 is a reply to message #1401503] Tue, 15 July 2014 22:13 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1715
Registered: July 2012
Senior Member
No, I would not recommend doing it this way. The possible side effects might cause strange behavior like overriding the label stack at some time or something else.

The way to go is to use label accumulators. But I typically use the IDataProvider instead of the DataLayer to inspect the data value for applying additional labels.

Examples for that can be found in the Tutorial examples, e.g. ThemeStylingExample. Also the example code related to the German articles that are linked on our website are showing it this way. And if I remember correctly, it is an example in the styling documentation.
Re: Best way to apply dynamic styling in 1.1 [message #1401612 is a reply to message #1401514] Tue, 15 July 2014 22:17 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1715
Registered: July 2012
Senior Member
No I don't recommend doing it that way. Adding labels in a CellPainterWrapper is the wrong way to attach labels.

For attaching labels there is the concept of label accumulators. You are just seeing the default implementations, but you can also directly implement the interface. And typically you should inspect the DataLayer in your accumulator, but inspect the IDataProvider. There is an example for that in the documentation, in the Tutorial Examples the ThemeStylingExample is using it that way and the examples for the German articles show it that way.
Previous Topic:Mouse Event for certain Layer
Next Topic:Scrolling the Viewport uses the wrong IDisplayConverter
Goto Forum:
  


Current Time: Wed Jul 01 06:42:28 GMT 2015

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

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