From afb51092666a9f2ea07c19b6ed1d1233803f5f8a Mon Sep 17 00:00:00 2001 From: jglick Date: Wed, 22 Apr 2009 00:29:43 +0000 Subject: [PATCH] [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 --- core/src/main/java/hudson/model/ListView.java | 38 ++++++++++-- .../java/hudson/views/LastStableColumn.java | 60 +++++++++++++++++++ .../java/hudson/views/ListViewColumn.java | 14 +++-- .../model/ListView/configure-entries.jelly | 13 +++- .../views/LastStableColumn/column.jelly | 38 ++++++++++++ .../views/LastStableColumn/columnHeader.jelly | 27 +++++++++ .../hudson/views/ListViewColumn/config.jelly | 26 ++++++++ .../main/resources/lib/form/hetero-list.jelly | 2 +- 8 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 core/src/main/java/hudson/views/LastStableColumn.java create mode 100644 core/src/main/resources/hudson/views/LastStableColumn/column.jelly create mode 100644 core/src/main/resources/hudson/views/LastStableColumn/columnHeader.jelly create mode 100644 core/src/main/resources/hudson/views/ListViewColumn/config.jelly diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index 0a090cf9c7..953493da8c 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -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 jobNames = new TreeSet(CaseInsensitiveComparator.INSTANCE); - protected transient List columns = new ArrayList(); + private DescribableList> 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 r = new ArrayList(); DescriptorExtensionList> 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 filter = r.iterator(); + while (filter.hasNext()) { + if (!filter.next().shownByDefault()) { + filter.remove(); + } + } + columns = new DescribableList>(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 getColumns() { + public Iterable 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>(NO_SAVABLE); + } + columns.rebuildHetero(req, req.getSubmittedForm(), Hudson.getInstance().getDescriptorList(ListViewColumn.class), "columns"); } @Extension diff --git a/core/src/main/java/hudson/views/LastStableColumn.java b/core/src/main/java/hudson/views/LastStableColumn.java new file mode 100644 index 0000000000..5c1d6cbf9f --- /dev/null +++ b/core/src/main/java/hudson/views/LastStableColumn.java @@ -0,0 +1,60 @@ +/* + * 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 getDescriptor() { + return DESCRIPTOR; + } + + public static final Descriptor DESCRIPTOR = new DescriptorImpl(); + + @Extension + public static class DescriptorImpl extends Descriptor { + + @Override + public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException { + return new LastStableColumn(); + } + + @Override + public String getDisplayName() { + return "Last Stable"; + } + + } + +} diff --git a/core/src/main/java/hudson/views/ListViewColumn.java b/core/src/main/java/hudson/views/ListViewColumn.java index 72f7ae26fe..e976f1bd37 100644 --- a/core/src/main/java/hudson/views/ListViewColumn.java +++ b/core/src/main/java/hudson/views/ListViewColumn.java @@ -48,11 +48,6 @@ import org.kohsuke.stapler.export.Exported; *

* This object may have an additional columHeader.jelly. The default ColmnHeader * will render ColumnCaption. - *

- * 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 = new DescriptorList(ListViewColumn.class); + /** + * Whether this column will be shown by default. + * The default implementation is true. + * @since 1.301 + */ + public boolean shownByDefault() { + return true; + } + } diff --git a/core/src/main/resources/hudson/model/ListView/configure-entries.jelly b/core/src/main/resources/hudson/model/ListView/configure-entries.jelly index 561f3d18bc..5149cf47b4 100644 --- a/core/src/main/resources/hudson/model/ListView/configure-entries.jelly +++ b/core/src/main/resources/hudson/model/ListView/configure-entries.jelly @@ -40,4 +40,15 @@ THE SOFTWARE. - \ No newline at end of file + + + + + + + + + diff --git a/core/src/main/resources/hudson/views/LastStableColumn/column.jelly b/core/src/main/resources/hudson/views/LastStableColumn/column.jelly new file mode 100644 index 0000000000..b6159cb9d0 --- /dev/null +++ b/core/src/main/resources/hudson/views/LastStableColumn/column.jelly @@ -0,0 +1,38 @@ + + + + + + + + ${lstBuild.timestampString} + (#${lstBuild.number}) + + + ${%N/A} + + + + diff --git a/core/src/main/resources/hudson/views/LastStableColumn/columnHeader.jelly b/core/src/main/resources/hudson/views/LastStableColumn/columnHeader.jelly new file mode 100644 index 0000000000..81e749b382 --- /dev/null +++ b/core/src/main/resources/hudson/views/LastStableColumn/columnHeader.jelly @@ -0,0 +1,27 @@ + + + + ${%Last Stable} + diff --git a/core/src/main/resources/hudson/views/ListViewColumn/config.jelly b/core/src/main/resources/hudson/views/ListViewColumn/config.jelly new file mode 100644 index 0000000000..75d61b9f10 --- /dev/null +++ b/core/src/main/resources/hudson/views/ListViewColumn/config.jelly @@ -0,0 +1,26 @@ + + + + diff --git a/core/src/main/resources/lib/form/hetero-list.jelly b/core/src/main/resources/lib/form/hetero-list.jelly index 3a3d2423f6..12f02bbf73 100644 --- a/core/src/main/resources/lib/form/hetero-list.jelly +++ b/core/src/main/resources/lib/form/hetero-list.jelly @@ -43,7 +43,7 @@ THE SOFTWARE. - +