提交 0050fb0e 编写于 作者: K kohsuke

added the view rename method.

onItemChange -> onItemRenamed for consistency

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13963 71c3de6d-444a-0410-be80-ed276b4c234a
上级 aedf6652
......@@ -469,6 +469,16 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
return secretKey;
}
/**
* @deprecated
* {@link Hudson} can't be renamed unlike a regular view.
*/
@Override
public void rename(String newName) throws ParseException {
throw new UnsupportedOperationException();
}
/**
* Gets the SCM descriptor by name. Primarily used for making them web-visible.
*/
......@@ -1017,6 +1027,10 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
return "";
}
public void onViewRenamed(View view, String oldName, String newName) {
// implementation of Hudson is immune to view name change.
}
@Override
public SearchIndexBuilder makeSearchIndex() {
return super.makeSearchIndex()
......@@ -1180,7 +1194,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
}
@Override
public void onJobChange(Item item, String oldName, String newName) {
public void onJobRenamed(Item item, String oldName, String newName) {
// noop
}
......@@ -1329,7 +1343,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
items.remove(item.getName());
if(views!=null) {
for (View v : views)
v.onJobChange(item, item.getName(), null);
v.onJobRenamed(item, item.getName(), null);
save();
}
}
......@@ -1344,7 +1358,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
if(views!=null) {
for (View v : views)
v.onJobChange(job, oldName, newName);
v.onJobRenamed(job, oldName, newName);
save();
}
}
......
......@@ -110,7 +110,7 @@ public class ListView extends View {
}
@Override
public synchronized void onJobChange(Item item, String oldName, String newName) {
public synchronized void onJobRenamed(Item item, String oldName, String newName) {
jobNames.remove(oldName);
if(newName!=null)
jobNames.add(newName);
......@@ -140,9 +140,7 @@ public class ListView extends View {
includePattern = null;
try {
String n = req.getParameter("name");
Hudson.checkGoodName(n);
name = n;
rename(req.getParameter("name"));
} catch (ParseException e) {
sendError(e, req, rsp);
return;
......
......@@ -60,7 +60,7 @@ public class MyView extends View {
}
@Override
public void onJobChange(Item item, String oldName, String newName) {
public void onJobRenamed(Item item, String oldName, String newName) {
// noop
}
......
......@@ -28,6 +28,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
/**
* Encapsulates the rendering of the list of {@link TopLevelItem}s
......@@ -89,12 +90,24 @@ public abstract class View extends AbstractModelObject implements AccessControll
/**
* Gets the name of all this collection.
*
* @see #rename(String)
*/
@Exported(visibility=2,name="name")
public String getViewName() {
return name;
}
/**
* Renames this view.
*/
public void rename(String newName) throws ParseException {
Hudson.checkGoodName(newName);
String oldName = name;
name = newName;
owner.onViewRenamed(this,oldName,newName);
}
/**
* Message displayed in the top page. Can be null. Includes HTML.
*/
......@@ -187,7 +200,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
* @param newName
* New name of the item, if the item is renamed. Or null, if the item is removed.
*/
public abstract void onJobChange(Item item, String oldName, String newName);
public abstract void onJobRenamed(Item item, String oldName, String newName);
@ExportedBean(defaultVisibility=2)
public static final class UserInfo implements Comparable<UserInfo> {
......
......@@ -37,4 +37,15 @@ public interface ViewGroup extends Saveable, ModelObject {
* like "foo/bar/zot/". Note no leading slash but trailing slash.
*/
String getUrl();
/**
* {@link View} calls this method when it's renamed.
* This method is intended to work as a notification to the {@link ViewGroup}
* (so that it can adjust its internal data structure, for example.)
*
* <p>
* It is the caller's responsibility to ensure that the new name is a
* {@linkplain Hudson#checkGoodName(String) legal view name}.
*/
void onViewRenamed(View view, String oldName, String newName);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册