modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java | 149 +++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java | 46 ---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertDataSource.java | 48 ---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertView.java | 31 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/ReportTopView.java | 5
5 files changed, 150 insertions(+), 129 deletions(-)
New commits:
commit 64ca778dd2c1f00130de10d72504dd1a30bc5083
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 24 17:23:30 2010 -0500
get subsystem alerts to show
get alert history view to be more purdy
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index 801c06f..7c20be5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.gui.coregui.client.alert;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -29,10 +31,14 @@ import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.Record;
-import com.smartgwt.client.data.fields.DataSourceDateField;
-import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.rpc.RPCResponse;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.AutoFitWidthApproach;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
+import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import org.rhq.core.domain.alert.Alert;
@@ -44,6 +50,8 @@ import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
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.util.MeasurementConverterClient;
@@ -52,12 +60,17 @@ import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
/**
* @author Ian Springer
* @author Joseph Marques
+ * @author John Mazzitelli
*/
public class AlertDataSource extends RPCDataSource<Alert> {
private AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService();
private EntityContext entityContext;
+ private static final String PRIORITY_ICON_HIGH = "/images/icons/Flag_red_16.png";
+ private static final String PRIORITY_ICON_MEDIUM = "/images/icons/Flag_yellow_16.png";
+ private static final String PRIORITY_ICON_LOW = "/images/icons/Flag_blue_16.png";
+
public AlertDataSource() {
this(EntityContext.forSubsystemView());
}
@@ -66,47 +79,95 @@ public class AlertDataSource extends RPCDataSource<Alert> {
super();
this.entityContext = context;
- // TODO: when these fields are added, AlertHistoryView breaks -- why?
-
- //List<DataSourceField> fields = addDataSourceFields();
- //addFields(fields);
+ addDataSourceFields();
}
@Override
protected List<DataSourceField> addDataSourceFields() {
+ // for some reason, the client seems to crash if you don't specify any data source fields
+ // even though we know we defined override ListGridFields for all columns. Define at least one field here.
List<DataSourceField> fields = super.addDataSourceFields();
+ fields.add(new DataSourceTextField("name", MSG.common_title_name()));
+ return fields;
+ }
- DataSourceDateField ctimeField = new DataSourceDateField(AlertCriteria.SORT_FIELD_CTIME, MSG
- .view_alerts_field_created_time());
- addField(ctimeField);
-
- DataSourceIntegerField ackTimeField = new DataSourceIntegerField("acknowledgeTime", MSG
- .view_alerts_field_ack_time());
- addField(ackTimeField);
-
- DataSourceTextField ackSubjectField = new DataSourceTextField("acknowledgingSubject", MSG
- .view_alerts_field_ack_subject());
- addField(ackSubjectField);
-
- DataSourceTextField nameField = new DataSourceTextField(AlertCriteria.SORT_FIELD_NAME, MSG
- .view_alerts_field_name());
- addField(nameField);
-
- DataSourceTextField conditionTextField = new DataSourceTextField("conditionText", MSG
- .view_alerts_field_condition_text());
- addField(conditionTextField);
-
- DataSourceTextField conditionValueField = new DataSourceTextField("conditionValue", MSG
- .view_alerts_field_condition_value());
- addField(conditionValueField);
-
- DataSourceTextField resourceNameField = new DataSourceTextField("resourceName", MSG
- .view_alerts_field_resource());
- addField(resourceNameField);
+ /**
+ * The view that contains the list grid which will display this datasource's data will call this
+ * method to get the field information which is used to control the display of the data.
+ *
+ * @return list grid fields used to display the datasource data
+ */
+ public ArrayList<ListGridField> getListGridFields() {
+ ArrayList<ListGridField> fields = new ArrayList<ListGridField>(6);
- DataSourceTextField priorityField = new DataSourceTextField(AlertCriteria.SORT_FIELD_PRIORITY, MSG
- .view_alerts_field_priority(), 15);
- addField(priorityField);
+ ListGridField ctimeField = new ListGridField(AlertCriteria.SORT_FIELD_CTIME, MSG
+ .view_alerts_field_created_time());
+ ctimeField.setAutoFitWidth(true);
+ ctimeField.setAutoFitWidthApproach(AutoFitWidthApproach.TITLE);
+ ctimeField.setCellFormatter(new TimestampCellFormatter());
+ fields.add(ctimeField);
+
+ ListGridField nameField = new ListGridField("name", MSG.view_alerts_field_name());
+ nameField.setWidth("30%");
+ fields.add(nameField);
+
+ ListGridField conditionField = new ListGridField("conditionText", MSG.view_alerts_field_condition_text());
+ conditionField.setWidth("*");
+ fields.add(conditionField);
+
+ ListGridField priorityField = new ListGridField("priority", MSG.view_alerts_field_priority());
+ priorityField.setType(ListGridFieldType.IMAGE);
+ priorityField.setAutoFitWidth(true);
+ priorityField.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
+ priorityField.setAlign(Alignment.CENTER);
+ priorityField.setShowHover(true);
+ priorityField.setHoverCustomizer(new HoverCustomizer() {
+ @Override
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String prio = record.getAttribute("priority");
+ if (PRIORITY_ICON_HIGH.equals(prio)) {
+ return MSG.common_alert_high();
+ } else if (PRIORITY_ICON_MEDIUM.equals(prio)) {
+ return MSG.common_alert_medium();
+ } else if (PRIORITY_ICON_LOW.equals(prio)) {
+ return MSG.common_alert_low();
+ } else {
+ return ""; // will never get here
+ }
+ }
+ });
+ fields.add(priorityField);
+
+ ListGridField statusField = new ListGridField("status", MSG.common_title_status());
+ priorityField.setAutoFitWidth(true);
+ priorityField.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
+ statusField.setCellFormatter(new CellFormatter() {
+ public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
+ String ackTime = listGridRecord.getAttribute("acknowledgeTime");
+ String ackSubject = listGridRecord.getAttribute("acknowledgingSubject");
+ if (ackSubject == null) {
+ return MSG.view_alerts_field_ack_status_empty();
+ } else {
+ String formattedTime = TimestampCellFormatter.DATE_TIME_FORMAT.format(new Date(Long
+ .parseLong(ackTime)));
+ return MSG.view_alerts_field_ack_status_filled(ackSubject, formattedTime);
+ }
+ }
+ });
+ fields.add(statusField);
+
+ if (this.entityContext.type != EntityContext.Type.Resource) {
+ // TODO need to disambiguate this
+ ListGridField resourceNameField = new ListGridField("resourceName", MSG.view_alerts_field_resource());
+ resourceNameField.setWidth("30%");
+ resourceNameField.setCellFormatter(new CellFormatter() {
+ public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
+ Integer resourceId = listGridRecord.getAttributeAsInt("resourceId");
+ return "<a href=\"" + LinkManager.getResourceLink(resourceId) + "\">" + o + "</a>";
+ }
+ });
+ fields.add(resourceNameField);
+ }
return fields;
}
@@ -149,6 +210,7 @@ public class AlertDataSource extends RPCDataSource<Alert> {
criteria.addFilterPriorities(getArrayFilter(request, "severities", AlertPriority.class));
criteria.addFilterEntityContext(entityContext);
+ criteria.fetchConditionLogs(true);
return criteria;
}
@@ -173,7 +235,20 @@ public class AlertDataSource extends RPCDataSource<Alert> {
record.setAttribute("resourceId", from.getAlertDefinition().getResource().getId());
record.setAttribute("resourceName", from.getAlertDefinition().getResource().getName());
record.setAttribute("name", from.getAlertDefinition().getName());
- record.setAttribute("priority", from.getAlertDefinition().getPriority().name());
+ switch (from.getAlertDefinition().getPriority()) {
+ case HIGH: {
+ record.setAttribute("priority", PRIORITY_ICON_HIGH);
+ break;
+ }
+ case MEDIUM: {
+ record.setAttribute("priority", PRIORITY_ICON_MEDIUM);
+ break;
+ }
+ case LOW: {
+ record.setAttribute("priority", PRIORITY_ICON_LOW);
+ break;
+ }
+ }
Set<AlertConditionLog> conditionLogs = from.getConditionLogs();
String conditionText;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
index ebd85d8..afa4cdc 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
@@ -20,7 +20,6 @@
package org.rhq.enterprise.gui.coregui.client.alert;
import java.util.Arrays;
-import java.util.Date;
import java.util.LinkedHashMap;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -29,7 +28,6 @@ import com.smartgwt.client.types.MultipleAppearance;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -37,11 +35,9 @@ import org.rhq.core.domain.alert.AlertPriority;
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
-import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
@@ -57,9 +53,10 @@ import org.rhq.enterprise.gui.coregui.client.util.message.Message;
* @author Joseph Marques
* @author Ian Springer
* @author Heiko W. Rupp
+ * @author John Mazzitelli
*/
public class AlertHistoryView extends TableSection {
- // TODO: Create a subclass for the subsystem view.
+
public static final ViewName SUBSYSTEM_VIEW_ID = new ViewName("RecentAlerts", MSG.common_title_recent_alerts());
private static SortSpecifier DEFAULT_SORT_SPECIFIER = new SortSpecifier(AlertCriteria.SORT_FIELD_CTIME,
@@ -103,45 +100,8 @@ public class AlertHistoryView extends TableSection {
@Override
protected void configureTable() {
- ListGridField ctimeField = new ListGridField("ctime", MSG.view_alerts_field_created_time(), 100);
- ctimeField.setCellFormatter(new TimestampCellFormatter());
-
- ListGridField nameField = new ListGridField("name", MSG.view_alerts_field_name(), 100);
- ListGridField conditionTextField = new ListGridField("conditionText", MSG.view_alerts_field_condition_text());
- ListGridField priorityField = new ListGridField("priority", MSG.view_alerts_field_priority(), 50);
-
- ListGridField statusField = new ListGridField("status", MSG.common_title_status(), 175);
- statusField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
- String ackTime = listGridRecord.getAttribute("acknowledgeTime");
- String ackSubject = listGridRecord.getAttribute("acknowledgingSubject");
- if (ackSubject == null) {
- return MSG.view_alerts_field_ack_status_empty();
- } else {
- String formattedTime = TimestampCellFormatter.DATE_TIME_FORMAT.format(new Date(Long
- .parseLong(ackTime)));
- return MSG.view_alerts_field_ack_status_filled(ackSubject, formattedTime);
- }
- }
- });
-
- ListGridField resourceNameField = new ListGridField("resourceName", MSG.view_alerts_field_resource(), 125);
- resourceNameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
- Integer resourceId = listGridRecord.getAttributeAsInt("resourceId");
- return "<a href=\"" + LinkManager.getResourceLink(resourceId) + "\">" + o + "</a>";
- }
- });
-
- if (context.type == EntityContext.Type.Resource) {
- getListGrid().setFields(ctimeField, nameField, conditionTextField, priorityField, statusField);
- } else {
- getListGrid().setFields(ctimeField, nameField, conditionTextField, priorityField, statusField,
- resourceNameField);
- }
-
+ getListGrid().setFields(((AlertDataSource) getDataSource()).getListGridFields().toArray(new ListGridField[0]));
setupTableInteractions();
-
}
private void setupTableInteractions() {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertDataSource.java
deleted file mode 100644
index 867f0ed..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertDataSource.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 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, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * 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 and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.alert;
-
-import com.smartgwt.client.data.DataSourceField;
-import com.smartgwt.client.data.fields.DataSourceIntegerField;
-
-import org.rhq.core.domain.criteria.AlertCriteria;
-
-/**
- * @author Ian Springer
- */
-public class SubsystemResourceAlertDataSource extends AlertDataSource {
- @Override
- protected void onInit() {
- super.onInit();
-
- DataSourceField[] fields = getFields();
- DataSourceField[] updatedFields = new DataSourceField[fields.length + 1];
-
- // TODO: Replace 'Resource Id' column with 'Resource Name' and 'Resource Lineage' columns.
- DataSourceField resourceIdField = new DataSourceIntegerField(AlertCriteria.SORT_FIELD_RESOURCE_ID, MSG
- .common_title_resource_id());
- updatedFields[0] = resourceIdField;
-
- System.arraycopy(fields, 0, updatedFields, 1, fields.length);
- }
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertView.java
new file mode 100644
index 0000000..98ccda9
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/SubsystemResourceAlertView.java
@@ -0,0 +1,31 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.alert;
+
+import org.rhq.core.domain.common.EntityContext;
+
+public class SubsystemResourceAlertView extends AlertHistoryView {
+ public SubsystemResourceAlertView(String locatorId, boolean hasWriteAccess) {
+ super(locatorId, MSG.common_title_recent_alerts(), EntityContext.forSubsystemView(), hasWriteAccess);
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/ReportTopView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/ReportTopView.java
index 1783a71..eab6d06 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/ReportTopView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/ReportTopView.java
@@ -32,6 +32,7 @@ import com.smartgwt.client.widgets.layout.VLayout;
import org.rhq.enterprise.gui.coregui.client.admin.AdministrationView;
import org.rhq.enterprise.gui.coregui.client.admin.templates.ResourceTypeTreeView;
import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
+import org.rhq.enterprise.gui.coregui.client.alert.SubsystemResourceAlertView;
import org.rhq.enterprise.gui.coregui.client.components.FullHTMLPane;
import org.rhq.enterprise.gui.coregui.client.components.TitleBar;
import org.rhq.enterprise.gui.coregui.client.components.view.AbstractSectionedLeftNavigationView;
@@ -123,7 +124,9 @@ public class ReportTopView extends AbstractSectionedLeftNavigationView {
NavigationItem recentAlertsItem = new NavigationItem(AlertHistoryView.SUBSYSTEM_VIEW_ID,
"subsystems/alert/Alert_LOW_16.png", new ViewFactory() {
public Canvas createView() {
- return new AlertHistoryView(extendLocatorId(AlertHistoryView.SUBSYSTEM_VIEW_ID.getName()));
+ // TODO: how do we know if the user is able to ack the alerts? right now, I hardcode false to not allow it
+ return new SubsystemResourceAlertView(
+ extendLocatorId(AlertHistoryView.SUBSYSTEM_VIEW_ID.getName()), false);
}
});