Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 474397 - TreeViewer shows wrong content
Summary: TreeViewer shows wrong content
Status: CLOSED DUPLICATE of bug 466499
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: 4.5.1   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 475502 (view as bug list)
Depends on:
Blocks: 471956
  Show dependency tree
 
Reported: 2015-08-06 06:13 EDT by Lukas Schmidt CLA
Modified: 2015-12-08 14:49 EST (History)
3 users (show)

See Also:


Attachments
Screen shot running I20150805-2000 (15.36 KB, image/png)
2015-08-06 08:55 EDT, Sravan Kumar Lakkimsetti CLA
no flags Details
after start on mars 4.5 (40.20 KB, image/jpeg)
2015-08-06 09:16 EDT, Lukas Schmidt CLA
no flags Details
after selecting second tree node on mars 4.5 (40.27 KB, image/jpeg)
2015-08-06 09:16 EDT, Lukas Schmidt CLA
no flags Details
after selecting second then first tree node on mars 4.5 (41.40 KB, image/jpeg)
2015-08-06 09:17 EDT, Lukas Schmidt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Schmidt CLA 2015-08-06 06:13:07 EDT
The little test program works as expected if I use the old Eclipse Luna jars:

org.eclipse.core.commands_3.6.100.v20140528-1422.jar
org.eclipse.equinox.common_3.6.200.v20130402-1505.jar
org.eclipse.jface_3.10.2.v20141021-1035.jar
org.eclipse.swt.gtk.linux.x86_64_3.103.2.v20150203-1351.jar
org.eclipse.swt_3.103.2.v20150203-1313.jar

but if I switch to the ones provided with Eclipse Mars:

org.eclipse.core.commands_3.7.0.v20150422-0725.jar
org.eclipse.equinox.common_3.7.0.v20150402-1709.jar
org.eclipse.jface_3.11.0.v20150602-1400.jar
org.eclipse.swt.gtk.linux.x86_64_3.104.0.v20150528-0211.jar
org.eclipse.swt_3.104.0.v20150528-0211.jar

the behavior breaks. The content of the TreeViewer only shows one entry repeatedly The entry that is shown depends on the line you click on. All very wrong and disturbing.

I don't know if this affects other versions than mine (Linux (Kubuntu 15.04, KDE Plasma 5.2.2, Qt 5.4.1, Kernel 3.19.0-22, 64 bit)

Here is the test program:

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.layout.TreeColumnLayout;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;


public class JFaceTreeBug {

	public class GameRefsTreeContentProvider implements ITreeContentProvider {
		private List<GameRef> gameRefs;

		@Override
		public void dispose() {
		}

		@SuppressWarnings("unchecked")
		@Override
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			this.gameRefs = (List<GameRef>)newInput;
		}

		@Override
		public Object[] getElements(Object inputElement) {
			return gameRefs.toArray();
		}

		@Override
		public Object[] getChildren(Object parentElement) {		
			if (parentElement instanceof GameRef){
				GameRef gameRef = (GameRef)parentElement;

				if (gameRef.getGames() != null){
					return gameRef.getGames().toArray();
				}
			}
			return null;
		}

		@Override
		public Object getParent(Object element) {
			if (element instanceof Game){
				return ((Game)element).getParent();
			}
			return null;
		}

