提交 75d748e6 编写于 作者: K Kohsuke Kawaguchi

Allowed Item to expose a status icon

上级 c662b147
/*
* The MIT License
*
* Copyright (c) 2010, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model;
/**
* Partial base class for {@link StatusIcon}.
*
* @author Kohsuke Kawaguchi
* @since 1.390
*/
public abstract class AbstractStatusIcon implements StatusIcon {
}
......@@ -23,9 +23,12 @@
*/
package hudson.model;
import hudson.Functions;
import hudson.util.ColorPalette;
import org.jvnet.localizer.LocaleProvider;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import java.awt.*;
import java.util.Locale;
......@@ -50,7 +53,7 @@ import java.util.Locale;
*
* @author Kohsuke Kawaguchi
*/
public enum BallColor {
public enum BallColor implements StatusIcon {
RED("red",Messages._BallColor_Failed(), ColorPalette.RED),
RED_ANIME("red_anime",Messages._BallColor_InProgress(), ColorPalette.RED),
YELLOW("yellow",Messages._BallColor_Unstable(), ColorPalette.YELLOW),
......@@ -86,6 +89,10 @@ public enum BallColor {
return image;
}
public String getImageOf(String size) {
return Stapler.getCurrentRequest().getContextPath()+'/'+Hudson.RESOURCE_PATH+'/'+size+'/'+image;
}
/**
* Gets the human-readable description used as img/@alt.
*/
......
/*
* The MIT License
*
* Copyright (c) 2010, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model;
/**
* {@link Item} can return this from the "getIconColor" method so that
* its "status icon" can be shown in Hudson UI.
*
* <p>
* For future compatibility, please extend from {@link AbstractStatusIcon}
* instead of implementing this directly, so that we can add methods later.
*
* <p>
* This is a generalization of {@link BallColor}.
*
* @author Kohsuke Kawaguchi
* @since 1.390
*/
public interface StatusIcon {
/**
* Returns the URL to the image.
*
* @param size
* The size specified. Must support "16x16", "24x24", and "32x32" at least.
* For forward compatibility, if you receive a size that's not supported,
* consider returning your biggest icon (and let the browser rescale.)
* @return
* The URL is rendered as is in the img @src attribute, so it must contain
* the context path, etc.
*/
String getImageOf(String size);
/**
* Gets the human-readable description used as img/@alt.
*/
String getDescription();
}
......@@ -24,8 +24,14 @@
package hudson.views;
import hudson.Extension;
import hudson.model.StatusIcon;
import org.kohsuke.stapler.DataBoundConstructor;
/**
* Shows the status icon for item. It's colored ball for jobs.
*
* @see StatusIcon
*/
public class StatusColumn extends ListViewColumn {
@DataBoundConstructor
public StatusColumn() {
......
......@@ -32,9 +32,9 @@ THE SOFTWARE.
</st:attribute>
</st:documentation>
<td data="${it.ordinal()}">
<j:if test="${it!=null}">
<img src="${imagesURL}/${iconSize}/${it.image}" alt="${it.description}"
<j:if test="${attrs.it!=null}">
<img src="${it.getImageOf(iconSize)}" alt="${it.description}"
tooltip="${it.description}" style="${attrs.style}"/>
</j:if>
</td>
</j:jelly>
\ No newline at end of file
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册