From 97f5e8d8dfdb87c2c04fb912528021f7c60f4bb7 Mon Sep 17 00:00:00 2001 From: Tom Huybrechts Date: Mon, 2 Aug 2010 17:39:13 +0200 Subject: [PATCH] support for transient View actions --- core/src/main/java/hudson/model/ListView.java | 13 +++--- .../model/TransientViewActionFactory.java | 40 +++++++++++++++++++ core/src/main/java/hudson/model/View.java | 19 ++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 core/src/main/java/hudson/model/TransientViewActionFactory.java diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index e3174b39e2..8561fb88e1 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -167,13 +167,14 @@ public class ListView extends View implements Saveable { } /** - * Returns the transient {@link Action}s associated with the top page. - * - * @see Hudson#getActions() + * Used to determine if we want to display the Add button. */ - @Override - public List getActions() { - return Hudson.getInstance().getActions(); + public boolean hasJobFilterExtensions() { + return !ViewJobFilter.all().isEmpty(); + } + + public Iterable getJobFilters() { + return jobFilters; } /** diff --git a/core/src/main/java/hudson/model/TransientViewActionFactory.java b/core/src/main/java/hudson/model/TransientViewActionFactory.java new file mode 100644 index 0000000000..ac041ef363 --- /dev/null +++ b/core/src/main/java/hudson/model/TransientViewActionFactory.java @@ -0,0 +1,40 @@ +package hudson.model; + +import hudson.ExtensionList; + +import java.util.ArrayList; +import java.util.List; + +/** + * Extension point for adding transient {@link Action}s to {@link View}s. + * + */ +public abstract class TransientViewActionFactory { + + /** + * returns a list of (transient) actions never null, may be empty + * + * @param v + * @return + */ + public abstract List createFor(View v); + + /** + * Returns all the registered {@link TransientViewActionFactory}s. + */ + public static ExtensionList all() { + return Hudson.getInstance().getExtensionList(TransientViewActionFactory.class); + } + + /** + * Creates {@link Action)s for a view, using all registered {@link TransientViewActionFactory}s. + */ + public static List createAllFor(View v) { + List result = new ArrayList(); + for (TransientViewActionFactory f: all()) { + result.addAll(f.createFor(v)); + } + return result; + } + +} diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 919848d546..d8e9a136ee 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -108,6 +108,8 @@ public abstract class View extends AbstractModelObject implements AccessControll * If true, only show relevant queue items */ protected boolean filterQueue; + + protected transient List transientActions; protected View(String name) { this.name = name; @@ -313,7 +315,22 @@ public abstract class View extends AbstractModelObject implements AccessControll * @see Hudson#getActions() */ public List getActions() { - return Hudson.getInstance().getActions(); + List result = new ArrayList(); + result.addAll(Hudson.getInstance().getActions()); + synchronized (this) { + if (transientActions == null) { + transientActions = TransientViewActionFactory.createAllFor(this); + } + result.addAll(transientActions); + } + return result; + } + + public Object getDynamic(String token) { + for (Action a : getActions()) + if(a.getUrlName().equals(token)) + return a; + return null; } /**