Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-31162] A new API was added to handle Item icons
  • Loading branch information
recena committed Mar 16, 2016
1 parent 467ab3a commit 602eca7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/ItemGroupMixIn.java
Expand Up @@ -354,6 +354,7 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
metadata.put("displayName", descriptor.getDisplayName());
metadata.put("description", ItemCategoryConfigurator.getDescription(descriptor));
metadata.put("iconFilePathPattern", ItemCategoryConfigurator.getIconFilePathPattern(descriptor));

Category category = categories.getItem(ic.getId());
if (category != null) {
Expand Down
Expand Up @@ -19,7 +19,7 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint {
/**
* Provides the category for the requested item or null if this mapper doesn't have one.
*
* @param descriptor the item to categorize
* @param descriptor the item it is asking about.
*
* @return A {@link ItemCategory} or null
*/
Expand All @@ -30,7 +30,7 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint {
* Finds the category specified by the first configurator.
* If none can be found {@link ItemCategory.UncategorizedCategory} is returned.
*
* @param descriptor the item to categorize.
* @param descriptor the item it is asking about.
*
* @return A {@link ItemCategory}
*/
Expand All @@ -48,7 +48,7 @@ public static ItemCategory getCategory(@Nonnull TopLevelItemDescriptor descripto
/**
* Provides the weight for the requested item. Helpful to order a list.
*
* @param descriptor the item to categorize
* @param descriptor the item it is asking about.
*
* @return the weight or null
*/
Expand All @@ -59,7 +59,7 @@ public static ItemCategory getCategory(@Nonnull TopLevelItemDescriptor descripto
* 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.
* @param descriptor the item it is asking about.
*
* @return the weight
*/
Expand All @@ -77,7 +77,7 @@ public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) {
/**
* Provides the description for the requested item or null if this configurator doesn't have one.
*
* @param descriptor the item to categorize
* @param descriptor the item it is asking about.
*
* @return A {@link ItemCategory} or null
*/
Expand All @@ -88,7 +88,7 @@ public static Integer getWeight(@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.
* @param descriptor the item it is asking about.
*
* @return A {@link ItemCategory}
*/
Expand All @@ -106,7 +106,7 @@ public static String getDescription(@Nonnull TopLevelItemDescriptor descriptor)
/**
* Provides the effective clazz for the requested item or null if this configurator doesn't have one.
*
* @param descriptor the item to categorize
* @param descriptor the item it is asking about.
*
* @return A string or null
*/
Expand All @@ -117,9 +117,9 @@ public static String getDescription(@Nonnull TopLevelItemDescriptor descriptor)
* Finds the effective clazz specified by the first configurator.
* If none can be found a empty string with {@code descriptor.clazz.getName();} is returned. {@see DefaultConfigurator#getEffectiveClazzFor}.
*
* @param descriptor the item to categorize.
* @param descriptor the item it is asking about.
*
* @return A {@link ItemCategory}
* @return A string
*/
@Nonnull
public static String getEffectiveClazz(@Nonnull TopLevelItemDescriptor descriptor) {
Expand All @@ -132,6 +132,37 @@ public static String getEffectiveClazz(@Nonnull TopLevelItemDescriptor descripto
throw new IllegalStateException("At least, a default value must exist for clazz field");
}

/**
* Provides the icon path pattern for the requested item or null if this configurator doesn't have one.
* For example: /plugin/shortnme-of-myplugin/icons/item/:size:/myitem.pngm where :size should be replaced by the consumer using
* the standard sizes in Jenkins: 16x16, 24x24, etc...
*
* @param descriptor the item it is asking about.
*
* @return A string or null
*/
@CheckForNull
protected abstract String getIconFilePathPatternFor(@Nonnull TopLevelItemDescriptor descriptor);

/**
* Finds the icon path pattern specified by the first configurator.
* If none can be found a empty string is returned. {@see DefaultConfigurator#getIconFilePathFor}.
*
* @param descriptor the item it is asking about.
*
* @return A string
*/
@Nonnull
public static String getIconFilePathPattern(@Nonnull TopLevelItemDescriptor descriptor) {
for (ItemCategoryConfigurator m : all()) {
String path = m.getIconFilePathPatternFor(descriptor);
if (path != null) {
return path;
}
}
throw new IllegalStateException("At least, a default value must exist for icon path pattern");
}

public static Collection<ItemCategoryConfigurator> all() {
return ExtensionList.lookup(ItemCategoryConfigurator.class);
}
Expand Down Expand Up @@ -165,5 +196,12 @@ public String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor) {
public String getEffectiveClazzFor(@Nonnull TopLevelItemDescriptor descriptor) {
return descriptor.clazz.getName();
}

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

}
}

0 comments on commit 602eca7

Please sign in to comment.