modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
| 31 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/queue/AutodiscoveryPortlet.java
| 22 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
| 131 +++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/AutodiscoveryQueueDataSource.java
| 61 ++--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
| 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java
| 38 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
| 117 ++++++++
7 files changed, 334 insertions(+), 78 deletions(-)
New commits:
commit e3467c9c4e144cf4f1859fdce25711b6239c2783
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Mon Sep 13 09:00:28 2010 -0400
enable server side for autodiscovery and some cleanup.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/queue/AutodiscoveryPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/queue/AutodiscoveryPortlet.java
index e66f091..8159d23 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/queue/AutodiscoveryPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/queue/AutodiscoveryPortlet.java
@@ -35,6 +35,7 @@ import
org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
+import
org.rhq.enterprise.gui.coregui.client.inventory.resource.discovery.AutodiscoveryQueueDataSource;
import
org.rhq.enterprise.gui.coregui.client.inventory.resource.discovery.ResourceAutodiscoveryView;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
@@ -54,6 +55,15 @@ public class AutodiscoveryPortlet extends ResourceAutodiscoveryView
implements C
super(locatorId, true);
}
+ @Override
+ protected void onInit() {
+ super.onInit();
+ //initialize the datasource to include Portlet instance
+ if (getTreeGrid() != null) {
+ getTreeGrid().setDataSource(new AutodiscoveryQueueDataSource(this));
+ }
+ }
+
/** Implement configure action.
*/
@Override
@@ -63,9 +73,9 @@ public class AutodiscoveryPortlet extends ResourceAutodiscoveryView
implements C
//retrieve and translate to int
String retrieved =
storedPortlet.getConfiguration().getSimple(AUTODISCOVERY_PLATFORM_MAX).getStringValue();
if (retrieved.equals(unlimited)) {
- maximumPlatformsToDisplay = -1;
+ setMaximumPlatformsToDisplay(-1);
} else {
- maximumPlatformsToDisplay = Integer.parseInt(retrieved);
+ setMaximumPlatformsToDisplay(Integer.parseInt(retrieved));
}
} else {//create setting
storedPortlet.getConfiguration().put(new
PropertySimple(AUTODISCOVERY_PLATFORM_MAX, defaultValue));
@@ -153,4 +163,12 @@ public class AutodiscoveryPortlet extends ResourceAutodiscoveryView
implements C
return new AutodiscoveryPortlet(locatorId);
}
}
+
+ public int getMaximumPlatformsToDisplay() {
+ return maximumPlatformsToDisplay;
+ }
+
+ public void setMaximumPlatformsToDisplay(int maximumPlatformsToDisplay) {
+ this.maximumPlatformsToDisplay = maximumPlatformsToDisplay;
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/AutodiscoveryQueueDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/AutodiscoveryQueueDataSource.java
index 01a5ad3..63ed782 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/AutodiscoveryQueueDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/AutodiscoveryQueueDataSource.java
@@ -20,7 +20,6 @@ package
org.rhq.enterprise.gui.coregui.client.inventory.resource.discovery;
import java.util.ArrayList;
import java.util.Date;
-import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -40,6 +39,8 @@ import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageOrdering;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.queue.AutodiscoveryPortlet;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
@@ -48,15 +49,20 @@ import
org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
*/
public class AutodiscoveryQueueDataSource extends DataSource {
-
+ private Portlet portlet = null;
+ private int unlimited = -1;
private ResourceGWTServiceAsync resourceService =
GWTServiceLookup.getResourceService();
+ public AutodiscoveryQueueDataSource(Portlet portlet) {
+ this();
+ this.portlet = portlet;
+ }
+
public AutodiscoveryQueueDataSource() {
setClientOnly(false);
setDataProtocol(DSProtocol.CLIENTCUSTOM);
setDataFormat(DSDataFormat.CUSTOM);
-
DataSourceTextField idField = new DataSourceTextField("id",
"ID");
idField.setPrimaryKey(true);
@@ -75,7 +81,8 @@ public class AutodiscoveryQueueDataSource extends DataSource {
DataSourceTextField statusField = new DataSourceTextField("status",
"Inventory Status");
- setFields(idField, parentIdField, resourceNameField, resourceKeyField,
resourceTypeField, descriptionField, statusField, timestampField);
+ setFields(idField, parentIdField, resourceNameField, resourceKeyField,
resourceTypeField, descriptionField,
+ statusField, timestampField);
}
protected Object transformRequest(DSRequest request) {
@@ -84,17 +91,16 @@ public class AutodiscoveryQueueDataSource extends DataSource {
// Asume success
response.setStatus(0);
switch (request.getOperationType()) {
- case FETCH:
- executeFetch(request, response);
- break;
- default:
- break;
+ case FETCH:
+ executeFetch(request, response);
+ break;
+ default:
+ break;
}
return request.getData();
}
-
protected void executeFetch(final DSRequest request, final DSResponse response) {
PageControl pc = getPageControl(request);
@@ -114,21 +120,18 @@ public class AutodiscoveryQueueDataSource extends DataSource {
statuses.add(InventoryStatus.NEW);
}
+ resourceService.getQueuedPlatformsAndServers(statuses, pc, new
AsyncCallback<Map<Resource, List<Resource>>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to load inventory
discovery queue", caught);
+ }
- resourceService.getQueuedPlatformsAndServers(statuses, pc,
- new AsyncCallback<Map<Resource, List<Resource>>>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to load
inventory discovery queue", caught);
- }
-
- public void onSuccess(Map<Resource, List<Resource>>
result) {
- response.setData(buildNodes(result));
- processResponse(request.getRequestId(), response);
- }
- });
+ public void onSuccess(Map<Resource, List<Resource>> result) {
+ response.setData(buildNodes(result));
+ processResponse(request.getRequestId(), response);
+ }
+ });
}
-
private TreeNode[] buildNodes(Map<Resource, List<Resource>> result) {
ArrayList<ResourceTreeNode> nodes = new
ArrayList<ResourceTreeNode>();
@@ -146,7 +149,6 @@ public class AutodiscoveryQueueDataSource extends DataSource {
return treeNodes;
}
-
/**
* Returns a prepopulated PageControl based on the provided DSRequest. This will set
sort fields,
* pagination, but *not* filter fields.
@@ -157,10 +159,12 @@ public class AutodiscoveryQueueDataSource extends DataSource {
protected PageControl getPageControl(DSRequest request) {
// Initialize paging.
PageControl pageControl;
- if (request.getStartRow() == null || request.getEndRow() == null) {
- pageControl = new PageControl();
+ //retrieve portlet.configurationInformation
+ if ((this.portlet != null) || (this.portlet instanceof AutodiscoveryPortlet))
{//using default
+ AutodiscoveryPortlet settings = (AutodiscoveryPortlet) this.portlet;
+ pageControl = new PageControl(0, settings.getMaximumPlatformsToDisplay());
} else {
- pageControl = PageControl.getExplicitPageControl(request.getStartRow(),
request.getEndRow() - request.getStartRow());
+ pageControl = new PageControl(0, unlimited);
}
// Initialize sorting.
@@ -177,7 +181,6 @@ public class AutodiscoveryQueueDataSource extends DataSource {
return pageControl;
}
-
public static class ResourceTreeNode extends TreeNode {
private Resource resource;
@@ -186,8 +189,8 @@ public class AutodiscoveryQueueDataSource extends DataSource {
this.resource = resource;
String id = String.valueOf(resource.getId());
- String parentId = resource.getParentResource() == null ? null
- : String.valueOf((resource.getParentResource().getId()));
+ String parentId = resource.getParentResource() == null ? null :
String.valueOf((resource
+ .getParentResource().getId()));
setID(id);
setParentID(parentId);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
index 2d81fe0..445d1cb 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.IButton;
@@ -57,6 +58,7 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
private boolean simple = false;
private TreeGrid treeGrid;
private ToolStrip footer;
+ private DataSource dataSource = null;
private ResourceGWTServiceAsync resourceService =
GWTServiceLookup.getResourceService();
@@ -107,7 +109,7 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
treeGrid.setHeight100();
- treeGrid.setDataSource(new AutodiscoveryQueueDataSource());
+ treeGrid.setDataSource(dataSource = new AutodiscoveryQueueDataSource());
treeGrid.setAutoFetchData(true);
treeGrid.setResizeFieldsInRealTime(true);
@@ -230,4 +232,12 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
this.treeGrid.invalidateCache();
this.treeGrid.markForRedraw();
}
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ public TreeGrid getTreeGrid() {
+ return treeGrid;
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
index bc72530..1dd89ce 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
@@ -1,5 +1,23 @@
package org.rhq.enterprise.gui.coregui.client.util;
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
import java.util.ArrayList;
import java.util.List;
commit 3bd640d779cbd010aa70fa13a81a54598ed78ada
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sun Sep 12 21:23:06 2010 -0400
add footer for portlet and port of measurement utility.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
index f30ab10..0d4e6d6 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
@@ -77,12 +77,13 @@ public class Table extends LocatableHLayout {
private TableFilter filterForm;
private ListGrid listGrid;
private ToolStrip footer;
- private Label tableInfo;
+ protected Label tableInfo;
private List<String> headerIcons = new ArrayList<String>();
private boolean showHeader = true;
- private boolean showFooter = true;
+ protected boolean showFooter = true;
+ private boolean showFooterRefresh = true;
private String tableTitle;
private Criteria criteria;
@@ -122,7 +123,7 @@ public class Table extends LocatableHLayout {
private List<TableActionInfo> tableActions = new
ArrayList<TableActionInfo>();
private boolean tableActionDisableOverride = false;
- private List<Canvas> extraWidgets = new ArrayList<Canvas>();
+ protected List<Canvas> extraWidgets = new ArrayList<Canvas>();
public Table(String locatorId) {
this(locatorId, null, null, null, null, true);
@@ -314,13 +315,15 @@ public class Table extends LocatableHLayout {
footer.addMember(new LayoutSpacer());
- IButton refreshButton = new
LocatableIButton(extendLocatorId("Refresh"), "Refresh");
- refreshButton.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent clickEvent) {
- listGrid.invalidateCache();
- }
- });
- footer.addMember(refreshButton);
+ if (isShowFooterRefresh()) {
+ IButton refreshButton = new
LocatableIButton(extendLocatorId("Refresh"), "Refresh");
+ refreshButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ listGrid.invalidateCache();
+ }
+ });
+ footer.addMember(refreshButton);
+ }
footer.addMember(tableInfo);
@@ -648,4 +651,12 @@ public class Table extends LocatableHLayout {
this.actionButton = actionButton;
}
}
+
+ public boolean isShowFooterRefresh() {
+ return showFooterRefresh;
+ }
+
+ public void setShowFooterRefresh(boolean showFooterRefresh) {
+ this.showFooterRefresh = showFooterRefresh;
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
index 815afd7..3faa954 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
@@ -19,9 +19,14 @@ package
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.problems
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+//import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
@@ -34,11 +39,14 @@ import
org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TableWidget;
import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
import org.rhq.enterprise.gui.coregui.client.resource.ProblemResourcesDataSource;
+import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
/**
* A view that displays a paginated table of Resources with alerts,
@@ -48,13 +56,13 @@ import
org.rhq.enterprise.gui.coregui.client.resource.ProblemResourcesDataSource
*/
public class ProblemResourcesPortlet extends Table implements CustomSettingsPortlet {
+ //keys for smart gwt elements. should be unique
public static final String PROBLEM_RESOURCE_SHOW_HRS =
"max-problems-query-span";
public static final String PROBLEM_RESOURCE_SHOW_MAX =
"max-problems-shown";
public static final String KEY = "Has Alerts or Currently Unavailable";
private static final String TITLE = KEY;
- private int maximumProblemResourcesToDisplay = -1;
- private int maximumProblemResourcesWithinHours = -1;
private DashboardPortlet storedPortlet;
+ //constants
public static final String unlimited = "unlimited";
public static final String defaultValue = unlimited;
@@ -62,10 +70,13 @@ public class ProblemResourcesPortlet extends Table implements
CustomSettingsPort
super(locatorId, TITLE, true);
setShowHeader(false);
- setShowFooter(false);
+ setShowFooter(true);
+ //disable footer refresh
+ setShowFooterRefresh(false);
setOverflow(Overflow.HIDDEN);
+ //insert the datasource
this.dataSource = new ProblemResourcesDataSource(this);
setDataSource(this.dataSource);
@@ -82,16 +93,18 @@ public class ProblemResourcesPortlet extends Table implements
CustomSettingsPort
listGrid.setCellHeight(50);
//wrap to display disambiguation
listGrid.setWrapCells(true);
-
listGrid.getField(ProblemResourcesDataSource.resource).setWidth("40%");
-
listGrid.getField(ProblemResourcesDataSource.location).setWidth("40%");
-
listGrid.getField(ProblemResourcesDataSource.alerts).setWidth("10%");
-
listGrid.getField(ProblemResourcesDataSource.available).setWidth("10%");
+ addExtraWidget(new TimeRange(this.getLocatorId(), this));
}
}
//reference to datasource
private ProblemResourcesDataSource dataSource;
+ @Override
+ public ProblemResourcesDataSource getDataSource() {
+ return (ProblemResourcesDataSource) super.getDataSource();
+ }
+
/** Implement configure action.
*
*/
@@ -99,27 +112,39 @@ public class ProblemResourcesPortlet extends Table implements
CustomSettingsPort
public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
this.storedPortlet = storedPortlet;
- if (storedPortlet.getConfiguration().getSimple(PROBLEM_RESOURCE_SHOW_MAX) !=
null) {
+ int configuredValue = -1;
+
+ //determine configuration value for ProblemResourceShowMax
+ configuredValue = populateConfigurationValue(storedPortlet,
PROBLEM_RESOURCE_SHOW_MAX, defaultValue);
+ getDataSource().setMaximumProblemResourcesToDisplay(configuredValue);
+
+ //determine configuration value for ProblemResourceShowHrs
+ configuredValue = populateConfigurationValue(storedPortlet,
PROBLEM_RESOURCE_SHOW_HRS, defaultValue);
+ getDataSource().setMaximumProblemResourcesWithinHours(configuredValue);
+ }
+
+ /**Determine which configuration value to use given the property passed in.
+ *
+ * @param storedPortlet DashboardPortlet instance
+ * @param propertyKey Widget key
+ * @param defaultKeyValue default value to be used if property not yet set.
+ * @return int value of configuration, Ex. 1,5,10,unlimited where unlimited==-1.
+ */
+ private int populateConfigurationValue(DashboardPortlet storedPortlet, String
propertyKey, String defaultKeyValue) {
+ int configuredValue;
+ if ((storedPortlet != null) &&
(storedPortlet.getConfiguration().getSimple(propertyKey) != null)) {
//retrieve and translate to int
- String retrieved =
storedPortlet.getConfiguration().getSimple(PROBLEM_RESOURCE_SHOW_MAX).getStringValue();
+ String retrieved =
storedPortlet.getConfiguration().getSimple(propertyKey).getStringValue();
if (retrieved.equals(unlimited)) {
- maximumProblemResourcesToDisplay = -1;
+ configuredValue = -1;
} else {
- maximumProblemResourcesToDisplay = Integer.parseInt(retrieved);
+ configuredValue = Integer.parseInt(retrieved);
}
- } else {//create setting
- storedPortlet.getConfiguration().put(new
PropertySimple(PROBLEM_RESOURCE_SHOW_MAX, defaultValue));
- }
- if (storedPortlet.getConfiguration().getSimple(PROBLEM_RESOURCE_SHOW_HRS) !=
null) {
- String retrieved =
storedPortlet.getConfiguration().getSimple(PROBLEM_RESOURCE_SHOW_HRS).getStringValue();
- if (retrieved.equals(unlimited)) {
- setMaximumProblemResourcesWithinHours(-1);
- } else {
- setMaximumProblemResourcesWithinHours(Integer.parseInt(retrieved));
- }
- } else {
- storedPortlet.getConfiguration().put(new
PropertySimple(PROBLEM_RESOURCE_SHOW_HRS, defaultValue));
+ } else {//create setting if not already there.
+ storedPortlet.getConfiguration().put(new PropertySimple(propertyKey,
defaultKeyValue));
+ configuredValue = -1;
}
+ return configuredValue;
}
@Override
@@ -198,6 +223,7 @@ public class ProblemResourcesPortlet extends Table implements
CustomSettingsPort
storedPortlet.getConfiguration().put(
new PropertySimple(PROBLEM_RESOURCE_SHOW_HRS,
form.getValue(PROBLEM_RESOURCE_SHOW_HRS)));
}
+ refresh();
}
});
@@ -224,19 +250,62 @@ public class ProblemResourcesPortlet extends Table implements
CustomSettingsPort
return definition;
}
- public int getMaximumProblemResourcesToDisplay() {
- return maximumProblemResourcesToDisplay;
+ protected void refreshTableInfo() {
+ if (showFooter) {
+ long begin = 0;
+ List<Long> bounds =
MeasurementUtility.calculateTimeFrame(getDataSource()
+ .getMaximumProblemResourcesWithinHours(),
MeasurementUtility.UNIT_HOURS);
+ begin = bounds.get(0);
+ long end = bounds.get(1);
+
+ //if range spans greater than year then change formatter.
+ if ((end - begin) > MeasurementUtility.ONE_YEAR) {
+ timeRange = new String[] {
MeasurementUtility.getDateTimeYearFormatter().format(new Date(begin)),
+ MeasurementUtility.getDateTimeYearFormatter().format(new Date(end))
};
+ } else {
+ timeRange = new String[] {
MeasurementUtility.getDateTimeFormatter().format(new Date(begin)),
+ MeasurementUtility.getDateTimeFormatter().format(new Date(end)) };
+ }
+ for (Canvas extraWidget : extraWidgets) {
+ if (extraWidget instanceof TableWidget) {
+ ((TableWidget) extraWidget).refresh(getListGrid());
+ }
+ }
+ //remove selected count as portlet is view only. Selection not used.
+ this.tableInfo.setContents("Total: " +
getListGrid().getTotalRows());
+ }
+ }
+
+ private String[] timeRange = null;
+
+ public String[] getTimeRange() {
+ return timeRange;
}
- public void setMaximumProblemResourcesToDisplay(int maxPerRow) {
- this.maximumProblemResourcesToDisplay = maxPerRow;
+}
+
+/**Construct table widget Label to display timerange settings used with latest datasource
query.
+ *
+ * @author spinder
+ */
+class TimeRange extends LocatableHLayout implements TableWidget {
+ private Label label = new Label();
+ private ProblemResourcesPortlet portlet = null;
+
+ public TimeRange(String locatorId, ProblemResourcesPortlet problemResourcesPortlet)
{
+ super(locatorId);
+ this.portlet = problemResourcesPortlet;
}
- public void setMaximumProblemResourcesWithinHours(int
maximumProblemResourcesWithinHours) {
- this.maximumProblemResourcesWithinHours = maximumProblemResourcesWithinHours;
+ @Override
+ public void refresh(ListGrid listGrid) {
+ this.label.setWidth(400);
+ this.label.setContents("From " + portlet.getTimeRange()[0] + " to
" + portlet.getTimeRange()[1]);
}
- public int getMaximumProblemResourcesWithinHours() {
- return maximumProblemResourcesWithinHours;
+ @Override
+ protected void onDraw() {
+ super.onDraw();
+ addMember(this.label);
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java
index 7597d13..38c316b 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/resource/ProblemResourcesDataSource.java
@@ -52,6 +52,10 @@ public class ProblemResourcesDataSource extends
RPCDataSource<DisambiguationRepo
public static final String alerts = "alerts";
public static final String available = "available";
private Portlet portlet = null;
+ private long oldestDate = -1;
+ //configure elements
+ private int maximumProblemResourcesToDisplay = -1;
+ private int maximumProblemResourcesWithinHours = -1;
/** Build list of fields for the datasource and then adds them to it.
* @param problemResourcesPortlet
@@ -108,13 +112,13 @@ public class ProblemResourcesDataSource extends
RPCDataSource<DisambiguationRepo
ProblemResourcesPortlet problemPortlet = (ProblemResourcesPortlet)
this.portlet;
//populate criteria with portlet preferences defined.
if (problemPortlet != null) {
- if (problemPortlet.getMaximumProblemResourcesToDisplay() > 0) {
- maxItems = problemPortlet.getMaximumProblemResourcesToDisplay();
+ if (getMaximumProblemResourcesToDisplay() > 0) {
+ maxItems = getMaximumProblemResourcesToDisplay();
}
//define the time window
- if (problemPortlet.getMaximumProblemResourcesWithinHours() > 0) {
- ctime = System.currentTimeMillis()
- - (problemPortlet.getMaximumProblemResourcesWithinHours() * 60 *
60 * 1000);
+ if (getMaximumProblemResourcesWithinHours() > 0) {
+ ctime = System.currentTimeMillis() -
(getMaximumProblemResourcesWithinHours() * 60 * 60 * 1000);
+ setOldestDate(ctime);
}
}
}
@@ -200,4 +204,28 @@ public class ProblemResourcesDataSource extends
RPCDataSource<DisambiguationRepo
public DisambiguationReport<ProblemResourceComposite> copyValues(ListGridRecord
from) {
throw new UnsupportedOperationException("ProblemResource data is read
only");
}
+
+ public long getOldestDate() {
+ return oldestDate;
+ }
+
+ public void setOldestDate(long oldestDate) {
+ this.oldestDate = oldestDate;
+ }
+
+ public int getMaximumProblemResourcesToDisplay() {
+ return maximumProblemResourcesToDisplay;
+ }
+
+ public void setMaximumProblemResourcesToDisplay(int maxPerRow) {
+ this.maximumProblemResourcesToDisplay = maxPerRow;
+ }
+
+ public void setMaximumProblemResourcesWithinHours(int
maximumProblemResourcesWithinHours) {
+ this.maximumProblemResourcesWithinHours = maximumProblemResourcesWithinHours;
+ }
+
+ public int getMaximumProblemResourcesWithinHours() {
+ return maximumProblemResourcesWithinHours;
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
new file mode 100644
index 0000000..bc72530
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/MeasurementUtility.java
@@ -0,0 +1,99 @@
+package org.rhq.enterprise.gui.coregui.client.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.i18n.client.DateTimeFormat;
+
+public class MeasurementUtility {
+
+ private static DateTimeFormat formatter = DateTimeFormat.getFormat("MMM d, hh:mm
a");
+ private static DateTimeFormat formatterYear = DateTimeFormat.getFormat("MMM d,
yyyy hh:mm a");
+
+ //Time constants
+ public static final int UNIT_COLLECTION_POINTS = 1;
+ public static final int UNIT_MINUTES = 2;
+ public static final int UNIT_HOURS = 3;
+ public static final int UNIT_DAYS = 4;
+ public static final int UNIT_WEEKS = 5;
+ /*
+ * show units in terms of milliseconds
+ */
+ public static final long MINUTES = 60000;
+ public static final long HOURS = 3600000;
+ public static final long DAYS = 86400000;
+ public static final long WEEKS = 604800000;
+
+ /**
+ * five minutes in millisecond increments
+ */
+ public static final long FIVE_MINUTES = 300000;
+ public static final long ONE_YEAR = WEEKS * 52;
+
+ /**
+ * Method calculateTimeFrame
+ * <p/>
+ * Returns a two element<code>List</code> of
<code>Long</code> objects representing the begin and end times (in
+ * milliseconds since the epoch) of the timeframe. Returns null instead if the time
unit is indicated as
+ * <code>UNIT_COLLECTION_POINTS</code>. Ported to GWT from
MeasurementUtils(i:server side dep
+ * ii:old DateFormat doesn't play well with GWT).
+ *
+ * @param lastN the number of time units in the time frame
+ * @param unit the unit of time (as defined by <code>UNIT_*</code>
constants
+ * @return List
+ */
+ public static List<Long> calculateTimeFrame(int lastN, int unit) {
+ List<Long> l = new ArrayList<Long>(0);
+ if (unit == UNIT_COLLECTION_POINTS) {
+ return null;
+ }
+
+ long now = System.currentTimeMillis();
+
+ long retrospective = lastN;
+
+ switch (unit) {
+ case UNIT_WEEKS:
+ retrospective *= WEEKS;
+ break;
+ case UNIT_MINUTES:
+ retrospective *= MINUTES;
+ break;
+ case UNIT_HOURS:
+ retrospective *= HOURS;
+ break;
+ case UNIT_DAYS:
+ retrospective *= DAYS;
+ break;
+ default:
+ retrospective = -1;
+ break;
+ }
+
+ if (retrospective < 0) {//translate unlimited hrs to 0 time.
+ retrospective = now;
+ }
+
+ l.add(now - retrospective);
+ l.add(now);
+
+ return l;
+ }
+
+ /**Utility to return shared DateTimeFormat("MMM d, hh:mm a");
+ *
+ * @return DateTimeFormat
+ */
+ public static DateTimeFormat getDateTimeFormatter() {
+ return formatter;
+ }
+
+ /**Utility to return shared DateTimeFormat("MMM d, yyyy hh:mm a");
+ *
+ * @return DateTimeFormat
+ */
+ public static DateTimeFormat getDateTimeYearFormatter() {
+ return formatterYear;
+ }
+
+}