提交 57e4bacb 编写于 作者: K kohsuke

[HUDSON-232] Shuffling methods around to make way for nestable views.

I changed the signature of getViews() in this change. Grep indicates that no current plugins are using this method.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13958 71c3de6d-444a-0410-be80-ed276b4c234a
上级 469bfbf4
......@@ -148,7 +148,7 @@ import javax.servlet.RequestDispatcher;
*
* @author Kohsuke Kawaguchi
*/
public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node, StaplerProxy {
public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node, StaplerProxy, ViewGroup {
private transient final Queue queue;
/**
......@@ -847,20 +847,18 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
* Gets the read-only list of all {@link View}s.
*/
@Exported
public synchronized View[] getViews() {
public synchronized Collection<View> getViews() {
if(views==null)
views = new ArrayList<View>();
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.<View>singletonList(this);
List<View> copy = new ArrayList<View>(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<TopLevelItem>, Node,
// create a view
View v = View.LIST.findByName(mode).newInstance(req,req.getSubmittedForm());
v.owner = this;
if(views==null)
views = new Vector<View>();
views.add(v);
......
......@@ -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<Action> 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.
*/
......
......@@ -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<Action> 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;
}
......
......@@ -47,6 +47,16 @@ import java.util.Map;
*/
@ExportedBean
public abstract class View extends AbstractModelObject implements AccessControlled, Describable<View>, 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.
*
* <p>
* If views don't want to show top-level actions, this method
* can be overridden to return different objects.
*
* @see Hudson#getActions()
*/
public List<Action> 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.
*
......
package hudson.model;
import java.io.IOException;
import java.util.Collection;
/**
* Container of {@link View}s.
*
* <h2>STILL EXPERIMENTAL: DO NOT IMPLEMENT</h2>
*
* @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<View> 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();
}
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:task icon="images/24x24/edit-delete.gif" href="delete" title="${%Delete View}" permission="${it.CONFIGURE}" />
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册