@Override\r
public int compare(Viewer viewer, Object e1, Object e2) {\r
\r
+ int rc = 0;\r
\r
int cat1 = category(e1);\r
int cat2 = category(e2);\r
\r
if (cat1 != cat2) {\r
- return cat1 - cat2;\r
- }\r
+ rc = cat1 - cat2;\r
+ } else {\r
\r
- String name1 = null;\r
- String name2 = null;\r
- \r
- \r
- \r
- if (viewer == null || !(viewer instanceof ContentViewer)) {\r
- name1 = e1.toString();\r
- name2 = e2.toString();\r
- } else {\r
- IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();\r
- if (viewer instanceof TableViewer && ((TableViewer)viewer).getLabelProvider(propertyIndex) != null) {\r
- CellLabelProvider clp = ((TableViewer)viewer).getLabelProvider(propertyIndex);\r
- if (clp instanceof ILabelProvider) {\r
- ILabelProvider ilb = (ILabelProvider)clp;\r
- name1 = ilb.getText(e1);\r
- name2 = ilb.getText(e2);\r
- }\r
- }\r
- if (name1 == null) {\r
- if (prov instanceof ITableLabelProvider) {\r
- ITableLabelProvider lprov = (ITableLabelProvider) prov;\r
- name1 = lprov.getColumnText(e1,propertyIndex);\r
- name2 = lprov.getColumnText(e2,propertyIndex);\r
- } else if (prov instanceof ILabelProvider) {\r
- ILabelProvider lprov = (ILabelProvider) prov;\r
- name1 = lprov.getText(e1);\r
- name2 = lprov.getText(e2);\r
- } else {\r
- name1 = e1.toString();\r
- name2 = e2.toString();\r
+ String name1 = null;\r
+ String name2 = null;\r
+ \r
+ \r
+ \r
+ if (viewer == null || !(viewer instanceof ContentViewer)) {\r
+ name1 = e1.toString();\r
+ name2 = e2.toString();\r
+ } else {\r
+ IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();\r
+ if (viewer instanceof TableViewer && ((TableViewer)viewer).getLabelProvider(propertyIndex) != null) {\r
+ CellLabelProvider clp = ((TableViewer)viewer).getLabelProvider(propertyIndex);\r
+ if (clp instanceof ILabelProvider) {\r
+ ILabelProvider ilb = (ILabelProvider)clp;\r
+ name1 = ilb.getText(e1);\r
+ name2 = ilb.getText(e2);\r
+ }\r
}\r
- }\r
- }\r
- if (name1 == null) {\r
- name1 = "";//$NON-NLS-1$\r
- }\r
- if (name2 == null) {\r
- name2 = "";//$NON-NLS-1$\r
+ if (name1 == null) {\r
+ if (prov instanceof ITableLabelProvider) {\r
+ ITableLabelProvider lprov = (ITableLabelProvider) prov;\r
+ name1 = lprov.getColumnText(e1,propertyIndex);\r
+ name2 = lprov.getColumnText(e2,propertyIndex);\r
+ } else if (prov instanceof ILabelProvider) {\r
+ ILabelProvider lprov = (ILabelProvider) prov;\r
+ name1 = lprov.getText(e1);\r
+ name2 = lprov.getText(e2);\r
+ } else {\r
+ name1 = e1.toString();\r
+ name2 = e2.toString();\r
+ }\r
+ }\r
+ }\r
+ if (name1 == null) {\r
+ name1 = "";//$NON-NLS-1$\r
+ }\r
+ if (name2 == null) {\r
+ name2 = "";//$NON-NLS-1$\r
+ }\r
+ \r
+ // use the comparator to compare the strings\r
+ rc = getComparator().compare(name1, name2);\r
}\r
-\r
- // use the comparator to compare the strings\r
- int rc = getComparator().compare(name1, name2);\r
if (direction != DESCENDING)\r
rc = -rc;\r
return rc;\r
public static TableViewerColumn addColumn(final TableViewer viewer, String text, boolean resize, boolean sort, int width) {\r
final TableViewerColumn twc = new TableViewerColumn(viewer, SWT.NONE);\r
final TableColumn tc = twc.getColumn();\r
- //final TableColumn tc = new TableColumn(viewer.getTable(), SWT.NONE);\r
tc.setText(text);\r
tc.setResizable(resize);\r
tc.setWidth(width);\r
tc.addSelectionListener(new SelectionAdapter() {\r
@Override\r
public void widgetSelected(SelectionEvent e) {\r
- StringColumnComparator comparator = (StringColumnComparator)viewer.getComparator();\r
- //TableColumn tc = twc.getColumn();\r
+ StringColumnComparator comparator = null;\r
+ if (viewer.getComparator() instanceof StringColumnComparator) {\r
+ comparator = (StringColumnComparator)viewer.getComparator();\r
+ } else {\r
+ comparator = new StringColumnComparator();\r
+ viewer.setComparator(comparator);\r
+ }\r
TableColumn tcs[] = viewer.getTable().getColumns();\r
int index = -1;\r
for (int i = 0; i <tcs.length; i++) {\r