modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
| 37 ++++++++--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
| 3
2 files changed, 34 insertions(+), 6 deletions(-)
New commits:
commit a2619e9946f686fdb50f161df01766d88964980f
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Dec 21 17:14:28 2010 -0500
[BZ 661808 - Removing portlets from the dashboard is not working]
Actually it turns out it was "rapid" portlet removal was not working. There
is a basic issue with the implementation in that the user can perform
several callback-initiating actions (like portlet removal) faster than
DashboardView's async save() method can complete. The save() method's
async success() method updates the stored dashboard with the results
of the save (merge operation). This in effect can "overwrite" any work
that had been done on the "old" Dashboard while the update was taking
place.
I've protected add/remove portlet using some synchronization but it we need
to go further we may need to put a locking mechanism in place.
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 02e6b00..81d3bb2 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
@@ -238,7 +238,11 @@ public class DashboardView extends LocatableVLayout {
}
}
- private void addPortlet(String portletKey, String portletName) {
+ /**
+ * A synchronized call to ensure add/remove/save are exclusive.
+ *
+ */
+ synchronized private void addPortlet(String portletKey, String portletName) {
DashboardPortlet storedPortlet = new DashboardPortlet(portletName, portletKey,
250);
final PortletWindow newPortlet = new PortletWindow(extendLocatorId(portletKey),
this, storedPortlet);
@@ -278,11 +282,32 @@ public class DashboardView extends LocatableVLayout {
newPortlet.show();
}
}, 750);
- save();
+ save(storedDashboard);
+ }
+
+ /**
+ * A synchronized call to ensure the remove and save are atomic.
+ *
+ * @param portlet
+ */
+ synchronized public void removePortlet(DashboardPortlet portlet) {
+ storedDashboard.removePortlet(portlet);
+ save(storedDashboard);
+ }
+
+ /**
+ * A synchronized call to ensure add/remove/save are exclusive.
+ */
+ synchronized private void setDashboard(Dashboard dashboard) {
+ storedDashboard = dashboard;
}
public void save() {
- GWTServiceLookup.getDashboardService().storeDashboard(storedDashboard, new
AsyncCallback<Dashboard>() {
+ save(storedDashboard);
+ }
+
+ private void save(Dashboard dashboard) {
+ GWTServiceLookup.getDashboardService().storeDashboard(dashboard, new
AsyncCallback<Dashboard>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_dashboardManager_error(),
caught);
}
@@ -290,7 +315,11 @@ public class DashboardView extends LocatableVLayout {
public void onSuccess(Dashboard result) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_dashboardManager_saved(result.getName()),
Message.Severity.Info));
- storedDashboard = result;
+ // use the synchronized call to ensure add/delete portlet doesn't get
interrupted. This is really
+ // just limited protection for add/remove portlet. Since this now sets
storedDashboard,
+ // anything using the old version could lose edits. If we want to make
this more robust we'll probably
+ // need a locking mechanism for editing the dashboard.
+ setDashboard(storedDashboard);
updateConfigs(result);
}
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 caffe54..3277aeb 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
@@ -148,8 +148,7 @@ public class PortletWindow extends LocatableWindow {
addCloseClickHandler(new CloseClickHandler() {
public void onCloseClick(CloseClientEvent closeClientEvent) {
-
PortletWindow.this.dashboardPortlet.getDashboard().removePortlet(PortletWindow.this.dashboardPortlet);
- save();
+
PortletWindow.this.dashboardView.removePortlet(PortletWindow.this.dashboardPortlet);
destroy();
}
});
Show replies by date