Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Add buttons on a TreeViewer(button treeviewer LabelProvider java jface swt)
Add buttons on a TreeViewer [message #1842835] Fri, 02 July 2021 11:35
rose merel is currently offline rose merelFriend
Messages: 1
Registered: July 2021
Junior Member

I would like to add a button on some rows of my TreeViewer. To do that, I've used a method that I saw on a forum and it was working on a TableViewer.

I've implemented my own Label provider on the column where I want the button to be. So I've overriden the class update(ViewerCell cell) which calls my method addButton(cell):

	private void addButton(ViewerCell cell) {
		TreeItem item = (TreeItem) cell.getItem(); 
		Button btn = new Button((Composite) cell.getViewerRow().getControl(), SWT.NONE); 
		btn.setText(" select variable ");
		btn.addListener(SWT.Selection, new SelectVariableButtonListener(tree,
				DataTypeTreeUtils.getTreeNodeDataTypeInstance(cell.getElement()), viewer));

		TreeEditor editor = new TreeEditor(item.getParent());
		editor.grabHorizontal = true;
		editor.grabVertical = true;
		// editor.horizontalAlignment = SWT.RIGHT;
		editor.minimumWidth = btn.getSize().x + 110;
		editor.setEditor(btn, item, cell.getColumnIndex());

It's almost working. Except that the buttons of the column of buttons is duplicated when I want to extend the column.

The left "column of buttons'' : is completely working. The buttons are functional and they adapt themself to the extension of the nodes in the tree Viewer.

The right "column of buttons" : is fixed on the viewer and the buttons are not completely functional. And when I want to extend or not the nodes in the tree, the buttons are not corresponding to their rows anymore. (These are also the buttons in the foreground).

So I would like to not have the right columns which probably appeared because of a bug. I think this could be due to the composite to which the button is initialized :

Or just because buttons are simply bugging when they are on Tree Viewers ? The same method is working on Table Viewers.

Just in case and if it helps, this is the declaration of the viewer:
viewer = new TreeViewer(treeContainer, SWT.FULL_SELECTION);
		viewer.setContentProvider(new TreeNodeTreeContentProvider());
		viewer.setLabelProvider(new CustomColumnLabelProvider());

and this is the declaration of the column where I want to add the buttons:

		//column with the buttons "select variable"
		TreeViewerColumn viewerSetValueColumn = new TreeViewerColumn(viewer, SWT.NONE);
		viewerSetValueColumn.setLabelProvider(new SelectVariableButtonLabelProvider(viewer, getAllVariables()));

Can someone Help me ? Thank you.
Previous Topic:The code in my Java project isn't finding the imports from a referenced library
Next Topic:System.console() missing
Goto Forum:

Current Time: Thu Oct 28 07:49:52 GMT 2021

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

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

Back to the top