Search in sources :

Example 1 with QuotaDcStatusColumn

use of org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn in project ovirt-engine by oVirt.

the class MainQuotaView method initTable.

void initTable() {
    getTable().enableColumnResizing();
    QuotaDcStatusColumn dcStatusColumn = new QuotaDcStatusColumn();
    dcStatusColumn.setContextMenuTitle(constants.dcStatusQuota());
    // $NON-NLS-1$
    getTable().addColumn(dcStatusColumn, constants.empty(), "30px");
    AbstractTextColumn<Quota> nameColumn = new AbstractLinkColumn<Quota>(new FieldUpdater<Quota, String>() {

        @Override
        public void update(int index, Quota quota, String value) {
            Map<String, String> parameters = new HashMap<>();
            parameters.put(FragmentParams.NAME.getName(), quota.getName());
            parameters.put(FragmentParams.DATACENTER.getName(), quota.getStoragePoolName());
            // The link was clicked, now fire an event to switch to details.
            getPlaceTransitionHandler().handlePlaceTransition(WebAdminApplicationPlaces.quotaClusterSubTabPlace, parameters);
        }
    }) {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getQuotaName() == null ? "" : object.getQuotaName();
        }
    };
    nameColumn.makeSortable(QuotaConditionFieldAutoCompleter.NAME);
    // $NON-NLS-1$
    getTable().addColumn(nameColumn, constants.nameQuota(), "120px");
    AbstractTextColumn<Quota> dataCenterColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            return object.getStoragePoolName() == null ? "" : object.getStoragePoolName();
        }
    };
    dataCenterColumn.makeSortable(QuotaConditionFieldAutoCompleter.STORAGEPOOLNAME);
    // $NON-NLS-1$
    getTable().addColumn(dataCenterColumn, constants.dcQuota(), "120px");
    AbstractTextColumn<Quota> descriptionColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getDescription() == null ? "" : object.getDescription();
        }
    };
    descriptionColumn.makeSortable(QuotaConditionFieldAutoCompleter.DESCRIPTION);
    // $NON-NLS-1$
    getTable().addColumn(descriptionColumn, constants.descriptionQuota(), "120px");
    getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {

        @Override
        protected Integer getProgressValue(Quota object) {
            int value;
            long allocated = 0;
            long used = 0;
            if (object.getGlobalQuotaCluster() != null) {
                allocated = object.getGlobalQuotaCluster().getMemSizeMB();
                used = object.getGlobalQuotaCluster().getMemSizeMBUsage();
            } else {
                for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
                    if (!QuotaCluster.UNLIMITED_MEM.equals(quotaCluster.getMemSizeMB())) {
                        allocated += quotaCluster.getMemSizeMB() != null ? quotaCluster.getMemSizeMB() : 0;
                        used += quotaCluster.getMemSizeMBUsage();
                    } else {
                        allocated = QuotaCluster.UNLIMITED_MEM;
                        break;
                    }
                }
            }
            if (allocated == 0) {
                return 0;
            }
            value = (int) (((double) used / allocated) * 100);
            return allocated < 0 ? -1 : value > 100 ? 100 : value;
        }
    }, constants.usedMemoryQuota(), // $NON-NLS-1$
    "145px");
    getTable().addColumn(new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            int value;
            long allocated = 0;
            long used = 0;
            if (object.getGlobalQuotaCluster() != null) {
                allocated = object.getGlobalQuotaCluster().getMemSizeMB();
                used = object.getGlobalQuotaCluster().getMemSizeMBUsage();
            } else {
                for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
                    if (!QuotaCluster.UNLIMITED_MEM.equals(quotaCluster.getMemSizeMB())) {
                        allocated += quotaCluster.getMemSizeMB() != null ? quotaCluster.getMemSizeMB() : 0;
                        used += quotaCluster.getMemSizeMBUsage();
                    } else {
                        allocated = QuotaCluster.UNLIMITED_MEM;
                        break;
                    }
                }
            }
            value = (int) (allocated - used);
            String returnVal;
            if (allocated < 0) {
                returnVal = constants.unlimited();
            } else if (value <= 0) {
                // $NON-NLS-1$
                returnVal = messages.megabytes("0");
            } else if (value <= 5 * 1024) {
                returnVal = messages.megabytes(String.valueOf(value));
            } else {
                returnVal = messages.gibibytes(decimalFormat.format((double) value / 1024));
            }
            return returnVal;
        }
    }, constants.freeMemory(), // $NON-NLS-1$
    "100px");
    getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {

        @Override
        protected Integer getProgressValue(Quota object) {
            int value;
            int allocated = 0;
            int used = 0;
            if (object.getGlobalQuotaCluster() != null) {
                allocated = object.getGlobalQuotaCluster().getVirtualCpu() != null ? object.getGlobalQuotaCluster().getVirtualCpu() : 0;
                used = object.getGlobalQuotaCluster().getVirtualCpuUsage();
            } else {
                for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
                    if (!QuotaCluster.UNLIMITED_VCPU.equals(quotaCluster.getVirtualCpu())) {
                        allocated += quotaCluster.getVirtualCpu();
                        used += quotaCluster.getVirtualCpuUsage();
                    } else {
                        allocated = QuotaCluster.UNLIMITED_VCPU;
                        break;
                    }
                }
            }
            if (allocated == 0) {
                return 0;
            }
            value = (int) (((double) used / allocated) * 100);
            return allocated < 0 ? -1 : value > 100 ? 100 : value;
        }
    }, constants.runningCpuQuota(), // $NON-NLS-1$
    "135px");
    getTable().addColumn(new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            int value;
            int allocated = 0;
            int used = 0;
            if (object.getGlobalQuotaCluster() != null) {
                allocated = object.getGlobalQuotaCluster().getVirtualCpu() != null ? object.getGlobalQuotaCluster().getVirtualCpu() : 0;
                used = object.getGlobalQuotaCluster().getVirtualCpuUsage();
            } else {
                for (QuotaCluster quotaCluster : object.getQuotaClusters()) {
                    if (!QuotaCluster.UNLIMITED_VCPU.equals(quotaCluster.getVirtualCpu())) {
                        allocated += quotaCluster.getVirtualCpu();
                        used += quotaCluster.getVirtualCpuUsage();
                    } else {
                        allocated = QuotaCluster.UNLIMITED_VCPU;
                        break;
                    }
                }
            }
            value = allocated - used;
            String returnVal;
            if (allocated < 0) {
                returnVal = constants.unlimited();
            } else if (value <= 0) {
                // $NON-NLS-1$
                returnVal = "0";
            } else {
                // $NON-NLS-1$
                returnVal = value + "";
            }
            return returnVal;
        }
    }, constants.freeVcpu(), // $NON-NLS-1$
    "100px");
    getTable().addColumn(new AbstractQuotaPercentColumn<Quota>() {

        @Override
        protected Integer getProgressValue(Quota object) {
            int value;
            double allocated = 0;
            double used = 0;
            if (object.getGlobalQuotaStorage() != null) {
                allocated = object.getGlobalQuotaStorage().getStorageSizeGB();
                used = object.getGlobalQuotaStorage().getStorageSizeGBUsage();
            } else {
                for (QuotaStorage quotaStorage : object.getQuotaStorages()) {
                    if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
                        allocated += quotaStorage.getStorageSizeGB();
                        used += quotaStorage.getStorageSizeGBUsage();
                    } else {
                        allocated = QuotaStorage.UNLIMITED;
                        break;
                    }
                }
            }
            if (allocated == 0) {
                return 0;
            }
            value = (int) ((used / allocated) * 100);
            return allocated < 0 ? -1 : value > 100 ? 100 : value;
        }
    }, constants.usedStorageQuota(), // $NON-NLS-1$
    "155px");
    getTable().addColumn(new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            double value;
            double allocated = 0;
            double used = 0;
            if (object.getGlobalQuotaStorage() != null) {
                allocated = object.getGlobalQuotaStorage().getStorageSizeGB();
                used = object.getGlobalQuotaStorage().getStorageSizeGBUsage();
            } else {
                for (QuotaStorage quotaStorage : object.getQuotaStorages()) {
                    if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
                        allocated += quotaStorage.getStorageSizeGB();
                        used += quotaStorage.getStorageSizeGBUsage();
                    } else {
                        allocated = QuotaStorage.UNLIMITED;
                        break;
                    }
                }
            }
            value = allocated - used;
            String returnVal;
            if (allocated < 0) {
                returnVal = constants.unlimited();
            } else if (value <= 0) {
                // $NON-NLS-1$
                returnVal = messages.gibibytes("0");
            } else {
                returnVal = diskSizeRenderer.render(value);
            }
            return returnVal;
        }
    }, constants.freeStorage(), // $NON-NLS-1$
    "100px");
}
Also used : QuotaDcStatusColumn(org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn) AbstractLinkColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractLinkColumn) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with QuotaDcStatusColumn

