final BindingComparator comparator = new BindingComparator();
comparator.setSortColumn(0);
// Create the columns for the tree.
final TreeColumn commandNameColumn = new TreeColumn(tree, SWT.LEFT,
BindingLabelProvider.COLUMN_COMMAND);
commandNameColumn
.setText(NewKeysPreferenceMessages.CommandNameColumn_Text);
tree.setSortColumn(commandNameColumn);
tree.setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
commandNameColumn.addSelectionListener(new ResortColumn(comparator,
commandNameColumn, tree, BindingLabelProvider.COLUMN_COMMAND));
final TreeColumn triggerSequenceColumn = new TreeColumn(tree, SWT.LEFT,
BindingLabelProvider.COLUMN_TRIGGER_SEQUENCE);
triggerSequenceColumn
.setText(NewKeysPreferenceMessages.TriggerSequenceColumn_Text);
triggerSequenceColumn.addSelectionListener(new ResortColumn(comparator,
triggerSequenceColumn, tree,
BindingLabelProvider.COLUMN_TRIGGER_SEQUENCE));
final TreeColumn whenColumn = new TreeColumn(tree, SWT.LEFT,
BindingLabelProvider.COLUMN_WHEN);
whenColumn.setText(NewKeysPreferenceMessages.WhenColumn_Text);
whenColumn.addSelectionListener(new ResortColumn(comparator,
whenColumn, tree, BindingLabelProvider.COLUMN_WHEN));
final TreeColumn categoryColumn = new TreeColumn(tree, SWT.LEFT,
BindingLabelProvider.COLUMN_CATEGORY);
categoryColumn.setText(NewKeysPreferenceMessages.CategoryColumn_Text);
categoryColumn.addSelectionListener(new ResortColumn(comparator,
categoryColumn, tree, BindingLabelProvider.COLUMN_CATEGORY));
final TreeColumn userMarker = new TreeColumn(tree, SWT.LEFT,
BindingLabelProvider.COLUMN_USER);
userMarker.setText(NewKeysPreferenceMessages.UserColumn_Text);
userMarker.addSelectionListener(new ResortColumn(comparator,
userMarker, tree, BindingLabelProvider.COLUMN_USER));
// Set up the providers for the viewer.
final TreeViewer viewer = filteredTree.getViewer();
viewer.setLabelProvider(new BindingLabelProvider());