diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index a747cc39e4aa8a807f15a1526d0b105a9ad21d22..71fecaa5353e772db1ef4c441c4961acbf163939 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -469,6 +469,16 @@ public final class Hudson extends View implements ItemGroup, 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, 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, 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, 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, Node, if(views!=null) { for (View v : views) - v.onJobChange(job, oldName, newName); + v.onJobRenamed(job, oldName, newName); save(); } } diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index ba3ea0ab9ad8d7449270c05935f2075fe53ca734..77e44a7b0c1decdc8d60ee812b1f77dbf048bbbc 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -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; diff --git a/core/src/main/java/hudson/model/MyView.java b/core/src/main/java/hudson/model/MyView.java index 99e1b5e52dc0f60867b7bea69f94f04277a40dd4..fc91b176010874b1d3a1af3b654b235d32b3bea2 100644 --- a/core/src/main/java/hudson/model/MyView.java +++ b/core/src/main/java/hudson/model/MyView.java @@ -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 } diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 5fcc85db287db845401f26223b13d7fe669b6a4c..a6774edfca031954c0bb8d4791ff45edec44f397 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -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 { diff --git a/core/src/main/java/hudson/model/ViewGroup.java b/core/src/main/java/hudson/model/ViewGroup.java index 19928d7e98083e67b33d991b1bef369171667d9a..2de0bae69f6466d2bfa66c016272a13156ce9afe 100644 --- a/core/src/main/java/hudson/model/ViewGroup.java +++ b/core/src/main/java/hudson/model/ViewGroup.java @@ -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.) + * + *

+ * 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); }