Bug 111836 - 3.1.1 tree background problem
Summary: 3.1.1 tree background problem
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.2   Edit
Assignee: Steve Northover CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-06 15:49 EDT by Billy Biggs CLA Friend
Modified: 2005-10-06 16:41 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Billy Biggs CLA Friend 2005-10-06 15:49:22 EDT
From the eclipse.platform.swt newsgroup:

I am building a tree table using the new Tree functionality.  When setting 
the background on a TreeItem using SWT 3.1.1, only the item background color 
in the Tree is set.  The rest of the columns are not.  In SWT 3.1.0, the 
entire row background color was set.

The reason I need this to work is I have a recursive routine that alternates 
row color, much like the behaviour of tables in GTK when showGrid is true. 
I am using Windows, which of course shows a grid instead of alternating 
colors.  I call the routine after the tree is populated and when items are 
expanded or collapsed.

Any answers to this problem are appretiated.

If anyone is interested, here is a snippet from my custom viewer:

int ri;

  public void stripeRows(final TreeItem[] items)
  {
    ri = 0;
    Display.getDefault().asyncExec(new Runnable() {

      public void run()
      {
        traverseAndColor(items);
      }

    });
  }

  private void traverseAndColor(TreeItem[] items)
  {
    for (int i = 0; i < items.length; i++) {
      TreeItem item = items[i];
      if (ri % 2 == 0) {
        item.setBackground(evenColor);
        setControlsBackground(item, evenColor);
      }
      else {
        item.setBackground(oddColor);
        setControlsBackground(item, oddColor);
      }
      ri++;
      if (item.getExpanded())
        traverseAndColor(item.getItems());
    }
  }

  private void setControlsBackground(TreeItem item, Color color)
  {
    if (item.getData() != null && item.getData() instanceof Control[]) {
      Control[] controls = (Control[]) item.getData();
      for (Control control : controls)
        if (control != null) {
          control.setBackground(color);
        }
    }
  }
Comment 1 Billy Biggs CLA Friend 2005-10-06 16:39:41 EDT
Standalone example that reproduces the problem:

static Color even, odd;
static int pos;
public static void traverseAndColor(Display display, TreeItem[] items) {	
	for(int i = 0; i < items.length; i++) {
		TreeItem item = items[i];
		item.setBackground((pos++ & 1) == 0 ? even : odd);
		if (item.getExpanded()) {
			traverseAndColor(display, item.getItems());
		}
	}
}
public static void main(String [] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	even = display.getSystemColor(SWT.COLOR_GRAY);
	odd = display.getSystemColor(SWT.COLOR_WHITE);
	final Tree tree = new Tree(shell, SWT.FULL_SELECTION);
	TreeColumn c1 = new TreeColumn(tree, SWT.NONE);
	TreeColumn c2 = new TreeColumn(tree, SWT.NONE);
	TreeColumn c3 = new TreeColumn(tree, SWT.NONE);
	for(int i = 0; i < 5; i++) {
		TreeItem item = new TreeItem(tree, SWT.NONE);
		item.setText(new String[] { "Hello", "Root", "World" } );
		for(int j = 0; j < 5; j++) {
			TreeItem item2 = new TreeItem(item, SWT.NONE);
			item2.setText(new String[] { "Hello", "Sub", "World" });
		}
	}
	c1.pack(); c2.pack(); c3.pack();
	final Runnable runnable = new Runnable() {
		public void run() {
			pos = 0;
			traverseAndColor(display, tree.getItems());			
		};
	};
	Listener listener = new Listener() {
		public void handleEvent(Event event) {
			display.asyncExec(runnable);
		}
	};
	tree.addListener(SWT.Expand, listener);
	tree.addListener(SWT.Collapse, listener);
	runnable.run();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
Comment 2 Billy Biggs CLA Friend 2005-10-06 16:41:17 EDT
Note that to reproduce the problem, you must use SWT.FULL_SELECTION.  This was
caused by the fix for bug 106289 which has been backed out for 3.1.2.  I have
verified that with the change backed out, this problem goes away.

Marking as FIXED for 3.1.2.