Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1069545] The resource tree view now renders subcategories as well…
Browse files Browse the repository at this point in the history
… as nested subcategories with the identical names properly.
  • Loading branch information
Stefan Negrea committed May 15, 2014
1 parent 39bb847 commit 6863de9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,28 @@ private static void addSubCategoryNodes(List<TreeNode> allNodes, Set<String> all
ResourceType type = resource.getResourceType();

String subCategoryNodeId = null;
String treeParentId = ResourceTreeNode.idOf(parentResourceId);

String[] subCategories = type.getSubCategory().split("\\|");
for (String currentSubCategory : subCategories) {
subCategoryNodeId = SubCategoryTreeNode.idOf(currentSubCategory, parentResourceId);
String[] subcategoryNames = type.getSubCategory().split("\\|");
String subcategoryAncestry = null;
for (String subcategoryName : subcategoryNames) {
if (subcategoryAncestry == null) {
subcategoryAncestry = subcategoryName;
} else {
subcategoryAncestry = subcategoryAncestry + "|" + subcategoryName;
}

subCategoryNodeId = SubCategoryTreeNode.idOf(subcategoryAncestry, parentResourceId);

if (!allNodeIds.contains(subCategoryNodeId)) {
SubCategoryTreeNode subCategoryNode = new SubCategoryTreeNode(currentSubCategory, parentResourceId);
SubCategoryTreeNode subCategoryNode = new SubCategoryTreeNode(subcategoryName, subcategoryAncestry,
parentResourceId, treeParentId);

allNodeIds.add(subCategoryNodeId);
allNodes.add(subCategoryNode);
}

//parentResourceId = currentSubCategory.hashCode();
treeParentId = subCategoryNodeId;
}
}

Expand Down Expand Up @@ -370,10 +380,9 @@ private ResourceTreeNode(Resource resource, boolean isLocked) {
this.parentAutoGroup = true;

} else {
String subcategoriesString = resource.getResourceType().getSubCategory();
if (null != subcategoriesString) {
String[] subcategories = subcategoriesString.split("\\|");
parentId = SubCategoryTreeNode.idOf(subcategories[subcategories.length - 1], parentResource);
String subcategory = resource.getResourceType().getSubCategory();
if (null != subcategory) {
parentId = SubCategoryTreeNode.idOf(subcategory, parentResource.getId());
this.parentSubCategory = true;
} else
parentId = ResourceTreeNode.idOf(parentResource);
Expand Down Expand Up @@ -424,37 +433,21 @@ public static String idOf(int resourceId) {
*/
public static class SubCategoryTreeNode extends EnhancedTreeNode {

public SubCategoryTreeNode(String subcategoryName, Resource parentResource) {
String id = idOf(subcategoryName, parentResource);
setID(id);

setParentID(ResourceTreeNode.idOf(parentResource));

// Note, subCategory names are typically already plural, so there's no need to pluralize them.
setName(subcategoryName);
public SubCategoryTreeNode(String subcategoryName, String subcategoryAncestry, int parentResourceId,
String parentTreeId) {

setAttribute(Attributes.DESCRIPTION, subcategoryName);
}

public SubCategoryTreeNode(String subcategoryName, int parentResourceId) {
String id = idOf(subcategoryName, parentResourceId);
String id = idOf(subcategoryAncestry, parentResourceId);
setID(id);

setParentID(ResourceTreeNode.idOf(parentResourceId));
setParentID(parentTreeId);

// Note, subCategory names are typically already plural, so there's no need to pluralize them.
setName(subcategoryName);

setAttribute(Attributes.DESCRIPTION, subcategoryName);
}

public static String idOf(String subcategoryName, Resource parentResource) {
Log.debug(subcategoryName);
return "subcat_" + subcategoryName.hashCode() + "_" + parentResource.getId();
}

public static String idOf(String subcategoryName, int parentResourceId) {
Log.debug(subcategoryName);
return "subcat_" + subcategoryName.hashCode() + "_" + parentResourceId;
}
}
Expand Down Expand Up @@ -482,11 +475,9 @@ private AutoGroupTreeNode(Resource resource) {

// parent node is either a subCategory node or a resource node
String parentId;
String subcategoriesString = this.resourceType.getSubCategory();
if (subcategoriesString != null) {
//TODO: BZ 1069545 fix this
String[] subcategories = subcategoriesString.split("\\|");
parentId = SubCategoryTreeNode.idOf(subcategories[subcategories.length - 1], this.parentResource);
String subcategory = this.resourceType.getSubCategory();
if (subcategory != null) {
parentId = SubCategoryTreeNode.idOf(subcategory, this.parentResource.getId());
this.parentSubcategory = true;
} else {
parentId = ResourceTreeNode.idOf(this.parentResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10468,7 +10468,7 @@
discovery="SubsystemDiscovery"
description="JBoss Diagnostic Reporter (JDR) Subsystem."
singleton="true"
subCategory="Subsystems|Weird">
subCategory="Subsystems|Weird|Subsystems">

<runs-inside>
<parent-resource-type name="JBossAS7 Standalone Server" plugin="&pluginName;"/>
Expand Down

0 comments on commit 6863de9

Please sign in to comment.