提交 f9d83a48 编写于 作者: K Kohsuke Kawaguchi

- making context richer

- simplifying Jelly view and submission handling
上级 31cd6033
......@@ -29,6 +29,8 @@ import hudson.ExtensionPoint;
import hudson.Util;
import hudson.model.Descriptor.FormException;
import hudson.model.Node.Mode;
import hudson.model.labels.LabelAtomProperty;
import hudson.model.labels.LabelAtomPropertyDescriptor;
import hudson.scm.ChangeLogSet.Entry;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder;
......@@ -205,6 +207,19 @@ public abstract class View extends AbstractModelObject implements AccessControll
return properties;
}
/**
* Returns all the {@link LabelAtomPropertyDescriptor}s that can be potentially configured
* on this label.
*/
public List<ViewPropertyDescriptor> getApplicablePropertyDescriptors() {
List<ViewPropertyDescriptor> r = new ArrayList<ViewPropertyDescriptor>();
for (ViewPropertyDescriptor pd : ViewProperty.all()) {
if (pd.isEnabledFor(this))
r.add(pd);
}
return r;
}
public void save() throws IOException {
// persistence is a part of the owner
// due to initialization timing issue, it can be null when this method is called
......@@ -620,25 +635,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
JSONObject json = req.getSubmittedForm();
List<ViewProperty> props = new ArrayList<ViewProperty>();
int i = 0;
for (ViewPropertyDescriptor d: ViewProperty.all()) {
ViewProperty p = properties.get(d.clazz);
JSONObject o = json.optJSONObject("viewProperty" + (i++));
if (o != null) {
if (p != null) {
p = p.reconfigure(req, o);
} else {
p = d.newInstance(req, o);
}
}
if (p != null) {
props.add(p);
}
}
properties.replaceBy(props);
properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());
save();
......
......@@ -25,9 +25,14 @@ package hudson.model;
import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleAnnotatorFactory;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import java.util.ArrayList;
import java.util.List;
/**
* Extensible property of {@link View}.
*
......@@ -68,5 +73,4 @@ public class ViewProperty implements Describable<ViewProperty>, ExtensionPoint {
public ViewProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException {
return getDescriptor().newInstance(req, form);
}
}
......@@ -67,8 +67,11 @@ public abstract class ViewPropertyDescriptor extends Descriptor<ViewProperty> {
* <p>
* This mechanism is useful if the availability of the property is
* contingent of some other settings.
*
* @param view
* View for which this property is considered. Never null.
*/
public boolean isEnabled() {
public boolean isEnabledFor(View view) {
return true;
}
}
......@@ -51,20 +51,7 @@ THE SOFTWARE.
<st:include page="configure-entries.jelly" optional="true" />
<!-- view property configurations -->
<j:invokeStatic var="descriptors" className="hudson.model.ViewProperty" method="all" />
<j:set var="instances" value="${it.properties}" />
<j:forEach var="d" items="${descriptors}" varStatus="loop">
<j:if test="${d.enabled}">
<f:section title="${d.displayName}">
<j:set var="descriptor" value="${d}" />
<j:set var="instance" value="${instances[d]}" />
<f:rowSet name="viewProperty${loop.index}">
<st:include from="${d}" page="${d.configPage}"/>
</f:rowSet>
</f:section>
</j:if>
</j:forEach>
<f:descriptorList descriptors="${it.getApplicablePropertyDescriptors()}" instances="${it.properties}" />
<f:block>
<f:submit value="OK" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册