package org.ovirt.engine.ui.common.widget.table.column;

import org.ovirt.engine.core.common.businessentities.Permissions;

import com.google.gwt.resources.client.ImageResource;

/**
 * Image column that corresponds to XAML {@code PermissionTypeDataTemplate}.
 */
public class PermissionTypeColumn extends ImageResourceColumn<Permissions> {

    @Override
    public ImageResource getValue(Permissions user) {
        switch (user.getRoleType()) {
        case ADMIN:
            return getCommonResources().adminImage();
        case USER:
            return getCommonResources().userImage();
        default:
            return getCommonResources().userImage();
        }
    }

}

package org.ovirt.engine.ui.common.widget.table.column;

import java.util.Comparator;

import org.ovirt.engine.core.common.businessentities.Permissions;

import com.google.gwt.resources.client.ImageResource;

/**
 * Image column that corresponds to XAML {@code PermissionTypeDataTemplate}.
 */
public class PermissionTypeColumn extends ImageResourceColumn<Permissions> {

    public PermissionTypeColumn() {
        makeSortable(new Comparator<Permissions>() {

            @Override
            public int compare(Permissions o1, Permissions o2) {
                if (getValue(o1).equals(getValue(o2))) {
                    return 0;
                } else {
                    return (getCommonResources().userImage().equals(getValue(o1))) ? -1 : 1;
                }
            }
        });
    }

    @Override
    public ImageResource getValue(Permissions user) {
        switch (user.getRoleType()) {
        case ADMIN:
            return getCommonResources().adminImage();
        case USER:
            return getCommonResources().userImage();
        default:
            return getCommonResources().userImage();
        }
    }

}

Implement permission sorting by role icon
webadmin: Implement permission sorting by role icon

Implemented sorting for permission subtabs according to the role icon
(ordinary user is lesser than administrator).

Change-Id: I3a2c97315bda060e44b662562e1e08652881d72f
Signed-off-by: Lior Vernia <0888e9bab805ddf64d6b8b84d91c33e7509a697e@redhat.com>
