From 6fc699ff7406628271bbab7038b552481653436e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 15:09:23 -0700 Subject: [PATCH] - making context richer - simplifying Jelly view and submission handling --- core/src/main/java/hudson/model/View.java | 35 +++++++++---------- .../main/java/hudson/model/ViewProperty.java | 6 +++- .../hudson/model/ViewPropertyDescriptor.java | 5 ++- .../hudson/model/View/configure.jelly | 15 +------- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 81c4eb3074..ed40898026 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -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 getApplicablePropertyDescriptors() { + List r = new ArrayList(); + 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 props = new ArrayList(); - 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(); diff --git a/core/src/main/java/hudson/model/ViewProperty.java b/core/src/main/java/hudson/model/ViewProperty.java index 74cdb40a67..2c576a652e 100644 --- a/core/src/main/java/hudson/model/ViewProperty.java +++ b/core/src/main/java/hudson/model/ViewProperty.java @@ -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, ExtensionPoint { public ViewProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException { return getDescriptor().newInstance(req, form); } - } diff --git a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java index b7c474b47f..f073050f57 100644 --- a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java +++ b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java @@ -67,8 +67,11 @@ public abstract class ViewPropertyDescriptor extends Descriptor { *

* 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; } } diff --git a/core/src/main/resources/hudson/model/View/configure.jelly b/core/src/main/resources/hudson/model/View/configure.jelly index acee8d3038..a648febb2a 100644 --- a/core/src/main/resources/hudson/model/View/configure.jelly +++ b/core/src/main/resources/hudson/model/View/configure.jelly @@ -51,20 +51,7 @@ THE SOFTWARE. - - - - - - - - - - - - - - + -- GitLab