Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TableViwer Alternating rows Colors (whene extending ObservableMapLabelProvider)
TableViwer Alternating rows Colors [message #1065514] Wed, 26 June 2013 05:14 Go to next message
AIT YAHIA Idir is currently offline AIT YAHIA Idir
Messages: 29
Registered: April 2013
Junior Member
Hello

i have implemented alternating rows color on my TableViewer, i have made some test with 30 000 rows :

without Color alternating i take 20 sec to load the table and 1 m 40 sec with colors alternating.

so my algorithm is not optimized for a table of this size,i would like to implement a m├ęthode demonstrated in this snippet

but it's not the same case, me i have extented ObservableMapLabelProvider (i have used a DataBinding,

public class CompteEntrysLabelProvider extends ObservableMapLabelProvider
		implements IColorProvider {

@Override
	public Color getBackground(Object element) {
	   
           WritableList list = new WritableList() ;
	   list= (WritableList) this.tableViewer.getInput();
	
	   int index = list.indexOf(element);
		
          if ((index % 2) == 0) {
			
			return gray; // color
			
		} else {
			return null;
		}

	
	}



}

where can i initialize the even variable in my case, or there is an other way to implement a more efficient algorithm.




with my thanks
icon14.gif  Re: TableViwer Alternating rows Colors [message #1065797 is a reply to message #1065514] Thu, 27 June 2013 09:52 Go to previous message
AIT YAHIA Idir is currently offline AIT YAHIA Idir
Messages: 29
Registered: April 2013
Junior Member
I have implemented my own method, what do you think about? I reduced the loading time of my TableViewer by half

public class CompteEntrysLabelProvider extends ObservableMapLabelProvider
		implements IColorProvider {

private boolean isEven = true;

public String getColumnText(Object element, int columnIndex) {

switch (columnIndex) {
	case 0:
		isEven = !isEven; //toggle isEven value each first column

		//get column 3 text
		
	
	case 1:
		//get column 2 text
		
	case 2:
		//get column 3 text
		
	case 3:
        
         default: return "";

}

@Override
 public Color getBackground(Object element) {
	
	//based on IsEven value we alternate the row color	
       if (isEven) {  return gray;} else {return null;	}

	
   }

}


I hope it will help more than one
Previous Topic:treeviewer resize issue
Next Topic:[Databinding] Howto add a single childs to the databinding properties for child nodes of a Treeviewe
Goto Forum:
  


Current Time: Sun Apr 20 04:15:11 EDT 2014

Powered by FUDForum. Page generated in 0.02023 seconds