diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index e37f9a79adf1e898b5d806c8a4995349b02a6dfd..f52f1896c002b33ae22601fd145e59cb734a99e0 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -148,7 +148,7 @@ import javax.servlet.RequestDispatcher; * * @author Kohsuke Kawaguchi */ -public final class Hudson extends View implements ItemGroup, Node, StaplerProxy { +public final class Hudson extends View implements ItemGroup, Node, StaplerProxy, ViewGroup { private transient final Queue queue; /** @@ -847,20 +847,18 @@ public final class Hudson extends View implements ItemGroup, Node, * Gets the read-only list of all {@link View}s. */ @Exported - public synchronized View[] getViews() { + public synchronized Collection getViews() { if(views==null) - views = new ArrayList(); - - View[] r = new View[views.size()+1]; - views.toArray(r); - // sort Views and put "all" at the very beginning - r[r.length-1] = r[0]; - Arrays.sort(r,1,r.length, View.SORTER); - r[0] = this; - return r; + return Collections.singletonList(this); + + List copy = new ArrayList(views.size()+1); + copy.add(this); + copy.addAll(views); + Collections.sort(copy, View.SORTER); + return copy; } - public synchronized void deleteView(ListView view) throws IOException { + public synchronized void deleteView(View view) throws IOException { if(views!=null) { views.remove(view); save(); @@ -1894,6 +1892,7 @@ public final class Hudson extends View implements ItemGroup, Node, // create a view View v = View.LIST.findByName(mode).newInstance(req,req.getSubmittedForm()); + v.owner = this; if(views==null) views = new Vector(); views.add(v); diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index c0e155d2900954587816c29b4e1be6deffaa9082..2b7d69ebaa4897f32d8cc065a5ae131eff4fee94 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -37,11 +37,6 @@ public class ListView extends View { */ private String name; - /** - * Message displayed in the view page. - */ - private String description; - /** * Include regex string. */ @@ -58,14 +53,6 @@ public class ListView extends View { this.owner = Hudson.getInstance(); } - /** - * Returns the transient {@link Action}s associated with the top page. - * - * @see Hudson#getActions() - */ - public List getActions() { - return Hudson.getInstance().getActions(); - } /** * Returns a read-only view of all {@link Job}s in this view. @@ -118,10 +105,6 @@ public class ListView extends View { return name; } - public String getDescription() { - return description; - } - public String getIncludeRegex() { return includeRegex; } @@ -183,28 +166,6 @@ public class ListView extends View { rsp.sendRedirect2("../"+name); } - /** - * Accepts the new description. - */ - public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { - checkPermission(CONFIGURE); - - req.setCharacterEncoding("UTF-8"); - description = req.getParameter("description"); - owner.save(); - rsp.sendRedirect("."); // go to the top page - } - - /** - * Deletes this view. - */ - public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { - checkPermission(DELETE); - - owner.deleteView(this); - rsp.sendRedirect2(req.getContextPath()+"/"); - } - /** * Checks if the include regular expression is valid. */ diff --git a/core/src/main/java/hudson/model/MyView.java b/core/src/main/java/hudson/model/MyView.java index 36fb7f6a7e29060b37f7c0039952906fb3293b3e..7b47523e45c32cc6d57b6d48252d561ad22858b3 100644 --- a/core/src/main/java/hudson/model/MyView.java +++ b/core/src/main/java/hudson/model/MyView.java @@ -21,7 +21,6 @@ import org.kohsuke.stapler.DataBoundConstructor; public class MyView extends View { private String name; private final Hudson owner; - private String description; @DataBoundConstructor public MyView(String name) { @@ -40,20 +39,6 @@ public class MyView extends View { return owner.doCreateItem(req, rsp); } - @Override - public String getDescription() { - return description; - } - - /** - * Returns the transient {@link Action}s associated with the top page. - * - * @see Hudson#getActions() - */ - public List getActions() { - return Hudson.getInstance().getActions(); - } - @Override public TopLevelItem getItem(String name) { return owner.getItem(name); @@ -94,18 +79,6 @@ public class MyView extends View { return getItem(name); } - /** - * Accepts the new description. - */ - public synchronized void doSubmitDescription(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { - checkPermission(CONFIGURE); - - req.setCharacterEncoding("UTF-8"); - description = req.getParameter("description"); - owner.save(); - rsp.sendRedirect("."); // go to the top page - } - public ViewDescriptor getDescriptor() { return DESCRIPTOR; } diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 58f6de61c85dfaf8fce048f096f4d8fd61861be0..e75a57d9d209b3e081736014e4bd3d4c9edf42fb 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -47,6 +47,16 @@ import java.util.Map; */ @ExportedBean public abstract class View extends AbstractModelObject implements AccessControlled, Describable, ExtensionPoint { + /** + * Container of this view. Set right after the construction + * and never change thereafter. + */ + protected /*final*/ ViewGroup owner; + + /** + * Message displayed in the view page. + */ + protected String description; /** * Gets all the items in this collection in a read-only view. @@ -74,7 +84,9 @@ public abstract class View extends AbstractModelObject implements AccessControll * Message displayed in the top page. Can be null. Includes HTML. */ @Exported - public abstract String getDescription(); + public String getDescription() { + return description; + } public abstract ViewDescriptor getDescriptor(); @@ -94,6 +106,19 @@ public abstract class View extends AbstractModelObject implements AccessControll return getUrl(); } + /** + * Returns the transient {@link Action}s associated with the top page. + * + *

+ * If views don't want to show top-level actions, this method + * can be overridden to return different objects. + * + * @see Hudson#getActions() + */ + public List getActions() { + return Hudson.getInstance().getActions(); + } + /** * Gets the absolute URL of this view. */ @@ -301,6 +326,29 @@ public abstract class View extends AbstractModelObject implements AccessControll }); } + /** + * Accepts the new description. + */ + public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { + checkPermission(CONFIGURE); + + req.setCharacterEncoding("UTF-8"); + description = req.getParameter("description"); + owner.save(); + rsp.sendRedirect("."); // go to the top page + } + + /** + * Deletes this view. + */ + public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { + checkPermission(DELETE); + + owner.deleteView(this); + rsp.sendRedirect2(req.getContextPath()+"/"); + } + + /** * Creates a new {@link Item} in this collection. * diff --git a/core/src/main/java/hudson/model/ViewGroup.java b/core/src/main/java/hudson/model/ViewGroup.java new file mode 100644 index 0000000000000000000000000000000000000000..34cfeb829176a69f3dfab5a7915e1aade1c300c6 --- /dev/null +++ b/core/src/main/java/hudson/model/ViewGroup.java @@ -0,0 +1,40 @@ +package hudson.model; + +import java.io.IOException; +import java.util.Collection; + +/** + * Container of {@link View}s. + * + *

STILL EXPERIMENTAL: DO NOT IMPLEMENT

+ * + * @author Kohsuke Kawaguchi + * @since 1.269 + */ +public interface ViewGroup extends Saveable, ModelObject { + /** + * Deletes a view in this group. + */ + void deleteView(View view) throws IOException; + + /** + * Gets all the views in this group. + * + * @return + * can be empty but never null. + */ + Collection getViews(); + + /** + * Gets a view of the given name. + * + * This also creates the URL binding for views (in the form of ".../view/FOOBAR/..." + */ + View getView(String name); + + /** + * Returns the path of this group, relative to the context root, + * like "foo/bar/zot/". Note no leading slash but trailing slash. + */ + String getUrl(); +} diff --git a/core/src/main/resources/hudson/model/MyView/sidepanel2.jelly b/core/src/main/resources/hudson/model/MyView/sidepanel2.jelly new file mode 100644 index 0000000000000000000000000000000000000000..133c3ca9270f4426d9c3482dfdc389134fbf677f --- /dev/null +++ b/core/src/main/resources/hudson/model/MyView/sidepanel2.jelly @@ -0,0 +1,4 @@ + + + + diff --git a/core/src/main/resources/hudson/model/ListView/delete.jelly b/core/src/main/resources/hudson/model/View/delete.jelly similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete.jelly rename to core/src/main/resources/hudson/model/View/delete.jelly diff --git a/core/src/main/resources/hudson/model/ListView/delete_de.properties b/core/src/main/resources/hudson/model/View/delete_de.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_de.properties rename to core/src/main/resources/hudson/model/View/delete_de.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_fr.properties b/core/src/main/resources/hudson/model/View/delete_fr.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_fr.properties rename to core/src/main/resources/hudson/model/View/delete_fr.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_ja.properties b/core/src/main/resources/hudson/model/View/delete_ja.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_ja.properties rename to core/src/main/resources/hudson/model/View/delete_ja.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_nl.properties b/core/src/main/resources/hudson/model/View/delete_nl.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_nl.properties rename to core/src/main/resources/hudson/model/View/delete_nl.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_pt_BR.properties b/core/src/main/resources/hudson/model/View/delete_pt_BR.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_pt_BR.properties rename to core/src/main/resources/hudson/model/View/delete_pt_BR.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_ru.properties b/core/src/main/resources/hudson/model/View/delete_ru.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_ru.properties rename to core/src/main/resources/hudson/model/View/delete_ru.properties diff --git a/core/src/main/resources/hudson/model/ListView/delete_tr.properties b/core/src/main/resources/hudson/model/View/delete_tr.properties similarity index 100% rename from core/src/main/resources/hudson/model/ListView/delete_tr.properties rename to core/src/main/resources/hudson/model/View/delete_tr.properties