support for transient View actions

This commit is contained in:
Tom Huybrechts committed 2010-10-16 22:05:54 +02:00
1 parent 5140d50319
commit 97f5e8d8df
3 files changed
+65 -7

No files matched your search

@@ -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<Action> getActions() {
return Hudson.getInstance().getActions();
public boolean hasJobFilterExtensions() {
return !ViewJobFilter.all().isEmpty();
}
public Iterable<ViewJobFilter> getJobFilters() {
return jobFilters;
}
/**
@@ -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<Action> createFor(View v);
/**
* Returns all the registered {@link TransientViewActionFactory}s.
*/
public static ExtensionList<TransientViewActionFactory> all() {
return Hudson.getInstance().getExtensionList(TransientViewActionFactory.class);
}
/**
* Creates {@link Action)s for a view, using all registered {@link TransientViewActionFactory}s.
*/
public static List<Action> createAllFor(View v) {
List<Action> result = new ArrayList<Action>();
for (TransientViewActionFactory f: all()) {
result.addAll(f.createFor(v));
}
return result;
}
}
+18 -1
View File
@@ -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<Action> 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<Action> getActions() {
return Hudson.getInstance().getActions();
List<Action> result = new ArrayList<Action>();
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;
}
/**