modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java | 8 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java | 177 ++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/AbstractMeasurementRangeEditor.java | 340 +++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java | 179 ++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/MeasurementRangeEditor.java | 211 ---- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/UserPreferencesMeasurementRangeEditor.java | 56 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java | 27 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java | 102 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java | 25 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/PortletConfigurationEditorComponent.java | 198 ++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java | 398 +++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java | 419 +++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java | 426 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java | 1 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java | 47 - modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java | 1 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/summary/ActivityView2.java | 16 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java | 4 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MeasurementTableView.java | 4 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/preferences/MeasurementUserPreferences.java | 36 20 files changed, 2393 insertions(+), 282 deletions(-)
New commits: commit 60684c2c6bb89d80b584f56bc53a2d743122688f Author: Simeon Pinder spinder@redhat.com Date: Thu Mar 10 07:33:36 2011 -0500
i)shared portlet config cleanup ii)GroupMetricsPortlet: incomplete as still has criteria issue. iii)GroupAlert2 portlet in table format. iv)share AbstractActivityView methods.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java index 0cd64b2..e8dc553 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java @@ -404,4 +404,12 @@ public class ImageManager {
return "subsystems/event/Events" + icon + "_16.png"; } + + public static String getMonitorIcon() { + return "subsystems/monitor/Monitor_16.png"; + } + + public static String getMonitorLargeIcon() { + return "subsystems/monitor/Monitor_24.png"; + } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java new file mode 100644 index 0000000..6ccd6af --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java @@ -0,0 +1,177 @@ +package org.rhq.enterprise.gui.coregui.client.alert; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.DSRequest; +import com.smartgwt.client.data.DSResponse; +import com.smartgwt.client.rpc.RPCResponse; + +import org.rhq.core.domain.alert.Alert; +import org.rhq.core.domain.alert.AlertPriority; +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.Property; +import org.rhq.core.domain.configuration.PropertyList; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.domain.criteria.AlertCriteria; +import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.core.domain.util.PageControl; +import org.rhq.core.domain.util.PageList; +import org.rhq.core.domain.util.PageOrdering; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.RecentAlertsPortlet; + +public class AlertPortletConfigurationDataSource extends AlertDataSource { + //configuration attributes + private Integer[] alertFilterResourceIds = {}; + private DashboardPortlet portlet = null; + private Configuration configuration = null; + private Integer groupId = null; + private Integer[] resourceIds = null; + private String alertResourcesToUse; + + public AlertPortletConfigurationDataSource() { + super(); + } + + public AlertPortletConfigurationDataSource(DashboardPortlet recentAlertsPortlet, Configuration configuration, + Integer groupId, Integer[] resourceIds) { + super(); + this.portlet = recentAlertsPortlet; + this.configuration = configuration; + this.groupId = groupId; + this.resourceIds = resourceIds; + } + + /** Override the executeFetch for AlertPortlet to allow specifying smaller than total + * result displays. + */ + protected void executeFetch(final DSRequest request, final DSResponse response) { + final long start = System.currentTimeMillis(); + AlertCriteria criteria = new AlertCriteria(); + //initialize to only five for quick queries. + criteria.setPageControl(new PageControl(0, Integer + .valueOf(PortletConfigurationEditorComponent.Constant.RESULT_COUNT_DEFAULT))); + //retrieve previous settings from portlet config + if ((portlet != null) && (this.portlet instanceof DashboardPortlet)) { + Configuration portletConfig = configuration; + //filter priority + PropertySimple property = portletConfig.getSimple(Constant.ALERT_PRIORITY); + if (property != null) { + String currentSetting = property.getStringValue(); + String[] parsedValues = currentSetting.trim().split(","); + if (currentSetting.trim().isEmpty() || parsedValues.length == 3) { + //all alert priorities assumed + } else { + AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length]; + int indx = 0; + for (String priority : parsedValues) { + AlertPriority p = AlertPriority.valueOf(priority); + filterPriorities[indx++] = p; + } + criteria.addFilterPriorities(filterPriorities); + } + } + PageControl pc = new PageControl(); + //result sort order + property = portletConfig.getSimple(Constant.RESULT_SORT_ORDER); + if (property != null) { + String currentSetting = property.getStringValue(); + if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase(PageOrdering.DESC.name())) { + criteria.addSortCtime(PageOrdering.DESC); + pc.setPrimarySortOrder(PageOrdering.DESC); + } else { + criteria.addSortCtime(PageOrdering.ASC); + pc.setPrimarySortOrder(PageOrdering.ASC); + } + } + //result timeframe if enabled + property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE); + if (Boolean.valueOf(property.getBooleanValue())) {//then proceed setting + property = portletConfig.getSimple(Constant.METRIC_RANGE); + if (property != null) { + String currentSetting = property.getStringValue(); + String[] range = currentSetting.split(","); + criteria.addFilterStartTime(Long.valueOf(range[0])); + criteria.addFilterEndTime(Long.valueOf(range[1])); + } + } + + //result count + property = portletConfig.getSimple(Constant.RESULT_COUNT); + if (property != null) { + String currentSetting = property.getStringValue(); + if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase("5")) { + PageControl pageControl = new PageControl(0, 5); + pc.setPageSize(5); + } else { + PageControl pageControl = new PageControl(0, Integer.valueOf(currentSetting)); + pc.setPageSize(Integer.valueOf(currentSetting)); + } + } + criteria.setPageControl(pc); + if (groupId != null) { + criteria.addFilterResourceGroupIds(groupId); + } + if ((resourceIds != null) && (resourceIds.length > 0)) { + criteria.addFilterResourceIds(resourceIds); + } + } + criteria.fetchAlertDefinition(true); + criteria.fetchRecoveryAlertDefinition(true); + + getAlertService().findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() { + + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught); + response.setStatus(RPCResponse.STATUS_FAILURE); + processResponse(request.getRequestId(), response); + } + + public void onSuccess(PageList<Alert> result) { + long fetchTime = System.currentTimeMillis() - start; + Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms"); + response.setData(buildRecords(result)); + response.setTotalRows(result.size()); + processResponse(request.getRequestId(), response); + } + }); + } + + public String getAlertResourcesToUse() { + return alertResourcesToUse; + } + + public void setAlertResourcesToUse(String resourcesToUse) { + this.alertResourcesToUse = resourcesToUse; + } + + public Integer[] getAlertFilterResourceIds() { + return alertFilterResourceIds; + } + + public void setAlertFilterResourceId(Integer[] alertFilterResourceId) { + this.alertFilterResourceIds = alertFilterResourceId; + } + + public Integer[] extractFilterResourceIds(DashboardPortlet storedPortlet, Integer[] filterResourceIds) { + PropertyList propertyList = storedPortlet.getConfiguration().getList( + RecentAlertsPortlet.ALERT_RANGE_RESOURCE_IDS); + if ((propertyList != null) && (propertyList.getList() != null) && (!propertyList.getList().isEmpty()) + && (propertyList.getList().get(0) != null)) { + Property container = propertyList.getList().get(0); + if (container instanceof PropertyList) { + PropertyList anotherList = (PropertyList) container; + if (anotherList.getList() != null) { + filterResourceIds = new Integer[anotherList.getList().size()]; + int index = 0; + for (Property p : anotherList.getList()) { + filterResourceIds[index++] = ((PropertySimple) p).getIntegerValue(); + } + } + } + } + return filterResourceIds; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java index 260655f..f4e9a0e 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java @@ -23,16 +23,16 @@ import java.util.List;
import org.rhq.core.domain.configuration.Configuration; import org.rhq.core.domain.configuration.PropertySimple; -import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant; import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
public class CustomConfigMeasurementRangeEditor extends AbstractMeasurementRangeEditor {
- public static final String PREF_METRIC_RANGE = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE; - public static final String PREF_METRIC_RANGE_LASTN = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_LASTN; - public static final String PREF_METRIC_RANGE_UNIT = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_UNIT; - public static final String PREF_METRIC_RANGE_BEGIN_END_FLAG = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG; - public static final String ALERT_METRIC_RANGE_ENABLE = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_ENABLE; + public static final String PREF_METRIC_RANGE = Constant.METRIC_RANGE; + public static final String PREF_METRIC_RANGE_LASTN = Constant.METRIC_RANGE_LASTN; + public static final String PREF_METRIC_RANGE_UNIT = Constant.METRIC_RANGE_UNIT; + public static final String PREF_METRIC_RANGE_BEGIN_END_FLAG = Constant.METRIC_RANGE_BEGIN_END_FLAG; + public static final String ALERT_METRIC_RANGE_ENABLE = Constant.METRIC_RANGE_ENABLE;
public static final String DEFAULT_VALUE_RANGE_RO = Boolean.FALSE.toString(); public static final Integer DEFAULT_VALUE_RANGE_LASTN = Integer.valueOf(8); @@ -156,7 +156,7 @@ public class CustomConfigMeasurementRangeEditor extends AbstractMeasurementRange //disable text field view to prevent bad data entry. Use widget or dropdowns. //TODO: spinder 3/9/11: this should be renabled to allow minute/second tuning here too, but need to handle validation. advancedStartItem.setUseTextField(false); - // advancedEndItem.setUseTextField(false); + advancedEndItem.setUseTextField(false); advancedStartItem.setType("selection"); simpleLastValuesItem.setWidth(50); simpleLastUnitsItem.setWidth(70); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java index 0d109ab..87193f4 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java @@ -25,6 +25,8 @@ import java.util.List; import org.rhq.core.domain.dashboard.DashboardPortlet; import org.rhq.enterprise.gui.coregui.client.ImageManager; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet2; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupMetricsPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.queue.AutodiscoveryPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.FavoriteResourcesPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.graph.GraphPortlet; @@ -92,10 +94,14 @@ public class PortletFactory { //defines mapping for Group Activity Dashboard registeredGroupPortletFactoryMap = new HashMap<String, PortletViewFactory>(); registeredGroupPortletFactoryMap.put(GroupAlertsPortlet.KEY, GroupAlertsPortlet.Factory.INSTANCE); + registeredGroupPortletFactoryMap.put(GroupAlertsPortlet2.KEY, GroupAlertsPortlet2.Factory.INSTANCE); + // registeredGroupPortletFactoryMap.put(GroupMetricsPortlet.KEY, GroupMetricsPortlet.Factory.INSTANCE);
//register group portlet names registeredGroupPortletNameMap = new HashMap<String, String>(registeredGroupPortletFactoryMap.size()); registeredGroupPortletNameMap.put(GroupAlertsPortlet.KEY, GroupAlertsPortlet.NAME); + registeredGroupPortletNameMap.put(GroupAlertsPortlet2.KEY, GroupAlertsPortlet2.NAME); + // registeredGroupPortletNameMap.put(GroupMetricsPortlet.KEY, GroupMetricsPortlet.NAME);
//############## Resource Activity Dashboard ############################################ //defines mapping for Group Activity Dashboard @@ -108,6 +114,8 @@ public class PortletFactory { //register portlet names registeredPortletIconMap = new HashMap<String, String>(registeredPortletFactoryMap.size()); registeredPortletIconMap.put(GroupAlertsPortlet.KEY, ImageManager.getAlertLargeIcon()); + registeredPortletIconMap.put(GroupAlertsPortlet2.KEY, ImageManager.getAlertLargeIcon()); + registeredPortletIconMap.put(GroupMetricsPortlet.KEY, ImageManager.getMonitorLargeIcon()); }
public static Portlet buildPortlet(String locatorId, PortletWindow portletWindow, DashboardPortlet storedPortlet) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/PortletConfigurationEditorComponent.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/PortletConfigurationEditorComponent.java new file mode 100644 index 0000000..e68b6cc --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/PortletConfigurationEditorComponent.java @@ -0,0 +1,198 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 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. + */ +package org.rhq.enterprise.gui.coregui.client.dashboard.portlets; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import com.smartgwt.client.types.MultipleAppearance; +import com.smartgwt.client.widgets.form.fields.SelectItem; + +import org.rhq.core.domain.alert.AlertPriority; +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.util.PageOrdering; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.ImageManager; +import org.rhq.enterprise.gui.coregui.client.Messages; +import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor; + +/** Shared portlet configuration component where initial configuration settings + * and widgets shared across portlet editors is defined. + * + * @author Simeon Pinder + */ +public class PortletConfigurationEditorComponent { + + static Messages MSG = CoreGUI.getMessages(); + + public interface Constant { + String ALERT_PRIORITY = "ALERT_PRIORITY"; + String METRIC_RANGE_ENABLE = "METRIC_RANGE_ENABLE"; + String METRIC_RANGE_BEGIN_END_FLAG = "METRIC_RANGE_BEGIN_END_FLAG"; + String METRIC_RANGE = "METRIC_RANGE"; + String METRIC_RANGE_LASTN = "METRIC_RANGE_LASTN"; + String METRIC_RANGE_LASTN_DEFAULT = String.valueOf(8); + String METRIC_RANGE_UNIT = "METRIC_RANGE_UNIT"; + String RESULT_SEVERITY = "severities"; + String RESULT_SORT_ORDER = "RESULT_SORT_ORDER"; + String RESULT_SORT_PRIORITY = "sort.priority"; + String RESULT_COUNT = "RESULT_COUNT"; + String RESULT_COUNT_DEFAULT = "5"; + String CUSTOM_REFRESH = "CUSTOM_REFRESH"; + } + + //configuration map initialization + public static Map<String, String> CONFIG_PROPERTY_INITIALIZATION = new HashMap<String, String>(); + static {// Key, Default value + //alert priority, if empty initialize to "" i.e. all priorities + CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_PRIORITY, ""); + //result sort order, if empty initialize to "DESC" + CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_SORT_ORDER, PageOrdering.DESC.name()); + //result count, if empty initialize to 5 + CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT); + //whether to specify time range for alerts. Defaults to false + CONFIG_PROPERTY_INITIALIZATION.put(Constant.METRIC_RANGE_ENABLE, String.valueOf(false)); + //whether Begin and End values set for time. Aka. Advanced/full range setting Defaults to false + CONFIG_PROPERTY_INITIALIZATION.put(Constant.METRIC_RANGE_BEGIN_END_FLAG, String.valueOf(false)); + //whether in simple mode. Ex. 8 hrs. Defaults to 8 + CONFIG_PROPERTY_INITIALIZATION.put(Constant.METRIC_RANGE_LASTN, Constant.METRIC_RANGE_LASTN_DEFAULT); + } + + /* Single select combobox for number of items to display on the dashboard + * + * @return Populated selectItem instance. + */ + public static SelectItem getResultCountEditor(Configuration portletConfig) { + + final SelectItem maximumResultsComboBox = new SelectItem(Constant.RESULT_COUNT); + maximumResultsComboBox.setTitle("Results Count"); + maximumResultsComboBox.setWrapTitle(false); + maximumResultsComboBox.setTooltip("<nobr><b> " + "Displays N results with alerts" + "</b></nobr>"); + //spinder 9/3/10: the following is required workaround to disable editability of combobox. + maximumResultsComboBox.setType("selection"); + //set width of dropdown display region + maximumResultsComboBox.setWidth(100); + + //TODO: spinder 3/4/11 this is arbitrary. Get UXD input for better acceptable defaults + int[] selectionValues = { 5, 10, 30, 100 }; + + //define acceptable values for display amount + String[] displayValues = new String[selectionValues.length]; + int i = 0; + for (int selection : selectionValues) { + displayValues[i++] = String.valueOf(selection); + } + maximumResultsComboBox.setValueMap(displayValues); + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.RESULT_COUNT).getStringValue(); + if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT)) { + maximumResultsComboBox.setValue(Constant.RESULT_COUNT_DEFAULT); + } else { + maximumResultsComboBox.setValue(currentValue); + } + return maximumResultsComboBox; + } + + /* Multiple select combobox for alert priorities to display on dashboard + * + * @return Populated selectItem instance. + */ + public static SelectItem getAlertPriorityEditor(Configuration portletConfig) { + SelectItem priorityFilter = new SelectItem(Constant.RESULT_SEVERITY, MSG.view_alerts_table_filter_priority()); + priorityFilter.setWrapTitle(false); + priorityFilter.setWidth(200); + priorityFilter.setMultiple(true); + priorityFilter.setMultipleAppearance(MultipleAppearance.PICKLIST); + + LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(3); + priorities.put(AlertPriority.HIGH.name(), MSG.common_alert_high()); + priorities.put(AlertPriority.MEDIUM.name(), MSG.common_alert_medium()); + priorities.put(AlertPriority.LOW.name(), MSG.common_alert_low()); + LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(3); + priorityIcons.put(AlertPriority.HIGH.name(), ImageManager.getAlertIcon(AlertPriority.HIGH)); + priorityIcons.put(AlertPriority.MEDIUM.name(), ImageManager.getAlertIcon(AlertPriority.MEDIUM)); + priorityIcons.put(AlertPriority.LOW.name(), ImageManager.getAlertIcon(AlertPriority.LOW)); + priorityFilter.setValueMap(priorities); + priorityFilter.setValueIcons(priorityIcons); + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.ALERT_PRIORITY).getStringValue(); + if (currentValue.isEmpty() || currentValue.split(",").length == AlertPriority.values().length) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); + } else { + //spinder:3/4/11 doing this nonsense due to some weird smartgwt issue with SelectItem in VLayout. + if (currentValue.equalsIgnoreCase("HIGH")) { + priorityFilter.setValues(AlertPriority.HIGH.name()); + } else if (currentValue.equalsIgnoreCase("HIGH,MEDIUM")) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name()); + } else if (currentValue.equalsIgnoreCase("HIGH,LOW")) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.LOW.name()); + } else if (currentValue.equalsIgnoreCase("MEDIUM")) { + priorityFilter.setValues(AlertPriority.MEDIUM.name()); + } else if (currentValue.equalsIgnoreCase("MEDIUM,LOW")) { + priorityFilter.setValues(AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); + } else { + priorityFilter.setValues(AlertPriority.LOW.name()); + } + } + return priorityFilter; + } + + /* Single select combobox for sort order of items to display on dashboard + * + * @return Populated selectItem instance. + */ + public static SelectItem getResulSortOrderEditor(Configuration portletConfig) { + SelectItem sortPrioritySelection = new SelectItem(Constant.RESULT_SORT_PRIORITY, "Sort Order"); + sortPrioritySelection.setWrapTitle(false); + sortPrioritySelection.setTooltip("Sets sort order for results."); + LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(2); + priorities.put(PageOrdering.ASC.name(), "Ascending"); + priorities.put(PageOrdering.DESC.name(), "Descending"); + LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(2); + priorityIcons.put(PageOrdering.ASC.name(), "ascending"); + priorityIcons.put(PageOrdering.DESC.name(), "descending"); + + sortPrioritySelection.setValueMap(priorities); + sortPrioritySelection.setValueIcons(priorityIcons); + //TODO: spinder 3/4/11 not sure why this is necessary. [SKIN] not being interpreted. + String skinDir = "../org.rhq.enterprise.gui.coregui.CoreGUI/sc/skins/Enterprise/images"; + sortPrioritySelection.setImageURLPrefix(skinDir + "/actions/sort_"); + sortPrioritySelection.setImageURLSuffix(".png"); + + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.RESULT_SORT_ORDER).getStringValue(); + if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(PageOrdering.DESC.name())) {//default to descending order + sortPrioritySelection.setDefaultValue(PageOrdering.DESC.name()); + } else { + sortPrioritySelection.setDefaultValue(PageOrdering.ASC.name()); + } + return sortPrioritySelection; + } + + /** Convenience method to construct CustomConfigMeasurementRangeEditor instances. + * + * @param portletConfig + * @return + */ + public static CustomConfigMeasurementRangeEditor getMeasurementRangeEditor(Configuration portletConfig) { + return new CustomConfigMeasurementRangeEditor("alertTimeFrame", portletConfig); + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java index 1d63f04..483d858 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java @@ -18,16 +18,12 @@ */ package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
-import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map;
import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.types.MultipleAppearance; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.HTMLFlow; import com.smartgwt.client.widgets.form.DynamicForm; @@ -51,14 +47,14 @@ import org.rhq.core.domain.util.PageList; import org.rhq.core.domain.util.PageOrdering; import org.rhq.enterprise.gui.coregui.client.ImageManager; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; -import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent; -import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener; import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor; import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; 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.dashboard.portlets.PortletConfigurationEditorComponent; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant; import org.rhq.enterprise.gui.coregui.client.gwt.AlertGWTServiceAsync; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView; @@ -77,51 +73,12 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; * * @author Simeon Pinder */ -public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet, - PropertyValueChangeListener { - - public interface Constant { - String ALERT_PRIORITY = "ALERT_PRIORITY"; - String ALERT_METRIC_RANGE_ENABLE = "ALERT_METRIC_RANGE_ENABLE"; - String ALERT_METRIC_RANGE_BEGIN_END_FLAG = "ALERT_METRIC_RANGE_BEGIN_END_FLAG"; - String ALERT_METRIC_RANGE = "ALERT_METRIC_RANGE"; - String ALERT_METRIC_RANGE_LASTN = "ALERT_METRIC_RANGE_LASTN"; - String ALERT_METRIC_RANGE_LASTN_DEFAULT = String.valueOf(8); - String ALERT_METRIC_RANGE_UNIT = "ALERT_METRIC_RANGE_UNIT"; - String RESULT_SORT_ORDER = "RESULT_SORT_ORDER"; - String RESULT_COUNT = "RESULT_COUNT"; - String RESULT_COUNT_DEFAULT = "5"; - String CUSTOM_REFRESH = "CUSTOM_REFRESH"; - } - - //configuration map initialization - private static Map<String, String> CONFIG_PROPERTY_INITIALIZATION = new HashMap<String, String>(); - static {// Key, Default value - //alert priority, if empty initialize to "" i.e. all priorities - CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_PRIORITY, ""); - //result sort order, if empty initialize to "DESC" - CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_SORT_ORDER, PageOrdering.DESC.name()); - //result count, if empty initialize to 5 - CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT); - //whether to specify time range for alerts. Defaults to false - CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_METRIC_RANGE_ENABLE, String.valueOf(false)); - //whether Begin and End values set for time. Aka. Advanced/full range setting Defaults to false - CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG, String.valueOf(false)); - //whether in simple mode. Ex. 8 hrs. Defaults to 8 - CONFIG_PROPERTY_INITIALIZATION - .put(Constant.ALERT_METRIC_RANGE_LASTN, Constant.ALERT_METRIC_RANGE_LASTN_DEFAULT); - - } - +public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet { private int groupId = -1; protected LocatableCanvas recentAlertsContent = new LocatableCanvas(extendLocatorId("RecentAlerts")); private static AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService(); private boolean currentlyLoading = false; private Configuration portletConfig = null; - private SelectItem alertPrioritySelector = null; - private SelectItem resultSortSelector = null; - private SelectItem resultCountSelector = null; - private CustomConfigMeasurementRangeEditor measurementRangeEditor = null; private DashboardPortlet storedPortlet;
public GroupAlertsPortlet(String locatorId) { @@ -175,14 +132,12 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin portletConfig = storedPortlet.getConfiguration();
//lazy init any elements not yet configured. - for (String key : CONFIG_PROPERTY_INITIALIZATION.keySet()) { + for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) { if (portletConfig.getSimple(key) == null) { - portletConfig.put(new PropertySimple(key, CONFIG_PROPERTY_INITIALIZATION.get(key))); + portletConfig.put(new PropertySimple(key, + PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key))); } } - - //custom refresh - //CUSTOM_REFRESH }
public Canvas getHelpCanvas() { @@ -236,9 +191,9 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin } } //result timeframe if enabled - property = portletConfig.getSimple(Constant.ALERT_METRIC_RANGE_ENABLE); + property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE); if (Boolean.valueOf(property.getBooleanValue())) {//then proceed setting - property = portletConfig.getSimple(Constant.ALERT_METRIC_RANGE); + property = portletConfig.getSimple(Constant.METRIC_RANGE); if (property != null) { String currentSetting = property.getStringValue(); String[] range = currentSetting.split(","); @@ -294,7 +249,7 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin } else { LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow(recentAlertsContent // .extendLocatorId("None"), AbstractActivityView.RECENT_ALERTS_NONE); - .extendLocatorId("None"), "No results using criteria specified."); + .extendLocatorId("None"), "No results found using criteria specified."); column.addMember(row); } for (Canvas child : recentAlertsContent.getChildren()) { @@ -327,20 +282,19 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin //add label about what configuration affects
//add alert priority selector - alertPrioritySelector = getAlertPriorityEditor(); + final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent + .getAlertPriorityEditor(portletConfig); //add sort priority selector - resultSortSelector = getResulSortOrderEditor("sort.priority", "Sort Order", "Sets sort order for results."); + // final SelectItem resultSortSelector = PortletConfigurationEditorComponent + // .getResulSortOrderEditor(portletConfig); //add result count selector - //TODO: spinder 3/4/11 this is arbitrary. Get UXD input for better acceptable defaults - int[] countSelections = { 5, 10, 30, 100 }; - resultCountSelector = getResultCountEditor(Constant.RESULT_COUNT, "Results Count", - "Displays N results with alerts", countSelections); - + final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig); //add range selector - measurementRangeEditor = new CustomConfigMeasurementRangeEditor(page.extendLocatorId("alertTimeFrame"), - portletConfig); - - form.setItems(alertPrioritySelector, resultSortSelector, resultCountSelector); + final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent + .getMeasurementRangeEditor(portletConfig); + //TODO: spinder 3/10/11 renable sort selector once it's working in criteria + // form.setItems(alertPrioritySelector, resultSortSelector, resultCountSelector); + form.setItems(alertPrioritySelector, resultCountSelector);
//submit handler customSettings.addSubmitValuesHandler(new SubmitValuesHandler() { @@ -354,13 +308,13 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin } else {//some subset of available alertPriorities will be used portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, selectedValue)); } - //result sort order - selectedValue = resultSortSelector.getValue().toString(); - if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc - portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); - } else { - portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC)); - } + // //result sort order + // selectedValue = resultSortSelector.getValue().toString(); + // if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc + // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); + // } else { + // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC)); + // } //result count selectedValue = resultCountSelector.getValue().toString(); if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT))) {//then 5 @@ -374,20 +328,19 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin CheckboxItem itemC = (CheckboxItem) item; selectedValue = String.valueOf(itemC.getValueAsBoolean()); if (!selectedValue.trim().isEmpty()) {//then call - portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE_ENABLE, selectedValue)); + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, selectedValue)); }
//alert time advanced time filter enabled. selectedValue = String.valueOf(measurementRangeEditor.isAdvanced()); if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) { - portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG, selectedValue)); + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue)); }
//alert time frame List<Long> begEnd = measurementRangeEditor.getBeginEndTimes(); if (begEnd.get(0) != 0) {//advanced settings - portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE, (begEnd.get(0) + "," + begEnd - .get(1)))); + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE, (begEnd.get(0) + "," + begEnd.get(1)))); }
//persist @@ -403,111 +356,6 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin return customSettings; }
- /* single select combobox for number of items to display on the dashboard - * - * @param identifier Form identifier - * @param selectionTitle Title to left of combobox - * @param selectionHint Hint to display on mouseover - * @param selectionValues Integer[] to show as drop down options. - * @return Populated selectItem instance. - */ - private SelectItem getResultCountEditor(String identifier, String selectionTitle, String selectionHint, - int[] selectionValues) { - - final SelectItem maximumResultsComboBox = new SelectItem(identifier); - maximumResultsComboBox.setTitle(selectionTitle); - maximumResultsComboBox.setWrapTitle(false); - maximumResultsComboBox.setTooltip("<nobr><b> " + selectionHint + "</b></nobr>"); - //spinder 9/3/10: the following is required workaround to disable editability of combobox. - maximumResultsComboBox.setType("selection"); - //set width of dropdown display region - maximumResultsComboBox.setWidth(100); - - //define acceptable values for display amount - String[] displayValues = new String[selectionValues.length]; - int i = 0; - for (int selection : selectionValues) { - displayValues[i++] = String.valueOf(selection); - } - maximumResultsComboBox.setValueMap(displayValues); - //reload current settings if they exist, otherwise enable all. - String currentValue = portletConfig.getSimple(Constant.RESULT_COUNT).getStringValue(); - if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT)) { - maximumResultsComboBox.setValue(Constant.RESULT_COUNT_DEFAULT); - } else { - maximumResultsComboBox.setValue(currentValue); - } - return maximumResultsComboBox; - } - - private SelectItem getAlertPriorityEditor() { - SelectItem priorityFilter = new SelectItem("severities", MSG.view_alerts_table_filter_priority()); - priorityFilter.setWrapTitle(false); - priorityFilter.setWidth(200); - priorityFilter.setMultiple(true); - priorityFilter.setMultipleAppearance(MultipleAppearance.PICKLIST); - - LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(3); - priorities.put(AlertPriority.HIGH.name(), MSG.common_alert_high()); - priorities.put(AlertPriority.MEDIUM.name(), MSG.common_alert_medium()); - priorities.put(AlertPriority.LOW.name(), MSG.common_alert_low()); - LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(3); - priorityIcons.put(AlertPriority.HIGH.name(), ImageManager.getAlertIcon(AlertPriority.HIGH)); - priorityIcons.put(AlertPriority.MEDIUM.name(), ImageManager.getAlertIcon(AlertPriority.MEDIUM)); - priorityIcons.put(AlertPriority.LOW.name(), ImageManager.getAlertIcon(AlertPriority.LOW)); - priorityFilter.setValueMap(priorities); - priorityFilter.setValueIcons(priorityIcons); - //reload current settings if they exist, otherwise enable all. - String currentValue = portletConfig.getSimple(Constant.ALERT_PRIORITY).getStringValue(); - if (currentValue.isEmpty() || currentValue.split(",").length == AlertPriority.values().length) { - priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); - } else { - //spinder:3/4/11 doing this nonsense due to some weird smartgwt issue with SelectItem in VLayout. - if (currentValue.equalsIgnoreCase("HIGH")) { - priorityFilter.setValues(AlertPriority.HIGH.name()); - } else if (currentValue.equalsIgnoreCase("HIGH,MEDIUM")) { - priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name()); - } else if (currentValue.equalsIgnoreCase("HIGH,LOW")) { - priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.LOW.name()); - } else if (currentValue.equalsIgnoreCase("MEDIUM")) { - priorityFilter.setValues(AlertPriority.MEDIUM.name()); - } else if (currentValue.equalsIgnoreCase("MEDIUM,LOW")) { - priorityFilter.setValues(AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); - } else { - priorityFilter.setValues(AlertPriority.LOW.name()); - } - } - return priorityFilter; - } - - private SelectItem getResulSortOrderEditor(String identifier, String selectionTitle, String selectionHint) { - SelectItem sortPrioritySelection = new SelectItem(identifier, selectionTitle); - sortPrioritySelection.setWrapTitle(false); - sortPrioritySelection.setTooltip(selectionHint); - LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(2); - priorities.put(PageOrdering.ASC.name(), "Ascending"); - priorities.put(PageOrdering.DESC.name(), "Descending"); - LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(2); - priorityIcons.put(PageOrdering.ASC.name(), "ascending"); - priorityIcons.put(PageOrdering.DESC.name(), "descending"); - - sortPrioritySelection.setValueMap(priorities); - sortPrioritySelection.setValueIcons(priorityIcons); - //TODO: spinder 3/4/11 not sure why this is necessary. [SKIN] not being interpreted. - String skinDir = "../org.rhq.enterprise.gui.coregui.CoreGUI/sc/skins/Enterprise/images"; - sortPrioritySelection.setImageURLPrefix(skinDir + "/actions/sort_"); - sortPrioritySelection.setImageURLSuffix(".png"); - - //reload current settings if they exist, otherwise enable all. - String currentValue = portletConfig.getSimple(Constant.RESULT_SORT_ORDER).getStringValue(); - if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(PageOrdering.DESC.name())) {//default to descending order - sortPrioritySelection.setDefaultValue(PageOrdering.DESC.name()); - } else { - sortPrioritySelection.setDefaultValue(PageOrdering.ASC.name()); - } - return sortPrioritySelection; - } - @Override public void startRefreshCycle() { //current setting @@ -547,10 +395,4 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin super.redraw(); loadData(); } - - @Override - public void propertyValueChanged(PropertyValueChangeEvent event) { - // TODO Auto-generated method stub - - } } \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java index 72631b6..ee8cdd0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java @@ -18,8 +18,11 @@ */ package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
+import java.util.HashMap; +import java.util.List; import java.util.Set;
+import com.google.gwt.user.client.History; import com.google.gwt.user.client.Timer; import com.smartgwt.client.types.Overflow; import com.smartgwt.client.widgets.Canvas; @@ -29,18 +32,15 @@ import com.smartgwt.client.widgets.events.DoubleClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.events.SubmitValuesEvent; import com.smartgwt.client.widgets.form.events.SubmitValuesHandler; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.SpacerItem; -import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; -import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridRecord; -import com.smartgwt.client.widgets.layout.VLayout;
-import org.rhq.core.domain.alert.AlertPriority; import org.rhq.core.domain.authz.Permission; -import org.rhq.core.domain.configuration.PropertyList; +import org.rhq.core.domain.configuration.Configuration; import org.rhq.core.domain.configuration.PropertySimple; import org.rhq.core.domain.dashboard.DashboardPortlet; import org.rhq.core.domain.resource.ResourceType; @@ -49,17 +49,18 @@ import org.rhq.enterprise.gui.coregui.client.LinkManager; import org.rhq.enterprise.gui.coregui.client.Messages; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView; -import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletDataSource; +import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletConfigurationDataSource; +import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor; import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; 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.dashboard.portlets.PortletConfigurationEditorComponent; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.PortletAlertSelector; import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; -import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout; -import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableLabel; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
@@ -69,39 +70,16 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility; public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSettingsPortlet, AutoRefreshPortlet {
// A non-displayed, persisted identifier for the portlet - public static final String KEY = "Group: Alerts2"; + public static final String KEY = "GroupAlerts2"; // A default displayed, persisted name for the portlet - public static final String NAME = MSG.view_portlet_defaultName_recentAlerts(); + // public static final String NAME = MSG.view_portlet_defaultName_recentAlerts(); + public static final String NAME = "Group: Alerts2";
- //widget keys also used in form population - public static final String ALERT_RANGE_DISPLAY_AMOUNT_VALUE = "alert-range-display-amount-value"; - public static final String ALERT_RANGE_PRIORITY_VALUE = "alert-range-priority-value"; - public static final String ALERT_RANGE_TIME_VALUE = "alert-range-time-value"; public static final String ALERT_RANGE_RESOURCES_VALUE = "alert-range-resource-value"; public static final String ALERT_RANGE_RESOURCE_IDS = "alert-range-resource-ids"; - //configuration default information - private static final String defaultAlertCountValue = "5"; - private static final String PRIORITY_ALL = MSG.common_label_all(); - private static final String PRIORITY_HIGH = AlertPriority.HIGH.getDisplayName(); - private static final String PRIORITY_MEDIUM = AlertPriority.MEDIUM.getDisplayName(); - private static final String PRIORITY_LOW = AlertPriority.LOW.getDisplayName(); - private static final String defaultPriorityValue = PRIORITY_ALL; - private static final String TIME_30_MINS = "30 " + MSG.common_label_minutes(); - private static final String TIME_HOUR = MSG.common_label_hour(); - private static final String TIME_12_HRS = "12 " + MSG.common_label_hours(); - private static final String TIME_DAY = MSG.common_label_day(); - private static final String TIME_WEEK = MSG.common_label_week(); - private static final String TIME_MONTH = MSG.common_label_month(); - private static final String defaultTimeValue = TIME_DAY; public static final String RESOURCES_ALL = MSG.common_label_all_resources(); public static final String RESOURCES_SELECTED = MSG.common_label_selected_resources(); public static final String defaultResourceValue = RESOURCES_ALL; - private static final String unlimited = MSG.common_label_unlimited(); - //alert resource labels - public static final String ALERT_LABEL_SELECTED_RESOURCES = MSG.common_title_selected_resources(); - public static final String ALERT_LABEL_AVAILABLE_RESOURCES = MSG.common_title_available_resources(); - public static final String ALERT_LABEL_RESOURCE_INVENTORY = MSG.common_title_resource_inventory(); - public static final int ALERT_RESOURCE_SELECTION_WIDTH = 800; public static final String ID = "id";
// set on initial configuration, the window for this portlet view. @@ -110,17 +88,29 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti //shared private UI elements private AlertResourceSelectorRegion resourceSelector;
- private AlertPortletDataSource dataSource; + private AlertPortletConfigurationDataSource dataSource; //instance ui widgets private Canvas containerCanvas;
private Timer refreshTimer; + private DashboardPortlet storedPortlet; + private Configuration portletConfig; + private int groupId; + private boolean portletConfigInitialized = false;
public GroupAlertsPortlet2(String locatorId) { super(locatorId);
//override the shared datasource - this.dataSource = new AlertPortletDataSource(); + //figure out which page we're loading + String currentPage = History.getToken(); + String[] elements = currentPage.split("/"); + int currentGroupIdentifier = Integer.valueOf(elements[1]); + this.groupId = currentGroupIdentifier; + + //initalize the datasource + this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, currentGroupIdentifier, + null); setDataSource(this.dataSource);
setShowHeader(false); @@ -131,8 +121,18 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti setOverflow(Overflow.VISIBLE); }
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) { + private static HashMap<String, String> updatedMapping = new HashMap<String, String>(); + static { + updatedMapping.putAll(PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION); + //Key, default + updatedMapping.put(ALERT_RANGE_RESOURCES_VALUE, RESOURCES_ALL); + updatedMapping.put(ALERT_RANGE_RESOURCE_IDS, RESOURCES_ALL); + }
+ /** Responsible for initialization and lazy configuration of the portlet values + */ + public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) { + //populate portlet configuration details if (null == this.portletWindow && null != portletWindow) { this.portletWindow = portletWindow; } @@ -140,56 +140,21 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) { return; } + this.storedPortlet = storedPortlet; + portletConfig = storedPortlet.getConfiguration();
- //Operation range property - retrieve existing value - PropertySimple property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE); - if ((property != null) && (property.getStringValue() != null)) { - //retrieve and translate to int - String retrieved = property.getStringValue(); - int translatedAlertRangeSelection = translatedAlertRangeSelection(retrieved); - getDataSource().setAlertRangeCompleted(translatedAlertRangeSelection); - } else {//create setting - storedPortlet.getConfiguration().put( - new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue)); - getDataSource().setAlertRangeCompleted(Integer.parseInt(defaultAlertCountValue)); - } - //Operation priority property setting - property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE); - if ((property != null) && (property.getStringValue() != null)) { - //retrieve and translate to int - String retrieved = property.getStringValue(); - int translatedPriorityIndex = translatedPriorityToValidIndex(retrieved); - getDataSource().setAlertPriorityIndex(translatedPriorityIndex); - } else {//create setting - storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue)); - getDataSource().setAlertPriorityIndex(translatedPriorityToValidIndex(PRIORITY_ALL)); + if (!portletConfigInitialized) { + this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, this.groupId, null); + setDataSource(this.dataSource); + portletConfigInitialized = true; }
- //Range to time that alerts will be shown for - property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE); - if ((property != null) && (property.getStringValue() != null)) { - //retrieve and translate to int - String retrieved = property.getStringValue(); - long translatedRange = translateTimeToValidRange(retrieved); - getDataSource().setAlertTimeRange(translatedRange); - } else {//create setting - storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue)); - getDataSource().setAlertTimeRange(translateTimeToValidRange(defaultTimeValue)); - } - - //Range of resources to be included in the query - property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE); - if ((property != null) && (property.getStringValue() != null)) { - //retrieve and translate to int - String retrieved = property.getStringValue(); - if (retrieved.trim().equalsIgnoreCase(RESOURCES_SELECTED)) { - getDataSource().setAlertResourcesToUse(RESOURCES_SELECTED); - } else { - getDataSource().setAlertResourcesToUse(RESOURCES_ALL); + //lazy init any elements not yet configured. + for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) { + if (portletConfig.getSimple(key) == null) { + portletConfig.put(new PropertySimple(key, + PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key))); } - } else {//create setting - storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue)); - getDataSource().setAlertResourcesToUse(RESOURCES_ALL); }
//resource ids to be conditionally included in the query @@ -213,347 +178,99 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti containerCanvas.addChild(new Canvas()); } } - } - - private int translatedAlertRangeSelection(String retrieved) { - int translated = -1; - if ((retrieved != null) && (!retrieved.trim().isEmpty())) { - if (retrieved.equalsIgnoreCase(unlimited)) { - translated = -1; - } else { - translated = Integer.parseInt(retrieved);//default to all - } - } else {//default to defaultValue - if (defaultAlertCountValue.equalsIgnoreCase(unlimited)) { - translated = -1; - } else { - translated = Integer.parseInt(defaultAlertCountValue); - } - } - return translated; - } - - private int translatedPriorityToValidIndex(String retrieved) { - int translatedPriority = 0;//default to all - if ((retrieved != null) && (!retrieved.trim().isEmpty())) { - if (retrieved.equalsIgnoreCase(PRIORITY_HIGH)) { - translatedPriority = 3; - } else if (retrieved.equalsIgnoreCase(PRIORITY_MEDIUM)) { - translatedPriority = 2; - } else if (retrieved.equalsIgnoreCase(PRIORITY_LOW)) { - translatedPriority = 1; - } else { - translatedPriority = 0;//default to all - } - } - return translatedPriority; - }
- /**Translates the UI selection options into time values for alert query. - * - * @param retrieved - * @return long value mapping to string passed in. - */ - private long translateTimeToValidRange(String retrieved) { - long translated = 0;//default to ALL - if ((retrieved != null) && (!retrieved.trim().isEmpty())) { - if (retrieved.equalsIgnoreCase(TIME_30_MINS)) { - translated = MeasurementUtility.MINUTES * 30; - } else if (retrieved.equalsIgnoreCase(TIME_HOUR)) { - translated = MeasurementUtility.HOURS; - } else if (retrieved.equalsIgnoreCase(TIME_12_HRS)) { - translated = MeasurementUtility.HOURS * 12; - } else if (retrieved.equalsIgnoreCase(TIME_DAY)) { - translated = MeasurementUtility.DAYS; - } else if (retrieved.equalsIgnoreCase(TIME_WEEK)) { - translated = MeasurementUtility.WEEKS; - } else if (retrieved.equalsIgnoreCase(TIME_MONTH)) { - translated = MeasurementUtility.DAYS * 28;//replicated from old struts def. - } else { - translated = MeasurementUtility.DAYS;//default to day otherwise. - } - } - return translated; }
public Canvas getHelpCanvas() { return new HTMLFlow(MSG.view_portlet_help_recentAlerts()); }
+ @Override public DynamicForm getCustomSettingsForm() { - //root dynamic form instance - final LocatableDynamicForm form = new LocatableDynamicForm(extendLocatorId("custom-settings")); - form.setWidth(GroupAlertsPortlet2.ALERT_RESOURCE_SELECTION_WIDTH + 40);//largest widget display + 40 for buttons - form.setHeight(400); + LocatableDynamicForm customSettings = new LocatableDynamicForm(extendLocatorId("customSettings")); + LocatableVLayout page = new LocatableVLayout(customSettings.extendLocatorId("page")); + //build editor form container + final LocatableDynamicForm form = new LocatableDynamicForm(page.extendLocatorId("alert-filter")); form.setMargin(5);
- final DashboardPortlet storedPortlet = portletWindow.getStoredPortlet(); - - //vertical container - VLayout column = new VLayout(); - - //label - LocatableLabel alertRangeLabel = new LocatableLabel(extendLocatorId("DynamicForm_Label_Alert_Range"), "<b>" - + MSG.common_title_alert_range() + "</b>"); - - //horizontal layout - LocatableHLayout row = new LocatableHLayout(extendLocatorId("alert-range-settings-row-1")); - row.setMembersMargin(10); - - //-------------combobox for number of completed scheduled ops to display on the dashboard - final SelectItem alertRangeLastComboBox = new SelectItem(ALERT_RANGE_DISPLAY_AMOUNT_VALUE); - alertRangeLastComboBox.setTitle(MSG.view_measureRange_last()); - alertRangeLastComboBox.setType("selection"); - alertRangeLastComboBox.setWrapTitle(false); - //define acceptable values for display amount - String[] acceptableDisplayValues = { "5", "10", MSG.common_label_unlimited() }; - alertRangeLastComboBox.setValueMap(acceptableDisplayValues); - //set width of dropdown display region - alertRangeLastComboBox.setWidth(100); - alertRangeLastComboBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - String selectedItem = "" + event.getValue(); - //stuff into the master form for retrieval - form.setValue(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, selectedItem); - } - }); + //add label about what configuration affects
- //default selected value to 'unlimited'(live lists) and check both combobox settings here. - String selectedValue = defaultAlertCountValue; - if (storedPortlet != null) { - //if property exists retrieve it - if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) != null) { - selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) - .getStringValue(); - } else {//insert default value - storedPortlet.getConfiguration().put( - new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue)); - } - } - //prepopulate the combobox with the previously stored selection - alertRangeLastComboBox.setDefaultValue(selectedValue); - - //-------------combobox for number of completed scheduled ops to display on the dashboard - final SelectItem alertRangePriorityComboBox = new SelectItem(ALERT_RANGE_PRIORITY_VALUE); - alertRangePriorityComboBox.setTitle(""); - alertRangePriorityComboBox.setHint("<nobr> <b> " + MSG.view_portlet_recentAlerts_config_priority_label() - + "</b></nobr>"); - alertRangePriorityComboBox.setType("selection"); - //define acceptable values for display amount - String[] acceptablePriorityDisplayValues = { PRIORITY_ALL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW }; - alertRangePriorityComboBox.setValueMap(acceptablePriorityDisplayValues); - //set width of dropdown display region - alertRangePriorityComboBox.setWidth(100); - alertRangePriorityComboBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - String selectedItem = "" + event.getValue(); - //stuff into the master form for retrieval - form.setValue(ALERT_RANGE_PRIORITY_VALUE, selectedItem); - } - }); + //add alert priority selector + final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent + .getAlertPriorityEditor(portletConfig); + //add sort priority selector + // final SelectItem resultSortSelector = PortletConfigurationEditorComponent + // .getResulSortOrderEditor(portletConfig); + //add result count selector + final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
- //default selected value to 'unlimited'(live lists) and check both combobox settings here. - selectedValue = defaultPriorityValue; - if (storedPortlet != null) { - //if property exists retrieve it - if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE) != null) { - selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE).getStringValue(); - } else {//insert default value - storedPortlet.getConfiguration().put( - new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue)); - } - } - //prepopulate the combobox with the previously stored selection - alertRangePriorityComboBox.setDefaultValue(selectedValue); - row.addMember(alertRangeLabel); - DynamicForm wrappedRange = new DynamicForm(); - wrappedRange.setFields(alertRangeLastComboBox); - row.addMember(wrappedRange); - - DynamicForm wrappedPriority = new DynamicForm(); - wrappedPriority.setFields(alertRangePriorityComboBox); - row.addMember(wrappedPriority); - - //horizontal layout - LocatableHLayout row2 = new LocatableHLayout(extendLocatorId("alert-range-settings-row-2")); - - LocatableLabel alertRangeSpanLabel = new LocatableLabel(extendLocatorId("range-span-label"), "<b>" - + MSG.view_portlet_recentAlerts_config_when() + "<b>"); - //------------- Build second combobox for timeframe for problem resources search. - final SelectItem alertRangeTimeComboBox = new SelectItem(ALERT_RANGE_TIME_VALUE); - alertRangeTimeComboBox.setTitle(""); - alertRangeTimeComboBox.setHint(""); - alertRangeTimeComboBox.setType("selection"); - String[] acceptableTimeDisplayValues = { TIME_30_MINS, TIME_HOUR, TIME_12_HRS, TIME_DAY, TIME_WEEK, TIME_MONTH }; - alertRangeTimeComboBox.setValueMap(acceptableTimeDisplayValues); - alertRangeTimeComboBox.setWidth(100); - alertRangeTimeComboBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - String selectedItem = "" + event.getValue(); - //stuff into the master form for retrieval - form.setValue(ALERT_RANGE_TIME_VALUE, selectedItem); - } - }); + //add range selector + final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent + .getMeasurementRangeEditor(portletConfig);
- //set to default - selectedValue = defaultTimeValue; - if (storedPortlet != null) { - //if property exists retrieve it - if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE) != null) { - selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE).getStringValue(); - } else {//insert default value - storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue)); - } - } - //prepopulate the combobox with the previously stored selection - alertRangeTimeComboBox.setDefaultValue(selectedValue); - DynamicForm timeSelectionWrapper = new DynamicForm(); - timeSelectionWrapper.setFields(alertRangeTimeComboBox); - - // build resource selection drop down - //------------- Build second combobox for timeframe for problem resources search. - final SelectItem alertResourcesComboBox = new SelectItem(ALERT_RANGE_RESOURCES_VALUE); - alertResourcesComboBox.setTitle(MSG.common_val_for()); - alertResourcesComboBox.setHint(""); - alertResourcesComboBox.setType("selection"); - String[] acceptableResourceDisplayValues = { RESOURCES_ALL, RESOURCES_SELECTED }; - alertResourcesComboBox.setValueMap(acceptableResourceDisplayValues); - alertResourcesComboBox.setWidth(150); - alertResourcesComboBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - String selectedItem = "" + event.getValue(); - //stuff into the master form for retrieval - form.setValue(ALERT_RANGE_RESOURCES_VALUE, selectedItem); - //empty out earlier canvas - for (Canvas c : containerCanvas.getChildren()) { - c.destroy(); + form.setItems(alertPrioritySelector, resultCountSelector); + + //submit handler + customSettings.addSubmitValuesHandler(new SubmitValuesHandler() { + + @Override + public void onSubmitValues(SubmitValuesEvent event) { + //alert severity + String selectedValue = alertPrioritySelector.getValue().toString(); + if ((selectedValue.trim().isEmpty()) || (selectedValue.split(",").length == 3)) {//then no alertPriority specified + portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, "")); + } else {//some subset of available alertPriorities will be used + portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, selectedValue)); } - if (selectedItem.equals(RESOURCES_SELECTED)) { - containerCanvas.addChild(resourceSelector.getCanvas()); + // //result sort order + // selectedValue = resultSortSelector.getValue().toString(); + // if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc + // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); + // } else { + // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC)); + // } + //result count + selectedValue = resultCountSelector.getValue().toString(); + if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT))) {//then 5 + portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT)); } else { - containerCanvas.addChild(new Canvas()); + portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue)); } - } - });
- //set to default - selectedValue = defaultResourceValue; - if (storedPortlet != null) { - //if property exists retrieve it - if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) != null) { - selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) - .getStringValue(); - } else {//insert default value - storedPortlet.getConfiguration().put( - new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue)); - } - } - //prepopulate the combobox with the previously stored selection - alertResourcesComboBox.setDefaultValue(selectedValue); - DynamicForm resourceSelectionWrapper = new DynamicForm(); - resourceSelectionWrapper.setFields(alertResourcesComboBox); - - alertRangeSpanLabel.setWrap(false); - alertRangeSpanLabel.setWidth(150); - row2.addMember(alertRangeSpanLabel); - row2.addMember(timeSelectionWrapper); - row2.addMember(resourceSelectionWrapper); - - //if portlet config setting exist, then retrieve - Integer[] alertFilterResourceIds = null; - alertFilterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, alertFilterResourceIds); - - LocatableHLayout resourceSelectionRegion = new LocatableHLayout(extendLocatorId("selection-canvas")); - resourceSelector = new AlertResourceSelectorRegion(extendLocatorId("ResourcesWithAlerts"), - alertFilterResourceIds); - resourceSelectionRegion.setWidth100(); - - if (alertFilterResourceIds != null) { - getDataSource().setAlertFilterResourceId(alertFilterResourceIds); - resourceSelector.setCurrentlyAssignedIds(alertFilterResourceIds); - } - - //instantiate canvas area to display empty or rich resource selection based on dropdown selection - containerCanvas = new Canvas(); - String previousAlertFilterChoice = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) - .getStringValue(); - - //reload the ResourceSelectionRegion if user has chosen to focus on specific resources with alerts - if (previousAlertFilterChoice.equals(RESOURCES_SELECTED)) { - containerCanvas.addChild(resourceSelector.getCanvas()); - } else {// define empty canvas - containerCanvas.addChild(new Canvas()); - } - - //add contain resource selection region. - resourceSelectionRegion.addMember(containerCanvas); + //alert time range filter. Check for enabled and then persist property. Dealing with compound widget. + FormItem item = measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM); + CheckboxItem itemC = (CheckboxItem) item; + selectedValue = String.valueOf(itemC.getValueAsBoolean()); + if (!selectedValue.trim().isEmpty()) {//then call + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, selectedValue)); + }
- //finish construction of the layout - column.addMember(row); - column.addMember(row2); - SpacerItem verticalSpace = new SpacerItem(); - verticalSpace.setHeight(20); - DynamicForm spacerWrapper = new DynamicForm(); - spacerWrapper.setItems(verticalSpace); - column.addMember(spacerWrapper); - column.addMember(resourceSelectionRegion); - form.addChild(column); + //alert time advanced time filter enabled. + selectedValue = String.valueOf(measurementRangeEditor.isAdvanced()); + if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) { + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue)); + }
- //submit handler - form.addSubmitValuesHandler(new SubmitValuesHandler() { - @Override - public void onSubmitValues(SubmitValuesEvent event) { - //no need to insert validation here as user not allowed to enter values - parseFormAndPopulateConfiguration(form, storedPortlet, ALERT_RANGE_DISPLAY_AMOUNT_VALUE, - ALERT_RANGE_PRIORITY_VALUE, ALERT_RANGE_RESOURCES_VALUE, ALERT_RANGE_TIME_VALUE); - - //retrieve alert-resource-selection property - PropertySimple prop = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE); - - //check to see if "Selected Resources" or "All Resources" - if (prop != null && RESOURCES_SELECTED.equals(prop.getStringValue())) { - //retrieve currentlyAssignedIds - Integer[] valuesToPersist = resourceSelector.getListGridValues(); - resourceSelector.setCurrentlyAssignedIds(valuesToPersist); - - //build property list of ids to persist - PropertyList list = new PropertyList(ALERT_RANGE_RESOURCE_IDS); - for (int rid : resourceSelector.getCurrentlyAssignedIds()) { - list.add(new PropertySimple(ALERT_RANGE_RESOURCE_IDS, rid)); - } - storedPortlet.getConfiguration().put(new PropertyList(ALERT_RANGE_RESOURCE_IDS, list)); - getDataSource().setAlertFilterResourceId(resourceSelector.getCurrentlyAssignedIds()); + //alert time frame + List<Long> begEnd = measurementRangeEditor.getBeginEndTimes(); + if (begEnd.get(0) != 0) {//advanced settings + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE, (begEnd.get(0) + "," + begEnd.get(1)))); }
+ //persist and reload portlet + storedPortlet.setConfiguration(portletConfig); configure(portletWindow, storedPortlet); - - refresh();//reload form with new data selections - markForRedraw(); + refresh(); } }); - - return form; - } - - /**Iterates over DynamicForm instance to check for properties passed in and if they have been set - * to put that property into the DashboardPortlet configuration. - * - * @param form Dynamic form storing user selections - * @param portlet Container for configuration changes - * @param properties Variable list of keys used to verify or populate properties. - */ - private void parseFormAndPopulateConfiguration(final DynamicForm form, DashboardPortlet storedPortlet, - String... properties) { - if ((form != null) && (storedPortlet != null)) { - for (String property : properties) { - if (form.getValue(property) != null) {//if new value supplied - storedPortlet.getConfiguration().put(new PropertySimple(property, form.getValue(property))); - } - } - } + form.markForRedraw(); + page.addMember(measurementRangeEditor); + page.addMember(form); + customSettings.addChild(page); + return customSettings; }
- public AlertPortletDataSource getDataSource() { + public AlertPortletConfigurationDataSource getDataSource() { return dataSource; }
@@ -592,7 +309,6 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti @Override protected void onDestroy() { if (refreshTimer != null) { - refreshTimer.cancel(); }
@@ -627,7 +343,6 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti
@Override protected void configureTable() { - // TODO Auto-generated method stub super.configureTable();
setListGridDoubleClickHandler(new DoubleClickHandler() { @@ -644,9 +359,27 @@ public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSetti }); }
+ @Override + protected void onInit() { + super.onInit(); + getListGrid().setEmptyMessage("No results found using specified criteria."); + } + + @Override + protected void refreshTableInfo() { + super.refreshTableInfo(); + if (getTableInfo() != null) { + int count = getListGrid().getSelection().length; + getTableInfo().setContents( + // MSG.view_table_totalRows(String.valueOf(listGrid.getTotalRows()), String.valueOf(count))); + //Ex. Total Rows: {0} (selected: {1}) + "Matching Rows: " + String.valueOf(getListGrid().getTotalRows()) + " (selected " + + String.valueOf(count) + ")"); + } + } }
-/** Bundles a ResourceSelector instance with labelling in Canvas for display. +/** Bundles a ResourceSelector instance with labeling in Canvas for display. * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act accordingly. */ class AlertResourceSelectorRegion extends LocatableVLayout { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java new file mode 100644 index 0000000..e26f08c --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java @@ -0,0 +1,426 @@ +/* + * 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. + */ +package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.History; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.ContentsType; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.HTMLFlow; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.events.SubmitValuesEvent; +import com.smartgwt.client.widgets.form.events.SubmitValuesHandler; +import com.smartgwt.client.widgets.form.fields.CanvasItem; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.LinkItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.layout.VLayout; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.domain.criteria.ResourceGroupCriteria; +import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.core.domain.measurement.MeasurementDefinition; +import org.rhq.core.domain.measurement.composite.MeasurementDataNumericHighLowComposite; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.core.domain.resource.group.ResourceGroup; +import org.rhq.core.domain.resource.group.composite.ResourceGroupComposite; +import org.rhq.core.domain.util.PageList; +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; +import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor; +import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; +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.dashboard.portlets.PortletConfigurationEditorComponent; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView; +import org.rhq.enterprise.gui.coregui.client.resource.disambiguation.ReportDecorator; +import org.rhq.enterprise.gui.coregui.client.util.BrowserUtility; +import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableCanvas; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; + +/**This portlet allows the end user to customize the metric display + * + * @author Simeon Pinder + */ +public class GroupMetricsPortlet extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet { + + private int groupId = -1; + protected LocatableCanvas recentMeasurementsContent = new LocatableCanvas(extendLocatorId("RecentMetrics")); + private boolean currentlyLoading = false; + private Configuration portletConfig = null; + private DashboardPortlet storedPortlet; + + public GroupMetricsPortlet(String locatorId) { + super(locatorId); + //figure out which page we're loading + String currentPage = History.getToken(); + String[] elements = currentPage.split("/"); + int currentGroupIdentifier = Integer.valueOf(elements[1]); + this.groupId = currentGroupIdentifier; + initializeUi(); + } + + @Override + protected void onInit() { + super.onInit(); + loadData(); + } + + /**Defines layout for the portlet page. + */ + protected void initializeUi() { + setPadding(5); + setMembersMargin(5); + addMember(recentMeasurementsContent); + } + + // A non-displayed, persisted identifier for the portlet + public static final String KEY = "GroupMetrics"; + // A default displayed, persisted name for the portlet + public static final String NAME = "Group: Metrics"; + public static final String ID = "id"; + + // set on initial configuration, the window for this portlet view. + private PortletWindow portletWindow; + //instance ui widgets + + private Timer refreshTimer; + + /** Responsible for initialization and lazy configuration of the portlet values + */ + public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) { + //populate portlet configuration details + if (null == this.portletWindow && null != portletWindow) { + this.portletWindow = portletWindow; + } + + if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) { + return; + } + this.storedPortlet = storedPortlet; + portletConfig = storedPortlet.getConfiguration(); + + //lazy init any elements not yet configured. + for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) { + if (portletConfig.getSimple(key) == null) { + portletConfig.put(new PropertySimple(key, + PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key))); + } + } + } + + public Canvas getHelpCanvas() { + //TODO: spinder change. + return new HTMLFlow(MSG.view_portlet_help_recentAlerts()); + } + + public static final class Factory implements PortletViewFactory { + public static PortletViewFactory INSTANCE = new Factory(); + + public final Portlet getInstance(String locatorId) { + return new GroupMetricsPortlet(locatorId); + } + } + + protected void loadData() { + currentlyLoading = true; + getRecentMetrics(); + } + + @Override + public DynamicForm getCustomSettingsForm() { + LocatableDynamicForm customSettings = new LocatableDynamicForm(extendLocatorId("customSettings")); + LocatableVLayout page = new LocatableVLayout(customSettings.extendLocatorId("page")); + final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent + .getMeasurementRangeEditor(portletConfig); + + //submit handler + customSettings.addSubmitValuesHandler(new SubmitValuesHandler() { + + @Override + public void onSubmitValues(SubmitValuesEvent event) { + + //alert time range filter. Check for enabled and then persist property. Dealing with compound widget. + FormItem item = measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM); + CheckboxItem itemC = (CheckboxItem) item; + String selectedValue = String.valueOf(itemC.getValueAsBoolean()); + if (!selectedValue.trim().isEmpty()) {//then call + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, selectedValue)); + } + + //alert time advanced time filter enabled. + selectedValue = String.valueOf(measurementRangeEditor.isAdvanced()); + if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) { + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue)); + } + + //alert time frame + List<Long> begEnd = measurementRangeEditor.getBeginEndTimes(); + if (begEnd.get(0) != 0) {//advanced settings + portletConfig.put(new PropertySimple(Constant.METRIC_RANGE, (begEnd.get(0) + "," + begEnd.get(1)))); + } + + //persist + storedPortlet.setConfiguration(portletConfig); + configure(portletWindow, storedPortlet); + loadData(); + } + }); + page.addMember(measurementRangeEditor); + customSettings.addChild(page); + return customSettings; + } + + /** Fetches recent metric information and updates the DynamicForm instance with i)sparkline information, + * ii) link to recent metric graph for more details and iii) last metric value formatted to show significant + * digits. + */ + private void getRecentMetrics() { + + //display container + final VLayout column = new VLayout(); + column.setHeight(10);//pack + // final int groupId = this.groupComposite.getResourceGroup().getId(); + final int groupId = this.groupId; + ResourceGroupCriteria criteria = new ResourceGroupCriteria(); + criteria.addFilterIds(groupId); + criteria.fetchGroupDefinition(true); + criteria.fetchResourceType(true); + criteria.fetchExplicitResources(true); + GWTServiceLookup.getResourceGroupService().findResourceGroupCompositesByCriteria(criteria, + new AsyncCallback<PageList<ResourceGroupComposite>>() { + @Override + public void onFailure(Throwable caught) { + Log.debug("Error retrieving resource group composite for group [" + groupId + "]:" + + caught.getMessage()); + } + + @Override + public void onSuccess(PageList<ResourceGroupComposite> result) { + if (!result.isEmpty()) { + //retrieve all relevant measurement definition ids. + // Set<MeasurementDefinition> definitions = this.groupComposite.getResourceGroup().getResourceType() + ResourceGroupComposite composite = result.get(0); + ResourceGroup group = composite.getResourceGroup(); + ResourceType type = group.getResourceType(); + Set<MeasurementDefinition> defs = type.getMetricDefinitions(); + // Log.debug("------------- Composite:" + composite); + // Log.debug("------------- Group:" + group); + // Log.debug("------------- Type:" + type); + // Log.debug("------------- Defs:" + defs); + + Set<MeasurementDefinition> definitions = result.get(0).getResourceGroup().getResourceType() + .getMetricDefinitions(); + + //build id mapping for measurementDefinition instances Ex. Free Memory -> MeasurementDefinition[100071] + final HashMap<String, MeasurementDefinition> measurementDefMap = new HashMap<String, MeasurementDefinition>(); + for (MeasurementDefinition definition : definitions) { + measurementDefMap.put(definition.getDisplayName(), definition); + } + //bundle definition ids for asynch call. + int[] definitionArrayIds = new int[definitions.size()]; + final String[] displayOrder = new String[definitions.size()]; + measurementDefMap.keySet().toArray(displayOrder); + //sort the charting data ex. Free Memory, Free Swap Space,..System Load + Arrays.sort(displayOrder); + + //organize definitionArrayIds for ordered request on server. + int index = 0; + for (String definitionToDisplay : displayOrder) { + definitionArrayIds[index++] = measurementDefMap.get(definitionToDisplay).getId(); + } + + //make the asynchronous call for all the measurement data + GWTServiceLookup.getMeasurementDataService().findDataForCompatibleGroup(groupId, + definitionArrayIds, System.currentTimeMillis() - (1000L * 60 * 60 * 8), + System.currentTimeMillis(), 60, + new AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() { + @Override + public void onFailure(Throwable caught) { + Log.debug("Error retrieving recent metrics charting data for group [" + groupId + + "]:" + caught.getMessage()); + } + + @Override + public void onSuccess(List<List<MeasurementDataNumericHighLowComposite>> results) { + if (!results.isEmpty()) { + boolean someChartedData = false; + //iterate over the retrieved charting data + for (int index = 0; index < displayOrder.length; index++) { + //retrieve the correct measurement definition + MeasurementDefinition md = measurementDefMap.get(displayOrder[index]); + + //load the data results for the given metric definition + List<MeasurementDataNumericHighLowComposite> data = results.get(index); + + //locate last and minimum values. + double lastValue = -1; + double minValue = Double.MAX_VALUE;// + for (MeasurementDataNumericHighLowComposite d : data) { + if ((!Double.isNaN(d.getValue())) + && (String.valueOf(d.getValue()).indexOf("NaN") == -1)) { + if (d.getValue() < minValue) { + minValue = d.getValue(); + } + lastValue = d.getValue(); + } + } + + //collapse the data into comma delimited list for consumption by third party javascript library(jquery.sparkline) + String commaDelimitedList = ""; + + for (MeasurementDataNumericHighLowComposite d : data) { + if ((!Double.isNaN(d.getValue())) + && (String.valueOf(d.getValue()).indexOf("NaN") == -1)) { + commaDelimitedList += d.getValue() + ","; + } + } + LocatableDynamicForm row = new LocatableDynamicForm( + recentMeasurementsContent.extendLocatorId(md.getName())); + row.setNumCols(3); + HTMLFlow graph = new HTMLFlow(); + // String contents = "<span id='sparkline_" + index + "' class='dynamicsparkline' width='0'>" + // + commaDelimitedList + "</span>"; + String contents = "<span id='sparkline_" + index + + "' class='dynamicsparkline' width='0' " + "values='" + + commaDelimitedList + "'>...</span>"; + graph.setContents(contents); + graph.setContentsType(ContentsType.PAGE); + //diable scrollbars on span + graph.setScrollbarSize(0); + + CanvasItem graphContainer = new CanvasItem(); + graphContainer.setShowTitle(false); + graphContainer.setHeight(16); + graphContainer.setWidth(60); + graphContainer.setCanvas(graph); + + //Link/title element + //TODO: spinder, change link whenever portal.war/graphing is removed. + String title = md.getDisplayName() + ":"; + // String destination = "/resource/common/monitor/Visibility.do?mode=chartSingleMetricSingleResource&id=" + // + resourceId + "&m=" + md.getId(); + String destination = "/resource/common/monitor/Visibility.do?mode=chartSingleMetricMultiResource&groupId=" + + groupId + "&m=" + md.getId(); + LinkItem link = AbstractActivityView.newLinkItem(title, destination); + + //Value + String convertedValue = lastValue + " " + md.getUnits(); + convertedValue = AbstractActivityView.convertLastValueForDisplay(lastValue, + md); + StaticTextItem value = AbstractActivityView.newTextItem(convertedValue); + + row.setItems(graphContainer, link, value); + //if graph content returned + if ((md.getName().trim().indexOf("Trait.") == -1) && (lastValue != -1)) { + column.addMember(row); + someChartedData = true; + } + } + if (!someChartedData) {// when there are results but no chartable entries. + LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow( + recentMeasurementsContent.extendLocatorId("None"), + AbstractActivityView.RECENT_MEASUREMENTS_NONE); + column.addMember(row); + } else { + //insert see more link + LocatableDynamicForm row = new LocatableDynamicForm( + recentMeasurementsContent + .extendLocatorId("RecentMeasurementsContentSeeMore")); + AbstractActivityView.addSeeMoreLink(row, ReportDecorator.GWT_GROUP_URL + + groupId + "/Monitoring/Graphs/", column); + } + //call out to 3rd party javascript lib + BrowserUtility.graphSparkLines(); + } else { + LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow( + recentMeasurementsContent.extendLocatorId("None"), + AbstractActivityView.RECENT_MEASUREMENTS_NONE); + column.addMember(row); + } + } + }); + } + + } + }); + + //cleanup + for (Canvas child : recentMeasurementsContent.getChildren()) { + child.destroy(); + } + recentMeasurementsContent.addChild(column); + recentMeasurementsContent.markForRedraw(); + } + + @Override + public void startRefreshCycle() { + //current setting + final int refreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval(); + + //cancel any existing timer + if (refreshTimer != null) { + refreshTimer.cancel(); + } + + if (refreshInterval >= MeasurementUtility.MINUTES) { + + refreshTimer = new Timer() { + public void run() { + if (!currentlyLoading) { + loadData(); + redraw(); + } + } + }; + + refreshTimer.scheduleRepeating(refreshInterval); + } + } + + @Override + protected void onDestroy() { + if (refreshTimer != null) { + + refreshTimer.cancel(); + } + super.onDestroy(); + } + + @Override + public void redraw() { + super.redraw(); + loadData(); + } + +} \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java index 6db94eb..b183bf5 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java @@ -379,7 +379,8 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R * @param md MeasurementDefinition * @return formatted String representation of the last value retrieved. */ - protected String convertLastValueForDisplay(double lastValue, MeasurementDefinition md) { + // protected String convertLastValueForDisplay(double lastValue, MeasurementDefinition md) { + public static String convertLastValueForDisplay(double lastValue, MeasurementDefinition md) { String convertedValue = ""; String[] convertedValues = GwtMonitorUtils.formatSimpleMetrics(new double[] { lastValue }, md); convertedValue = convertedValues[0];
commit 992f2357e314aed1198596a9c6ce870ab7e26669 Author: Simeon Pinder spinder@redhat.com Date: Wed Mar 9 15:15:48 2011 -0500
abstractMeasurementRangeEditor and associated UI widget changes.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/AbstractMeasurementRangeEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/AbstractMeasurementRangeEditor.java new file mode 100644 index 0000000..82be574 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/AbstractMeasurementRangeEditor.java @@ -0,0 +1,340 @@ +/* + * 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. + */ +package org.rhq.enterprise.gui.coregui.client.components.measurement; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; + +import com.smartgwt.client.widgets.form.fields.ButtonItem; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.DateTimeItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.widgets.grid.ListGrid; + +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.components.table.TableWidget; +import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; +import org.rhq.enterprise.gui.coregui.client.util.message.Message; +import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; + +/** + * @author Simeon Pinder + * @author Greg Hinkle + */ +public abstract class AbstractMeasurementRangeEditor extends LocatableDynamicForm implements TableWidget { + + //keyed map of translated date units Ex. minutes,hours,days + private static LinkedHashMap<String, String> lastUnits; + //array of values available for displaying/selecting 'last N hours|minutes|days'. + private static String[] lastValues; + + protected boolean advanced; + private ButtonItem advancedSimpleButton; + protected SelectItem simpleLastValuesItem; + protected SelectItem simpleLastUnitsItem; + protected DateTimeItem advancedStartItem; + protected DateTimeItem advancedEndItem; + private boolean displaySetButton = true; + private boolean displayEnableButton = false; + private boolean displayRangeItemGrouping = false; + protected CheckboxItem enableRangeItem; + + private ButtonItem setButton; + public static String ENABLE_RANGE_ITEM = "ENABLE_RANGE_ITEM"; + public static String ADVANCED_BUTTON_ITEM = "advanced"; + public static String SIMPLE_VALUE_ITEM = "lastValues"; + public static String SIMPLE_UNIT_ITEM = "lastUnits"; + public static String ADVANCED_START_ITEM = "start"; + public static String ADVANCED_END_ITEM = "end"; + public static String SET_ITEM = "set"; + + static { + lastUnits = new LinkedHashMap<String, String>(3); + lastUnits.put(String.valueOf(MeasurementUtility.UNIT_MINUTES), MSG.common_label_minutes()); + lastUnits.put(String.valueOf(MeasurementUtility.UNIT_HOURS), MSG.common_label_hours()); + lastUnits.put(String.valueOf(MeasurementUtility.UNIT_DAYS), MSG.common_label_days()); + + lastValues = new String[] { "4", "8", "12", "24", "30", "36", "48", "60", "90", "120" }; + } + + public AbstractMeasurementRangeEditor(String locatorId) { + super(locatorId); + setNumCols(12); + setWrapItemTitles(false); + } + + /** + * Returns the current range that is persisted. Note this may NOT be the begin and end times + * as shown in the UI if the user changed the values but did not hit the set button. + * @return begin/end epoch times in a list + */ + public abstract List<Long> getBeginEndTimes(); + + public abstract MetricRangePreferences getMetricRangePreferences(); + + public abstract void setMetricRangeProperties(MetricRangePreferences prefs); + + @Override + protected void onInit() { + super.onInit(); + if (isDisplayRangeItemGrouping()) { + setIsGroup(true); + setGroupTitle("Filter by: Time"); + } + enableRangeItem = new CheckboxItem(ENABLE_RANGE_ITEM, ""); + enableRangeItem.setStartRow(true); + enableRangeItem.setShowTitle(false); + enableRangeItem.setShowLabel(false); + enableRangeItem.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent event) { + boolean enableRange = Boolean.valueOf(event.getItem().getValue() + ""); + enableMeasurementRange(enableRange); + } + }); + + //combobox of last items + simpleLastValuesItem = new SelectItem(SIMPLE_VALUE_ITEM, MSG.view_measureRange_last()); + simpleLastValuesItem.setStartRow(false); + simpleLastValuesItem.setEndRow(false); + simpleLastValuesItem.setValueMap(lastValues); + simpleLastValuesItem.setWidth("*"); + simpleLastValuesItem.setRedrawOnChange(true); + + //combobox of units of time + simpleLastUnitsItem = new SelectItem(SIMPLE_UNIT_ITEM); + simpleLastUnitsItem.setStartRow(false); + simpleLastUnitsItem.setEndRow(false); + simpleLastUnitsItem.setValueMap(lastUnits); + simpleLastUnitsItem.setShowTitle(false); + simpleLastUnitsItem.setWidth("*"); + simpleLastUnitsItem.setRedrawOnChange(true); + + //time range start from + advancedStartItem = new DateTimeItem(ADVANCED_START_ITEM, MSG.view_measureRange_start()); + advancedStartItem.setStartRow(false); + advancedStartItem.setEndRow(false); + + //time range end + advancedEndItem = new DateTimeItem(ADVANCED_END_ITEM, MSG.common_title_end()); + advancedEndItem.setStartRow(false); + advancedEndItem.setEndRow(false); + + setButton = new ButtonItem(SET_ITEM, MSG.common_button_set()); + setButton.setStartRow(false); + setButton.setEndRow(false); + setButton.setShowTitle(false); + setButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + MetricRangePreferences prefs = new MetricRangePreferences(); + prefs.explicitBeginEnd = advanced; + if (advanced) { + prefs.begin = advancedStartItem.getValueAsDate().getTime(); + prefs.end = advancedEndItem.getValueAsDate().getTime(); + } else { + prefs.lastN = Integer.valueOf(simpleLastValuesItem.getValueAsString()); + prefs.unit = Integer.valueOf(simpleLastUnitsItem.getValueAsString()); + } + setMetricRangeProperties(prefs); + } + }); + + advancedSimpleButton = new ButtonItem(ADVANCED_BUTTON_ITEM, MSG.common_button_advanced()); + advancedSimpleButton.setStartRow(false); + advancedSimpleButton.setEndRow(false); + advancedSimpleButton.setShowTitle(false); + advancedSimpleButton.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent clickEvent) { + advanced = !advanced; + update(); + } + }); + + MetricRangePreferences metricRangePrefs = getMetricRangePreferences(); + if (metricRangePrefs != null) { + advanced = (metricRangePrefs.explicitBeginEnd); + } + + if (displaySetButton) { + setItems(simpleLastValuesItem, simpleLastUnitsItem, advancedStartItem, advancedEndItem, setButton, + advancedSimpleButton); + } else {//not displaying Set button + if (displayEnableButton) { + setItems(enableRangeItem, simpleLastValuesItem, simpleLastUnitsItem, advancedStartItem, + advancedEndItem, advancedSimpleButton); + setNumCols(9);//extend to encompass expanded + } else { + setItems(simpleLastValuesItem, simpleLastUnitsItem, advancedStartItem, advancedEndItem, + advancedSimpleButton); + } + } + update(); + } + + private void assignDefaultsToAdvancedItems() { + advancedStartItem.setValue(new Date(System.currentTimeMillis() - (1000L * 60 * 60 * 8))); + advancedEndItem.setValue(new Date()); + } + + private void assignDefaultsToSimpleItems() { + simpleLastValuesItem.setValue("8"); + simpleLastUnitsItem.setValue(String.valueOf(MeasurementUtility.UNIT_HOURS)); + } + + protected void enableMeasurementRange(boolean enableRange) { + if (enableRange) { + simpleLastValuesItem.disable(); + simpleLastUnitsItem.disable(); + advancedStartItem.disable(); + advancedEndItem.disable(); + advancedSimpleButton.disable(); + } else { + simpleLastValuesItem.enable(); + simpleLastUnitsItem.enable(); + advancedStartItem.enable(); + advancedEndItem.enable(); + advancedSimpleButton.enable(); + } + } + + private void update() { + if (advanced) { + advancedSimpleButton.setTitle(MSG.view_measureRange_simple()); + showItem("start"); + showItem("end"); + hideItem("lastValues"); + hideItem("lastUnits"); + } else { + advancedSimpleButton.setTitle(MSG.common_button_advanced()); + hideItem("start"); + hideItem("end"); + showItem("lastValues"); + showItem("lastUnits"); + } + + // populate the fields - first with defaults in case we have no prefs, then with the appropriate prefs + assignDefaultsToSimpleItems(); + assignDefaultsToAdvancedItems(); + + try { + MetricRangePreferences metricRangePrefs = getMetricRangePreferences(); + if (metricRangePrefs.explicitBeginEnd) { + if (metricRangePrefs.begin != null && metricRangePrefs.end != null) { + advancedStartItem.setValue(new Date(metricRangePrefs.begin.longValue())); + advancedEndItem.setValue(new Date(metricRangePrefs.end.longValue())); + } + } else { + if (lastUnits.containsKey(String.valueOf(metricRangePrefs.unit))) { + simpleLastUnitsItem.setValue(String.valueOf(metricRangePrefs.unit)); + } + if (Arrays.asList(lastValues).contains(String.valueOf(metricRangePrefs.lastN))) { + simpleLastValuesItem.setValue(String.valueOf(metricRangePrefs.lastN)); + } + } + } catch (Exception e) { + // in case any odd errors occur (like bad format of preference strings), just fill in some defaults + CoreGUI.getMessageCenter().notify( + new Message("Failed to get range user preferences, using defaults", e, Severity.Warning)); + assignDefaultsToSimpleItems(); + assignDefaultsToAdvancedItems(); + } + + markForRedraw(); + } + + @Override + public void refresh(ListGrid listGrid) { + update(); + } + + public static class MetricRangePreferences { + // if readOnly is true, then the beginning and ending range dates are specified with explicit dates + // if readOnly is false, then the time is relative to NOW and is specified as <lastN> units of <unit> time + public boolean explicitBeginEnd; + + // simple, when readOnly is false + public int lastN; + public int unit; // see MeasurementUtility.UNIT_xxx + + // advanced, when readOnly is true + public Long begin; + public Long end; + + /** + * 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 time frame. + **/ + public ArrayList<Long> getBeginEndTimes() { + if (explicitBeginEnd) { + ArrayList<Long> times = new ArrayList<Long>(2); + times.add(begin); + times.add(end); + return times; + } else { + return MeasurementUtility.calculateTimeFrame(lastN, unit); + } + } + + public String toString() { + return (explicitBeginEnd) ? "[begin=" + begin + end + ",end=" + end + "]" : "[lastN=" + lastN + ",unit=" + + unit + "]"; + } + } + + public boolean isDisplaySetButton() { + return displaySetButton; + } + + public void setDisplaySetButton(boolean displaySetButton) { + this.displaySetButton = displaySetButton; + } + + public boolean isDisplayEnableButton() { + return displayEnableButton; + } + + public void setDisplayEnableButton(boolean displayEnableButton) { + this.displayEnableButton = displayEnableButton; + } + + public boolean isAdvanced() { + return advanced; + } + + public void setAdvanced(boolean advanced) { + this.advanced = advanced; + } + + public boolean isDisplayRangeItemGrouping() { + return displayRangeItemGrouping; + } + + public void setDisplayRangeItemGrouping(boolean displayRangeItemGrouping) { + this.displayRangeItemGrouping = displayRangeItemGrouping; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java new file mode 100644 index 0000000..260655f --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/CustomConfigMeasurementRangeEditor.java @@ -0,0 +1,179 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 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. + */ +package org.rhq.enterprise.gui.coregui.client.components.measurement; + +import java.util.ArrayList; +import java.util.List; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet; +import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; + +public class CustomConfigMeasurementRangeEditor extends AbstractMeasurementRangeEditor { + + public static final String PREF_METRIC_RANGE = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE; + public static final String PREF_METRIC_RANGE_LASTN = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_LASTN; + public static final String PREF_METRIC_RANGE_UNIT = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_UNIT; + public static final String PREF_METRIC_RANGE_BEGIN_END_FLAG = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG; + public static final String ALERT_METRIC_RANGE_ENABLE = GroupAlertsPortlet.Constant.ALERT_METRIC_RANGE_ENABLE; + + public static final String DEFAULT_VALUE_RANGE_RO = Boolean.FALSE.toString(); + public static final Integer DEFAULT_VALUE_RANGE_LASTN = Integer.valueOf(8); + public static final Integer DEFAULT_VALUE_RANGE_UNIT = Integer.valueOf(3); + + private ConfigurationMeasurementPreferences measurementPrefs; + + public CustomConfigMeasurementRangeEditor(String locatorId, Configuration config) { + super(locatorId); + measurementPrefs = new ConfigurationMeasurementPreferences(config); + setDisplaySetButton(false); + setDisplayEnableButton(true); + setDisplayRangeItemGrouping(true); + setWidth(650); + } + + @Override + public List<Long> getBeginEndTimes() { + List<Long> beginEndTimes = new ArrayList<Long>(); + if (advanced) { + beginEndTimes.add(advancedStartItem.getValueAsDate().getTime()); + beginEndTimes.add(advancedEndItem.getValueAsDate().getTime()); + return beginEndTimes; + } else { + int lastN = Integer.valueOf(simpleLastValuesItem.getValueAsString()); + String unit = simpleLastUnitsItem.getValueAsString(); + return MeasurementUtility.calculateTimeFrame(lastN, Integer.valueOf(unit)); + } + } + + @Override + public MetricRangePreferences getMetricRangePreferences() { + return measurementPrefs.getMetricRangePreferences(); + } + + @Override + public void setMetricRangeProperties(MetricRangePreferences prefs) { + measurementPrefs.setMetricRangePreferences(prefs); + } + + public String getSimpleProperty(String propertyKey) { + String propertyValue = ""; + if ((propertyKey != null) && (propertyKey.trim().length() > 0)) { + if ((measurementPrefs != null) && (measurementPrefs.configuration != null)) { + PropertySimple property = measurementPrefs.configuration.getSimple(propertyKey); + if (property != null) { + propertyValue = property.getStringValue(); + } + } + } + return propertyValue; + } + + public void setSimpleProperty(String propertyKey, String value) { + if ((propertyKey != null) && (propertyKey.trim().length() > 0) && (value != null) && (!value.trim().isEmpty())) { + if ((measurementPrefs != null) && (measurementPrefs.configuration != null)) { + measurementPrefs.configuration.put(new PropertySimple(propertyKey, value)); + } + } + } + + class ConfigurationMeasurementPreferences { + + private MetricRangePreferences metricRangePreferences; + private Configuration configuration; + + public ConfigurationMeasurementPreferences(Configuration config) { + if (metricRangePreferences == null) { + metricRangePreferences = new MetricRangePreferences(); + } + // //parse config and lazily init timing elements + metricRangePreferences.explicitBeginEnd = Boolean.valueOf( + config.getSimple(PREF_METRIC_RANGE_BEGIN_END_FLAG).getStringValue()).booleanValue(); + //check to display advanced settings widget components + if (metricRangePreferences.explicitBeginEnd == false) { + metricRangePreferences.lastN = config.getSimple(PREF_METRIC_RANGE_LASTN).getIntegerValue(); + List<Long> range = MeasurementUtility.calculateTimeFrame(metricRangePreferences.lastN, + metricRangePreferences.unit); + metricRangePreferences.begin = range.get(0); + metricRangePreferences.end = range.get(1); + } else {//in advanced view + try { + String rangeString = config.getSimpleValue(PREF_METRIC_RANGE, ""); + if (rangeString != null && rangeString.trim().length() > 0) { + if (rangeString.contains(",")) { // legacy support: old prefs used to use commas + rangeString = rangeString.replace(",", "|"); + //userPrefs.setPreference(PREF_METRIC_RANGE, rangeString); // TODO set only if we don't support JSF anymore + } + String[] beginEnd = rangeString.split("\|"); + metricRangePreferences.begin = Long.parseLong(beginEnd[0]); + metricRangePreferences.end = Long.parseLong(beginEnd[1]); + } + } catch (IllegalArgumentException iae) { + // that's OK, range will remain null and we might use the lastN / unit + List<Long> range = MeasurementUtility.calculateTimeFrame(DEFAULT_VALUE_RANGE_LASTN, + DEFAULT_VALUE_RANGE_UNIT); + metricRangePreferences.begin = range.get(0); + metricRangePreferences.end = range.get(1); + } + } + // update configuration + this.configuration = config; + } + + public void setMetricRangePreferences(MetricRangePreferences metricRangePreferences) { + this.metricRangePreferences = metricRangePreferences; + } + + public MetricRangePreferences getMetricRangePreferences() { + return metricRangePreferences; + } + } + + @Override + protected void onInit() { + super.onInit(); + //turn on date entry validation + enableRangeItem.setWidth(30); + // advancedStartItem.setEnforceDate(true); + // advancedEndItem.setEnforceDate(true); + //disable text field view to prevent bad data entry. Use widget or dropdowns. + //TODO: spinder 3/9/11: this should be renabled to allow minute/second tuning here too, but need to handle validation. + advancedStartItem.setUseTextField(false); + // advancedEndItem.setUseTextField(false); + advancedStartItem.setType("selection"); + simpleLastValuesItem.setWidth(50); + simpleLastUnitsItem.setWidth(70); + + //set fields to previously populated values + PropertySimple cp = measurementPrefs.configuration.getSimple(ALERT_METRIC_RANGE_ENABLE); + if (Boolean.valueOf(measurementPrefs.configuration.getSimple(ALERT_METRIC_RANGE_ENABLE).getStringValue())) { + enableRangeItem.setValue(true); + enableMeasurementRange(false); + } else { + enableRangeItem.setValue(false); + enableMeasurementRange(true); + } + //AlertMetric rangeValues + cp = measurementPrefs.configuration.getSimple(PREF_METRIC_RANGE); + if ((cp != null) && (!cp.getStringValue().trim().isEmpty())) { + String metricRange = cp.getStringValue(); + } + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/MeasurementRangeEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/MeasurementRangeEditor.java deleted file mode 100644 index a0a5e9f..0000000 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/MeasurementRangeEditor.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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. - */ -package org.rhq.enterprise.gui.coregui.client.components.measurement; - -import java.util.Arrays; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; - -import com.smartgwt.client.widgets.form.fields.ButtonItem; -import com.smartgwt.client.widgets.form.fields.DateTimeItem; -import com.smartgwt.client.widgets.form.fields.SelectItem; -import com.smartgwt.client.widgets.form.fields.events.ClickEvent; -import com.smartgwt.client.widgets.form.fields.events.ClickHandler; -import com.smartgwt.client.widgets.grid.ListGrid; - -import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.UserSessionManager; -import org.rhq.enterprise.gui.coregui.client.components.table.TableWidget; -import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; -import org.rhq.enterprise.gui.coregui.client.util.message.Message; -import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity; -import org.rhq.enterprise.gui.coregui.client.util.preferences.MeasurementUserPreferences; -import org.rhq.enterprise.gui.coregui.client.util.preferences.MeasurementUserPreferences.MetricRangePreferences; -import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; - -/** - * @author Greg Hinkle - */ -public class MeasurementRangeEditor extends LocatableDynamicForm implements TableWidget { - - private static LinkedHashMap<String, String> lastUnits; - private static String[] lastValues; - - private MeasurementUserPreferences measurementUserPrefs; - - private boolean advanced; - private ButtonItem advancedSimpleButton; - private SelectItem simpleLastValuesItem; - private SelectItem simpleLastUnitsItem; - private DateTimeItem advancedStartItem; - private DateTimeItem advancedEndItem; - private ButtonItem setButton; - - static { - lastUnits = new LinkedHashMap<String, String>(3); - lastUnits.put(String.valueOf(MeasurementUtility.UNIT_MINUTES), MSG.common_label_minutes()); - lastUnits.put(String.valueOf(MeasurementUtility.UNIT_HOURS), MSG.common_label_hours()); - lastUnits.put(String.valueOf(MeasurementUtility.UNIT_DAYS), MSG.common_label_days()); - - lastValues = new String[] { "4", "8", "12", "24", "30", "36", "48", "60", "90", "120" }; - } - - public MeasurementRangeEditor(String locatorId) { - super(locatorId); - setNumCols(12); - setWrapItemTitles(false); - - measurementUserPrefs = new MeasurementUserPreferences(UserSessionManager.getUserPreferences()); - } - - /** - * Returns the current range that is persisted. Note this may NOT be the begin and end times - * as shown in the UI if the user changed the values but did not hit the set button. - * @return begin/end epoch times in a list - */ - public List<Long> getBeginEndTimes() { - return measurementUserPrefs.getMetricRangePreferences().getBeginEndTimes(); - } - - @Override - protected void onInit() { - super.onInit(); - - simpleLastValuesItem = new SelectItem("lastValues", MSG.view_measureRange_last()); - simpleLastValuesItem.setStartRow(false); - simpleLastValuesItem.setEndRow(false); - simpleLastValuesItem.setValueMap(lastValues); - simpleLastValuesItem.setWidth("*"); - simpleLastValuesItem.setRedrawOnChange(true); - - simpleLastUnitsItem = new SelectItem("lastUnits"); - simpleLastUnitsItem.setStartRow(false); - simpleLastUnitsItem.setEndRow(false); - simpleLastUnitsItem.setValueMap(lastUnits); - simpleLastUnitsItem.setShowTitle(false); - simpleLastUnitsItem.setWidth("*"); - simpleLastUnitsItem.setRedrawOnChange(true); - - advancedStartItem = new DateTimeItem("start", MSG.view_measureRange_start()); - advancedStartItem.setStartRow(false); - advancedStartItem.setEndRow(false); - - advancedEndItem = new DateTimeItem("end", MSG.common_title_end()); - advancedEndItem.setStartRow(false); - advancedEndItem.setEndRow(false); - - setButton = new ButtonItem("set", MSG.common_button_set()); - setButton.setStartRow(false); - setButton.setEndRow(false); - setButton.setShowTitle(false); - setButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - MetricRangePreferences prefs = new MetricRangePreferences(); - prefs.explicitBeginEnd = advanced; - if (advanced) { - prefs.begin = advancedStartItem.getValueAsDate().getTime(); - prefs.end = advancedEndItem.getValueAsDate().getTime(); - } else { - prefs.lastN = Integer.valueOf(simpleLastValuesItem.getValueAsString()); - prefs.unit = Integer.valueOf(simpleLastUnitsItem.getValueAsString()); - } - measurementUserPrefs.setMetricRangePreferences(prefs); - } - }); - - advancedSimpleButton = new ButtonItem("advanced", MSG.common_button_advanced()); - advancedSimpleButton.setStartRow(false); - advancedSimpleButton.setEndRow(false); - advancedSimpleButton.setShowTitle(false); - advancedSimpleButton.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent clickEvent) { - advanced = !advanced; - update(); - } - }); - - MetricRangePreferences metricRangePrefs = measurementUserPrefs.getMetricRangePreferences(); - advanced = (metricRangePrefs.explicitBeginEnd); - - setItems(simpleLastValuesItem, simpleLastUnitsItem, advancedStartItem, advancedEndItem, setButton, - advancedSimpleButton); - } - - private void assignDefaultsToAdvancedItems() { - advancedStartItem.setValue(new Date(System.currentTimeMillis() - (1000L * 60 * 60 * 8))); - advancedEndItem.setValue(new Date()); - } - - private void assignDefaultsToSimpleItems() { - simpleLastValuesItem.setValue("8"); - simpleLastUnitsItem.setValue(String.valueOf(MeasurementUtility.UNIT_HOURS)); - } - - private void update() { - if (advanced) { - advancedSimpleButton.setTitle(MSG.view_measureRange_simple()); - showItem("start"); - showItem("end"); - hideItem("lastValues"); - hideItem("lastUnits"); - } else { - advancedSimpleButton.setTitle(MSG.common_button_advanced()); - hideItem("start"); - hideItem("end"); - showItem("lastValues"); - showItem("lastUnits"); - } - - // populate the fields - first with defaults in case we have no prefs, then with the appropriate prefs - assignDefaultsToSimpleItems(); - assignDefaultsToAdvancedItems(); - - try { - MetricRangePreferences metricRangePrefs = measurementUserPrefs.getMetricRangePreferences(); - if (metricRangePrefs.explicitBeginEnd) { - if (metricRangePrefs.begin != null && metricRangePrefs.end != null) { - advancedStartItem.setValue(new Date(metricRangePrefs.begin.longValue())); - advancedEndItem.setValue(new Date(metricRangePrefs.end.longValue())); - } - } else { - if (lastUnits.containsKey(String.valueOf(metricRangePrefs.unit))) { - simpleLastUnitsItem.setValue(String.valueOf(metricRangePrefs.unit)); - } - if (Arrays.asList(lastValues).contains(String.valueOf(metricRangePrefs.lastN))) { - simpleLastValuesItem.setValue(String.valueOf(metricRangePrefs.lastN)); - } - } - } catch (Exception e) { - // in case any odd errors occur (like bad format of preference strings), just fill in some defaults - CoreGUI.getMessageCenter().notify( - new Message("Failed to get range user preferences, using defaults", e, Severity.Warning)); - assignDefaultsToSimpleItems(); - assignDefaultsToAdvancedItems(); - } - - markForRedraw(); - } - - @Override - public void refresh(ListGrid listGrid) { - update(); - } -} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/UserPreferencesMeasurementRangeEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/UserPreferencesMeasurementRangeEditor.java new file mode 100644 index 0000000..02733e8 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/measurement/UserPreferencesMeasurementRangeEditor.java @@ -0,0 +1,56 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 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. + */ + +package org.rhq.enterprise.gui.coregui.client.components.measurement; + +import java.util.List; + +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; +import org.rhq.enterprise.gui.coregui.client.util.preferences.MeasurementUserPreferences; + +public class UserPreferencesMeasurementRangeEditor extends AbstractMeasurementRangeEditor { + + private MeasurementUserPreferences measurementUserPrefs; + + public UserPreferencesMeasurementRangeEditor(String locatorId) { + super(locatorId); + measurementUserPrefs = new MeasurementUserPreferences(UserSessionManager.getUserPreferences()); + } + + /** + * Returns the current range that is persisted. Note this may NOT be the begin and end times + * as shown in the UI if the user changed the values but did not hit the set button. + * @return begin/end epoch times in a list + */ + @Override + public List<Long> getBeginEndTimes() { + return measurementUserPrefs.getMetricRangePreferences().getBeginEndTimes(); + } + + @Override + public MetricRangePreferences getMetricRangePreferences() { + return measurementUserPrefs.getMetricRangePreferences(); + } + + @Override + public void setMetricRangeProperties(MetricRangePreferences prefs) { + measurementUserPrefs.setMetricRangePreferences(prefs); + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java index 74c3ee9..1d63f04 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java @@ -18,7 +18,9 @@ */ package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
+import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map;
import com.allen_sauer.gwt.log.client.Log; @@ -31,6 +33,8 @@ import com.smartgwt.client.widgets.HTMLFlow; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.events.SubmitValuesEvent; import com.smartgwt.client.widgets.form.events.SubmitValuesHandler; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.LinkItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem; @@ -49,7 +53,7 @@ import org.rhq.enterprise.gui.coregui.client.ImageManager; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent; import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener; -import org.rhq.enterprise.gui.coregui.client.components.measurement.MeasurementRangeEditor; +import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor; import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet; @@ -63,7 +67,6 @@ import org.rhq.enterprise.gui.coregui.client.util.GwtRelativeDurationConverter; import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableCanvas; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; -import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**This portlet allows the end user to customize the: @@ -77,14 +80,39 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet, PropertyValueChangeListener {
- private interface Constant { + public interface Constant { String ALERT_PRIORITY = "ALERT_PRIORITY"; + String ALERT_METRIC_RANGE_ENABLE = "ALERT_METRIC_RANGE_ENABLE"; + String ALERT_METRIC_RANGE_BEGIN_END_FLAG = "ALERT_METRIC_RANGE_BEGIN_END_FLAG"; + String ALERT_METRIC_RANGE = "ALERT_METRIC_RANGE"; + String ALERT_METRIC_RANGE_LASTN = "ALERT_METRIC_RANGE_LASTN"; + String ALERT_METRIC_RANGE_LASTN_DEFAULT = String.valueOf(8); + String ALERT_METRIC_RANGE_UNIT = "ALERT_METRIC_RANGE_UNIT"; String RESULT_SORT_ORDER = "RESULT_SORT_ORDER"; String RESULT_COUNT = "RESULT_COUNT"; String RESULT_COUNT_DEFAULT = "5"; String CUSTOM_REFRESH = "CUSTOM_REFRESH"; }
+ //configuration map initialization + private static Map<String, String> CONFIG_PROPERTY_INITIALIZATION = new HashMap<String, String>(); + static {// Key, Default value + //alert priority, if empty initialize to "" i.e. all priorities + CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_PRIORITY, ""); + //result sort order, if empty initialize to "DESC" + CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_SORT_ORDER, PageOrdering.DESC.name()); + //result count, if empty initialize to 5 + CONFIG_PROPERTY_INITIALIZATION.put(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT); + //whether to specify time range for alerts. Defaults to false + CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_METRIC_RANGE_ENABLE, String.valueOf(false)); + //whether Begin and End values set for time. Aka. Advanced/full range setting Defaults to false + CONFIG_PROPERTY_INITIALIZATION.put(Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG, String.valueOf(false)); + //whether in simple mode. Ex. 8 hrs. Defaults to 8 + CONFIG_PROPERTY_INITIALIZATION + .put(Constant.ALERT_METRIC_RANGE_LASTN, Constant.ALERT_METRIC_RANGE_LASTN_DEFAULT); + + } + private int groupId = -1; protected LocatableCanvas recentAlertsContent = new LocatableCanvas(extendLocatorId("RecentAlerts")); private static AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService(); @@ -93,7 +121,7 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin private SelectItem alertPrioritySelector = null; private SelectItem resultSortSelector = null; private SelectItem resultCountSelector = null; - private MeasurementRangeEditor measurementRangeEditor = null; + private CustomConfigMeasurementRangeEditor measurementRangeEditor = null; private DashboardPortlet storedPortlet;
public GroupAlertsPortlet(String locatorId) { @@ -128,12 +156,9 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin
// set on initial configuration, the window for this portlet view. private PortletWindow portletWindow; - // private AlertPortletDataSource dataSource; //instance ui widgets - private Canvas containerCanvas;
private Timer refreshTimer; - private LocatableIButton saveButton;
/** Responsible for initialization and lazy configuration of the portlet values */ @@ -150,17 +175,10 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin portletConfig = storedPortlet.getConfiguration();
//lazy init any elements not yet configured. - //alert priority, if empty initialize to "" i.e. all priorities - if (portletConfig.getSimple(Constant.ALERT_PRIORITY) == null) { - portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, "")); - } - //result sort order, if empty initialize to "DESC" - if (portletConfig.getSimple(Constant.RESULT_SORT_ORDER) == null) { - portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); - } - //result count, if empty initialize to 5 - if (portletConfig.getSimple(Constant.RESULT_COUNT) == null) { - portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT)); + for (String key : CONFIG_PROPERTY_INITIALIZATION.keySet()) { + if (portletConfig.getSimple(key) == null) { + portletConfig.put(new PropertySimple(key, CONFIG_PROPERTY_INITIALIZATION.get(key))); + } }
//custom refresh @@ -175,7 +193,6 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin public static PortletViewFactory INSTANCE = new Factory();
public final Portlet getInstance(String locatorId) { - return new GroupAlertsPortlet(locatorId); } } @@ -218,6 +235,18 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin pc.setPrimarySortOrder(PageOrdering.ASC); } } + //result timeframe if enabled + property = portletConfig.getSimple(Constant.ALERT_METRIC_RANGE_ENABLE); + if (Boolean.valueOf(property.getBooleanValue())) {//then proceed setting + property = portletConfig.getSimple(Constant.ALERT_METRIC_RANGE); + if (property != null) { + String currentSetting = property.getStringValue(); + String[] range = currentSetting.split(","); + criteria.addFilterStartTime(Long.valueOf(range[0])); + criteria.addFilterEndTime(Long.valueOf(range[1])); + } + } + //result count property = portletConfig.getSimple(Constant.RESULT_COUNT); if (property != null) { @@ -264,7 +293,8 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin + "/Alerts/History/", column); } else { LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow(recentAlertsContent - .extendLocatorId("None"), AbstractActivityView.RECENT_ALERTS_NONE); + // .extendLocatorId("None"), AbstractActivityView.RECENT_ALERTS_NONE); + .extendLocatorId("None"), "No results using criteria specified."); column.addMember(row); } for (Canvas child : recentAlertsContent.getChildren()) { @@ -288,8 +318,8 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin
@Override public DynamicForm getCustomSettingsForm() { - LocatableDynamicForm custom = new LocatableDynamicForm(extendLocatorId("customSettings")); - LocatableVLayout page = new LocatableVLayout(custom.extendLocatorId("page")); + LocatableDynamicForm customSettings = new LocatableDynamicForm(extendLocatorId("customSettings")); + LocatableVLayout page = new LocatableVLayout(customSettings.extendLocatorId("page")); //build editor form container final LocatableDynamicForm form = new LocatableDynamicForm(page.extendLocatorId("alert-filter")); form.setMargin(5); @@ -307,12 +337,13 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin "Displays N results with alerts", countSelections);
//add range selector - measurementRangeEditor = new MeasurementRangeEditor(page.extendLocatorId("alertTimeFrame")); + measurementRangeEditor = new CustomConfigMeasurementRangeEditor(page.extendLocatorId("alertTimeFrame"), + portletConfig);
form.setItems(alertPrioritySelector, resultSortSelector, resultCountSelector);
//submit handler - custom.addSubmitValuesHandler(new SubmitValuesHandler() { + customSettings.addSubmitValuesHandler(new SubmitValuesHandler() {
@Override public void onSubmitValues(SubmitValuesEvent event) { @@ -338,9 +369,26 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue)); }
+ //alert time range filter. Check for enabled and then persist property. Dealing with compound widget. + FormItem item = measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM); + CheckboxItem itemC = (CheckboxItem) item; + selectedValue = String.valueOf(itemC.getValueAsBoolean()); + if (!selectedValue.trim().isEmpty()) {//then call + portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE_ENABLE, selectedValue)); + } + + //alert time advanced time filter enabled. + selectedValue = String.valueOf(measurementRangeEditor.isAdvanced()); + if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) { + portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE_BEGIN_END_FLAG, selectedValue)); + } + //alert time frame - Map selectedValue3 = measurementRangeEditor.getValues(); - String selectedValue2 = measurementRangeEditor.getValue("") + ""; + List<Long> begEnd = measurementRangeEditor.getBeginEndTimes(); + if (begEnd.get(0) != 0) {//advanced settings + portletConfig.put(new PropertySimple(Constant.ALERT_METRIC_RANGE, (begEnd.get(0) + "," + begEnd + .get(1)))); + }
//persist storedPortlet.setConfiguration(portletConfig); @@ -351,8 +399,8 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin form.markForRedraw(); page.addMember(measurementRangeEditor); page.addMember(form); - custom.addChild(page); - return custom; + customSettings.addChild(page); + return customSettings; }
/* single select combobox for number of items to display on the dashboard @@ -395,7 +443,6 @@ public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettin private SelectItem getAlertPriorityEditor() { SelectItem priorityFilter = new SelectItem("severities", MSG.view_alerts_table_filter_priority()); priorityFilter.setWrapTitle(false); - // priorityFilter.setWidth("*"); priorityFilter.setWidth(200); priorityFilter.setMultiple(true); priorityFilter.setMultipleAppearance(MultipleAppearance.PICKLIST); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java new file mode 100644 index 0000000..72631b6 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet2.java @@ -0,0 +1,686 @@ +/* + * 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. + */ +package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups; + +import java.util.Set; + +import com.google.gwt.user.client.Timer; +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.HTMLFlow; +import com.smartgwt.client.widgets.events.DoubleClickEvent; +import com.smartgwt.client.widgets.events.DoubleClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.events.SubmitValuesEvent; +import com.smartgwt.client.widgets.form.events.SubmitValuesHandler; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.SpacerItem; +import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.VLayout; + +import org.rhq.core.domain.alert.AlertPriority; +import org.rhq.core.domain.authz.Permission; +import org.rhq.core.domain.configuration.PropertyList; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.LinkManager; +import org.rhq.enterprise.gui.coregui.client.Messages; +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; +import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView; +import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletDataSource; +import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; +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.dashboard.portlets.recent.alerts.PortletAlertSelector; +import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableLabel; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; +import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility; + +/** + * @author Simeon Pinder + */ +public class GroupAlertsPortlet2 extends AlertHistoryView implements CustomSettingsPortlet, AutoRefreshPortlet { + + // A non-displayed, persisted identifier for the portlet + public static final String KEY = "Group: Alerts2"; + // A default displayed, persisted name for the portlet + public static final String NAME = MSG.view_portlet_defaultName_recentAlerts(); + + //widget keys also used in form population + public static final String ALERT_RANGE_DISPLAY_AMOUNT_VALUE = "alert-range-display-amount-value"; + public static final String ALERT_RANGE_PRIORITY_VALUE = "alert-range-priority-value"; + public static final String ALERT_RANGE_TIME_VALUE = "alert-range-time-value"; + public static final String ALERT_RANGE_RESOURCES_VALUE = "alert-range-resource-value"; + public static final String ALERT_RANGE_RESOURCE_IDS = "alert-range-resource-ids"; + //configuration default information + private static final String defaultAlertCountValue = "5"; + private static final String PRIORITY_ALL = MSG.common_label_all(); + private static final String PRIORITY_HIGH = AlertPriority.HIGH.getDisplayName(); + private static final String PRIORITY_MEDIUM = AlertPriority.MEDIUM.getDisplayName(); + private static final String PRIORITY_LOW = AlertPriority.LOW.getDisplayName(); + private static final String defaultPriorityValue = PRIORITY_ALL; + private static final String TIME_30_MINS = "30 " + MSG.common_label_minutes(); + private static final String TIME_HOUR = MSG.common_label_hour(); + private static final String TIME_12_HRS = "12 " + MSG.common_label_hours(); + private static final String TIME_DAY = MSG.common_label_day(); + private static final String TIME_WEEK = MSG.common_label_week(); + private static final String TIME_MONTH = MSG.common_label_month(); + private static final String defaultTimeValue = TIME_DAY; + public static final String RESOURCES_ALL = MSG.common_label_all_resources(); + public static final String RESOURCES_SELECTED = MSG.common_label_selected_resources(); + public static final String defaultResourceValue = RESOURCES_ALL; + private static final String unlimited = MSG.common_label_unlimited(); + //alert resource labels + public static final String ALERT_LABEL_SELECTED_RESOURCES = MSG.common_title_selected_resources(); + public static final String ALERT_LABEL_AVAILABLE_RESOURCES = MSG.common_title_available_resources(); + public static final String ALERT_LABEL_RESOURCE_INVENTORY = MSG.common_title_resource_inventory(); + public static final int ALERT_RESOURCE_SELECTION_WIDTH = 800; + public static final String ID = "id"; + + // set on initial configuration, the window for this portlet view. + private PortletWindow portletWindow; + + //shared private UI elements + private AlertResourceSelectorRegion resourceSelector; + + private AlertPortletDataSource dataSource; + //instance ui widgets + private Canvas containerCanvas; + + private Timer refreshTimer; + + public GroupAlertsPortlet2(String locatorId) { + super(locatorId); + + //override the shared datasource + this.dataSource = new AlertPortletDataSource(); + setDataSource(this.dataSource); + + setShowHeader(false); + setShowFooter(true); + setShowFooterRefresh(false); //disable footer refresh + setShowFilterForm(false); //disable filter form for portlet + + setOverflow(Overflow.VISIBLE); + } + + public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) { + + if (null == this.portletWindow && null != portletWindow) { + this.portletWindow = portletWindow; + } + + if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) { + return; + } + + //Operation range property - retrieve existing value + PropertySimple property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE); + if ((property != null) && (property.getStringValue() != null)) { + //retrieve and translate to int + String retrieved = property.getStringValue(); + int translatedAlertRangeSelection = translatedAlertRangeSelection(retrieved); + getDataSource().setAlertRangeCompleted(translatedAlertRangeSelection); + } else {//create setting + storedPortlet.getConfiguration().put( + new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue)); + getDataSource().setAlertRangeCompleted(Integer.parseInt(defaultAlertCountValue)); + } + //Operation priority property setting + property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE); + if ((property != null) && (property.getStringValue() != null)) { + //retrieve and translate to int + String retrieved = property.getStringValue(); + int translatedPriorityIndex = translatedPriorityToValidIndex(retrieved); + getDataSource().setAlertPriorityIndex(translatedPriorityIndex); + } else {//create setting + storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue)); + getDataSource().setAlertPriorityIndex(translatedPriorityToValidIndex(PRIORITY_ALL)); + } + + //Range to time that alerts will be shown for + property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE); + if ((property != null) && (property.getStringValue() != null)) { + //retrieve and translate to int + String retrieved = property.getStringValue(); + long translatedRange = translateTimeToValidRange(retrieved); + getDataSource().setAlertTimeRange(translatedRange); + } else {//create setting + storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue)); + getDataSource().setAlertTimeRange(translateTimeToValidRange(defaultTimeValue)); + } + + //Range of resources to be included in the query + property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE); + if ((property != null) && (property.getStringValue() != null)) { + //retrieve and translate to int + String retrieved = property.getStringValue(); + if (retrieved.trim().equalsIgnoreCase(RESOURCES_SELECTED)) { + getDataSource().setAlertResourcesToUse(RESOURCES_SELECTED); + } else { + getDataSource().setAlertResourcesToUse(RESOURCES_ALL); + } + } else {//create setting + storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue)); + getDataSource().setAlertResourcesToUse(RESOURCES_ALL); + } + + //resource ids to be conditionally included in the query + Integer[] filterResourceIds = null; + filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, filterResourceIds); + //no defaults + + if (filterResourceIds != null) { + getDataSource().setAlertFilterResourceId(filterResourceIds); + } + + //conditionally display the selected resources ui + if (containerCanvas != null) { + //empty out earlier canvas + for (Canvas c : containerCanvas.getChildren()) { + c.destroy(); + } + if ((resourceSelector != null) && getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) { + containerCanvas.addChild(resourceSelector.getCanvas()); + } else { + containerCanvas.addChild(new Canvas()); + } + } + } + + private int translatedAlertRangeSelection(String retrieved) { + int translated = -1; + if ((retrieved != null) && (!retrieved.trim().isEmpty())) { + if (retrieved.equalsIgnoreCase(unlimited)) { + translated = -1; + } else { + translated = Integer.parseInt(retrieved);//default to all + } + } else {//default to defaultValue + if (defaultAlertCountValue.equalsIgnoreCase(unlimited)) { + translated = -1; + } else { + translated = Integer.parseInt(defaultAlertCountValue); + } + } + return translated; + } + + private int translatedPriorityToValidIndex(String retrieved) { + int translatedPriority = 0;//default to all + if ((retrieved != null) && (!retrieved.trim().isEmpty())) { + if (retrieved.equalsIgnoreCase(PRIORITY_HIGH)) { + translatedPriority = 3; + } else if (retrieved.equalsIgnoreCase(PRIORITY_MEDIUM)) { + translatedPriority = 2; + } else if (retrieved.equalsIgnoreCase(PRIORITY_LOW)) { + translatedPriority = 1; + } else { + translatedPriority = 0;//default to all + } + } + return translatedPriority; + } + + /**Translates the UI selection options into time values for alert query. + * + * @param retrieved + * @return long value mapping to string passed in. + */ + private long translateTimeToValidRange(String retrieved) { + long translated = 0;//default to ALL + if ((retrieved != null) && (!retrieved.trim().isEmpty())) { + if (retrieved.equalsIgnoreCase(TIME_30_MINS)) { + translated = MeasurementUtility.MINUTES * 30; + } else if (retrieved.equalsIgnoreCase(TIME_HOUR)) { + translated = MeasurementUtility.HOURS; + } else if (retrieved.equalsIgnoreCase(TIME_12_HRS)) { + translated = MeasurementUtility.HOURS * 12; + } else if (retrieved.equalsIgnoreCase(TIME_DAY)) { + translated = MeasurementUtility.DAYS; + } else if (retrieved.equalsIgnoreCase(TIME_WEEK)) { + translated = MeasurementUtility.WEEKS; + } else if (retrieved.equalsIgnoreCase(TIME_MONTH)) { + translated = MeasurementUtility.DAYS * 28;//replicated from old struts def. + } else { + translated = MeasurementUtility.DAYS;//default to day otherwise. + } + } + return translated; + } + + public Canvas getHelpCanvas() { + return new HTMLFlow(MSG.view_portlet_help_recentAlerts()); + } + + public DynamicForm getCustomSettingsForm() { + //root dynamic form instance + final LocatableDynamicForm form = new LocatableDynamicForm(extendLocatorId("custom-settings")); + form.setWidth(GroupAlertsPortlet2.ALERT_RESOURCE_SELECTION_WIDTH + 40);//largest widget display + 40 for buttons + form.setHeight(400); + form.setMargin(5); + + final DashboardPortlet storedPortlet = portletWindow.getStoredPortlet(); + + //vertical container + VLayout column = new VLayout(); + + //label + LocatableLabel alertRangeLabel = new LocatableLabel(extendLocatorId("DynamicForm_Label_Alert_Range"), "<b>" + + MSG.common_title_alert_range() + "</b>"); + + //horizontal layout + LocatableHLayout row = new LocatableHLayout(extendLocatorId("alert-range-settings-row-1")); + row.setMembersMargin(10); + + //-------------combobox for number of completed scheduled ops to display on the dashboard + final SelectItem alertRangeLastComboBox = new SelectItem(ALERT_RANGE_DISPLAY_AMOUNT_VALUE); + alertRangeLastComboBox.setTitle(MSG.view_measureRange_last()); + alertRangeLastComboBox.setType("selection"); + alertRangeLastComboBox.setWrapTitle(false); + //define acceptable values for display amount + String[] acceptableDisplayValues = { "5", "10", MSG.common_label_unlimited() }; + alertRangeLastComboBox.setValueMap(acceptableDisplayValues); + //set width of dropdown display region + alertRangeLastComboBox.setWidth(100); + alertRangeLastComboBox.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent event) { + String selectedItem = "" + event.getValue(); + //stuff into the master form for retrieval + form.setValue(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, selectedItem); + } + }); + + //default selected value to 'unlimited'(live lists) and check both combobox settings here. + String selectedValue = defaultAlertCountValue; + if (storedPortlet != null) { + //if property exists retrieve it + if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) != null) { + selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) + .getStringValue(); + } else {//insert default value + storedPortlet.getConfiguration().put( + new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue)); + } + } + //prepopulate the combobox with the previously stored selection + alertRangeLastComboBox.setDefaultValue(selectedValue); + + //-------------combobox for number of completed scheduled ops to display on the dashboard + final SelectItem alertRangePriorityComboBox = new SelectItem(ALERT_RANGE_PRIORITY_VALUE); + alertRangePriorityComboBox.setTitle(""); + alertRangePriorityComboBox.setHint("<nobr> <b> " + MSG.view_portlet_recentAlerts_config_priority_label() + + "</b></nobr>"); + alertRangePriorityComboBox.setType("selection"); + //define acceptable values for display amount + String[] acceptablePriorityDisplayValues = { PRIORITY_ALL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW }; + alertRangePriorityComboBox.setValueMap(acceptablePriorityDisplayValues); + //set width of dropdown display region + alertRangePriorityComboBox.setWidth(100); + alertRangePriorityComboBox.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent event) { + String selectedItem = "" + event.getValue(); + //stuff into the master form for retrieval + form.setValue(ALERT_RANGE_PRIORITY_VALUE, selectedItem); + } + }); + + //default selected value to 'unlimited'(live lists) and check both combobox settings here. + selectedValue = defaultPriorityValue; + if (storedPortlet != null) { + //if property exists retrieve it + if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE) != null) { + selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE).getStringValue(); + } else {//insert default value + storedPortlet.getConfiguration().put( + new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue)); + } + } + //prepopulate the combobox with the previously stored selection + alertRangePriorityComboBox.setDefaultValue(selectedValue); + row.addMember(alertRangeLabel); + DynamicForm wrappedRange = new DynamicForm(); + wrappedRange.setFields(alertRangeLastComboBox); + row.addMember(wrappedRange); + + DynamicForm wrappedPriority = new DynamicForm(); + wrappedPriority.setFields(alertRangePriorityComboBox); + row.addMember(wrappedPriority); + + //horizontal layout + LocatableHLayout row2 = new LocatableHLayout(extendLocatorId("alert-range-settings-row-2")); + + LocatableLabel alertRangeSpanLabel = new LocatableLabel(extendLocatorId("range-span-label"), "<b>" + + MSG.view_portlet_recentAlerts_config_when() + "<b>"); + //------------- Build second combobox for timeframe for problem resources search. + final SelectItem alertRangeTimeComboBox = new SelectItem(ALERT_RANGE_TIME_VALUE); + alertRangeTimeComboBox.setTitle(""); + alertRangeTimeComboBox.setHint(""); + alertRangeTimeComboBox.setType("selection"); + String[] acceptableTimeDisplayValues = { TIME_30_MINS, TIME_HOUR, TIME_12_HRS, TIME_DAY, TIME_WEEK, TIME_MONTH }; + alertRangeTimeComboBox.setValueMap(acceptableTimeDisplayValues); + alertRangeTimeComboBox.setWidth(100); + alertRangeTimeComboBox.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent event) { + String selectedItem = "" + event.getValue(); + //stuff into the master form for retrieval + form.setValue(ALERT_RANGE_TIME_VALUE, selectedItem); + } + }); + + //set to default + selectedValue = defaultTimeValue; + if (storedPortlet != null) { + //if property exists retrieve it + if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE) != null) { + selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE).getStringValue(); + } else {//insert default value + storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue)); + } + } + //prepopulate the combobox with the previously stored selection + alertRangeTimeComboBox.setDefaultValue(selectedValue); + DynamicForm timeSelectionWrapper = new DynamicForm(); + timeSelectionWrapper.setFields(alertRangeTimeComboBox); + + // build resource selection drop down + //------------- Build second combobox for timeframe for problem resources search. + final SelectItem alertResourcesComboBox = new SelectItem(ALERT_RANGE_RESOURCES_VALUE); + alertResourcesComboBox.setTitle(MSG.common_val_for()); + alertResourcesComboBox.setHint(""); + alertResourcesComboBox.setType("selection"); + String[] acceptableResourceDisplayValues = { RESOURCES_ALL, RESOURCES_SELECTED }; + alertResourcesComboBox.setValueMap(acceptableResourceDisplayValues); + alertResourcesComboBox.setWidth(150); + alertResourcesComboBox.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent event) { + String selectedItem = "" + event.getValue(); + //stuff into the master form for retrieval + form.setValue(ALERT_RANGE_RESOURCES_VALUE, selectedItem); + //empty out earlier canvas + for (Canvas c : containerCanvas.getChildren()) { + c.destroy(); + } + if (selectedItem.equals(RESOURCES_SELECTED)) { + containerCanvas.addChild(resourceSelector.getCanvas()); + } else { + containerCanvas.addChild(new Canvas()); + } + } + }); + + //set to default + selectedValue = defaultResourceValue; + if (storedPortlet != null) { + //if property exists retrieve it + if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) != null) { + selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) + .getStringValue(); + } else {//insert default value + storedPortlet.getConfiguration().put( + new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue)); + } + } + //prepopulate the combobox with the previously stored selection + alertResourcesComboBox.setDefaultValue(selectedValue); + DynamicForm resourceSelectionWrapper = new DynamicForm(); + resourceSelectionWrapper.setFields(alertResourcesComboBox); + + alertRangeSpanLabel.setWrap(false); + alertRangeSpanLabel.setWidth(150); + row2.addMember(alertRangeSpanLabel); + row2.addMember(timeSelectionWrapper); + row2.addMember(resourceSelectionWrapper); + + //if portlet config setting exist, then retrieve + Integer[] alertFilterResourceIds = null; + alertFilterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, alertFilterResourceIds); + + LocatableHLayout resourceSelectionRegion = new LocatableHLayout(extendLocatorId("selection-canvas")); + resourceSelector = new AlertResourceSelectorRegion(extendLocatorId("ResourcesWithAlerts"), + alertFilterResourceIds); + resourceSelectionRegion.setWidth100(); + + if (alertFilterResourceIds != null) { + getDataSource().setAlertFilterResourceId(alertFilterResourceIds); + resourceSelector.setCurrentlyAssignedIds(alertFilterResourceIds); + } + + //instantiate canvas area to display empty or rich resource selection based on dropdown selection + containerCanvas = new Canvas(); + String previousAlertFilterChoice = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) + .getStringValue(); + + //reload the ResourceSelectionRegion if user has chosen to focus on specific resources with alerts + if (previousAlertFilterChoice.equals(RESOURCES_SELECTED)) { + containerCanvas.addChild(resourceSelector.getCanvas()); + } else {// define empty canvas + containerCanvas.addChild(new Canvas()); + } + + //add contain resource selection region. + resourceSelectionRegion.addMember(containerCanvas); + + //finish construction of the layout + column.addMember(row); + column.addMember(row2); + SpacerItem verticalSpace = new SpacerItem(); + verticalSpace.setHeight(20); + DynamicForm spacerWrapper = new DynamicForm(); + spacerWrapper.setItems(verticalSpace); + column.addMember(spacerWrapper); + column.addMember(resourceSelectionRegion); + form.addChild(column); + + //submit handler + form.addSubmitValuesHandler(new SubmitValuesHandler() { + @Override + public void onSubmitValues(SubmitValuesEvent event) { + //no need to insert validation here as user not allowed to enter values + parseFormAndPopulateConfiguration(form, storedPortlet, ALERT_RANGE_DISPLAY_AMOUNT_VALUE, + ALERT_RANGE_PRIORITY_VALUE, ALERT_RANGE_RESOURCES_VALUE, ALERT_RANGE_TIME_VALUE); + + //retrieve alert-resource-selection property + PropertySimple prop = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE); + + //check to see if "Selected Resources" or "All Resources" + if (prop != null && RESOURCES_SELECTED.equals(prop.getStringValue())) { + //retrieve currentlyAssignedIds + Integer[] valuesToPersist = resourceSelector.getListGridValues(); + resourceSelector.setCurrentlyAssignedIds(valuesToPersist); + + //build property list of ids to persist + PropertyList list = new PropertyList(ALERT_RANGE_RESOURCE_IDS); + for (int rid : resourceSelector.getCurrentlyAssignedIds()) { + list.add(new PropertySimple(ALERT_RANGE_RESOURCE_IDS, rid)); + } + storedPortlet.getConfiguration().put(new PropertyList(ALERT_RANGE_RESOURCE_IDS, list)); + getDataSource().setAlertFilterResourceId(resourceSelector.getCurrentlyAssignedIds()); + } + + configure(portletWindow, storedPortlet); + + refresh();//reload form with new data selections + markForRedraw(); + } + }); + + return form; + } + + /**Iterates over DynamicForm instance to check for properties passed in and if they have been set + * to put that property into the DashboardPortlet configuration. + * + * @param form Dynamic form storing user selections + * @param portlet Container for configuration changes + * @param properties Variable list of keys used to verify or populate properties. + */ + private void parseFormAndPopulateConfiguration(final DynamicForm form, DashboardPortlet storedPortlet, + String... properties) { + if ((form != null) && (storedPortlet != null)) { + for (String property : properties) { + if (form.getValue(property) != null) {//if new value supplied + storedPortlet.getConfiguration().put(new PropertySimple(property, form.getValue(property))); + } + } + } + } + + public AlertPortletDataSource getDataSource() { + return dataSource; + } + + public static final class Factory implements PortletViewFactory { + public static PortletViewFactory INSTANCE = new Factory(); + + public final Portlet getInstance(String locatorId) { + + return new GroupAlertsPortlet2(locatorId); + } + } + + @Override + public void startRefreshCycle() { + //current setting + final int refreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval(); + + //cancel any existing timer + if (refreshTimer != null) { + refreshTimer.cancel(); + } + + if (refreshInterval >= MeasurementUtility.MINUTES) { + + refreshTimer = new Timer() { + public void run() { + + redraw(); + } + }; + + refreshTimer.scheduleRepeating(refreshInterval); + } + } + + @Override + protected void onDestroy() { + if (refreshTimer != null) { + + refreshTimer.cancel(); + } + + super.onDestroy(); + } + + @Override + protected void setupTableInteractions(boolean hasWriteAccess) { + // The portlet is a "subsystem" view. Meaning the alerts displayed can be from any accessible group for + // the user. This means the user can have varying permissions on the underlying groups and/or resources, + // which makes button enablement tricky. So, for the portlet don't even show the buttons unless the user + // is inventory manager. Other users will just have to navigate to the alert in question in order to + // manipulate it. + + //determine if the user is inventory manager and if so render the buttons + Set<Permission> permissions = this.portletWindow.getGlobalPermissions(); + if ((null != permissions) && permissions.contains(Permission.MANAGE_INVENTORY)) { + super.setupTableInteractions(true); + } + } + + protected CellFormatter getDetailsLinkColumnCellFormatter() { + return new CellFormatter() { + public String format(Object value, ListGridRecord record, int i, int i1) { + Integer recordId = getId(record); + Integer resourceId = record.getAttributeAsInt("resourceId"); + String detailsUrl = LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId); + return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(), null); + } + }; + } + + @Override + protected void configureTable() { + // TODO Auto-generated method stub + super.configureTable(); + + setListGridDoubleClickHandler(new DoubleClickHandler() { + @Override + public void onDoubleClick(DoubleClickEvent event) { + ListGrid listGrid = (ListGrid) event.getSource(); + ListGridRecord[] selectedRows = listGrid.getSelection(); + if (selectedRows != null && selectedRows.length == 1) { + Integer recordId = getId(selectedRows[0]); + Integer resourceId = selectedRows[0].getAttributeAsInt("resourceId"); + CoreGUI.goToView(LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId)); + } + } + }); + } + +} + +/** Bundles a ResourceSelector instance with labelling in Canvas for display. + * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act accordingly. + */ +class AlertResourceSelectorRegion extends LocatableVLayout { + public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) { + super(locatorId); + this.currentlyAssignedIds = assigned; + } + + private static final Messages MSG = CoreGUI.getMessages(); + private PortletAlertSelector selector = null; + + private Integer[] currentlyAssignedIds; + + public Integer[] getCurrentlyAssignedIds() { + return currentlyAssignedIds; + } + + public Integer[] getListGridValues() { + Integer[] listGridValues = new Integer[0]; + if (null != selector) { + listGridValues = selector.getAssignedListGridValues(); + } + return listGridValues; + } + + public Canvas getCanvas() { + if (selector == null) { + selector = new PortletAlertSelector(extendLocatorId("AlertSelector"), this.currentlyAssignedIds, + ResourceType.ANY_PLATFORM_TYPE, false); + } + return selector; + } + + public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) { + this.currentlyAssignedIds = currentlyAssignedIds; + } +} \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java index f8b7239..665898e 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java @@ -304,6 +304,7 @@ public class RecentAlertsPortlet extends AlertHistoryView implements CustomSetti final SelectItem alertRangeLastComboBox = new SelectItem(ALERT_RANGE_DISPLAY_AMOUNT_VALUE); alertRangeLastComboBox.setTitle(MSG.view_measureRange_last()); alertRangeLastComboBox.setType("selection"); + alertRangeLastComboBox.setWrapTitle(false); //define acceptable values for display amount String[] acceptableDisplayValues = { "5", "10", MSG.common_label_unlimited() }; alertRangeLastComboBox.setValueMap(acceptableDisplayValues); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java index 6f27e8f..dcd89d0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java @@ -36,7 +36,7 @@ import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.domain.resource.composite.ResourceComposite; import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.components.measurement.MeasurementRangeEditor; +import org.rhq.enterprise.gui.coregui.client.components.measurement.UserPreferencesMeasurementRangeEditor; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSelectListener; import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository; @@ -67,7 +67,7 @@ public class GraphListView extends LocatableVLayout implements ResourceSelectLis
// addMember(loadingLabel);
- addMember(new MeasurementRangeEditor(this.getLocatorId())); + addMember(new UserPreferencesMeasurementRangeEditor(this.getLocatorId()));
if (resource != null) { buildGraphs(); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MeasurementTableView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MeasurementTableView.java index 961dac4..f79dfef 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MeasurementTableView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MeasurementTableView.java @@ -34,7 +34,7 @@ import com.smartgwt.client.widgets.grid.ListGridRecord; import org.rhq.core.domain.measurement.MeasurementData; import org.rhq.core.domain.measurement.MeasurementUnits; import org.rhq.enterprise.gui.coregui.client.CoreGUI; -import org.rhq.enterprise.gui.coregui.client.components.measurement.MeasurementRangeEditor; +import org.rhq.enterprise.gui.coregui.client.components.measurement.UserPreferencesMeasurementRangeEditor; import org.rhq.enterprise.gui.coregui.client.components.table.Table; import org.rhq.enterprise.gui.coregui.client.components.table.TableAction; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; @@ -60,7 +60,7 @@ public class MeasurementTableView extends Table<MeasurementTableDataSource> { protected void configureTable() { ArrayList<ListGridField> fields = getDataSource().getListGridFields(); setListGridFields(fields.toArray(new ListGridField[0])); - addExtraWidget(new MeasurementRangeEditor(extendLocatorId("range")), true); + addExtraWidget(new UserPreferencesMeasurementRangeEditor(extendLocatorId("range")), true); addTableAction(extendLocatorId("liveValue"), MSG.view_measureTable_getLive(), new TableAction() { @Override public boolean isEnabled(ListGridRecord[] selection) { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/preferences/MeasurementUserPreferences.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/preferences/MeasurementUserPreferences.java index 76ca6c9..47ba05c 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/preferences/MeasurementUserPreferences.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/preferences/MeasurementUserPreferences.java @@ -19,10 +19,10 @@
package org.rhq.enterprise.gui.coregui.client.util.preferences;
-import java.util.ArrayList; import java.util.Arrays; import java.util.List;
+import org.rhq.enterprise.gui.coregui.client.components.measurement.AbstractMeasurementRangeEditor.MetricRangePreferences; import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
@@ -60,40 +60,6 @@ public class MeasurementUserPreferences { public List<String> views; }
- public static class MetricRangePreferences { - // if readOnly is true, then the beginning and ending range dates are specified with explicit dates - // if readOnly is false, then the time is relative to NOW and is specified as <lastN> units of <unit> time - public boolean explicitBeginEnd; - - // simple, when readOnly is false - public int lastN; - public int unit; // see MeasurementUtility.UNIT_xxx - - // advanced, when readOnly is true - public Long begin; - public Long end; - - /** - * 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 time frame. - **/ - public ArrayList<Long> getBeginEndTimes() { - if (explicitBeginEnd) { - ArrayList<Long> times = new ArrayList<Long>(2); - times.add(begin); - times.add(end); - return times; - } else { - return MeasurementUtility.calculateTimeFrame(lastN, unit); - } - } - - public String toString() { - return (explicitBeginEnd) ? "[begin=" + begin + end + ",end=" + end + "]" : "[lastN=" + lastN + ",unit=" - + unit + "]"; - } - } - public MetricRangePreferences getMetricRangePreferences() { MetricRangePreferences prefs = new MetricRangePreferences();
commit 438dbc355f104e60215e5bc737a7cd220f362ce1 Author: Simeon Pinder spinder@redhat.com Date: Tue Mar 8 07:46:30 2011 -0500
group alert dash commit: i)dashboard allows only appropriate portlet additions for focus resource/group. ii)icons for portlets iii)still issues with MeasurementRangeEditor widget and Alert Criteria results sorting.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java index f5f3fc8..456343d 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java @@ -50,6 +50,8 @@ import org.rhq.core.domain.authz.Permission; import org.rhq.core.domain.configuration.PropertySimple; import org.rhq.core.domain.dashboard.Dashboard; import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.core.domain.resource.Resource; +import org.rhq.core.domain.resource.group.ResourceGroup; import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.ImageManager; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; @@ -92,6 +94,8 @@ public class DashboardView extends LocatableVLayout { private int refreshInterval = 0; private LocatableIMenuButton refreshMenuButton; private HashMap<String, PortletViewFactory> portletMap = null; + private ResourceGroup focusGroup = null; + private Resource focusResource = null;
// this is used to prevent an odd smartgwt problem where onInit() can get called multiple times if // the view is set to a Tab's pane. @@ -104,6 +108,13 @@ public class DashboardView extends LocatableVLayout { this.storedDashboard = storedDashboard; }
+ public DashboardView(String locatorId, DashboardContainer dashboardContainer, Dashboard storedDashboard, + ResourceGroup group, Resource resource) { + this(locatorId, dashboardContainer, storedDashboard); + this.focusGroup = group; + this.focusResource = resource; + } + @Override protected void onInit() { if (!isInitialized) { @@ -230,6 +241,22 @@ public class DashboardView extends LocatableVLayout { for (String portletKey : keyNameMap.keySet()) { nameKeyMap.put(keyNameMap.get(portletKey), portletKey); } + //if resourceGroup passed in then add additional portlets to list + if (this.focusGroup != null) { + HashMap<String, String> groupKeyNameMap = PortletFactory.getRegisteredGroupPortletNameMap(); + for (String portletKey : groupKeyNameMap.keySet()) { + nameKeyMap.put(groupKeyNameMap.get(portletKey), portletKey); + } + } + + //if resource passed in then add additional portlets to list + if (this.focusResource != null) { + HashMap<String, String> resourceKeyNameMap = PortletFactory.getRegisteredResourcePortletNameMap(); + for (String portletKey : resourceKeyNameMap.keySet()) { + nameKeyMap.put(resourceKeyNameMap.get(portletKey), portletKey); + } + } + // now use the reversed map for the menu generation for (String portletName : nameKeyMap.keySet()) { MenuItem menuItem = new MenuItem(portletName); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java index eb1e172..0d109ab 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.List;
import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.enterprise.gui.coregui.client.ImageManager; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.queue.AutodiscoveryPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.FavoriteResourcesPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.graph.GraphPortlet; @@ -37,6 +39,7 @@ import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.util.MashupPortl import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.util.MessagePortlet;
/** + * @author Simeon Pinder * @author Greg Hinkle */ public class PortletFactory { @@ -44,7 +47,17 @@ public class PortletFactory { private static HashMap<String, PortletViewFactory> registeredPortletFactoryMap; private static HashMap<String, String> registeredPortletNameMap;
+ //Group portlet registrations, diff from default portlets as only applicable for specific group + private static HashMap<String, PortletViewFactory> registeredGroupPortletFactoryMap; + //Resource portlet registrations, diff from default portlets as only applicable for specific resource + private static HashMap<String, PortletViewFactory> registeredResourcePortletFactoryMap; + private static HashMap<String, String> registeredGroupPortletNameMap; + private static HashMap<String, String> registeredResourcePortletNameMap; + private static HashMap<String, String> registeredPortletIconMap; + static { + //############## Default Dashboard ############################ + //defines portlet factory mappings for landing page Dashboard registeredPortletFactoryMap = new HashMap<String, PortletViewFactory>(); registeredPortletFactoryMap.put(InventorySummaryPortlet.KEY, InventorySummaryPortlet.Factory.INSTANCE); registeredPortletFactoryMap.put(RecentlyAddedResourcesPortlet.KEY, @@ -60,6 +73,7 @@ public class PortletFactory { registeredPortletFactoryMap.put(ProblemResourcesPortlet.KEY, ProblemResourcesPortlet.Factory.INSTANCE); registeredPortletFactoryMap.put(OperationsPortlet.KEY, OperationsPortlet.Factory.INSTANCE);
+ //defines portlet name mappings for landing page Dashboard registeredPortletNameMap = new HashMap<String, String>(registeredPortletFactoryMap.size()); registeredPortletNameMap.put(InventorySummaryPortlet.KEY, InventorySummaryPortlet.NAME); registeredPortletNameMap.put(RecentlyAddedResourcesPortlet.KEY, RecentlyAddedResourcesPortlet.NAME); @@ -73,11 +87,38 @@ public class PortletFactory { registeredPortletNameMap.put(MessagePortlet.KEY, MessagePortlet.NAME); registeredPortletNameMap.put(ProblemResourcesPortlet.KEY, ProblemResourcesPortlet.NAME); registeredPortletNameMap.put(OperationsPortlet.KEY, OperationsPortlet.NAME); + + //############## Group Activity Dashboard ############################################ + //defines mapping for Group Activity Dashboard + registeredGroupPortletFactoryMap = new HashMap<String, PortletViewFactory>(); + registeredGroupPortletFactoryMap.put(GroupAlertsPortlet.KEY, GroupAlertsPortlet.Factory.INSTANCE); + + //register group portlet names + registeredGroupPortletNameMap = new HashMap<String, String>(registeredGroupPortletFactoryMap.size()); + registeredGroupPortletNameMap.put(GroupAlertsPortlet.KEY, GroupAlertsPortlet.NAME); + + //############## Resource Activity Dashboard ############################################ + //defines mapping for Group Activity Dashboard + registeredResourcePortletFactoryMap = new HashMap<String, PortletViewFactory>(); + + //register resource portlet names + registeredResourcePortletNameMap = new HashMap<String, String>(registeredResourcePortletFactoryMap.size()); + + //############## Portlet icon mappings ############################################ + //register portlet names + registeredPortletIconMap = new HashMap<String, String>(registeredPortletFactoryMap.size()); + registeredPortletIconMap.put(GroupAlertsPortlet.KEY, ImageManager.getAlertLargeIcon()); }
public static Portlet buildPortlet(String locatorId, PortletWindow portletWindow, DashboardPortlet storedPortlet) {
PortletViewFactory viewFactory = registeredPortletFactoryMap.get(storedPortlet.getPortletKey()); + if (viewFactory == null) {//check group view factory + viewFactory = registeredGroupPortletFactoryMap.get(storedPortlet.getPortletKey()); + } + if (viewFactory == null) {//check resource view factory + viewFactory = registeredResourcePortletFactoryMap.get(storedPortlet.getPortletKey()); + }
Portlet view = viewFactory.getInstance(locatorId); view.configure(portletWindow, storedPortlet); @@ -96,6 +137,18 @@ public class PortletFactory { return portletKeys; }
+ public static List<String> getRegisteredGroupPortletKeys() { + + ArrayList<String> portletKeys = new ArrayList<String>(registeredGroupPortletFactoryMap.keySet()); + return portletKeys; + } + + public static List<String> getRegisteredResourcePortletKeys() { + + ArrayList<String> portletKeys = new ArrayList<String>(registeredResourcePortletFactoryMap.keySet()); + return portletKeys; + } + /** * @return Unmodifiable Map of registered portlet keys to names */ @@ -104,11 +157,36 @@ public class PortletFactory { return registeredPortletNameMap; }
+ public static HashMap<String, String> getRegisteredGroupPortletNameMap() { + + return registeredGroupPortletNameMap; + } + + public static HashMap<String, String> getRegisteredResourcePortletNameMap() { + + return registeredResourcePortletNameMap; + } + public static String getRegisteredPortletName(String key) {
return registeredPortletNameMap.get(key); }
+ public static String getRegisteredGroupPortletName(String key) { + + return registeredGroupPortletNameMap.get(key); + } + + public static String getRegisteredResourcePortletName(String key) { + + return registeredResourcePortletNameMap.get(key); + } + + public static String getRegisteredPortletIcon(String key) { + + return registeredPortletIconMap.get(key); + } + public static PortletViewFactory getRegisteredPortletFactory(String key) { PortletViewFactory portletFactory = null; if ((key != null) & (!key.trim().isEmpty())) { @@ -117,4 +195,20 @@ public class PortletFactory { return portletFactory; }
+ public static PortletViewFactory getRegisteredGroupPortletFactory(String key) { + PortletViewFactory portletFactory = null; + if ((key != null) & (!key.trim().isEmpty())) { + portletFactory = registeredGroupPortletFactoryMap.get(key); + } + return portletFactory; + } + + public static PortletViewFactory getRegisteredResourcePortletFactory(String key) { + PortletViewFactory portletFactory = null; + if ((key != null) & (!key.trim().isEmpty())) { + portletFactory = registeredResourcePortletFactoryMap.get(key); + } + return portletFactory; + } + } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java index 2eac777..24f31b5 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java @@ -117,11 +117,28 @@ public class PortletWindow extends LocatableWindow { "[SKIN]/headerIcons/clipboard.png"), rssHandler); RssHeader.setTooltip(RSS);
+ //detect customized Header icon + HeaderControl headerIcon = null; + String portletKey = storedPortlet.getPortletKey(); + String iconUrl = PortletFactory.getRegisteredPortletIcon(portletKey); + if ((iconUrl != null) && (!iconUrl.trim().isEmpty())) { + HeaderIcon icon = new HeaderIcon(iconUrl); + headerIcon = new HeaderControl(icon); + } + // customize the appearance and order of the controls in the window header - setHeaderControls(HeaderControls.MINIMIZE_BUTTON, HeaderControls.HEADER_LABEL, new LocatableHeaderControl( - extendLocatorId("Refresh"), HeaderControl.REFRESH, refreshHandler), new LocatableHeaderControl( - extendLocatorId("Settings"), HeaderControl.SETTINGS, settingsHandler), new LocatableHeaderControl( - extendLocatorId("Help"), HeaderControl.HELP, helpHandler), HeaderControls.CLOSE_BUTTON); + if (headerIcon != null) { + setHeaderControls(HeaderControls.MINIMIZE_BUTTON, headerIcon, HeaderControls.HEADER_LABEL, + new LocatableHeaderControl(extendLocatorId("Refresh"), HeaderControl.REFRESH, refreshHandler), + new LocatableHeaderControl(extendLocatorId("Settings"), HeaderControl.SETTINGS, settingsHandler), + new LocatableHeaderControl(extendLocatorId("Help"), HeaderControl.HELP, helpHandler), + HeaderControls.CLOSE_BUTTON); + } else { + setHeaderControls(HeaderControls.MINIMIZE_BUTTON, HeaderControls.HEADER_LABEL, new LocatableHeaderControl( + extendLocatorId("Refresh"), HeaderControl.REFRESH, refreshHandler), new LocatableHeaderControl( + extendLocatorId("Settings"), HeaderControl.SETTINGS, settingsHandler), new LocatableHeaderControl( + extendLocatorId("Help"), HeaderControl.HELP, helpHandler), HeaderControls.CLOSE_BUTTON); + }
// enable predefined component animation setAnimateMinimize(true); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java new file mode 100644 index 0000000..74c3ee9 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java @@ -0,0 +1,509 @@ +/* + * 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. + */ +package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups; + +import java.util.LinkedHashMap; +import java.util.Map; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.History; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.MultipleAppearance; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.HTMLFlow; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.events.SubmitValuesEvent; +import com.smartgwt.client.widgets.form.events.SubmitValuesHandler; +import com.smartgwt.client.widgets.form.fields.LinkItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; +import com.smartgwt.client.widgets.layout.VLayout; + +import org.rhq.core.domain.alert.Alert; +import org.rhq.core.domain.alert.AlertPriority; +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.domain.criteria.AlertCriteria; +import org.rhq.core.domain.dashboard.DashboardPortlet; +import org.rhq.core.domain.util.PageControl; +import org.rhq.core.domain.util.PageList; +import org.rhq.core.domain.util.PageOrdering; +import org.rhq.enterprise.gui.coregui.client.ImageManager; +import org.rhq.enterprise.gui.coregui.client.UserSessionManager; +import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent; +import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener; +import org.rhq.enterprise.gui.coregui.client.components.measurement.MeasurementRangeEditor; +import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; +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.gwt.AlertGWTServiceAsync; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView; +import org.rhq.enterprise.gui.coregui.client.resource.disambiguation.ReportDecorator; +import org.rhq.enterprise.gui.coregui.client.util.GwtRelativeDurationConverter; +import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableCanvas; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; + +/**This portlet allows the end user to customize the: + * i)range + * ii)priority + * iii)etc. + * of alerts to display for the given group + * + * @author Simeon Pinder + */ +public class GroupAlertsPortlet extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet, + PropertyValueChangeListener { + + private interface Constant { + String ALERT_PRIORITY = "ALERT_PRIORITY"; + String RESULT_SORT_ORDER = "RESULT_SORT_ORDER"; + String RESULT_COUNT = "RESULT_COUNT"; + String RESULT_COUNT_DEFAULT = "5"; + String CUSTOM_REFRESH = "CUSTOM_REFRESH"; + } + + private int groupId = -1; + protected LocatableCanvas recentAlertsContent = new LocatableCanvas(extendLocatorId("RecentAlerts")); + private static AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService(); + private boolean currentlyLoading = false; + private Configuration portletConfig = null; + private SelectItem alertPrioritySelector = null; + private SelectItem resultSortSelector = null; + private SelectItem resultCountSelector = null; + private MeasurementRangeEditor measurementRangeEditor = null; + private DashboardPortlet storedPortlet; + + public GroupAlertsPortlet(String locatorId) { + super(locatorId); + //figure out which page we're loading + String currentPage = History.getToken(); + String[] elements = currentPage.split("/"); + int currentGroupIdentifier = Integer.valueOf(elements[1]); + this.groupId = currentGroupIdentifier; + initializeUi(); + } + + @Override + protected void onInit() { + super.onInit(); + loadData(); + } + + /**Defines layout for the Activity page. + */ + protected void initializeUi() { + setPadding(5); + setMembersMargin(5); + addMember(recentAlertsContent); + } + + // A non-displayed, persisted identifier for the portlet + public static final String KEY = "GroupAlerts"; + // A default displayed, persisted name for the portlet + public static final String NAME = "Group: Alerts"; + public static final String ID = "id"; + + // set on initial configuration, the window for this portlet view. + private PortletWindow portletWindow; + // private AlertPortletDataSource dataSource; + //instance ui widgets + private Canvas containerCanvas; + + private Timer refreshTimer; + private LocatableIButton saveButton; + + /** Responsible for initialization and lazy configuration of the portlet values + */ + public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) { + //populate portlet configuration details + if (null == this.portletWindow && null != portletWindow) { + this.portletWindow = portletWindow; + } + + if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) { + return; + } + this.storedPortlet = storedPortlet; + portletConfig = storedPortlet.getConfiguration(); + + //lazy init any elements not yet configured. + //alert priority, if empty initialize to "" i.e. all priorities + if (portletConfig.getSimple(Constant.ALERT_PRIORITY) == null) { + portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, "")); + } + //result sort order, if empty initialize to "DESC" + if (portletConfig.getSimple(Constant.RESULT_SORT_ORDER) == null) { + portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); + } + //result count, if empty initialize to 5 + if (portletConfig.getSimple(Constant.RESULT_COUNT) == null) { + portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT)); + } + + //custom refresh + //CUSTOM_REFRESH + } + + public Canvas getHelpCanvas() { + return new HTMLFlow(MSG.view_portlet_help_recentAlerts()); + } + + public static final class Factory implements PortletViewFactory { + public static PortletViewFactory INSTANCE = new Factory(); + + public final Portlet getInstance(String locatorId) { + + return new GroupAlertsPortlet(locatorId); + } + } + + /** Fetches alerts and updates the DynamicForm instance with the latest + * alert information. + */ + private void getRecentAlerts() { + final int groupId = this.groupId; + currentlyLoading = false; + //fetches last five alerts for this resource + AlertCriteria criteria = new AlertCriteria(); + //filter priority + PropertySimple property = portletConfig.getSimple(Constant.ALERT_PRIORITY); + if (property != null) { + String currentSetting = property.getStringValue(); + String[] parsedValues = currentSetting.trim().split(","); + if (currentSetting.trim().isEmpty() || parsedValues.length == 3) { + //all alert priorities assumed + } else { + AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length]; + int indx = 0; + for (String priority : parsedValues) { + AlertPriority p = AlertPriority.valueOf(priority); + filterPriorities[indx++] = p; + } + criteria.addFilterPriorities(filterPriorities); + } + } + PageControl pc = new PageControl(); + //result sort order + property = portletConfig.getSimple(Constant.RESULT_SORT_ORDER); + if (property != null) { + String currentSetting = property.getStringValue(); + if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase(PageOrdering.DESC.name())) { + criteria.addSortCtime(PageOrdering.DESC); + pc.setPrimarySortOrder(PageOrdering.DESC); + } else { + criteria.addSortCtime(PageOrdering.ASC); + pc.setPrimarySortOrder(PageOrdering.ASC); + } + } + //result count + property = portletConfig.getSimple(Constant.RESULT_COUNT); + if (property != null) { + String currentSetting = property.getStringValue(); + if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase("5")) { + PageControl pageControl = new PageControl(0, 5); + pc.setPageSize(5); + } else { + PageControl pageControl = new PageControl(0, Integer.valueOf(currentSetting)); + pc.setPageSize(Integer.valueOf(currentSetting)); + } + } + criteria.setPageControl(pc); + criteria.addFilterResourceGroupIds(groupId); + alertService.findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() { + @Override + public void onSuccess(PageList<Alert> result) { + VLayout column = new VLayout(); + column.setHeight(10); + if (!result.isEmpty()) { + int rowNum = 0; + for (Alert alert : result) { + // alert history records do not have a usable locatorId, we'll use rownum, which is unique and + // may be repeatable. + LocatableDynamicForm row = new LocatableDynamicForm(recentAlertsContent.extendLocatorId(String + .valueOf(rowNum++))); + row.setNumCols(3); + + StaticTextItem iconItem = AbstractActivityView.newTextItemIcon(ImageManager.getAlertIcon(alert + .getAlertDefinition().getPriority()), alert.getAlertDefinition().getPriority() + .getDisplayName()); + LinkItem link = AbstractActivityView.newLinkItem(alert.getAlertDefinition().getName() + ": ", + ReportDecorator.GWT_GROUP_URL + groupId + "/Alerts/History/" + alert.getId()); + StaticTextItem time = AbstractActivityView.newTextItem(GwtRelativeDurationConverter + .format(alert.getCtime())); + row.setItems(iconItem, link, time); + + column.addMember(row); + } + //link to more details + LocatableDynamicForm row = new LocatableDynamicForm(recentAlertsContent.extendLocatorId(String + .valueOf(rowNum++))); + AbstractActivityView.addSeeMoreLink(row, ReportDecorator.GWT_GROUP_URL + groupId + + "/Alerts/History/", column); + } else { + LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow(recentAlertsContent + .extendLocatorId("None"), AbstractActivityView.RECENT_ALERTS_NONE); + column.addMember(row); + } + for (Canvas child : recentAlertsContent.getChildren()) { + child.destroy(); + } + recentAlertsContent.addChild(column); + recentAlertsContent.markForRedraw(); + } + + @Override + public void onFailure(Throwable caught) { + Log.debug("Error retrieving recent alerts for group [" + groupId + "]:" + caught.getMessage()); + } + }); + } + + protected void loadData() { + currentlyLoading = true; + getRecentAlerts(); + } + + @Override + public DynamicForm getCustomSettingsForm() { + LocatableDynamicForm custom = new LocatableDynamicForm(extendLocatorId("customSettings")); + LocatableVLayout page = new LocatableVLayout(custom.extendLocatorId("page")); + //build editor form container + final LocatableDynamicForm form = new LocatableDynamicForm(page.extendLocatorId("alert-filter")); + form.setMargin(5); + + //add label about what configuration affects + + //add alert priority selector + alertPrioritySelector = getAlertPriorityEditor(); + //add sort priority selector + resultSortSelector = getResulSortOrderEditor("sort.priority", "Sort Order", "Sets sort order for results."); + //add result count selector + //TODO: spinder 3/4/11 this is arbitrary. Get UXD input for better acceptable defaults + int[] countSelections = { 5, 10, 30, 100 }; + resultCountSelector = getResultCountEditor(Constant.RESULT_COUNT, "Results Count", + "Displays N results with alerts", countSelections); + + //add range selector + measurementRangeEditor = new MeasurementRangeEditor(page.extendLocatorId("alertTimeFrame")); + + form.setItems(alertPrioritySelector, resultSortSelector, resultCountSelector); + + //submit handler + custom.addSubmitValuesHandler(new SubmitValuesHandler() { + + @Override + public void onSubmitValues(SubmitValuesEvent event) { + //alert severity + String selectedValue = alertPrioritySelector.getValue().toString(); + if ((selectedValue.trim().isEmpty()) || (selectedValue.split(",").length == 3)) {//then no alertPriority specified + portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, "")); + } else {//some subset of available alertPriorities will be used + portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, selectedValue)); + } + //result sort order + selectedValue = resultSortSelector.getValue().toString(); + if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc + portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC)); + } else { + portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC)); + } + //result count + selectedValue = resultCountSelector.getValue().toString(); + if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT))) {//then 5 + portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT)); + } else { + portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue)); + } + + //alert time frame + Map selectedValue3 = measurementRangeEditor.getValues(); + String selectedValue2 = measurementRangeEditor.getValue("") + ""; + + //persist + storedPortlet.setConfiguration(portletConfig); + configure(portletWindow, storedPortlet); + loadData(); + } + }); + form.markForRedraw(); + page.addMember(measurementRangeEditor); + page.addMember(form); + custom.addChild(page); + return custom; + } + + /* single select combobox for number of items to display on the dashboard + * + * @param identifier Form identifier + * @param selectionTitle Title to left of combobox + * @param selectionHint Hint to display on mouseover + * @param selectionValues Integer[] to show as drop down options. + * @return Populated selectItem instance. + */ + private SelectItem getResultCountEditor(String identifier, String selectionTitle, String selectionHint, + int[] selectionValues) { + + final SelectItem maximumResultsComboBox = new SelectItem(identifier); + maximumResultsComboBox.setTitle(selectionTitle); + maximumResultsComboBox.setWrapTitle(false); + maximumResultsComboBox.setTooltip("<nobr><b> " + selectionHint + "</b></nobr>"); + //spinder 9/3/10: the following is required workaround to disable editability of combobox. + maximumResultsComboBox.setType("selection"); + //set width of dropdown display region + maximumResultsComboBox.setWidth(100); + + //define acceptable values for display amount + String[] displayValues = new String[selectionValues.length]; + int i = 0; + for (int selection : selectionValues) { + displayValues[i++] = String.valueOf(selection); + } + maximumResultsComboBox.setValueMap(displayValues); + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.RESULT_COUNT).getStringValue(); + if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT)) { + maximumResultsComboBox.setValue(Constant.RESULT_COUNT_DEFAULT); + } else { + maximumResultsComboBox.setValue(currentValue); + } + return maximumResultsComboBox; + } + + private SelectItem getAlertPriorityEditor() { + SelectItem priorityFilter = new SelectItem("severities", MSG.view_alerts_table_filter_priority()); + priorityFilter.setWrapTitle(false); + // priorityFilter.setWidth("*"); + priorityFilter.setWidth(200); + priorityFilter.setMultiple(true); + priorityFilter.setMultipleAppearance(MultipleAppearance.PICKLIST); + + LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(3); + priorities.put(AlertPriority.HIGH.name(), MSG.common_alert_high()); + priorities.put(AlertPriority.MEDIUM.name(), MSG.common_alert_medium()); + priorities.put(AlertPriority.LOW.name(), MSG.common_alert_low()); + LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(3); + priorityIcons.put(AlertPriority.HIGH.name(), ImageManager.getAlertIcon(AlertPriority.HIGH)); + priorityIcons.put(AlertPriority.MEDIUM.name(), ImageManager.getAlertIcon(AlertPriority.MEDIUM)); + priorityIcons.put(AlertPriority.LOW.name(), ImageManager.getAlertIcon(AlertPriority.LOW)); + priorityFilter.setValueMap(priorities); + priorityFilter.setValueIcons(priorityIcons); + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.ALERT_PRIORITY).getStringValue(); + if (currentValue.isEmpty() || currentValue.split(",").length == AlertPriority.values().length) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); + } else { + //spinder:3/4/11 doing this nonsense due to some weird smartgwt issue with SelectItem in VLayout. + if (currentValue.equalsIgnoreCase("HIGH")) { + priorityFilter.setValues(AlertPriority.HIGH.name()); + } else if (currentValue.equalsIgnoreCase("HIGH,MEDIUM")) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.MEDIUM.name()); + } else if (currentValue.equalsIgnoreCase("HIGH,LOW")) { + priorityFilter.setValues(AlertPriority.HIGH.name(), AlertPriority.LOW.name()); + } else if (currentValue.equalsIgnoreCase("MEDIUM")) { + priorityFilter.setValues(AlertPriority.MEDIUM.name()); + } else if (currentValue.equalsIgnoreCase("MEDIUM,LOW")) { + priorityFilter.setValues(AlertPriority.MEDIUM.name(), AlertPriority.LOW.name()); + } else { + priorityFilter.setValues(AlertPriority.LOW.name()); + } + } + return priorityFilter; + } + + private SelectItem getResulSortOrderEditor(String identifier, String selectionTitle, String selectionHint) { + SelectItem sortPrioritySelection = new SelectItem(identifier, selectionTitle); + sortPrioritySelection.setWrapTitle(false); + sortPrioritySelection.setTooltip(selectionHint); + LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(2); + priorities.put(PageOrdering.ASC.name(), "Ascending"); + priorities.put(PageOrdering.DESC.name(), "Descending"); + LinkedHashMap<String, String> priorityIcons = new LinkedHashMap<String, String>(2); + priorityIcons.put(PageOrdering.ASC.name(), "ascending"); + priorityIcons.put(PageOrdering.DESC.name(), "descending"); + + sortPrioritySelection.setValueMap(priorities); + sortPrioritySelection.setValueIcons(priorityIcons); + //TODO: spinder 3/4/11 not sure why this is necessary. [SKIN] not being interpreted. + String skinDir = "../org.rhq.enterprise.gui.coregui.CoreGUI/sc/skins/Enterprise/images"; + sortPrioritySelection.setImageURLPrefix(skinDir + "/actions/sort_"); + sortPrioritySelection.setImageURLSuffix(".png"); + + //reload current settings if they exist, otherwise enable all. + String currentValue = portletConfig.getSimple(Constant.RESULT_SORT_ORDER).getStringValue(); + if (currentValue.isEmpty() || currentValue.equalsIgnoreCase(PageOrdering.DESC.name())) {//default to descending order + sortPrioritySelection.setDefaultValue(PageOrdering.DESC.name()); + } else { + sortPrioritySelection.setDefaultValue(PageOrdering.ASC.name()); + } + return sortPrioritySelection; + } + + @Override + public void startRefreshCycle() { + //current setting + final int refreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval(); + + //cancel any existing timer + if (refreshTimer != null) { + refreshTimer.cancel(); + } + + if (refreshInterval >= MeasurementUtility.MINUTES) { + + refreshTimer = new Timer() { + public void run() { + if (!currentlyLoading) { + loadData(); + redraw(); + } + } + }; + + refreshTimer.scheduleRepeating(refreshInterval); + } + } + + @Override + protected void onDestroy() { + if (refreshTimer != null) { + + refreshTimer.cancel(); + } + super.onDestroy(); + } + + @Override + public void redraw() { + super.redraw(); + loadData(); + } + + @Override + public void propertyValueChanged(PropertyValueChangeEvent event) { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java index ccbe871..6db94eb 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java @@ -78,23 +78,23 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R protected LocatableCanvas recentBundleDeployContent = new LocatableCanvas(extendLocatorId("RecentBundleDeploy"));
//retrieve localized text - protected String RECENT_MEASUREMENTS = MSG.common_title_recent_measurements(); - protected String RECENT_MEASUREMENTS_NONE = MSG.view_resource_inventory_activity_no_recent_metrics(); - protected String RECENT_ALERTS = MSG.common_title_recent_alerts(); - protected String RECENT_ALERTS_NONE = MSG.view_resource_inventory_activity_no_recent_alerts(); - protected String RECENT_OOB = MSG.common_title_recent_oob_metrics(); - protected String RECENT_OOB_NONE = MSG.view_resource_inventory_activity_no_recent_oob(); - protected String RECENT_CONFIGURATIONS = MSG.common_title_recent_configuration_updates(); - protected String RECENT_CONFIGURATIONS_NONE = MSG.view_resource_inventory_activity_no_recent_config_history(); - protected String RECENT_OPERATIONS = MSG.common_title_recent_operations(); - protected String RECENT_OPERATIONS_NONE = MSG.view_resource_inventory_activity_no_recent_operations(); - protected String RECENT_EVENTS = MSG.common_title_recent_event_counts(); - protected String RECENT_EVENTS_NONE = MSG.view_resource_inventory_activity_no_recent_events(); - protected String RECENT_PKG_HISTORY = MSG.common_title_recent_pkg_history(); - protected String RECENT_PKG_HISTORY_NONE = MSG.view_resource_inventory_activity_no_recent_pkg_history(); - protected String RECENT_BUNDLE_DEPLOY = MSG.common_title_recent_bundle_deployments(); - protected String RECENT_BUNDLE_DEPLOY_NONE = MSG.view_resource_inventory_activity_no_recent_bundle_deploy(); - protected String SEE_MORE = MSG.common_msg_see_more(); + public static String RECENT_MEASUREMENTS = MSG.common_title_recent_measurements(); + public static String RECENT_MEASUREMENTS_NONE = MSG.view_resource_inventory_activity_no_recent_metrics(); + public static String RECENT_ALERTS = MSG.common_title_recent_alerts(); + public static String RECENT_ALERTS_NONE = MSG.view_resource_inventory_activity_no_recent_alerts(); + public static String RECENT_OOB = MSG.common_title_recent_oob_metrics(); + public static String RECENT_OOB_NONE = MSG.view_resource_inventory_activity_no_recent_oob(); + public static String RECENT_CONFIGURATIONS = MSG.common_title_recent_configuration_updates(); + public static String RECENT_CONFIGURATIONS_NONE = MSG.view_resource_inventory_activity_no_recent_config_history(); + public static String RECENT_OPERATIONS = MSG.common_title_recent_operations(); + public static String RECENT_OPERATIONS_NONE = MSG.view_resource_inventory_activity_no_recent_operations(); + public static String RECENT_EVENTS = MSG.common_title_recent_event_counts(); + public static String RECENT_EVENTS_NONE = MSG.view_resource_inventory_activity_no_recent_events(); + public static String RECENT_PKG_HISTORY = MSG.common_title_recent_pkg_history(); + public static String RECENT_PKG_HISTORY_NONE = MSG.view_resource_inventory_activity_no_recent_pkg_history(); + public static String RECENT_BUNDLE_DEPLOY = MSG.common_title_recent_bundle_deployments(); + public static String RECENT_BUNDLE_DEPLOY_NONE = MSG.view_resource_inventory_activity_no_recent_bundle_deploy(); + public static String SEE_MORE = MSG.common_msg_see_more();
private ResourceGroupComposite groupComposite = null; private ResourceComposite resourceComposite = null; @@ -393,7 +393,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R * @param emptyMessage Contents of the empty region * @return */ - public LocatableDynamicForm createEmptyDisplayRow(String locatorId, String emptyMessage) { + public static LocatableDynamicForm createEmptyDisplayRow(String locatorId, String emptyMessage) { LocatableDynamicForm row = null; row = new LocatableDynamicForm(locatorId);
@@ -406,7 +406,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R return row; }
- public StaticTextItem newTextItemIcon(String imageSrc, String mouseOver) { + public static StaticTextItem newTextItemIcon(String imageSrc, String mouseOver) { StaticTextItem iconItem = new StaticTextItem(); FormItemIcon img = new FormItemIcon(); img.setSrc(imageSrc); @@ -420,7 +420,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R return iconItem; }
- public LinkItem newLinkItem(String title, String destination) { + public static LinkItem newLinkItem(String title, String destination) { LinkItem link = new LinkItem(); link.setLinkTitle(title); link.setTitle(title); @@ -430,7 +430,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R return link; }
- public StaticTextItem newTextItem(String contents) { + public static StaticTextItem newTextItem(String contents) { StaticTextItem item = new StaticTextItem(); item.setDefaultValue(contents); item.setShowTitle(false); @@ -445,7 +445,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R * @param linkDestination * @param column */ - protected void addSeeMoreLink(LocatableDynamicForm form, String linkDestination, VLayout column) { + public static void addSeeMoreLink(LocatableDynamicForm form, String linkDestination, VLayout column) { if ((form != null) && (column != null)) { form.setNumCols(1); LinkItem link = newLinkItem(SEE_MORE, linkDestination); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java index 15945c6..efcd6d7 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java @@ -219,7 +219,6 @@ public class ResourceGroupTreeView extends LocatableVLayout implements Bookmarka selectedNode = treeGrid.getTree().findById(String.valueOf(this.selectedGroup.getId())); }
- // TODO reselect tree to selected node if (selectedNode != null) { TreeNode[] parents = treeGrid.getTree().getParents(selectedNode); treeGrid.getTree().openFolders(parents); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/summary/ActivityView2.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/summary/ActivityView2.java index 121193f..d819d8b 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/summary/ActivityView2.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/summary/ActivityView2.java @@ -45,6 +45,7 @@ import org.rhq.enterprise.gui.coregui.client.PermissionsLoader; import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.dashboard.DashboardContainer; import org.rhq.enterprise.gui.coregui.client.dashboard.DashboardView; +import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet; import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.util.MessagePortlet; import org.rhq.enterprise.gui.coregui.client.gwt.DashboardGWTServiceAsync; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; @@ -55,6 +56,7 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; /** * The content pane for the group Summary>Dashboard subtab. * + * @author Simeon Pinder * @author Jay Shaughnessy */
@@ -125,7 +127,9 @@ public class ActivityView2 extends LocatableVLayout implements DashboardContaine Canvas[] members = getMembers(); removeMembers(members);
- dashboardView = new DashboardView(extendLocatorId(dashboard.getName()), this, dashboard); + //pass in the group information + dashboardView = new DashboardView(extendLocatorId(dashboard.getName()), this, dashboard, this.groupComposite + .getResourceGroup(), null); addMember(dashboardView);
footer = new LocatableToolStrip(extendLocatorId("Footer")); @@ -185,9 +189,13 @@ public class ActivityView2 extends LocatableVLayout implements DashboardContaine dashboard.getConfiguration().put(new PropertySimple(Dashboard.CFG_BACKGROUND, "#F1F2F3"));
// Left Column - DashboardPortlet dummyLeft = new DashboardPortlet(MessagePortlet.NAME, MessagePortlet.KEY, 220); - dummyLeft.getConfiguration().put(new PropertySimple("message", "<br/>Coming Soon... :-)")); - dashboard.addPortlet(dummyLeft, 0, 0); + // DashboardPortlet dummyLeft = new DashboardPortlet(MessagePortlet.NAME, MessagePortlet.KEY, 220); + // dummyLeft.getConfiguration().put(new PropertySimple("message", "<br/>Coming Soon... :-)")); + // dashboard.addPortlet(dummyLeft, 0, 0); + + DashboardPortlet groupAlerts = new DashboardPortlet(GroupAlertsPortlet.NAME, GroupAlertsPortlet.KEY, 220); + // groupAlerts.getConfiguration().put(new PropertySimple("message", "<br/>Coming Soon... :-)")); + dashboard.addPortlet(groupAlerts, 0, 0);
// right Column DashboardPortlet dummyRight = new DashboardPortlet(MessagePortlet.NAME, MessagePortlet.KEY, 220);
rhq-commits@lists.fedorahosted.org