Skip to content

Commit

Permalink
Refactored default ListView Columns to be isntances of ListViewColumn.
Browse files Browse the repository at this point in the history
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16003 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
martinficker committed Mar 4, 2009
1 parent ff48fbf commit 6f5dafd
Show file tree
Hide file tree
Showing 135 changed files with 487 additions and 856 deletions.
58 changes: 55 additions & 3 deletions core/src/main/java/hudson/model/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -80,10 +100,25 @@ private Object readResolve() {
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) {
Expand All @@ -104,6 +139,23 @@ public List<Action> getActions() {
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.
Expand Down
33 changes: 33 additions & 0 deletions core/src/main/java/hudson/views/BuildButtonColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
31 changes: 31 additions & 0 deletions core/src/main/java/hudson/views/JobColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}

}
30 changes: 30 additions & 0 deletions core/src/main/java/hudson/views/LastDurationColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
30 changes: 30 additions & 0 deletions core/src/main/java/hudson/views/LastFailureColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
30 changes: 30 additions & 0 deletions core/src/main/java/hudson/views/LastSuccessColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/views/ListViewColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
* is called for each cell of this column. The {@link Item} object
* is passed in the "job" variable. The view should render
* the &lt;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()}),
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/hudson/views/StatusColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}

}
31 changes: 31 additions & 0 deletions core/src/main/java/hudson/views/WeatherColumn.java
Original file line number Diff line number Diff line change
@@ -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";
}
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Alan Harder, Eric Lefevre-Ardant
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

started_by_project=Lancé par le projet amont <a href="{3}/{2}">{0}</a> avec le numéro de build <a href="{3}/{2}{1}/">{1}</a>

started_by_project=
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Alan Harder, Eric Lefevre-Ardant
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

started_by_user=Lancé par l''utilisateur <a href="{1}/user/{0}">{0}</a>

started_by_user=
Loading

0 comments on commit 6f5dafd

Please sign in to comment.