提交 afb51092 编写于 作者: J jglick

[FIXED HUDSON-3465] Permit configurable column lists in views, and add optional Last Stable column.

Currently no columns have configurable data, but this can be added if desired (see issue report for demo).
API changes: type change in ListView.columns and getColumns; ListViewColumn.shownByDefault added.
[merged https://hudson.dev.java.net/svn/hudson/branches/configurable-view-columns-3465]


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17352 71c3de6d-444a-0410-be80-ed276b4c234a
上级 4c6e0b5c
......@@ -36,6 +36,7 @@ import hudson.views.StatusColumn;
import hudson.views.WeatherColumn;
import hudson.model.Descriptor.FormException;
import hudson.util.CaseInsensitiveComparator;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import org.kohsuke.stapler.StaplerRequest;
......@@ -49,7 +50,10 @@ import java.util.List;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
......@@ -59,12 +63,17 @@ import java.util.regex.PatternSyntaxException;
* @author Kohsuke Kawaguchi
*/
public class ListView extends View {
private static final Saveable NO_SAVABLE = new Saveable() {
public void save() throws IOException {}
};
/**
* List of job names. This is what gets serialized.
*/
/*package*/ final SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
protected transient List<ListViewColumn> columns = new ArrayList<ListViewColumn>();
private DescribableList<ListViewColumn, Descriptor<ListViewColumn>> columns;
// First add all the known instances in the correct order:
private static final Descriptor [] defaultColumnDescriptors = {
......@@ -101,6 +110,11 @@ public class ListView extends View {
}
protected void initColumns() {
if (columns != null) {
// already persisted
return;
}
// OK, set up default list of columns:
// create all instances
ArrayList<ListViewColumn> r = new ArrayList<ListViewColumn>();
DescriptorExtensionList<ListViewColumn, Descriptor<ListViewColumn>> all = ListViewColumn.all();
......@@ -124,7 +138,18 @@ public class ListView extends View {
} catch (FormException e) {
// so far impossible. TODO: report
}
columns = Collections.unmodifiableList(r);
Iterator<ListViewColumn> filter = r.iterator();
while (filter.hasNext()) {
if (!filter.next().shownByDefault()) {
filter.remove();
}
}
columns = new DescribableList<ListViewColumn, Descriptor<ListViewColumn>>(NO_SAVABLE);
try {
columns.replaceBy(r);
} catch (IOException ex) {
Logger.getLogger(ListView.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
......@@ -137,7 +162,7 @@ public class ListView extends View {
return Hudson.getInstance().getActions();
}
public List<ListViewColumn> getColumns() {
public Iterable<ListViewColumn> getColumns() {
return columns;
}
......@@ -215,7 +240,7 @@ public class ListView extends View {
* Load view-specific properties here.
*/
@Override
protected void submit(StaplerRequest req) {
protected void submit(StaplerRequest req) throws ServletException, FormException {
jobNames.clear();
for (TopLevelItem item : Hudson.getInstance().getItems()) {
if(req.getParameter(item.getName())!=null)
......@@ -229,6 +254,11 @@ public class ListView extends View {
includeRegex = null;
includePattern = null;
}
if (columns == null) {
columns = new DescribableList<ListViewColumn,Descriptor<ListViewColumn>>(NO_SAVABLE);
}
columns.rebuildHetero(req, req.getSubmittedForm(), Hudson.getInstance().getDescriptorList(ListViewColumn.class), "columns");
}
@Extension
......
/*
* The MIT License
*
* Copyright (c) 2009, Sun Microsystems, Inc., Jesse Glick
*
* 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.
*/
package hudson.views;
import hudson.Extension;
import hudson.model.Descriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
public class LastStableColumn extends ListViewColumn {
@Override
public boolean shownByDefault() {
return false;
}
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 {
return new LastStableColumn();
}
@Override
public String getDisplayName() {
return "Last Stable";
}
}
}
......@@ -48,11 +48,6 @@ import org.kohsuke.stapler.export.Exported;
* <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()}),
* but the intention is eventually make each {@link ListViewColumn} fully configurable
* like {@link Publisher}.
*
* @author Kohsuke Kawaguchi
* @since 1.279
......@@ -83,4 +78,13 @@ public abstract class ListViewColumn implements ExtensionPoint, Describable<List
*/
public static final DescriptorList<ListViewColumn> LIST = new DescriptorList<ListViewColumn>(ListViewColumn.class);
/**
* Whether this column will be shown by default.
* The default implementation is true.
* @since 1.301
*/
public boolean shownByDefault() {
return true;
}
}
......@@ -40,4 +40,15 @@ THE SOFTWARE.
<f:textbox name="includeRegex" field="includeRegex" />
</f:entry>
</f:optionalBlock>
</j:jelly>
\ No newline at end of file
<f:section title="${%Columns}">
<j:invokeStatic var="allColumns" className="hudson.views.ListViewColumn" method="all"/>
<f:block>
<f:hetero-list name="columns" hasHeader="true"
descriptors="${allColumns}"
items="${it.columns}"
addCaption="${%Add column}"/>
</f:block>
</f:section>
</j:jelly>
<!--
The MIT License
Copyright (c) 2009, Sun Microsystems, Inc., Jesse Glick
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.
-->
<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">
<j:set var="lstBuild" value="${job.lastStableBuild}"/>
<td data="${lstBuild.timestampString2 ?: '-'}">
<j:choose>
<j:when test="${lstBuild!=null}">
${lstBuild.timestampString}
(<a href="${jobBaseUrl}${job.shortUrl}lastStableBuild/">#${lstBuild.number}</a>)
</j:when>
<j:otherwise>
${%N/A}
</j:otherwise>
</j:choose>
</td>
</j:jelly>
<!--
The MIT License
Copyright (c) 2009, Sun Microsystems, Inc., Jesse Glick
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.
-->
<j:jelly xmlns:j="jelly:core">
<th>${%Last Stable}</th>
</j:jelly>
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Jesse Glick
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.
-->
<!-- Columns normally have nothing to configure. -->
<j:jelly xmlns:j="jelly:core"/>
......@@ -43,7 +43,7 @@ THE SOFTWARE.
<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:local="local">
<d:taglib uri="local">
<d:tag name="body">
<table>
<table style="width:100%">
<j:set var="help" value="${descriptor.helpFile}" />
<j:if test="${hasHeader}">
<tr>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册