Hi,
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());
editor.layout();
}
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());
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
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.getColumn().setWidth(110);
viewerSetValueColumn.setLabelProvider(new SelectVariableButtonLabelProvider(viewer, getAllVariables()));
Can someone Help me ? Thank you.