modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
| 16 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java
| 84 +++++-----
2 files changed, 59 insertions(+), 41 deletions(-)
New commits:
commit 44ebe352011837c815122fff43497149e5008e1a
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Dec 23 13:05:51 2010 -0500
Dashboard Work for Adding Portlets to a Dashboard
- Add some more support to PortletFactory for better handling portlet
keys *and* names.
- Fix the 'add portlet' drop down menu to use names as opposed to keys.
- make sure when adding a portlet we properly specify name and key, key
was being passed incorrectly.
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 5843658..9631294 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
@@ -199,8 +199,11 @@ public class DashboardView extends LocatableVLayout {
});
Menu addPortletMenu = new Menu();
- for (String portletName : PortletFactory.getRegisteredPortletKeys()) {
- addPortletMenu.addItem(new MenuItem(portletName));
+ HashMap<String, String> keyNameMap =
PortletFactory.getRegisteredPortletNameMap();
+ for (String portletKey : keyNameMap.keySet()) {
+ MenuItem menuItem = new MenuItem(keyNameMap.get(portletKey));
+ menuItem.setAttribute("portletKey", portletKey);
+ addPortletMenu.addItem(menuItem);
}
addPortlet = new LocatableIMenuButton(extendLocatorId("AddPortlet"),
MSG.common_title_add_portlet(),
@@ -211,8 +214,9 @@ public class DashboardView extends LocatableVLayout {
addPortletMenu.addItemClickHandler(new ItemClickHandler() {
public void onItemClick(ItemClickEvent itemClickEvent) {
- String portletTitle = itemClickEvent.getItem().getTitle();
- addPortlet(portletTitle, portletTitle);
+ String key =
itemClickEvent.getItem().getAttribute("portletKey");
+ String name = itemClickEvent.getItem().getTitle();
+ addPortlet(key, name);
}
});
@@ -407,12 +411,12 @@ public class DashboardView extends LocatableVLayout {
if (portletMap == null) {
portletMap = new HashMap<String, PortletViewFactory>();
for (String key : PortletFactory.getRegisteredPortletKeys()) {
- portletMap.put(key, PortletFactory.getRegisteredPortlet(key));
+ portletMap.put(key,
PortletFactory.getRegisteredPortletFactory(key));
}
}
for (PortletWindow portletWindow : portlets) {
for (DashboardPortlet portlet : result.getPortlets()) {
- if (portletWindow.getDashboardPortlet().getId() == portlet.getId())
{
+ if (portletWindow.getDashboardPortlet().equals(portlet)) {
portletWindow.getDashboardPortlet().setConfiguration(portlet.getConfiguration());
//restarting port auto-refresh with newest settings
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 4e1ac46..aaa2229 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
@@ -19,10 +19,8 @@
package org.rhq.enterprise.gui.coregui.client.dashboard;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.inventory.queue.AutodiscoveryPortlet;
@@ -44,39 +42,44 @@ import
org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
*/
public class PortletFactory {
- private static Map<String, PortletViewFactory> registeredPortlets;
+ private static HashMap<String, PortletViewFactory>
registeredPortletFactoryMap;
+ private static HashMap<String, String> registeredPortletNameMap;
static {
- registeredPortlets = new HashMap<String, PortletViewFactory>();
-
- registeredPortlets.put(InventorySummaryPortlet.KEY,
InventorySummaryPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(RecentlyAddedResourcesPortlet.KEY,
RecentlyAddedResourcesPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(PlatformSummaryPortlet.KEY,
PlatformSummaryPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(AutodiscoveryPortlet.KEY,
AutodiscoveryPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(RecentAlertsPortlet.KEY,
RecentAlertsPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(GraphPortlet.KEY, GraphPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(TagCloudPortlet.KEY, TagCloudPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(FavoriteResourcesPortlet.KEY,
FavoriteResourcesPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(MashupPortlet.KEY, MashupPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(MessagePortlet.KEY, MessagePortlet.Factory.INSTANCE);
-
- registeredPortlets.put(ProblemResourcesPortlet.KEY,
ProblemResourcesPortlet.Factory.INSTANCE);
-
- registeredPortlets.put(OperationsPortlet.KEY,
OperationsPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap = new HashMap<String, PortletViewFactory>();
+ registeredPortletFactoryMap.put(InventorySummaryPortlet.KEY,
InventorySummaryPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(RecentlyAddedResourcesPortlet.KEY,
+ RecentlyAddedResourcesPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(PlatformSummaryPortlet.KEY,
PlatformSummaryPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(AutodiscoveryPortlet.KEY,
AutodiscoveryPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(RecentAlertsPortlet.KEY,
RecentAlertsPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(GraphPortlet.KEY,
GraphPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(TagCloudPortlet.KEY,
TagCloudPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(FavoriteResourcesPortlet.KEY,
FavoriteResourcesPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(MashupPortlet.KEY,
MashupPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(MessagePortlet.KEY,
MessagePortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(ProblemResourcesPortlet.KEY,
ProblemResourcesPortlet.Factory.INSTANCE);
+ registeredPortletFactoryMap.put(OperationsPortlet.KEY,
OperationsPortlet.Factory.INSTANCE);
+
+ registeredPortletNameMap = new HashMap<String,
String>(registeredPortletFactoryMap.size());
+ registeredPortletNameMap.put(InventorySummaryPortlet.KEY,
InventorySummaryPortlet.NAME);
+ registeredPortletNameMap.put(RecentlyAddedResourcesPortlet.KEY,
RecentlyAddedResourcesPortlet.NAME);
+ registeredPortletNameMap.put(PlatformSummaryPortlet.KEY,
PlatformSummaryPortlet.NAME);
+ registeredPortletNameMap.put(AutodiscoveryPortlet.KEY,
AutodiscoveryPortlet.NAME);
+ registeredPortletNameMap.put(RecentAlertsPortlet.KEY, RecentAlertsPortlet.NAME);
+ registeredPortletNameMap.put(GraphPortlet.KEY, GraphPortlet.NAME);
+ registeredPortletNameMap.put(TagCloudPortlet.KEY, TagCloudPortlet.NAME);
+ registeredPortletNameMap.put(FavoriteResourcesPortlet.KEY,
FavoriteResourcesPortlet.NAME);
+ registeredPortletNameMap.put(MashupPortlet.KEY, MashupPortlet.NAME);
+ registeredPortletNameMap.put(MessagePortlet.KEY, MessagePortlet.NAME);
+ registeredPortletNameMap.put(ProblemResourcesPortlet.KEY,
ProblemResourcesPortlet.NAME);
+ registeredPortletNameMap.put(OperationsPortlet.KEY, OperationsPortlet.NAME);
+ //registeredPortletNameMap =
Collections.unmodifiableMap(registeredPortletNameMap);
}
public static Portlet buildPortlet(PortletWindow portletWindow, DashboardPortlet
storedPortlet) {
- PortletViewFactory viewFactory =
registeredPortlets.get(storedPortlet.getPortletKey());
+ PortletViewFactory viewFactory =
registeredPortletFactoryMap.get(storedPortlet.getPortletKey());
// TODO: Note, we're using a sequence generated ID here as a locatorId. This
is not optimal for repeatable
// tests as a change in the number of default portlets, or a change in test order
could make a test
@@ -93,18 +96,29 @@ public class PortletFactory {
return view;
}
- @SuppressWarnings("unchecked")
public static List<String> getRegisteredPortletKeys() {
- ArrayList portlets = new ArrayList(registeredPortlets.keySet());
- Collections.sort(portlets);
- return portlets;
+ ArrayList<String> portletKeys = new
ArrayList<String>(registeredPortletFactoryMap.keySet());
+ return portletKeys;
+ }
+
+ /**
+ * @return Unmodifiable Map of registered portlet keys to names
+ */
+ public static HashMap<String, String> getRegisteredPortletNameMap() {
+
+ return registeredPortletNameMap;
+ }
+
+ public static String getRegisteredPortletName(String key) {
+
+ return registeredPortletNameMap.get(key);
}
- public static PortletViewFactory getRegisteredPortlet(String key) {
+ public static PortletViewFactory getRegisteredPortletFactory(String key) {
PortletViewFactory portletFactory = null;
if ((key != null) & (!key.trim().isEmpty())) {
- portletFactory = registeredPortlets.get(key);
+ portletFactory = registeredPortletFactoryMap.get(key);
}
return portletFactory;
}