@Override
 public int compare(Viewer viewer, Object e1, Object e2) {
   ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
   int result =
       SortableTableColumn.this.compare(
           labelProvider.getColumnText(e1, columnIndex),
           labelProvider.getColumnText(e2, columnIndex));
   if (direction == SWT.DOWN) result = -1 * result;
   return result;
 }
Exemple #2
0
    /*
     * (non-Javadoc)
     *
     * @see
     * org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.
     * viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public int compare(Viewer viewer, Object e1, Object e2) {
      String name1;
      String name2;

      if (viewer == null || !(viewer instanceof ContentViewer)) {
        if (descent) {
          name1 = e2.toString();
          name2 = e1.toString();
        } else {
          name1 = e1.toString();
          name2 = e2.toString();
        }
      } else {
        IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
        if (prov instanceof ITableLabelProvider) {
          ITableLabelProvider lprov = (ITableLabelProvider) prov;
          if (second) {
            if (descent) {
              name1 = lprov.getColumnText(e2, 1);
              name2 = lprov.getColumnText(e1, 1);
            } else {
              name1 = lprov.getColumnText(e1, 1);
              name2 = lprov.getColumnText(e2, 1);
            }
          } else {
            if (descent) {
              name1 = lprov.getColumnText(e2, 0);
              name2 = lprov.getColumnText(e1, 0);
            } else {
              name1 = lprov.getColumnText(e1, 0);
              name2 = lprov.getColumnText(e2, 0);
            }
          }
        } else {
          if (descent) {
            name1 = e2.toString();
            name2 = e1.toString();
          } else {
            name1 = e1.toString();
            name2 = e2.toString();
          }
        }
      }
      if (name1 == null) {
        name1 = ""; // $NON-NLS-1$
      }
      if (name2 == null) {
        name2 = ""; // $NON-NLS-1$
      }

      return collator.compare(name1, name2);
    }