Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Right way to traverse cells and apply styles ?
Right way to traverse cells and apply styles ? [message #1153274] Thu, 24 October 2013 13:51 Go to next message
SD Khan is currently offline SD KhanFriend
Messages: 63
Registered: May 2013
Member
Hi Dirk !

Actually i am applying styles on the base of data, like mark cell red if it contains value "0" (zero). I have applied labels already and for applying styles i used the following way to do it

getDataLayer().setConfigLabelAccumulator(new IConfigLabelAccumulator()
{
    @Override
    public void accumulateConfigLabels(LabelStack labels,int columnPos,int rowPos) 
    {
	 int rowIndex = dsTable.getRowIndexByPosition(rowPosition);
	 int columnIndex = dsTable.getColumnIndexByPosition(columnPosition);
	                
	 Object value = getDataValue(int rowIndex, int columnIndex)
	                
	 if(columnIndex == 0)
         {
	    if(value.toString().contains("0"))
            { 
	        setCellStyleAtPosition(rowPosition,columnPosition,colStyle);
	    }
	 }
     });
}
	


The styles get applied successfully but i think this is not the right way , as the above way is used when some one has to accumulate labels. while i am only traversing the cells, Is this way is fine to do the job? or Is there any other way through which i can traverse all the cells , whenever the labels are accumulated or updated ?
Re: Right way to traverse cells and apply styles ? [message #1153300 is a reply to message #1153274] Thu, 24 October 2013 14:11 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Sorry, but what are yu doing there?

For such styling you just add your labels to the label stack and register styles for the labels. Completely seperated from each other. Have a look at the documentation or the examples.

Use the ConfigRegistry to register a style for a label, like creati g a new AbstractRegistryConfiguration, but not directly in a label accumulator.
Re: Right way to traverse cells and apply styles ? [message #1154659 is a reply to message #1153300] Fri, 25 October 2013 11:04 Go to previous messageGo to next message
SD Khan is currently offline SD KhanFriend
Messages: 63
Registered: May 2013
Member
Inside this function
setCellStyleAtPosition(rowPosition,columnPosition,colStyle);
i am actually using config registry to apply styles, it's the helper method.

Actually, i wants to apply style on the base of data value present in the cell. For example if cell value is "200" then style will be applied on it but if i change the value from "200" to "356" then style should not be there now. So, for that case styles should be applied dynamically every time.
Re: Right way to traverse cells and apply styles ? [message #1154696 is a reply to message #1154659] Fri, 25 October 2013 11:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
No that is wrong!

You apply a label dependent on the value. And you register a style for that label via AbstractRegistryConfiguration. If you change the value, an update gets triggered, the label accumulator is asked again for the labels and won't apply the label as the value has changed.

This is explained in the conditional styling section of the documentation: http://www.eclipse.org/nattable/documentation.php?page=styling

You don't need to register the style everytime a label is added, you just create a configuration once and add it to your NatTable!
Re: Right way to traverse cells and apply styles ? [message #1154763 is a reply to message #1154696] Fri, 25 October 2013 12:36 Go to previous message
SD Khan is currently offline SD KhanFriend
Messages: 63
Registered: May 2013
Member
Yup, i got your point.

Thanks!
SD Khan
Previous Topic:Release Cycle
Next Topic:how to accumulate labels and apply painters on row header layer ?
Goto Forum:
  


Current Time: Fri Apr 19 23:25:20 GMT 2024

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

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

Back to the top