- // protected Table createTable(Composite parent) {
- // // TODO use a more flexible API
- // Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- // table.setLinesVisible(true);
- // table.setHeaderVisible(true);
- // TableColumn column = new TableColumn(table, SWT.LEFT, 0);
- // column.setText("Username");
- // column.setWidth(100);
- // column = new TableColumn(table, SWT.LEFT, 1);
- // column.setText("Displayed name");
- // column.setWidth(150);
- // column = new TableColumn(table, SWT.LEFT, 2);
- // column.setText("E-mail");
- // column.setWidth(100);
- // column = new TableColumn(table, SWT.LEFT, 3);
- // column.setText("First Name");
- // column.setWidth(100);
- // column = new TableColumn(table, SWT.LEFT, 4);
- // column.setText("Last Name");
- // column.setWidth(100);
- // column = new TableColumn(table, SWT.LEFT, 5);
- // column.setText("Status");
- // column.setWidth(50);
- // column = new TableColumn(table, SWT.LEFT, 6);
- // column.setText("Description");
- // column.setWidth(200);
- // return table;
- // }
-
- // private class UsersLabelProvider extends LabelProvider implements
- // ITableLabelProvider {
- // public String getColumnText(Object element, int columnIndex) {
- // try {
- // Node userHome = (Node) element;
- // Node userProfile = userHome.getNode(ARGEO_PROFILE);
- // switch (columnIndex) {
- // case 0:
- // String username = userHome.getProperty(ARGEO_USER_ID)
- // .getString();
- // if (username.equals(session.getUserID()))
- // return "[" + username + "]";
- // else
- // return username;
- // case 1:
- // return getProperty(userProfile, Property.JCR_TITLE);
- // case 2:
- // return getProperty(userProfile, ARGEO_PRIMARY_EMAIL);
- // case 3:
- // return getProperty(userProfile, ARGEO_FIRST_NAME);
- // case 4:
- // return getProperty(userProfile, ARGEO_LAST_NAME);
- // case 5:
- // return userProfile.getProperty(ARGEO_ENABLED).getBoolean() ? ""
- // : "disabled";
- // case 6:
- // return getProperty(userProfile, Property.JCR_DESCRIPTION);
- // default:
- // throw new ArgeoException("Unmanaged column " + columnIndex);
- // }
- // } catch (RepositoryException e) {
- // throw new ArgeoException("Cannot get text", e);
- // }
- // }
- //
- // public Image getColumnImage(Object element, int columnIndex) {
- // return null;
- // }
- //
- // }
+ private SelectionAdapter getSelectionAdapter(final int index) {
+ SelectionAdapter selectionAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ UsersViewerComparator comparator = (UsersViewerComparator) viewer
+ .getComparator();
+
+ if (index == comparator.getSortColumn()) {
+ comparator.setAscending(!comparator.isAscending());
+ }
+ comparator.setSortColumn(index);
+ viewer.getTable().setSortColumn(
+ viewer.getTable().getColumn(index));
+ viewer.getTable().setSortDirection(
+ comparator.isAscending() ? SWT.UP : SWT.DOWN);
+ viewer.refresh(false);
+ }
+ };
+ return selectionAdapter;
+ }
+
+ private class UsersViewerComparator extends ViewerComparator {
+
+ private List<String> propertyList;
+ private int sortColumn = 0;
+ private boolean ascending = true;
+ // use this to enable two levels sort
+ @SuppressWarnings("unused")
+ private int lastSortColumn = 0;
+ @SuppressWarnings("unused")
+ private boolean lastAscending = true;
+
+ public UsersViewerComparator(List<String> propertyList) {
+ super();
+ this.propertyList = propertyList;
+ }
+
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ String s1 = getProperty(e1, propertyList.get(sortColumn));
+ String s2 = getProperty(e2, propertyList.get(sortColumn));
+ int result = super.compare(viewer, s1, s2);
+ return ascending ? result : (-1) * result;
+ }
+
+ /**
+ * @return Returns the sortColumn.
+ */
+ public int getSortColumn() {
+ return sortColumn;
+ }
+
+ /**
+ * @param sortColumn
+ * The sortColumn to set.
+ */
+ public void setSortColumn(int sortColumn) {
+ if (this.sortColumn != sortColumn) {
+ lastSortColumn = this.sortColumn;
+ lastAscending = this.ascending;
+ this.sortColumn = sortColumn;
+ }
+ }
+
+ /**
+ * @return Returns the ascending.
+ */
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ /**
+ * @param ascending
+ * The ascending to set.
+ */
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+ }