Skip to content

Commit

Permalink
[JENKINS-38960 Follow-up] Make the IconSpec API for FolderIcon more …
Browse files Browse the repository at this point in the history
…reusable
  • Loading branch information
stephenc committed Oct 18, 2016
1 parent 3573f74 commit 9c718a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main/java/com/cloudbees/hudson/plugins/folder/FolderIcon.java
Expand Up @@ -30,6 +30,7 @@
import hudson.model.StatusIcon;
import jenkins.model.Jenkins;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
Expand Down Expand Up @@ -62,22 +63,25 @@ public String getIconClassName() {
}

protected String iconClassNameImageOf(String size) {
String spec = null;
if ("16x16".equals(size)) {
spec = "icon-sm";
} else if ("24x24".equals(size)) {
spec = "icon-md";
} else if ("32x32".equals(size)) {
spec = "icon-lg";
} else if ("48x48".equals(size)) {
spec = "icon-xlg";
}
if (spec != null) {
Icon icon = IconSet.icons.getIconByClassSpec("icon-folder " + spec);
if (icon != null) {
JellyContext ctx = new JellyContext();
ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
String iconClassName = getIconClassName();
if (StringUtils.isNotBlank(iconClassName)) {
String spec = null;
if ("16x16".equals(size)) {
spec = "icon-sm";
} else if ("24x24".equals(size)) {
spec = "icon-md";
} else if ("32x32".equals(size)) {
spec = "icon-lg";
} else if ("48x48".equals(size)) {
spec = "icon-xlg";
}
if (spec != null) {
Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " " + spec);
if (icon != null) {
JellyContext ctx = new JellyContext();
ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
}
}
}
return null;
Expand Down
Expand Up @@ -43,6 +43,11 @@ public class StockFolderIcon extends FolderIcon {
public StockFolderIcon() {
}

@Override
public String getIconClassName() {
return "icon-folder";
}

public String getImageOf(String size) {
String image = iconClassNameImageOf(size);
return image != null
Expand Down

0 comments on commit 9c718a0

Please sign in to comment.