提交 33af6b59 编写于 作者: K Kohsuke Kawaguchi

adding a databinding version of <f:hetero-list />

上级 27783878
......@@ -200,11 +200,18 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
}
/**
* Returns all the descriptors that produce types assignable to the item type.
* Returns all the descriptors that produce types assignable to the property type.
*/
public List<? extends Descriptor> getApplicableDescriptors() {
return Jenkins.getInstance().getDescriptorList(clazz);
}
/**
* Returns all the descriptors that produce types assignable to the item type for a collection property.
*/
public List<? extends Descriptor> getApplicableItemDescriptors() {
return Jenkins.getInstance().getDescriptorList(getItemType());
}
}
/**
......
......@@ -42,7 +42,6 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
import javax.annotation.concurrent.GuardedBy;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
......@@ -292,7 +291,7 @@ public class ListView extends View implements Saveable {
}
@Extension
public static final class DescriptorImpl extends ViewDescriptor {
public static class DescriptorImpl extends ViewDescriptor {
public String getDisplayName() {
return Messages.ListView_DisplayName();
}
......
......@@ -23,9 +23,14 @@
*/
package hudson.model;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import hudson.views.ViewJobFilter;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.QueryParameter;
import java.util.List;
/**
* {@link Descriptor} for {@link View}.
*
......@@ -88,4 +93,18 @@ public abstract class ViewDescriptor extends Descriptor<View> {
return r;
}
/**
* Possible {@link ListViewColumnDescriptor}s that can be used with this view.
*/
public List<Descriptor<ListViewColumn>> getColumnsDescriptors() {
return ListViewColumn.all();
}
/**
* Possible {@link ViewJobFilter} types that can be used with this view.
*/
public List<Descriptor<ViewJobFilter>> getJobFiltersDescriptors() {
return ViewJobFilter.all();
}
}
......@@ -54,24 +54,16 @@ THE SOFTWARE.
</f:optionalBlock>
<j:if test="${it.hasJobFilterExtensions()}">
<j:invokeStatic var="allJobFilters" className="hudson.views.ViewJobFilter" method="all"/>
<f:block>
<f:hetero-list name="jobFilters" hasHeader="true"
descriptors="${allJobFilters}"
items="${it.jobFilters}"
addCaption="${%Add Job Filter}" />
<f:repeatableHeteroProperty field="jobFilters" hasHeader="true" addCaption="${%Add Job Filter}" />
</f:block>
</j:if>
</f:section>
<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:repeatableHeteroProperty field="columns" hasHeader="true" addCaption="${%Add column}"/>
</f:block>
</f:section>
......
......@@ -29,6 +29,8 @@ THE SOFTWARE.
arbitrary items from the given list of descriptors, and configure them independently.
The submission can be data-bound into List&lt;T> where T is the common base type for the describable instances.
For databinding use, please use &lt;f:repeatableHeteroProperty />
<st:attribute name="name" use="required">
form name that receives an array for all the items in the heterogeneous list.
......
<!--
The MIT License
Copyright (c) 2012, CloudBees, Inc.
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.
-->
<?jelly escape-by-default='true'?>
<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">
<st:documentation> <![CDATA[
Data-bound only version of <f:hetero-list> that assumes the type pointed by the property is data-bound as well.
The nested property type must be Describable and it needs to have config.jelly.
The nested configuration fragment normally needs to have a delete button by adding a fragment like this:
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
</div>
</f:entry>
]]>
<st:attribute name="field" use="required">
Used for the data binding.
</st:attribute>
<st:attribute name="addCaption">
caption of the 'add' button.
</st:attribute>
<st:attribute name="deleteCaption">
caption of the 'delete' button.
</st:attribute>
<st:attribute name="targetType">
the type for which descriptors will be configured. Defaults to ${it.class} (optional)
</st:attribute>
<st:attribute name="hasHeader">
For each item, add a caption from descriptor.getDisplayName().
This also activates drag&amp;drop (where the header is a grip), and help text support.
</st:attribute>
<st:attribute name="oneEach">
If true, only allow up to one instance per descriptor.
</st:attribute>
<st:attribute name="menuAlign">
Menu alignment against the button. Defaults to tl-bl
</st:attribute>
<st:attribute name="honorOrder">
If true, insert new addition by default to their 'desired' location, which
is the order induced by the descriptors.
</st:attribute>
</st:documentation>
<!--
first try getFooBarDescriptors() then fall back to automatic inference by type
-->
<f:hetero-list name="${attrs.field}" items="${instance[attrs.field]}"
descriptors="${descriptor[attrs.field+'Descriptors'] ?: descriptor.getPropertyType(instance,attrs.field).getApplicableItemDescriptors()}"
addCaption="${attrs.addCaption}" deleteCaption="${attrs.deleteCaption}"
hasHeader="${attrs.hasHeader}" honorOrder="${attrs.honorOrder}"
menuAlign="${attrs.menuAlign}" oneEach="${attrs.oneEach}"
targetType="${attrs.targetType}"
/>
<!-- TODO: there should be a mechanism to pass-through map as parameters -->
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册