ofri masad has uploaded a new change for review. Change subject: userportal: Add quota bar tool-tip ......................................................................
userportal: Add quota bar tool-tip Quota bar had only a basic tool-tip. This was a problem specifically in cases the quota exceeded and the bar was colored red. The new tool-tip holds a small table showing in percentage and in units the total consumption, personal consumption, other users consumption and free quota. Change-Id: Icb877d23edceaccb8e1cd549bef8ef7d9d044ca7 Bug-Url: https://bugzilla.redhat.com/920250 Signed-off-by: Ofri Masad <oma...@redhat.com> --- M frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationConstants.java M frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationTemplates.java M frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/extended/SideTabExtendedResourceView.java M frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/QuotaProgressBar.java 4 files changed, 208 insertions(+), 56 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/34/13134/1 diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationConstants.java b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationConstants.java index c8f19af..2fbcfaa 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationConstants.java +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationConstants.java @@ -393,4 +393,10 @@ @DefaultStringValue("Virtual Machines' Disks & Snapshots ") String vmDisksAndSnapshots(); + + @DefaultStringValue("Quota") + String tooltipQuotaLabel(); + + @DefaultStringValue("Total usage") + String tooltipTotalUsageLabel(); } diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationTemplates.java b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationTemplates.java index 3b3fdee..f195154 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationTemplates.java +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/ApplicationTemplates.java @@ -12,4 +12,37 @@ @Template(" ({0})") SafeHtml vmDescriptionCellItem(String description); + + @Template("<table style=\"font-size:11px; background-color:#d0e4f6; border-collapse: collapse;\">\n" + + " <tr style=\"background-color: #95adc2;\">\n" + + " <th style=\"text-align:left; padding: 3px;\" >{0}</th>\n" + + " <th style=\"padding: 3px;\"> </th>\n" + + " <th style=\"text-align:right; padding: 3px;\" >{1}</th>\n" + + " </tr>\n" + + " <tr style=\"background-color: #b5cadc; padding: 3px;\">\n" + + " <td style=\"padding: 3px;\">{2} Usage</td>\n" + + " <td style=\"text-align:right; padding: 3px; padding-left: 18px; \" >{3}%</td>\n" + + " <td style=\"text-align:right; padding: 3px; padding-left: 18px; \" >{4}</td>\n" + + " </tr>\n" + + " <tr>\n" + + " <td style=\"padding: 3px;\">{5}</td>\n" + + " <td style=\"text-align:right; padding: 3px;\" >{6}%</td>\n" + + " <td style=\"text-align:right; padding: 3px;\" >{7}</td>\n" + + " </tr>\n" + + " <tr>\n" + + " <td style=\"padding: 3px;\">{8}</td>\n" + + " <td style=\"text-align:right; padding: 3px;\" >{9}%</td>\n" + + " <td style=\"text-align:right; padding: 3px;\" >{10}</td>\n" + + " </tr>\n" + + " <tr style=\"background-color: #b5cadc; \">\n" + + " <td style=\"border-bottom:1px solid #95adc2; padding: 3px;\">{11}</td>\n" + + " <td style=\"text-align:right; border-bottom:1px solid #95adc2; padding: 3px;\" >{12}%</td>\n" + + " <td style=\"text-align:right; border-bottom:1px solid #95adc2; padding: 3px;\" >{13}</td>\n" + + " </tr>\n" + + " </table>\n") + SafeHtml quotaForUserBarToolTip(String quotaLabel, String quota, + String totalUsageLabel, int totalUsagePercentage, String totalUsage, + String usedByYouLabel, int usedByYouPercentage,String usedByYou, + String usedByOthersLabel, int usedByOthersPercentage, String usedByOthers, + String freeLabel, int freePercentage, String free); } diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/extended/SideTabExtendedResourceView.java b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/extended/SideTabExtendedResourceView.java index 31b52f9..840a801 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/extended/SideTabExtendedResourceView.java +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/extended/SideTabExtendedResourceView.java @@ -18,6 +18,7 @@ import org.ovirt.engine.ui.uicompat.IEventListener; import org.ovirt.engine.ui.userportal.ApplicationConstants; import org.ovirt.engine.ui.userportal.ApplicationResources; +import org.ovirt.engine.ui.userportal.ApplicationTemplates; import org.ovirt.engine.ui.userportal.section.main.presenter.tab.extended.SideTabExtendedResourcePresenter; import org.ovirt.engine.ui.userportal.uicommon.model.resources.ResourcesModelProvider; import org.ovirt.engine.ui.userportal.widget.QuotaProgressBar; @@ -45,6 +46,7 @@ private ResourcesModel model; private static final int INFO_BOX_UPPER_PART_HEIGHT = 150; private static final int STORAGE_BOX_UPPER_PART_HEIGHT = 350; + private static final ApplicationTemplates templates = GWT.create(ApplicationTemplates.class); interface ViewUiBinder extends UiBinder<Widget, SideTabExtendedResourceView> { ViewUiBinder uiBinder = GWT.create(ViewUiBinder.class); @@ -159,9 +161,9 @@ SimpleRefreshManager refreshManager = new SimpleRefreshManager(modelProvider, eventBus, clientStorage); refreshPanel = refreshManager.getRefreshPanel(); - cpusProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.CPU); - memoryProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.MEM); - storageProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.STORAGE); + cpusProgressBar = new QuotaProgressBar(templates, QuotaProgressBar.QuotaType.CPU); + memoryProgressBar = new QuotaProgressBar(templates, QuotaProgressBar.QuotaType.MEM); + storageProgressBar = new QuotaProgressBar(templates, QuotaProgressBar.QuotaType.STORAGE); initWidget(ViewUiBinder.uiBinder.createAndBindUi(this)); Driver.driver.initialize(this); @@ -225,15 +227,9 @@ addQuotaToStorageQuotaList(quotaPerUserUsageEntity); } - cpusProgressBar.setValues(aggregatedUsage.getVcpuLimit(), - aggregatedUsage.getVcpuTotalUsage() - aggregatedUsage.getVcpuUsageForUser(), - aggregatedUsage.getVcpuUsageForUser()); - memoryProgressBar.setValues(aggregatedUsage.getMemoryLimit(), - aggregatedUsage.getMemoryTotalUsage() - aggregatedUsage.getMemoryUsageForUser(), - aggregatedUsage.getMemoryUsageForUser()); - storageProgressBar.setValues(aggregatedUsage.getStorageLimit(), - aggregatedUsage.getStorageTotalUsage() - aggregatedUsage.getStorageUsageForUser(), - aggregatedUsage.getStorageUsageForUser()); + cpusProgressBar.setQuotaUsagePerUser(aggregatedUsage); + memoryProgressBar.setQuotaUsagePerUser(aggregatedUsage); + storageProgressBar.setQuotaUsagePerUser(aggregatedUsage); String title = constants.showQuotaDistribution() + " (" + list.size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ vcpuExpander.setTitleWhenCollapsed(title); @@ -243,26 +239,17 @@ } private void addQuotaToVcpuQuotaList(QuotaUsagePerUser quotaPerUserUsageEntity) { - QuotaProgressBar vcpuQuotaProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.CPU); - vcpuQuotaProgressBar.setValues(quotaPerUserUsageEntity.getVcpuLimit(), - quotaPerUserUsageEntity.getVcpuTotalUsage() - quotaPerUserUsageEntity.getVcpuUsageForUser(), - quotaPerUserUsageEntity.getVcpuUsageForUser()); + QuotaProgressBar vcpuQuotaProgressBar = new QuotaProgressBar(templates, quotaPerUserUsageEntity, QuotaProgressBar.QuotaType.CPU); addQuotaRow(cpusQuotasList, quotaPerUserUsageEntity.getQuotaName(), vcpuQuotaProgressBar); } private void addQuotaToMemoryQuotaList(QuotaUsagePerUser quotaPerUserUsageEntity) { - QuotaProgressBar memoryQuotaProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.MEM); - memoryQuotaProgressBar.setValues(quotaPerUserUsageEntity.getMemoryLimit(), - quotaPerUserUsageEntity.getMemoryTotalUsage() - quotaPerUserUsageEntity.getMemoryUsageForUser(), - quotaPerUserUsageEntity.getMemoryUsageForUser()); + QuotaProgressBar memoryQuotaProgressBar = new QuotaProgressBar(templates, quotaPerUserUsageEntity, QuotaProgressBar.QuotaType.MEM); addQuotaRow(memoryQuotasList, quotaPerUserUsageEntity.getQuotaName(), memoryQuotaProgressBar); } private void addQuotaToStorageQuotaList(QuotaUsagePerUser quotaPerUserUsageEntity) { - QuotaProgressBar storageQuotaProgressBar = new QuotaProgressBar(QuotaProgressBar.QuotaType.STORAGE); - storageQuotaProgressBar.setValues(quotaPerUserUsageEntity.getStorageLimit(), - quotaPerUserUsageEntity.getStorageTotalUsage() - quotaPerUserUsageEntity.getStorageUsageForUser(), - quotaPerUserUsageEntity.getStorageUsageForUser()); + QuotaProgressBar storageQuotaProgressBar = new QuotaProgressBar(templates, quotaPerUserUsageEntity, QuotaProgressBar.QuotaType.STORAGE); addQuotaRow(storageQuotasList, quotaPerUserUsageEntity.getQuotaName(), storageQuotaProgressBar); } diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/QuotaProgressBar.java b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/QuotaProgressBar.java index fabf8aa..3b2b7a1 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/QuotaProgressBar.java +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/QuotaProgressBar.java @@ -1,24 +1,83 @@ package org.ovirt.engine.ui.userportal.widget; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.HasMouseOutHandlers; +import com.google.gwt.event.dom.client.HasMouseOverHandlers; +import com.google.gwt.event.dom.client.MouseOutEvent; +import com.google.gwt.event.dom.client.MouseOutHandler; +import com.google.gwt.event.dom.client.MouseOverEvent; +import com.google.gwt.event.dom.client.MouseOverHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.user.client.ui.DecoratedPopupPanel; +import com.google.gwt.user.client.ui.HTML; +import org.ovirt.engine.core.common.businessentities.QuotaUsagePerUser; +import org.ovirt.engine.ui.common.utils.PopupUtils; import org.ovirt.engine.ui.common.widget.renderer.DiskSizeRenderer; import org.ovirt.engine.ui.userportal.ApplicationConstants; import org.ovirt.engine.ui.userportal.ApplicationMessages; +import org.ovirt.engine.ui.userportal.ApplicationTemplates; -public class QuotaProgressBar extends DoublePercentageProgressBar { +public class QuotaProgressBar extends DoublePercentageProgressBar implements HasMouseOutHandlers, HasMouseOverHandlers, MouseOutHandler, MouseOverHandler { public static final int UNLIMITED = -1; private static final ApplicationMessages messages = GWT.create(ApplicationMessages.class); private static final ApplicationConstants constants = GWT.create(ApplicationConstants.class); private static final DiskSizeRenderer<Number> diskSizeRenderer = new DiskSizeRenderer<Number>(DiskSizeRenderer.DiskSizeUnit.GIGABYTE); + private static final SafeHtml EMPTY_HTML = new SafeHtml() { + @Override + public String asString() { + return ""; //$NON-NLS-1$ + } + }; + private final HTML tooltip = new HTML(); + private final DecoratedPopupPanel tooltipPanel = new DecoratedPopupPanel(); + private final ApplicationTemplates templates; private QuotaType type; private static final double GIGA = 1024; private static final double MB_GB_THRESHOLD = 4; // over this threshold number would be presented in GB not MB + private QuotaUsagePerUser quotaUsagePerUser; - public QuotaProgressBar(QuotaType type) { + public QuotaProgressBar(ApplicationTemplates templates, QuotaUsagePerUser quotaUsagePerUser, QuotaType type) { + this(templates, type); + setQuotaUsagePerUser(quotaUsagePerUser); + } + + public QuotaProgressBar(ApplicationTemplates templates, QuotaType type) { + this.templates = templates; this.type = type; + + tooltipPanel.setWidget(tooltip); + + addMouseOutHandler(this); + addMouseOverHandler(this); + } + + public void setQuotaUsagePerUser(QuotaUsagePerUser quotaUsagePerUser) { + this.quotaUsagePerUser = quotaUsagePerUser; + setValuesByType(quotaUsagePerUser); + } + + private void setValuesByType(QuotaUsagePerUser quotaUsagePerUser) { + switch (type) { + case STORAGE: + setValues(quotaUsagePerUser.getStorageLimit(), + quotaUsagePerUser.getStorageTotalUsage() - quotaUsagePerUser.getStorageUsageForUser(), + quotaUsagePerUser.getStorageUsageForUser()); + break; + case CPU: + setValues(quotaUsagePerUser.getVcpuLimit(), + quotaUsagePerUser.getVcpuTotalUsage() - quotaUsagePerUser.getVcpuUsageForUser(), + quotaUsagePerUser.getVcpuUsageForUser()); + break; + case MEM: + setValues(quotaUsagePerUser.getMemoryLimit(), + quotaUsagePerUser.getMemoryTotalUsage() - quotaUsagePerUser.getMemoryUsageForUser(), + quotaUsagePerUser.getMemoryUsageForUser()); + break; + } } public void setUnlimited() { @@ -30,39 +89,25 @@ } - public void setExceeded(String title) { + public void setExceeded() { percentageBarA.setStyleName(style.percentageBarExceeded()); percentageLabelA.setStyleName(style.percentageLabel()); percentageLabelA.setText("Exceeded"); //$NON-NLS-1$ - percentageLabelA.setTitle(title); percentageBarB.setVisible(false); } - public void setValues(double limit, double consumedByOthers, double consumedByUser) { + private void setValues(double limit, double consumedByOthers, double consumedByUser) { int othersConsumptionPercent = (int) Math.round(consumedByOthers * 100 / limit); int userConsumptionPercent = (int) Math.round(consumedByUser * 100 / limit); double free = limit - consumedByOthers - consumedByUser; - - setTitleInternal(free); if (limit == UNLIMITED) { // unlimited setUnlimited(); } else if (consumedByOthers + consumedByUser == 0) { // empty setZeroValue(); } else if (consumedByOthers + consumedByUser > limit) { // exceeded - switch (getType()) { - case STORAGE: - setExceeded(messages.exceedingStorage(othersConsumptionPercent + userConsumptionPercent - 100, -free)); - break; - case CPU: - setExceeded(messages.exceedingCpus(othersConsumptionPercent + userConsumptionPercent - 100, (int) -free)); - break; - case MEM: - String freeMem = free < (-MB_GB_THRESHOLD * GIGA) ? diskSizeRenderer.render(-free/GIGA) : (int) -free + "MB"; //$NON-NLS-1$ - setExceeded(messages.exceedingMem(othersConsumptionPercent + userConsumptionPercent - 100, freeMem)); - break; - } + setExceeded(); } else { percentageBarA.setStyleName(style.percentageBarA()); percentageLabelA.setStyleName(style.percentageLabelBlack()); @@ -73,20 +118,15 @@ } } - private void setTitleInternal(double free) { - switch (getType()) { - case STORAGE: - String freeStorage = free == 0 ? "0" : diskSizeRenderer.render(free); //$NON-NLS-1$ - setTitle(constants.freeStorage() + freeStorage); - break; - case CPU: - setTitle(messages.quotaFreeCpus((int) free)); - break; - case MEM: - String freeMem = free > (MB_GB_THRESHOLD * GIGA) ? diskSizeRenderer.render(free/GIGA) : (int) free + "MB"; //$NON-NLS-1$ - setTitle(constants.freeMemory() + freeMem); - break; + private String renderStorage(double storage) { + return storage <= 0 ? "0" : diskSizeRenderer.render(storage); //$NON-NLS-1$ + } + + private String renderMemory(double memory) { + if (memory <= 0) { + return "0"; //$NON-NLS-1$ } + return memory > Math.abs(MB_GB_THRESHOLD * GIGA) ? diskSizeRenderer.render(memory/GIGA) : (int) memory + "MB"; //$NON-NLS-1$ } public QuotaType getType() { @@ -97,10 +137,96 @@ this.type = type; } + @Override + public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { + return addDomHandler(handler, MouseOutEvent.getType()); + } + + @Override + public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { + return addDomHandler(handler, MouseOverEvent.getType()); + } + + @Override + public void onMouseOut(MouseOutEvent event) { + tooltipPanel.hide(true); + } + + @Override + public void onMouseOver(MouseOverEvent event) { + SafeHtml tooltipHtml= getTooltip(); + if(!"".equals(tooltipHtml.asString())){ //$NON-NLS-1$ + tooltip.setHTML(getTooltip()); + PopupUtils.adjustPopupLocationToFitScreenAndShow(tooltipPanel, event.getClientX(), event.getClientY() + 20); + } + } + public static enum QuotaType { STORAGE, CPU, MEM } + public SafeHtml getTooltip(){ + switch (type) { + case STORAGE: + if (quotaUsagePerUser.getStorageLimit() == UNLIMITED) { + return EMPTY_HTML; + } + return templateWithLabels(renderStorage(quotaUsagePerUser.getStorageLimit()), + (int) (quotaUsagePerUser.getOthersStorageUsagePercentage() + quotaUsagePerUser.getUserStorageUsagePercentage()), + renderStorage(quotaUsagePerUser.getStorageTotalUsage()), + (int) quotaUsagePerUser.getUserStorageUsagePercentage(), + renderStorage(quotaUsagePerUser.getStorageUsageForUser()), + (int) quotaUsagePerUser.getOthersStorageUsagePercentage(), + renderStorage(quotaUsagePerUser.getStorageTotalUsage() - quotaUsagePerUser.getStorageUsageForUser()), + (int) (100 - quotaUsagePerUser.getStorageTotalUsage()), + renderStorage(quotaUsagePerUser.getFreeStorage())); + case CPU: + if (quotaUsagePerUser.getVcpuLimit() == UNLIMITED) { + return EMPTY_HTML; + } + return templateWithLabels(String.valueOf(quotaUsagePerUser.getVcpuLimit()), + (int) (quotaUsagePerUser.getOthersVcpuUsagePercentage() + quotaUsagePerUser.getUserVcpuUsagePercentage()), + String.valueOf(quotaUsagePerUser.getVcpuTotalUsage()), + (int) quotaUsagePerUser.getUserVcpuUsagePercentage(), + String.valueOf(quotaUsagePerUser.getVcpuUsageForUser()), + (int) quotaUsagePerUser.getOthersVcpuUsagePercentage(), + String.valueOf(quotaUsagePerUser.getVcpuTotalUsage() - quotaUsagePerUser.getVcpuUsageForUser()), + (int) (100 - quotaUsagePerUser.getVcpuTotalUsage()), + String.valueOf(quotaUsagePerUser.getFreeVcpu())); + case MEM: + if (quotaUsagePerUser.getMemoryLimit() == UNLIMITED) { + return EMPTY_HTML; + } + return templateWithLabels(renderMemory(quotaUsagePerUser.getMemoryLimit()), + (int) (quotaUsagePerUser.getOthersMemoryUsagePercentage() + quotaUsagePerUser.getUserMemoryUsagePercentage()), + renderMemory(quotaUsagePerUser.getMemoryTotalUsage()), + (int) quotaUsagePerUser.getUserMemoryUsagePercentage(), + renderMemory(quotaUsagePerUser.getMemoryUsageForUser()), + (int) quotaUsagePerUser.getOthersMemoryUsagePercentage(), + renderMemory(quotaUsagePerUser.getMemoryTotalUsage() - quotaUsagePerUser.getMemoryUsageForUser()), + (int) (100 - quotaUsagePerUser.getMemoryTotalUsage()), + renderMemory(quotaUsagePerUser.getFreeMemory())); + } + return EMPTY_HTML; + } + + private SafeHtml templateWithLabels(String quota, + int totalUsagePercentage, String totalUsage, + int usedByYouPercentage, String usedByYou, + int usedByOthersPercentage, String usedByOthers, + int freePercentage, String free) { + return templates.quotaForUserBarToolTip(constants.tooltipQuotaLabel(), quota, + constants.tooltipTotalUsageLabel(), totalUsagePercentage, totalUsage, + constants.youUseQuota(), usedByYouPercentage, usedByYou, + constants.othersUseQuota(), usedByOthersPercentage, usedByOthers, + constants.freeQuota(), freePercentage, free); + } + + @Override + protected void onDetach() { + super.onDetach(); + tooltipPanel.hide(true); + } } -- To view, visit http://gerrit.ovirt.org/13134 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icb877d23edceaccb8e1cd549bef8ef7d9d044ca7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <oma...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches