modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java | 11 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java | 6 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java | 62 +++++----- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMetricD3GraphView.java | 31 ++--- 4 files changed, 70 insertions(+), 40 deletions(-)
New commits: commit 944f2e9a2cb4318d820010f3c37317a3cbfe58c5 Author: Jay Shaughnessy jshaughn@redhat.com Date: Fri Mar 8 16:19:19 2013 -0500
Work done with Mike to get graphs and portlets to play better together. - make DashTab switch update the portlets for the newly active dash - make ResourceD3GraphPortlet an AutorefreshPortlet. - get rid of what seem to be unnecessary removemembers calls, and added code such that drawgraph removes the legacy graphDiv.
Conflicts:
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java
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 6c6544c..6c81ba1 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 @@ -968,4 +968,15 @@ public class DashboardView extends LocatableVLayout { maximizedPortlet = null; portalLayout.markForRedraw(); } + + // If we redraw the dashboard then also redraw the portlets so that everything is up to date + @Override + public void redraw() { + super.redraw(); + + for (PortletWindow pw : portletWindows) { + // I think this should work with markForRedraw but for some reason it does not + ((Canvas) pw.getView()).redraw(); + } + } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java index 27071aa..48f66d3 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardsView.java @@ -231,6 +231,12 @@ public class DashboardsView extends LocatableVLayout implements DashboardContain selectedDashboard = selectedDashboardView.getDashboard(); editButton.setTitle(editMode ? MSG.common_title_view_mode() : MSG.common_title_edit_mode()); selectedDashboardView.setEditMode(editMode); + + // If re-selecting a Dashboard, make sure it, and its portlets, are up to date + if (selectedDashboardView.isDrawn()) { + // I think this should work with markForRedraw but for some reason it does not + selectedDashboardView.redraw(); + } } });
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java index f870172..6a63801 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/graph/ResourceD3GraphPortlet.java @@ -18,30 +18,12 @@ */ package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.resource.graph;
-/* - * RHQ Management Platform - * Copyright (C) 2005-2010 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Map;
+import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.types.Overflow; @@ -65,6 +47,8 @@ import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.components.lookup.ResourceLookupComboBoxItem; +import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet; +import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil; 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; @@ -85,7 +69,7 @@ import org.rhq.enterprise.server.measurement.util.MeasurementUtils; * @author Jay Shaughnessy * @author Mike Thompson */ -public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements CustomSettingsPortlet { +public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements AutoRefreshPortlet, CustomSettingsPortlet {
// A non-displayed, persisted identifier for the portlet public static final String KEY = "ResourceMetricD3"; @@ -95,10 +79,10 @@ public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements Cus public static final String CFG_DEFINITION_ID = "definitionId"; // set on initial configuration, the window for this portlet view. private PortletWindow portletWindow; + private Timer refreshTimer;
public ResourceD3GraphPortlet(String locatorId) { super(locatorId); - isPortalGraph = true; setOverflow(Overflow.HIDDEN); setGraph(new MetricStackedBarGraph(new MetricGraphData())); } @@ -278,9 +262,8 @@ public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements Cus storedPortlet.getConfiguration().put( new PropertySimple(CFG_DEFINITION_ID, form.getValue(CFG_DEFINITION_ID)));
+ // this will cause the graph to draw configure(portletWindow, storedPortlet); - - redraw(); } });
@@ -290,22 +273,23 @@ public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements Cus @Override public void redraw() { Log.debug("Redraw Portlet Graph and set data"); - super.redraw(); - - removeMembers(getMembers());
DashboardPortlet storedPortlet = portletWindow.getStoredPortlet(); PropertySimple simple = storedPortlet.getConfiguration().getSimple(CFG_RESOURCE_ID);
if (simple == null || simple.getIntegerValue() == null) { + removeMembers(getMembers()); addMember(new Label("<i>" + MSG.view_portlet_configure_needed() + "</i>")); } else { graph.getMetricGraphData().setEntityId(simple.getIntegerValue()); PropertySimple simpleDefId = storedPortlet.getConfiguration().getSimple(CFG_DEFINITION_ID); graph.getMetricGraphData().setDefinitionId(simpleDefId.getIntegerValue()); - Log.debug(" *** Redraw Portlet for entityId: "+simple.getIntegerValue()+"-"+simpleDefId.getIntegerValue()); + Log.debug(" *** Redraw Portlet for entityId: " + simple.getIntegerValue() + "-" + + simpleDefId.getIntegerValue()); drawGraph(); } + + super.redraw(); }
public static final class Factory implements PortletViewFactory { @@ -317,5 +301,29 @@ public class ResourceD3GraphPortlet extends ResourceMetricD3Graph implements Cus return new ResourceD3GraphPortlet(locatorId); } } + + public void startRefreshCycle() { + refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this, refreshTimer); + } + + @Override + protected void onDestroy() { + AutoRefreshPortletUtil.onDestroy(this, refreshTimer); + + super.onDestroy(); + } + + public boolean isRefreshing() { + return false; + } + + //Custom refresh operation as we are not directly extending Table + @Override + public void refresh() { + if (isVisible() && !isRefreshing()) { + drawGraph(); + } + } + }
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMetricD3GraphView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMetricD3GraphView.java index 91ac17a..4831a58 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMetricD3GraphView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMetricD3GraphView.java @@ -44,9 +44,9 @@ public abstract class AbstractMetricD3GraphView extends LocatableVLayout { //protected HTMLFlow resourceTitle; protected AbstractGraph graph; private Integer chartHeight; - protected boolean isPortalGraph = false; private int entityId; private int definitionId; + private HTMLFlow graphDiv = null;
public AbstractMetricD3GraphView(String locatorId) { super(locatorId); @@ -83,11 +83,9 @@ public abstract class AbstractMetricD3GraphView extends LocatableVLayout { + " </pattern>" + "</defs>"; }
- @Override protected void onDraw() { super.onDraw(); - removeMembers(getMembers()); if (graph.getDefinition() != null) { drawGraph(); } @@ -116,7 +114,6 @@ public abstract class AbstractMetricD3GraphView extends LocatableVLayout { return definitionId; }
- /** * Setup the page elements especially the div and svg elements that serve as * placeholders for the d3 stuff to grab onto and add svg tags to render the chart. @@ -125,18 +122,26 @@ public abstract class AbstractMetricD3GraphView extends LocatableVLayout { * */ protected void drawGraph() { - Log.debug("drawGraph marker in AbstractMetricD3GraphView for: " + graph.getMetricGraphData().getChartId()+ " " + graph.getChartTitle()); + Log.debug("drawGraph marker in AbstractMetricD3GraphView for: " + graph.getMetricGraphData().getChartId() + " " + + graph.getChartTitle());
StringBuilder divAndSvgDefs = new StringBuilder(); - divAndSvgDefs.append("<div id="rChart-" + graph.getMetricGraphData().getChartId() - + "" ><svg xmlns="http://www.w3.org/2000/svg%5C" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink%5C" style="height:" + getChartHeight() - + "px;">"); + divAndSvgDefs + .append("<div id="rChart-" + + graph.getMetricGraphData().getChartId() + + "" ><svg xmlns="http://www.w3.org/2000/svg%5C" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink%5C" style="height:" + + getChartHeight() + "px;">"); divAndSvgDefs.append(getSvgDefs()); divAndSvgDefs.append("</svg></div>"); - HTMLFlow graph = new HTMLFlow(divAndSvgDefs.toString()); - graph.setWidth100(); - graph.setHeight100(); - addMember(graph); + + if (null != graphDiv) { + removeMember(graphDiv); + } + + graphDiv = new HTMLFlow(divAndSvgDefs.toString()); + graphDiv.setWidth100(); + graphDiv.setHeight100(); + addMember(graphDiv);
new Timer() { @Override @@ -145,7 +150,7 @@ public abstract class AbstractMetricD3GraphView extends LocatableVLayout { //@todo: this is a hack around timing issue of jsni not seeing the DOM drawJsniChart(); } - }.schedule(900); + }.schedule(200); }