I am trying to set up a multi-column SWT Tree
(via a JFace TreeViewer
) that allows its columns to be re-ordered by the user by dragging the column headers. However, the first column should remain fixed and unmoveable. I can use the setMoveable(true)
method on each TreeColumn
except the first to get real close, but that doesn't prevent the user dragging a different column to the left of it. Any ideas how to resolve this?
Here's a simplified working snippet (without JFace) to illustrate the problem:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
public class TreeTableColumnMove {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.HORIZONTAL));
Tree tree = new Tree(shell, SWT.BORDER | SWT.CHECK);
tree.setLayoutData(new RowData(-1, 100));
tree.setHeaderVisible(true);
for (int i = 0; i < 5; i++) {
TreeColumn column = new TreeColumn(tree, SWT.CENTER);
column.setText("Col " + i);
column.setWidth(60);
if (i > 0) column.setMoveable(true);
}
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(new String[] { "c0", "c1", "c2", "c3", "c4" });
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}