[FIXED JENKINS-17715] Display Name is not shown

This commit is contained in:
ssogabe committed 2013-04-30 20:49:58 +09:00
1 parent d477296ffd
commit 55a68acca9
4 files changed
+103 -37

No files matched your search

+62 -4
View File
@@ -974,6 +974,67 @@ public class Functions {
return Items.getAllItems(root, TopLevelItem.class);
}
/**
* Gets the relative name or display name to the given item from the specified group.
*
* @since 1.515
* @param p the Item we want the relative display name
* @param g the ItemGroup used as point of reference for the item
* @param useDisplayName if true, returns a display name, otherwise returns a name
* @return
* String like "foo » bar"
*/
public static String getRelativeNameFrom(Item p, ItemGroup g, boolean useDisplayName) {
if (p == null) return null;
if (g == null) return useDisplayName ? p.getFullDisplayName() : p.getFullName();
String separationString = useDisplayName ? " » " : "/";
// first list up all the parents
Map<ItemGroup,Integer> parents = new HashMap<ItemGroup,Integer>();
int depth=0;
while (g!=null) {
parents.put(g, depth++);
if (g instanceof Item)
g = ((Item)g).getParent();
else
g = null;
}
StringBuilder buf = new StringBuilder();
Item i=p;
while (true) {
if (buf.length()>0) buf.insert(0,separationString);
buf.insert(0,useDisplayName ? i.getDisplayName() : i.getName());
ItemGroup gr = i.getParent();
Integer d = parents.get(gr);
if (d!=null) {
String s="";
for (int j=d; j>0; j--)
s+=".." + separationString;
return s+buf;
}
if (gr instanceof Item)
i = (Item)gr;
else
return null;
}
}
/**
* Gets the name to the given item relative to given group.
*
* @since 1.515
* @param p the Item we want the relative display name
* @param g the ItemGroup used as point of reference for the item
* @return
* String like "foo » bar"
*/
public static String getRelativeNameFrom(Item p, ItemGroup g) {
return getRelativeNameFrom(p, g, false);
}
/**
* Gets the relative display name to the given item from the specified group.
@@ -985,10 +1046,7 @@ public class Functions {
* String like "foo » bar"
*/
public static String getRelativeDisplayNameFrom(Item p, ItemGroup g) {
if (p == null) return null;
String relativeName = p.getRelativeNameFrom(g);
if (relativeName == null) return null;
return relativeName.replace("/", " » ");
return getRelativeNameFrom(p, g, true);
}
public static Map<Thread,StackTraceElement[]> dumpAllThreads() {
@@ -327,6 +327,18 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
else return n+" \u00BB "+getDisplayName();
}
/**
* Gets the display name of the current item relative to the given group.
*
* @since XXX
* @param p the ItemGroup used as point of reference for the item
* @return
* String like "foo » bar"
*/
public String getRelativeDisplayNameFrom(ItemGroup p) {
return Functions.getRelativeDisplayNameFrom(this, p);
}
/**
* This method only exists to disambiguate {@link #getRelativeNameFrom(ItemGroup)} and {@link #getRelativeNameFrom(Item)}
* @since 1.512
@@ -344,38 +356,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
* Nested ItemGroups are separated by / character.
*/
public String getRelativeNameFrom(ItemGroup p) {
if (p == null) return getFullName();
// first list up all the parents
Map<ItemGroup,Integer> parents = new HashMap<ItemGroup,Integer>();
int depth=0;
while (p!=null) {
parents.put(p, depth++);
if (p instanceof Item)
p = ((Item)p).getParent();
else
p = null;
}
StringBuilder buf = new StringBuilder();
Item i=this;
while (true) {
if (buf.length()>0) buf.insert(0,'/');
buf.insert(0,i.getName());
ItemGroup g = i.getParent();
Integer d = parents.get(g);
if (d!=null) {
String s="";
for (int j=d; j>0; j--)
s+="../";
return s+buf;
}
if (g instanceof Item)
i = (Item)g;
else
return null;
}
return Functions.getRelativeNameFrom(this, p);
}
public String getRelativeNameFrom(Item item) {