use of org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn in project ovirt-engine by oVirt.

the class SubTabDataCenterQuotaView method initTable.

void initTable() {
    getTable().enableColumnResizing();
    QuotaDcStatusColumn dcStatusColumn = new QuotaDcStatusColumn();
    dcStatusColumn.setContextMenuTitle(constants.dcStatusQuota());
    // $NON-NLS-1$
    getTable().addColumn(dcStatusColumn, constants.empty(), "30px");
    AbstractTextColumn<Quota> nameColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getQuotaName() == null ? "" : object.getQuotaName();
        }
    };
    nameColumn.makeSortable();
    // $NON-NLS-1$
    getTable().addColumn(nameColumn, constants.nameQuota(), "400px");
    AbstractTextColumn<Quota> descriptionColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getDescription() == null ? "" : object.getDescription();
        }
    };
    descriptionColumn.makeSortable();
    // $NON-NLS-1$
    getTable().addColumn(descriptionColumn, constants.descriptionQuota(), "400px");
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaDcStatusColumn(org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)

Example 3 with QuotaDcStatusColumn

use of org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn in project ovirt-engine by oVirt.

the class SubTabUserQuotaView method initTable.

void initTable() {
    getTable().enableColumnResizing();
    QuotaDcStatusColumn dcStatusColumn = new QuotaDcStatusColumn();
    dcStatusColumn.setContextMenuTitle(constants.dcStatusQuota());
    // $NON-NLS-1$
    getTable().addColumn(dcStatusColumn, constants.empty(), "30px");
    AbstractTextColumn<Quota> nameColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getQuotaName() == null ? "" : object.getQuotaName();
        }
    };
    nameColumn.makeSortable(QuotaComparator.NAME);
    // $NON-NLS-1$
    getTable().addColumn(nameColumn, constants.nameQuota(), "300px");
    AbstractTextColumn<Quota> descriptionColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getDescription() == null ? "" : object.getDescription();
        }
    };
    descriptionColumn.makeSortable(QuotaComparator.DESCRIPTION);
    // $NON-NLS-1$
    getTable().addColumn(descriptionColumn, constants.descriptionQuota(), "300px");
    AbstractTextColumn<Quota> datacenterColumn = new AbstractTextColumn<Quota>() {

        @Override
        public String getValue(Quota object) {
            // $NON-NLS-1$
            return object.getStoragePoolName() == null ? "" : object.getStoragePoolName();
        }
    };
    datacenterColumn.makeSortable(QuotaComparator.DATA_CENTER);
    // $NON-NLS-1$
    getTable().addColumn(datacenterColumn, constants.dcQuota(), "300px");
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaDcStatusColumn(org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)

Aggregations

Quota (org.ovirt.engine.core.common.businessentities.Quota)3 AbstractTextColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)3 QuotaDcStatusColumn (org.ovirt.engine.ui.webadmin.widget.table.column.QuotaDcStatusColumn)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)1 QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)1 AbstractLinkColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractLinkColumn)1