		@Override
		public boolean hasChildren(Object element) {
			if (this.getChildren(element)!=null && this.getChildren(element).length > 0) return true;
			return false;
		}
	}

	public class Game {
		private String name;
		private GameRef parent;

		public Game(String name, GameRef parent) {
			super();
			setName(name);
			setParent(parent);
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}

		public GameRef getParent() {
			return parent;
		}

		public void setParent(GameRef parent) {
			this.parent = parent;
			this.getParent().getGames().add(this);
		}

	}

	public class GameRef {

		private String name;
		private List<Game> games;

		public GameRef(String name) {
			super();
			this.name = name;
			this.games = new ArrayList<>();
		}

		public List<Game> getGames() {
			return games;
		}

		public String getName() {
			return name;
		}

	}


	public static void main(String[] args) {


		final Display display = new Display();
		final Shell shell = new Shell(display);

		shell.setText("Hello, world!");
		shell.setLayout(new RowLayout());

		final Composite composite = new Composite(shell, SWT.NONE);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		composite.setLayout(gridLayout);

		Label label = new Label(composite, SWT.SHADOW_NONE);
		label.setText("Tree");

		final Composite referenceGamesTreeCmpst = new Composite(composite, SWT.NONE);
		GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, true, 1, 1);
		gd.grabExcessVerticalSpace = true;
		gd.minimumHeight = 190;
		gd.heightHint = 250;
		gd.widthHint = 1008;
		referenceGamesTreeCmpst.setLayoutData(gd);

		//Add TreeColumnLayout
		TreeColumnLayout layout = new TreeColumnLayout();
		referenceGamesTreeCmpst.setLayout(layout);

		TreeViewer treeViewer = new TreeViewer(referenceGamesTreeCmpst, SWT.BORDER);
		Tree tree = treeViewer.getTree();
		tree.setHeaderVisible(true);


		TreeViewerColumn tvColName = new TreeViewerColumn(treeViewer, SWT.NONE);
		tvColName.getColumn().setText("name");
		layout.setColumnData(tvColName.getColumn(), new ColumnPixelData(70, true, true));
		tvColName.setLabelProvider(new StyledCellLabelProvider() {
			@Override
			public void update(ViewerCell cell) {
				if (cell.getElement() instanceof Game){
					cell.setText(((Game)cell.getElement()).getName());
				}
				else if (cell.getElement() instanceof GameRef){
					cell.setText(((GameRef)cell.getElement()).getName());
				}


				super.update(cell);
			}

		});
		TreeViewerColumn tvColType = new TreeViewerColumn(treeViewer, SWT.NONE);
		tvColType.getColumn().setText("type");
		layout.setColumnData(tvColType.getColumn(), new ColumnPixelData(70, true, true));
		tvColType.setLabelProvider(new StyledCellLabelProvider() {
			@Override
			public void update(ViewerCell cell) {
				if (cell.getElement() instanceof Game){
					cell.setText("game");
				}
				else if (cell.getElement() instanceof GameRef){
					cell.setText("ref game");
				}

				super.update(cell);
			}

		});

		JFaceTreeBug test = new JFaceTreeBug();
		List<GameRef> gameRefs = new ArrayList<>();
		GameRef gr1 = test.new GameRef("ref 1");
		GameRef gr2 = test.new GameRef("ref 2");

		Game g11 = test.new Game("g11", gr1);
		Game g12 = test.new Game("g12", gr1);

		Game g21 = test.new Game("g21", gr2);

		gameRefs.add(gr1);
		gameRefs.add(gr2);

		treeViewer.setContentProvider(test.new GameRefsTreeContentProvider());
		treeViewer.setInput(gameRefs);




		shell.open();
		// Set up the event loop.
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				// If no more entries in the event queue
				display.sleep();
			}
		}
		display.dispose();
	}
}
Comment 1 Sravan Kumar Lakkimsetti CLA 2015-08-06 08:55:48 EDT
Created attachment 255666 [details]
Screen shot running I20150805-2000

I got the following screenshot using the latest I build I20150805-2000

Please let me know whether this is expected result

I am using Ubuntu 15.10 with Unity desktop
Comment 2 Lukas Schmidt CLA 2015-08-06 09:15:19 EDT
This is how it should look when the tree is fully expanded, yes. I will attach what i see.
Comment 3 Lukas Schmidt CLA 2015-08-06 09:16:24 EDT
Created attachment 255667 [details]
after start on mars 4.5
Comment 4 Lukas Schmidt CLA 2015-08-06 09:16:56 EDT
Created attachment 255668 [details]
after selecting second tree node on mars 4.5
Comment 5 Lukas Schmidt CLA 2015-08-06 09:17:28 EDT
Created attachment 255669 [details]
after selecting second then first tree node on mars 4.5
Comment 6 Lukas Schmidt CLA 2015-08-06 09:28:04 EDT
I forgot to mention, that I use the RCP/RAP developer edition of Eclipse, not the standard edition. I don't know if that makes a difference. 

In them moment I can't moce to mars because of this. I maintain a couple of RCP applications the use TreeView and they are affected by this. Strangely, all TreeViewers within the IDE itself look fine and seem to work normally.
Comment 7 Sravan Kumar Lakkimsetti CLA 2015-08-07 08:10:40 EDT
I am able to reproduce this problem in Mars release. This problem is not reproducible in 4.6 M1 (which will be released by this week). We will identify the fix and push it to 4.5.1
Comment 8 Lukas Schmidt CLA 2015-08-07 08:30:01 EDT
Thank you. that is good news.
Comment 9 Alexander Kurtakov CLA 2015-08-07 08:52:58 EDT
Probably fix for bug 466499 .
Comment 10 Sravan Kumar Lakkimsetti CLA 2015-08-10 07:41:20 EDT
Hi Alex,

Can you please review the code and push it to maintenance branch

https://git.eclipse.org/r/#/c/53470/

Thanks
Sravan
Comment 11 Arun Thondapu CLA 2015-08-10 08:43:33 EDT

*** This bug has been marked as a duplicate of bug 466499 ***
Comment 12 Arun Thondapu CLA 2015-08-21 08:00:32 EDT
*** Bug 475502 has been marked as a duplicate of this bug. ***