modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/graph/ButtonBarDateTimeRangeEditor.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/DashboardLinkUtility.java
| 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/AddToDashboardComponent.java
| 269 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsTableView.java
| 36 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsViewDataSource.java
| 2
5 files changed, 291 insertions(+), 30 deletions(-)
New commits:
commit b464215123d251133599eedd080e56723eb65b80
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Wed Jul 24 15:18:13 2013 -0700
Consolidated Metrics - Add to Dashboard - change to new AddToDashboardComponent.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/graph/ButtonBarDateTimeRangeEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/graph/ButtonBarDateTimeRangeEditor.java
index 2075783..b4f1354 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/graph/ButtonBarDateTimeRangeEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/graph/ButtonBarDateTimeRangeEditor.java
@@ -77,7 +77,7 @@ public class ButtonBarDateTimeRangeEditor extends EnhancedVLayout {
prefs = measurementUserPreferences.getMetricRangePreferences();
Log.debug("ButtonBarDateTimeRangeEditor initialized with start Date: "
+ new Date(prefs.begin) + " end Date: "
+ new Date(prefs.end));
- createButtons();
+ //createButtons();
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/DashboardLinkUtility.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/DashboardLinkUtility.java
index 779f877..8ca1ac5 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/DashboardLinkUtility.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/DashboardLinkUtility.java
@@ -143,7 +143,7 @@ public class DashboardLinkUtility {
});
- }//end dashboard iteration
+ }
//add new menu item for adding current graphable element to
view if on Monitor/Graphs tab
String currentViewPath = History.getToken();
@@ -183,20 +183,20 @@ public class DashboardLinkUtility {
addNewMetric(String.valueOf(resource.getId()),
selectedView,
resourceGraphElements);
} else {
- Log.trace("Error
obtaining subject with id:" + sid);
+
Log.warn("DashboardLinkUtility: Error obtaining subject with id:" + sid);
}
}
public void onFailure(Throwable
caught) {
- Log.trace("Error obtaining
subject with id:" + sid, caught);
+
Log.warn("DashboardLinkUtility: Error obtaining subject with id:" + sid,
caught);
}
});
}
}
});
- } // end add the "add to view" menu item
- }//end trait exclusion
- }//end measurement def iteration
+ }
+ }
+ }
}
});
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/AddToDashboardComponent.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/AddToDashboardComponent.java
new file mode 100644
index 0000000..84e20eb
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/AddToDashboardComponent.java
@@ -0,0 +1,269 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 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.inventory.resource.detail.monitoring.table;
+
+import java.util.LinkedHashMap;
+
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.user.client.History;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.events.ClickEvent;
+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.grid.ListGridRecord;
+import com.smartgwt.client.widgets.menu.events.ClickHandler;
+import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
+import com.smartgwt.client.widgets.toolbar.ToolStrip;
+
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.criteria.DashboardCriteria;
+import org.rhq.core.domain.dashboard.Dashboard;
+import org.rhq.core.domain.dashboard.DashboardPortlet;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.measurement.MeasurementSchedule;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.graph.ResourceD3GraphPortlet;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.Log;
+import org.rhq.enterprise.gui.coregui.client.util.enhanced.Enhanced;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+
+/**
+ * @author Mike Thompson
+ */
+public class AddToDashboardComponent extends ToolStrip implements Enhanced {
+ final private Resource resource;
+ private SelectItem dashboardSelectItem;
+ private Dashboard selectedDashboard;
+ private IButton addToDashboardButton;
+ private LinkedHashMap<String, String> dashboardMenuMap;
+ private LinkedHashMap<Integer, Dashboard> dashboardMap;
+ private MetricsTableView.MetricsTableListGrid metricsListGrid;
+
+ public AddToDashboardComponent(Resource resource) {
+ this.resource = resource;
+ setPadding(5);
+ setMembersMargin(15);
+ setWidth(400);
+ dashboardMenuMap = new LinkedHashMap<String, String>();
+ dashboardMap = new LinkedHashMap<Integer, Dashboard>();
+ }
+
+ @Override
+ protected void onDraw() {
+ super.onDraw();
+ removeMembers(getMembers());
+ createToolstrip();
+ }
+
+ private void createToolstrip() {
+ addSpacer(15);
+ dashboardSelectItem = new SelectItem();
+ addToDashboardButton = new IButton(MSG.view_metric_addToDashboard());
+
+ dashboardSelectItem = new SelectItem();
+ dashboardSelectItem.setTitle("Dashboards");
+ dashboardSelectItem.setWidth(350);
+ dashboardSelectItem.setPickListWidth(250);
+ populateDashboardMenu();
+ addFormItem(dashboardSelectItem);
+ addMember(addToDashboardButton);
+
+ dashboardSelectItem.addChangeHandler(new ChangeHandler() {
+ @Override
+ public void onChange(ChangeEvent changeEvent) {
+ Integer selectedDashboardId = Integer.valueOf((String)
changeEvent.getValue());
+ selectedDashboard = dashboardMap.get(selectedDashboardId);
+ }
+ });
+ addToDashboardButton.addClickHandler(new
com.smartgwt.client.widgets.events.ClickHandler() {
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ ListGridRecord[] selectedRecords = metricsListGrid.getSelectedRecords();
+ for (ListGridRecord selectedRecord : selectedRecords) {
+ for (MeasurementDefinition measurementDefinition :
resource.getResourceType().getMetricDefinitions()) {
+ if(measurementDefinition.getId() ==
selectedRecord.getAttributeAsInt(MetricsViewDataSource.FIELD_METRIC_DEF_ID)){
+ Log.debug("**Add to Dashboard -- Storing:
"+measurementDefinition.getDisplayName() +" in "+
selectedDashboard.getName());
+
storeDashboardMetric(selectedDashboard,resource,measurementDefinition);
+ break;
+ }
+ }
+ }
+ }
+ });
+ }
+
+ public void populateDashboardMenu() {
+ dashboardMenuMap.clear();
+ dashboardMap.clear();
+
+ DashboardCriteria criteria = new DashboardCriteria();
+ GWTServiceLookup.getDashboardService().findDashboardsByCriteria(criteria,
+ new AsyncCallback<PageList<Dashboard>>() {
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_tree_common_contextMenu_loadFailed_dashboard(),
+ caught);
+ }
+
+ public void onSuccess(PageList<Dashboard> dashboards) {
+ for (final Dashboard dashboard : dashboards) {
+ dashboardMenuMap.put(String.valueOf(dashboard.getId()),
+
MSG.view_tree_common_contextMenu_addChartToDashboard(dashboard.getName()));
+ dashboardMap.put(dashboard.getId(), dashboard);
+ dashboardSelectItem.setValueMap(dashboardMenuMap);
+ }
+ }
+ });
+ }
+
+ /**
+ * The metrics list grid is not available on object creation so we must attach later
after it has been initialized.
+ * @param metricsListGrid
+ */
+ public void setMetricsListGrid(MetricsTableView.MetricsTableListGrid metricsListGrid)
{
+ this.metricsListGrid = metricsListGrid;
+ }
+
+ /** Locate the specific schedule definition using the definition identifier.
+ */
+ private static int getScheduleDefinitionId(Resource resource, int definitionId) {
+ int id = -1;
+ if (resource.getSchedules() != null) {
+ boolean located = false;
+ MeasurementSchedule[] schedules = new
MeasurementSchedule[resource.getSchedules().size()];
+ resource.getSchedules().toArray(schedules);
+ for (int i = 0; (!located && i < resource.getSchedules().size());
i++) {
+ MeasurementSchedule schedule = schedules[i];
+ MeasurementDefinition definition = schedule.getDefinition();
+ if ((definition != null) && definition.getId() == definitionId)
{
+ located = true;
+ id = schedule.getId();
+ }
+ }
+ }
+ return id;
+ }
+
+ private void storeDashboardMetric(Dashboard dashboard, Resource resource,
MeasurementDefinition definition) {
+ DashboardPortlet dashboardPortlet = new
DashboardPortlet(MSG.view_tree_common_contextMenu_resourceGraph(),
+ ResourceD3GraphPortlet.KEY, 250);
+ dashboardPortlet.getConfiguration().put(
+ new PropertySimple(ResourceD3GraphPortlet.CFG_RESOURCE_ID,
resource.getId()));
+ dashboardPortlet.getConfiguration().put(
+ new PropertySimple(ResourceD3GraphPortlet.CFG_DEFINITION_ID,
definition.getId()));
+
+ dashboard.addPortlet(dashboardPortlet);
+
+ GWTServiceLookup.getDashboardService().storeDashboard(dashboard, new
AsyncCallback<Dashboard>() {
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_tree_common_contextMenu_saveChartToDashboardFailure(),
+ caught);
+ }
+
+ public void onSuccess(Dashboard result) {
+ CoreGUI.getMessageCenter().notify(
+ new
Message(MSG.view_tree_common_contextMenu_saveChartToDashboardSuccessful(result.getName()),
+ Message.Severity.Info));
+ }
+ });
+ }
+
+ private static void addNewMetric(String id, String selectedView, String
resourceGraphElements) {
+ //construct portal.war url to access
+ String baseUrl =
"/resource/common/monitor/visibility/IndicatorCharts.do";
+ baseUrl += "?id=" + id;
+ baseUrl += "&view=" + selectedView;
+ baseUrl += "&action=addChart&metric=" + resourceGraphElements;
+ final String url = baseUrl;
+ //initiate HTTP request
+ final RequestBuilder b = new RequestBuilder(RequestBuilder.GET, baseUrl);
+
+ try {
+ b.setCallback(new RequestCallback() {
+ public void onResponseReceived(final Request request, final Response
response) {
+ Log.trace("Successfully submitted request to add graph to
view:" + url);
+
+ //kick off a page reload.
+ String currentViewPath = History.getToken();
+ CoreGUI.goToView(currentViewPath, true);
+ }
+
+ @Override
+ public void onError(Request request, Throwable t) {
+ Log.warn("Error adding Metric:" + url, t);
+ }
+ });
+ b.send();
+ } catch (RequestException e) {
+ Log.warn("Error adding Metric:" + url, e);
+ }
+
+ }
+
+ private static class AddToDashboardClickHandler implements ClickHandler {
+
+ private final Resource resource;
+ private final MeasurementDefinition definition;
+ private final Dashboard dashboard;
+
+ public AddToDashboardClickHandler(Resource resource, MeasurementDefinition
definition, Dashboard dashboard) {
+ this.resource = resource;
+ this.definition = definition;
+ this.dashboard = dashboard;
+ }
+
+ public void onClick(MenuItemClickEvent menuItemClickEvent) {
+ DashboardPortlet dashboardPortlet = new
DashboardPortlet(MSG.view_tree_common_contextMenu_resourceGraph(),
+ ResourceD3GraphPortlet.KEY, 250);
+ dashboardPortlet.getConfiguration().put(
+ new PropertySimple(ResourceD3GraphPortlet.CFG_RESOURCE_ID,
resource.getId()));
+ dashboardPortlet.getConfiguration().put(
+ new PropertySimple(ResourceD3GraphPortlet.CFG_DEFINITION_ID,
definition.getId()));
+
+ dashboard.addPortlet(dashboardPortlet);
+
+ GWTServiceLookup.getDashboardService().storeDashboard(dashboard, new
AsyncCallback<Dashboard>() {
+
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_tree_common_contextMenu_saveChartToDashboardFailure(),
caught);
+ }
+
+ public void onSuccess(Dashboard result) {
+ CoreGUI.getMessageCenter().notify(
+ new
Message(MSG.view_tree_common_contextMenu_saveChartToDashboardSuccessful(result.getName()),
+ Message.Severity.Info));
+ }
+ });
+
+ }
+
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsTableView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsTableView.java
index 010e06f..a4b15d1 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsTableView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsTableView.java
@@ -49,7 +49,6 @@ import com.smartgwt.client.widgets.grid.events.RecordExpandHandler;
import com.smartgwt.client.widgets.grid.events.SortChangedHandler;
import com.smartgwt.client.widgets.grid.events.SortEvent;
import com.smartgwt.client.widgets.layout.VLayout;
-import com.smartgwt.client.widgets.menu.Menu;
import org.rhq.core.domain.measurement.MeasurementData;
import org.rhq.core.domain.measurement.MeasurementDefinition;
@@ -65,7 +64,6 @@ import
org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractD3GraphLis
import org.rhq.enterprise.gui.coregui.client.inventory.common.graph.MetricGraphData;
import org.rhq.enterprise.gui.coregui.client.inventory.common.graph.RedrawGraphs;
import
org.rhq.enterprise.gui.coregui.client.inventory.common.graph.graphtype.StackedBarMetricGraphImpl;
-import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.DashboardLinkUtility;
import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.MetricD3Graph;
import org.rhq.enterprise.gui.coregui.client.util.BrowserUtility;
import org.rhq.enterprise.gui.coregui.client.util.Log;
@@ -84,7 +82,8 @@ public class MetricsTableView extends Table<MetricsViewDataSource>
implements Re
private final AbstractD3GraphListView abstractD3GraphListView;
private final MeasurementUserPreferences measurementUserPrefs;
- private final Menu addToDashboardMenu;
+ private final AddToDashboardComponent addToDashboardComponent;
+ private MetricsTableListGrid metricsTableListGrid;
Set<Integer> expandedRows = new HashSet<Integer>();
@@ -92,12 +91,9 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
super();
this.resource = resource;
this.abstractD3GraphListView = abstractD3GraphListView;
- setDataSource(new MetricsViewDataSource(resource));
- addToDashboardMenu = new Menu();
- addToDashboardMenu.setWidth(200);
-
addToDashboardMenu.setItems(DashboardLinkUtility.buildMetricsMenu(resource.getResourceType(),
resource,
- MSG.view_metric_addToDashboard()));
measurementUserPrefs = new
MeasurementUserPreferences(UserSessionManager.getUserPreferences());
+ setDataSource(new MetricsViewDataSource(resource));
+ addToDashboardComponent = new AddToDashboardComponent(resource);
}
/**
@@ -108,7 +104,9 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
*/
@Override
protected ListGrid createListGrid() {
- return new MetricsTableListGrid(this, resource, addToDashboardMenu);
+ metricsTableListGrid = new MetricsTableListGrid(this, resource);
+ addToDashboardComponent.setMetricsListGrid(metricsTableListGrid);
+ return metricsTableListGrid;
}
protected void configureTable() {
@@ -116,8 +114,7 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
setListGridFields(fields.toArray(new ListGridField[0]));
addTableAction(MSG.view_measureTable_getLive(), new
ShowLiveDataTableAction(this));
- //addExtraWidget(addToDashboardMenu, false);
-
+ addExtraWidget(addToDashboardComponent, false);
}
private static class ShowLiveDataTableAction implements TableAction {
@@ -251,20 +248,16 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
}
- private class MetricsTableListGrid extends ListGrid {
+ public class MetricsTableListGrid extends ListGrid {
private static final int TREEVIEW_DETAIL_CHART_HEIGHT = 205;
private static final int NUM_METRIC_POINTS = 60;
private Resource resource;
- final private Menu addToDashboardMenu;
final MetricsTableView metricsTableView;
- public MetricsTableListGrid(final MetricsTableView metricsTableView, final
Resource resource,
- final Menu dashboardMenu) {
+ public MetricsTableListGrid(final MetricsTableView metricsTableView, final
Resource resource) {
super();
this.resource = resource;
- this.addToDashboardMenu = dashboardMenu;
- this.addToDashboardMenu.disable();
this.metricsTableView = metricsTableView;
setCanExpandRecords(true);
setCanExpandMultipleRecords(true);
@@ -299,8 +292,9 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
int startRow = dataArrivedEvent.getStartRow();
int endRow = dataArrivedEvent.getEndRow();
for (int i = startRow; i < endRow; i++) {
- if
(metricsTableView.expandedRows.contains(getRecord(i).getAttributeAsInt(
- MetricsViewDataSource.FIELD_METRIC_DEF_ID))) {
+ if (null != metricsTableView.expandedRows
+ &&
metricsTableView.expandedRows.contains(getRecord(i).getAttributeAsInt(
+ MetricsViewDataSource.FIELD_METRIC_DEF_ID))) {
expandRecord(getRecord(i));
}
}
@@ -309,7 +303,6 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
}
-
@Override
protected Canvas getExpansionComponent(final ListGridRecord record) {
final Integer definitionId =
record.getAttributeAsInt(MetricsViewDataSource.FIELD_METRIC_DEF_ID);
@@ -318,7 +311,6 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
vLayout.setPadding(5);
final String chartId = "rChart-" + resourceId + "-" +
definitionId;
- Log.debug("getExpansionComponent for: " + chartId);
HTMLFlow htmlFlow = new
HTMLFlow(MetricD3Graph.createGraphMarkerTemplate(chartId,
TREEVIEW_DETAIL_CHART_HEIGHT));
vLayout.addMember(htmlFlow);
@@ -331,7 +323,7 @@ public class MetricsTableView extends
Table<MetricsViewDataSource> implements Re
new
AsyncCallback<List<List<MeasurementDataNumericHighLowComposite>>>() {
@Override
public void onFailure(Throwable caught) {
- Log.debug("Error retrieving recent metrics charting data for
resource [" + resourceId + "]:"
+ Log.warn("Error retrieving recent metrics charting data for
resource [" + resourceId + "]:"
+ caught.getMessage());
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsViewDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsViewDataSource.java
index fbb9bff..5c2fe25 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsViewDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/table/MetricsViewDataSource.java
@@ -296,7 +296,7 @@ public class MetricsViewDataSource extends
RPCDataSource<MetricDisplaySummary, C
@Override
public void
onSuccess(List<List<MeasurementDataNumericHighLowComposite>>
measurementDataList) {
- if (!measurementDataList.isEmpty()) {
+ if (null != measurementDataList &&
!measurementDataList.isEmpty()) {
metricsDataList = measurementDataList;
countDownLatch.countDown();
}