mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
Refactored default ListView Columns to be isntances of ListViewColumn.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16003 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
ff48fbf976
commit
6f5dafd343
135 files changed
+487
-856
No files matched your search
@@ -23,9 +23,18 @@
|
||||
*/
|
||||
package hudson.model;
|
||||
|
||||
import hudson.DescriptorExtensionList;
|
||||
import hudson.Util;
|
||||
import hudson.Extension;
|
||||
import hudson.views.BuildButtonColumn;
|
||||
import hudson.views.JobColumn;
|
||||
import hudson.views.LastDurationColumn;
|
||||
import hudson.views.LastFailureColumn;
|
||||
import hudson.views.LastSuccessColumn;
|
||||
import hudson.views.ListViewColumn;
|
||||
import hudson.views.StatusColumn;
|
||||
import hudson.views.WeatherColumn;
|
||||
import hudson.views.StatusColumn.DescriptorImpl;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.util.CaseInsensitiveComparator;
|
||||
import hudson.util.FormFieldValidator;
|
||||
@@ -55,7 +64,18 @@ public class ListView extends View {
|
||||
*/
|
||||
/*package*/ final Set<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
|
||||
|
||||
private transient List<ListViewColumn> columns = new ArrayList<ListViewColumn>();
|
||||
protected transient List<ListViewColumn> columns = new ArrayList<ListViewColumn>();
|
||||
|
||||
// First add all the known instances in the correct order:
|
||||
private static final Descriptor [] defaultColumnDescriptors = {
|
||||
StatusColumn.DESCRIPTOR,
|
||||
WeatherColumn.DESCRIPTOR,
|
||||
JobColumn.DESCRIPTOR,
|
||||
LastSuccessColumn.DESCRIPTOR,
|
||||
LastFailureColumn.DESCRIPTOR,
|
||||
LastDurationColumn.DESCRIPTOR,
|
||||
BuildButtonColumn.DESCRIPTOR
|
||||
};
|
||||
|
||||
/**
|
||||
* Include regex string.
|
||||
@@ -80,10 +100,25 @@ public class ListView extends View {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initColumns() {
|
||||
protected void initColumns() {
|
||||
// create all instances
|
||||
ArrayList<ListViewColumn> r = new ArrayList<ListViewColumn>();
|
||||
for (Descriptor<ListViewColumn> d : ListViewColumn.all())
|
||||
DescriptorExtensionList<ListViewColumn, Descriptor<ListViewColumn>> all = ListViewColumn.all();
|
||||
ArrayList <Descriptor<ListViewColumn>>left = new ArrayList();
|
||||
left.addAll(all);
|
||||
for (Descriptor d: defaultColumnDescriptors) {
|
||||
Descriptor<ListViewColumn> des = all.find(d.getClass().getName());
|
||||
if (des != null) {
|
||||
try {
|
||||
r.add (des.newInstance(null, null));
|
||||
left.remove(des);
|
||||
} catch (FormException e) {
|
||||
// so far impossible. TODO: report
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
for (Descriptor<ListViewColumn> d : left)
|
||||
try {
|
||||
r.add(d.newInstance(null,null));
|
||||
} catch (FormException e) {
|
||||
@@ -104,6 +139,23 @@ public class ListView extends View {
|
||||
public List<ListViewColumn> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public static List<ListViewColumn> getDefaultColumns() {
|
||||
ArrayList<ListViewColumn> r = new ArrayList<ListViewColumn>();
|
||||
DescriptorExtensionList<ListViewColumn, Descriptor<ListViewColumn>> all = ListViewColumn.all();
|
||||
for (Descriptor d: defaultColumnDescriptors) {
|
||||
Descriptor<ListViewColumn> des = all.find(d.getClass().getName());
|
||||
if (des != null) {
|
||||
try {
|
||||
r.add (des.newInstance(null, null));
|
||||
} catch (FormException e) {
|
||||
// so far impossible. TODO: report
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a read-only view of all {@link Job}s in this view.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package hudson.views;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.views.StatusColumn.DescriptorImpl;
|
||||
|
||||
public class BuildButtonColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be called with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new BuildButtonColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Build Button";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package hudson.views;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
public class JobColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be calles with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new JobColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Job";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package hudson.views;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
public class LastDurationColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be called with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new LastDurationColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Status";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package hudson.views;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
public class LastFailureColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be called with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new LastFailureColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Status";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package hudson.views;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
public class LastSuccessColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be called with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new LastSuccessColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Last Success";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,9 @@ import org.kohsuke.stapler.export.Exported;
|
||||
* is called for each cell of this column. The {@link Item} object
|
||||
* is passed in the "job" variable. The view should render
|
||||
* the <td> tag.
|
||||
*
|
||||
* <p>
|
||||
* This object may have an additional <tt>columHeader.jelly</tt>. The default ColmnHeader
|
||||
* will render ColumnCaption.
|
||||
* <p>
|
||||
* For now, {@link ListView} doesn't allow {@link ListViewColumn}s to be configured
|
||||
* (instead it just shows all the columns available in {@link #all()}),
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package hudson.views;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
|
||||
public class StatusColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be called with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new StatusColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Status";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package hudson.views;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Descriptor;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
public class WeatherColumn extends ListViewColumn {
|
||||
|
||||
public Descriptor<ListViewColumn> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<ListViewColumn> {
|
||||
@Override
|
||||
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
// This will be calles with req == null also the Descriptor's doc tells you not. so the default impl fails
|
||||
return new WeatherColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Weather";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user