modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/AlertDefinitionTemplateTypeView.java
| 11
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/DriftDefinitionTemplateTypeView.java
| 11
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/IgnoreResourceTypesView.java
| 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/MetricTemplateTypeView.java
| 11
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
| 153 ++++++++--
5 files changed, 157 insertions(+), 36 deletions(-)
New commits:
commit b33564602373317e5e73adbc71e0521929e0762e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu May 23 15:04:09 2013 -0400
BZ 962841 962845 fix the resource type admin pages to support types with multiple
parents (i.e. types with <runs-inside>)
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/AlertDefinitionTemplateTypeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/AlertDefinitionTemplateTypeView.java
index 9b4027e..4f790a1 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/AlertDefinitionTemplateTypeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/AlertDefinitionTemplateTypeView.java
@@ -197,14 +197,19 @@ public class AlertDefinitionTemplateTypeView extends
ResourceTypeTreeView {
}
public static class TreeNode extends ResourceTypeTreeNode {
-
public TreeNode(ResourceTypeTemplateCountComposite composite, String plugin)
{
-
super(composite, plugin);
-
setAttribute(ATTR_ENABLED_TEMPLATES, composite.getEnabledAlertCount());
setAttribute(ATTR_DISABLED_TEMPLATES,
composite.getDisabledAlertCount());
}
+
+ @Override
+ public ResourceTypeTreeNode copy() {
+ ResourceTypeTreeNode dup = super.copy();
+ dup.setAttribute(ATTR_ENABLED_TEMPLATES,
this.getAttributeAsLong(ATTR_ENABLED_TEMPLATES));
+ dup.setAttribute(ATTR_DISABLED_TEMPLATES,
this.getAttributeAsLong(ATTR_DISABLED_TEMPLATES));
+ return dup;
+ }
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/DriftDefinitionTemplateTypeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/DriftDefinitionTemplateTypeView.java
index 143c475..ebb2d9d 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/DriftDefinitionTemplateTypeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/DriftDefinitionTemplateTypeView.java
@@ -211,11 +211,8 @@ public class DriftDefinitionTemplateTypeView extends
ResourceTypeTreeView {
}
public static class TreeNode extends ResourceTypeTreeNode {
-
public TreeNode(ResourceTypeTemplateCountComposite composite, String plugin)
{
-
super(composite, plugin);
-
setAttribute(ATTR_PLUGIN_TEMPLATES,
composite.getPluginDriftTemplates());
setAttribute(ATTR_USER_TEMPLATES, composite.getUserDriftTemplates());
// If the type has no plugin templates then drift monitoring is not
enabled for the type
@@ -223,6 +220,14 @@ public class DriftDefinitionTemplateTypeView extends
ResourceTypeTreeView {
setAttribute(ATTRIB_EDIT, ImageManager.getEditDisabledIcon());
}
}
+
+ @Override
+ public ResourceTypeTreeNode copy() {
+ ResourceTypeTreeNode dup = super.copy();
+ dup.setAttribute(ATTR_PLUGIN_TEMPLATES,
this.getAttributeAsLong(ATTR_PLUGIN_TEMPLATES));
+ dup.setAttribute(ATTR_USER_TEMPLATES,
this.getAttributeAsLong(ATTR_USER_TEMPLATES));
+ return dup;
+ }
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/IgnoreResourceTypesView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/IgnoreResourceTypesView.java
index 246a71e..91a4ca2 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/IgnoreResourceTypesView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/IgnoreResourceTypesView.java
@@ -182,6 +182,13 @@ public class IgnoreResourceTypesView extends ResourceTypeTreeView {
super(composite, plugin);
setAttribute(ATTR_ENABLED,
ImageManager.getAvailabilityIcon(!composite.getType().isIgnored()));
}
+
+ @Override
+ public ResourceTypeTreeNode copy() {
+ ResourceTypeTreeNode dup = super.copy();
+ dup.setAttribute(ATTR_ENABLED, this.getAttribute(ATTR_ENABLED));
+ return dup;
+ }
}
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/MetricTemplateTypeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/MetricTemplateTypeView.java
index 19c53d2..e4aa4fe 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/MetricTemplateTypeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/MetricTemplateTypeView.java
@@ -170,11 +170,8 @@ public class MetricTemplateTypeView extends ResourceTypeTreeView {
}
public static class TreeNode extends ResourceTypeTreeNode {
-
public TreeNode(ResourceTypeTemplateCountComposite composite, String plugin)
{
-
super(composite, plugin);
-
setAttribute(ATTR_ENABLED_TEMPLATES, composite.getEnabledMetricCount());
setAttribute(ATTR_DISABLED_TEMPLATES,
composite.getDisabledMetricCount());
// If the type has no metrics then metric templates are enabled for the
type
@@ -182,6 +179,14 @@ public class MetricTemplateTypeView extends ResourceTypeTreeView {
setAttribute(ATTRIB_EDIT, ImageManager.getEditDisabledIcon());
}
}
+
+ @Override
+ public ResourceTypeTreeNode copy() {
+ ResourceTypeTreeNode dup = super.copy();
+ dup.setAttribute(ATTR_ENABLED_TEMPLATES,
this.getAttributeAsLong(ATTR_ENABLED_TEMPLATES));
+ dup.setAttribute(ATTR_DISABLED_TEMPLATES,
this.getAttributeAsLong(ATTR_DISABLED_TEMPLATES));
+ return dup;
+ }
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
index 72563c2..e90f398 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/templates/ResourceTypeTreeNodeBuilder.java
@@ -18,11 +18,14 @@
*/
package org.rhq.enterprise.gui.coregui.client.admin.templates;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.tree.Tree;
@@ -48,7 +51,7 @@ public abstract class ResourceTypeTreeNodeBuilder {
static private final Messages MSG = CoreGUI.getMessages();
public static final String ATTRIB_ID = "id";
- public static final String ATTRIB_PARENT_ID = "parentId";
+ public static final String ATTRIB_CHILDREN = "children";
public static final String ATTRIB_NAME = "name";
public static final String ATTRIB_PLUGIN = "plugin";
public static final String ATTRIB_CATEGORY = "category";
@@ -67,13 +70,18 @@ public abstract class ResourceTypeTreeNodeBuilder {
@Override
public void onSuccess(Map<Integer,
ResourceTypeTemplateCountComposite> result) {
+ // result contains all of our resource types, including the parent
hierarchy
HashSet<ResourceTypeListGridRecord> platformsRecords;
HashSet<ResourceTypeListGridRecord> platformServicesRecords;
- HashSet<ResourceTypeTreeNode> treeNodes;
+ HashMap<Integer, ResourceTypeTreeNode> serversNodes; // all
server nodes (top level and below)
+ HashSet<Integer> topServers; // those servers that are at the
root of the tree
+ HashMap<Integer, ArrayList<Integer>> childrenGraph; //
defines the children of all server nodes
platformsRecords = new HashSet<ResourceTypeListGridRecord>();
platformServicesRecords = new
HashSet<ResourceTypeListGridRecord>();
- treeNodes = new HashSet<ResourceTypeTreeNode>();
+ serversNodes = new HashMap<Integer, ResourceTypeTreeNode>();
+ topServers = new HashSet<Integer>();
+ childrenGraph = new HashMap<Integer,
ArrayList<Integer>>();
for (ResourceTypeTemplateCountComposite composite : result.values())
{
ResourceType type = composite.getType();
@@ -84,7 +92,9 @@ public abstract class ResourceTypeTreeNodeBuilder {
platformsRecords.add(getGridRecordInstance(composite));
} else {
// no parents but not a platform - these are our
top-level servers
- treeNodes.add(getTreeNodeInstance(composite,
type.getPlugin()));
+ ResourceTypeTreeNode node =
getTreeNodeInstance(composite, type.getPlugin());
+ topServers.add(node.getResourceTypeId());
+ serversNodes.put(node.getResourceTypeId(), node);
}
} else {
// has parents; if all the direct parents are top level
platforms
@@ -106,22 +116,37 @@ public abstract class ResourceTypeTreeNodeBuilder {
if (isPlatformService) {
platformServicesRecords.add(getGridRecordInstance(composite));
-
} else {
- // in some cases, a top level server is limited to which
platforms it can run on.
- // therefore, the parents will not be null/empty (as
would be the case if the top level
+ // In some cases, a top level server is limited to which
platforms it can run on.
+ // Therefore, the parents will not be null/empty (as
would be the case if the top level
// server can run on ALL platforms), but instead it will
have the subset of platforms
- // the type is valid on. But its the same type - so we
only want to show it once. Therefore,
- // once we see a parent that is a top level platform, we
don't add the type again for other
- // top level platforms. That's what gotPlatform
boolean tracks.
+ // the type is valid on. But its the same type - so we
only want to show it once.
+ // This is what gotPlatform tracks - whether we saw a
parent platform or not.
+ //
+ // But we also have the case where a server type can run
inside multiple parent server types.
+ // We want to show these under all their parents to make
it easier for the user to find them.
boolean gotPlatform = false;
for (ResourceType parentType :
type.getParentResourceTypes()) {
- boolean isPlatform = (parentType.getCategory() ==
ResourceCategory.PLATFORM && isEmpty(parentType
+ boolean isParentAPlatform = (parentType.getCategory()
== ResourceCategory.PLATFORM && isEmpty(parentType
.getParentResourceTypes()));
- if (!isPlatform || !gotPlatform) {
- treeNodes.add(getTreeNodeInstance(composite,
String.valueOf(parentType.getId())));
+ if (!isParentAPlatform || !gotPlatform) {
+ int parentId = parentType.getId();
+ String parentIdString =
String.valueOf(parentId);
+ ResourceTypeTreeNode node =
getTreeNodeInstance(composite, parentIdString);
+ serversNodes.put(node.getResourceTypeId(),
node);
+ if (isParentAPlatform) {
+ topServers.add(node.getResourceTypeId());
+ } else {
+ // we are a child to other type, add it to
the list of children
+ ArrayList<Integer> childList =
childrenGraph.get(parentId);
+ if (childList == null) {
+ childList = new
ArrayList<Integer>();
+ childrenGraph.put(parentId, childList);
+ }
+ childList.add(node.getResourceTypeId());
+ }
}
- if (isPlatform) {
+ if (isParentAPlatform) {
gotPlatform = true;
}
}
@@ -129,14 +154,50 @@ public abstract class ResourceTypeTreeNodeBuilder {
}
}
+ // now set up our UI components to show the data
+ platformsGrid.setSortField(ATTRIB_NAME);
+ platformServicesGrid.setSortField(ATTRIB_NAME);
+ serversGrid.setSortField(ATTRIB_NAME);
+
platformsGrid.setData(platformsRecords.toArray(new
ListGridRecord[platformsRecords.size()]));
platformServicesGrid.setData(platformServicesRecords
.toArray(new ListGridRecord[platformServicesRecords.size()]));
- Tree tree = serversGrid.getTree();
- if (tree != null) {
- TreeNode[] treeNodeArray = treeNodes.toArray(new
TreeNode[treeNodes.size()]);
- tree.linkNodes(treeNodeArray);
+ Tree tree = new Tree();
+ tree.setModelType(TreeModelType.CHILDREN);
+ tree.setChildrenProperty(ATTRIB_CHILDREN);
+ TreeNode rootNode = new TreeNode("0");
+ tree.setRoot(rootNode);
+
+ for (Integer topServerId : topServers) {
+ ResourceTypeTreeNode topServerNode =
serversNodes.get(topServerId);
+ topServerNode = topServerNode.copy();
+ fillHierarchy(topServerNode, serversNodes, childrenGraph);
+ tree.add(topServerNode, rootNode);
}
+ serversGrid.setData(tree);
+ }
+
+ private void fillHierarchy(ResourceTypeTreeNode node,
+ HashMap<Integer, ResourceTypeTreeNode> serversNodes,
+ HashMap<Integer, ArrayList<Integer>> childrenGraph) {
+
+ if (node.getChildren().length > 0) {
+ return; // we've already populated this node's children
before; nothing to do
+ }
+
+ ArrayList<Integer> childrenIds =
childrenGraph.get(node.getResourceTypeId());
+ if (childrenIds != null) {
+ for (Integer childrenId : childrenIds) {
+ ResourceTypeTreeNode childNode =
serversNodes.get(childrenId);
+ if (childNode != null) { // this should never be null, but
this let's us continue if we have a bug
+ childNode = childNode.copy();
+ fillHierarchy(childNode, serversNodes, childrenGraph);
+ node.addChild(childNode);
+ }
+ }
+ }
+
+ return;
}
@Override
@@ -184,25 +245,63 @@ public abstract class ResourceTypeTreeNodeBuilder {
public static class ResourceTypeTreeNode extends TreeNode {
- private String id;
+ private int id;
private String parentId;
+ private TreeNode[] children;
+
+ private ResourceTypeTreeNode() {
+ // for use by copy() method
+ }
protected ResourceTypeTreeNode(ResourceTypeTemplateCountComposite composite,
String parentId) {
ResourceType resourceType = composite.getType();
- String id = String.valueOf(resourceType.getId());
- setID(id);
- this.id = id;
-
- setParentID(parentId);
+ this.id = resourceType.getId();
this.parentId = parentId;
setAttribute(ATTRIB_ID, id);
- setAttribute(ATTRIB_PARENT_ID, parentId);
setAttribute(ATTRIB_NAME, resourceType.getName());
setAttribute(ATTRIB_PLUGIN, resourceType.getPlugin());
setAttribute(ATTRIB_CATEGORY, resourceType.getCategory().name());
setAttribute(ATTRIB_EDIT, ImageManager.getEditIcon());
+ setChildren(new TreeNode[0]);
+ }
+
+ public int getResourceTypeId() {
+ return this.id;
+ }
+
+ public TreeNode[] getChildren() {
+ return this.children;
+ }
+
+ @Override
+ public void setChildren(TreeNode[] children) {
+ this.children = children;
+ super.setChildren(children);
+ }
+
+ public void addChild(TreeNode newChild) {
+ TreeNode[] newChildren = new TreeNode[this.children.length + 1];
+ System.arraycopy(this.children, 0, newChildren, 0, this.children.length);
+ newChildren[this.children.length] = newChild;
+ setChildren(newChildren);
+ }
+
+ // clone this object and return it - subclasses should override this to copy
their own attributes
+ public ResourceTypeTreeNode copy() {
+ ResourceTypeTreeNode dup = new ResourceTypeTreeNode();
+ dup.id = this.id;
+ dup.parentId = this.parentId;
+ dup.children = this.children;
+
+ dup.setAttribute(ATTRIB_ID, this.getAttributeAsInt(ATTRIB_ID));
+ dup.setAttribute(ATTRIB_NAME, this.getAttribute(ATTRIB_NAME));
+ dup.setAttribute(ATTRIB_PLUGIN, this.getAttribute(ATTRIB_PLUGIN));
+ dup.setAttribute(ATTRIB_CATEGORY, this.getAttribute(ATTRIB_CATEGORY));
+ dup.setAttribute(ATTRIB_EDIT, this.getAttribute(ATTRIB_EDIT));
+
+ return dup;
}
@Override
@@ -216,7 +315,7 @@ public abstract class ResourceTypeTreeNodeBuilder {
ResourceTypeTreeNode that = (ResourceTypeTreeNode) o;
- if (!this.id.equals(that.id)) {
+ if (this.id != that.id) {
return false;
}
if (this.parentId == null) {
@@ -228,7 +327,7 @@ public abstract class ResourceTypeTreeNodeBuilder {
@Override
public int hashCode() {
int result = 31;
- result = result * id.hashCode();
+ result = result * id;
result = result + (parentId != null ? parentId.hashCode() : 0);
return result;
}