@Override
    public void widgetSelected(SelectionEvent e) {
        if (!(e.getSource() instanceof TableColumn)) {
            throw new IllegalArgumentException("Can only sort TableColumns.");
        }

        TableColumn currentCol = (TableColumn) e.getSource();

        if (lastSelection != null && lastSelection.equals(currentCol)) {
            if (dir == Direction.ASCENDING) {
                dir = Direction.DESCENDING;
            }
            else {
                dir = Direction.ASCENDING;
            }
        }

        lastSelection = currentCol;

        int columnIndex = Arrays.asList(viewer.getTable().getColumns()).indexOf(e.getSource());
        comparator.setCurrentColumnIndex(columnIndex);
        comparator.setDirection(dir);
        viewer.getTable().setSortDirection(dir.getValue());
        viewer.getTable().setSortColumn(currentCol);
        viewer.refresh();

    }