RouteColumn column = (RouteColumn) sortColumn.getData();
int result = 0;
int sortDirection = table.getSortDirection();
if (column != null) {
if (e1 instanceof CloudRoute && e2 instanceof CloudRoute) {
CloudRoute rt1 = (CloudRoute) e1;
CloudRoute rt2 = (CloudRoute) e2;
switch (column) {
case NAME:
result = rt1.getName().toLowerCase().compareTo(rt2.getName().toLowerCase());
break;
case DOMAIN:
result = rt1.getDomain().getName().compareTo(rt2.getDomain().getName());
break;
case IN_USE:
if (rt1.inUse() && !rt2.inUse()) {
result = -1;
}
else if (rt2.inUse() && !rt1.inUse()) {
result = 1;
}
break;
}
}
}
return sortDirection == SWT.UP ? result : -result;
}
return super.compare(viewer, e1, e2);
}
});
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object items, Object item) {
if (item instanceof CloudRoute) {
CloudRoute route = (CloudRoute) item;
return route.inUse() ? showInUseButton.getSelection()
: (showRemovedRoutesButton.getSelection() && routesToRemove.contains(route))
|| (!showRemovedRoutesButton.getSelection() && !routesToRemove.contains(route));
}
return false;
}