Skip to content
Permalink
Browse files
[JENKINS-31162] A new description field has been added for Items
  • Loading branch information
recena committed Mar 14, 2016
1 parent ac72888 commit 2356791978db17c19e767de7195ec07cb648b7a0
Showing 2 changed files with 42 additions and 5 deletions.
@@ -348,10 +348,12 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
ItemCategory ic = ItemCategoryConfigurator.getCategory(descriptor);
Map<String, Serializable> metadata = new HashMap<String, Serializable>();

// Information about Item.
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
metadata.put("name", descriptor.getDisplayName());
metadata.put("description", ItemCategoryConfigurator.getDescription(descriptor));

Category category = categories.getItem(ic.getId());
if (category != null) {
@@ -56,12 +56,12 @@ public static ItemCategory getCategory(@Nonnull TopLevelItemDescriptor descripto
protected abstract Integer getWeightFor(@Nonnull TopLevelItemDescriptor descriptor);

/**
* Finds the category specified by the first mapper.
* If none can be found {@link ItemCategory.Default} is returned.
* Finds the weight specified by the first configurator.
* If none can be found {@link Integer#MIN_VALUE} is returned. {@see DefaultConfigurator#getWeightFor}.
*
* @param descriptor the item to categorize.
*
* @return the category
* @return the weight
*/
@Nonnull
public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) {
@@ -71,15 +71,44 @@ public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) {
return weight;
}
}
throw new IllegalStateException("At least, must exist the category: " + ItemCategory.Default.class);
throw new IllegalStateException("At least, a default value must exist");
}

/**
* Provides the description for the requested item or null if this configurator doesn't have one.
*
* @param descriptor the item to categorize
*
* @return A {@link ItemCategory} or null
*/
@CheckForNull
protected abstract String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor);

/**
* Finds the weight specified by the first configurator.
* If none can be found a empty string is returned. {@see DefaultConfigurator#getDescriptionFor}.
*
* @param descriptor the item to categorize.
*
* @return A {@link ItemCategory}
*/
@Nonnull
public static String getDescription(@Nonnull TopLevelItemDescriptor descriptor) {
for (ItemCategoryConfigurator m : all()) {
String description = m.getDescriptionFor(descriptor);
if (description != null) {
return description;
}
}
throw new IllegalStateException("At least, a default value must exist");
}

public static Collection<ItemCategoryConfigurator> all() {
return ExtensionList.lookup(ItemCategoryConfigurator.class);
}

/**
* Mapper implementation with the lowest ordinal that simply returns {@link ItemCategory.Default}.
* Default configurator with the lowest ordinal that simply returns {@link ItemCategory.Default}.
*/
@Extension(ordinal = Integer.MIN_VALUE)
public static final class DefaultConfigurator extends ItemCategoryConfigurator {
@@ -96,5 +125,11 @@ public Integer getWeightFor(@Nonnull TopLevelItemDescriptor descriptor) {
return Integer.MIN_VALUE;
}

@Nonnull
@Override
public String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor) {
return "";
}

}
}

0 comments on commit 2356791

Please sign in to comment.