Search in sources :

Example 1 with SoftwarePackage

use of org.netxms.client.SoftwarePackage in project netxms by netxms.

the class SoftwarePackageComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    int result;
    // $NON-NLS-1$ //$NON-NLS-2$
    final int column = (viewer instanceof SortableTableViewer) ? (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID") : (Integer) ((SortableTreeViewer) viewer).getTree().getSortColumn().getData("ID");
    if (e1 instanceof SoftwareInventoryNode) {
        if (column == 0) {
            result = ((SoftwareInventoryNode) e1).getNode().getObjectName().compareToIgnoreCase(((SoftwareInventoryNode) e2).getNode().getObjectName());
        } else {
            result = 0;
        }
    } else {
        SoftwarePackage p1 = (SoftwarePackage) e1;
        SoftwarePackage p2 = (SoftwarePackage) e2;
        switch(column) {
            case SoftwareInventory.COLUMN_DATE:
                result = Long.signum(p1.getInstallDateMs() - p2.getInstallDateMs());
                break;
            case SoftwareInventory.COLUMN_DESCRIPTION:
                result = p1.getDescription().compareToIgnoreCase(p2.getDescription());
                break;
            case SoftwareInventory.COLUMN_NAME:
                result = p1.getName().compareToIgnoreCase(p2.getName());
                break;
            case SoftwareInventory.COLUMN_URL:
                result = p1.getSupportUrl().compareToIgnoreCase(p2.getSupportUrl());
                break;
            case SoftwareInventory.COLUMN_VENDOR:
                result = p1.getVendor().compareToIgnoreCase(p2.getVendor());
                break;
            case SoftwareInventory.COLUMN_VERSION:
                result = p1.getVersion().compareToIgnoreCase(p2.getVersion());
                break;
            default:
                result = 0;
                break;
        }
    }
    int direction = (viewer instanceof SortableTableViewer) ? ((SortableTableViewer) viewer).getTable().getSortDirection() : ((SortableTreeViewer) viewer).getTree().getSortDirection();
    return (direction == SWT.UP) ? result : -result;
}
Also used : SortableTreeViewer(org.netxms.ui.eclipse.widgets.SortableTreeViewer) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SoftwarePackage(org.netxms.client.SoftwarePackage)

Aggregations

SoftwarePackage (org.netxms.client.SoftwarePackage)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1 SortableTreeViewer (org.netxms.ui.eclipse.widgets.SortableTreeViewer)1