Package hudson.model
Class Actionable
- java.lang.Object
-
- hudson.model.AbstractModelObject
-
- hudson.model.Actionable
-
- All Implemented Interfaces:
ModelObject
,SearchableModelObject
,SearchItem
,ModelObjectWithContextMenu
- Direct Known Subclasses:
AbstractItem
,Cloud
,Computer
,Label
,Queue.Item
,Run
@ExportedBean public abstract class Actionable extends AbstractModelObject implements ModelObjectWithContextMenu
ModelObject
that can have additionalAction
s.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
-
Constructor Summary
Constructors Constructor Description Actionable()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAction(Action a)
Adds a new action.boolean
addOrReplaceAction(Action a)
Add an action, replacing any existing actions of the (exact) same class.ModelObjectWithContextMenu.ContextMenu
doContextMenu(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response)
Generates the context menu.Action
getAction(int index)
Deprecated.No clear purpose, since subclasses may have overriddengetActions()
, and does not considerTransientActionFactory
.<T extends Action>
TgetAction(Class<T> type)
Gets the action (first instance to be found) of a specified type that contributed to this build.List<Action>
getActions()
Deprecated.Normally outside code should not call this method any more.<T extends Action>
List<T>getActions(Class<T> type)
Gets all actions of a specified type that contributed to this object.List<? extends Action>
getAllActions()
Gets all actions, transient or persistent.Object
getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
boolean
removeAction(Action a)
Remove an action.boolean
removeActions(Class<? extends Action> clazz)
Removes any actions of the specified type.void
replaceAction(Action a)
Add an action, replacing any existing actions of the (exact) same class.boolean
replaceActions(Class<? extends Action> clazz, Action a)
Replaces any actions of the specified type by the supplied action.-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface hudson.model.ModelObject
getDisplayName
-
Methods inherited from interface hudson.search.SearchItem
getSearchUrl
-
-
-
-
Method Detail
-
getActions
@Deprecated @NonNull public List<Action> getActions()
Deprecated.Normally outside code should not call this method any more. UsegetAllActions()
, oraddAction(hudson.model.Action)
, orreplaceAction(hudson.model.Action)
. May still be called for compatibility reasons from subclasses predatingTransientActionFactory
.Gets actions contributed to this object.A new
Action
can be added byaddAction(hudson.model.Action)
.If you are reading the list, rather than modifying it, use
getAllActions()
instead. This method by default returns only persistent actions (though some subclasses override it to return an extended unmodifiable list).- Returns:
- a possibly empty list
-
getAllActions
@Exported(name="actions") @NonNull public final List<? extends Action> getAllActions()
Gets all actions, transient or persistent.getActions()
is supplemented with anything contributed byTransientActionFactory
.- Returns:
- an unmodifiable, possible empty list
- Since:
- 1.548
-
getActions
@NonNull public <T extends Action> List<T> getActions(Class<T> type)
Gets all actions of a specified type that contributed to this object.- Parameters:
type
- The type of action to return.- Returns:
- an unmodifiable, possible empty list
- See Also:
getAction(Class)
-
addAction
public void addAction(@NonNull Action a)
Adds a new action. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method will always modify the actions
-
replaceAction
public void replaceAction(@NonNull Action a)
Add an action, replacing any existing actions of the (exact) same class. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method does not affect transient actions contributed by aTransientActionFactory
. Note: this method cannot provide concurrency control due to the backing storage being aCopyOnWriteArrayList
so concurrent calls to any of the mutation methods may produce surprising results though technically consistent from the concurrency contract ofCopyOnWriteArrayList
(we would need some form of transactions or a different backing type).See also
addOrReplaceAction(Action)
if you want to know whether the backingactions
was modified, for example in cases where the caller would need to persist theActionable
in order to persist the change and there is a desire to elide unnecessary persistence of unmodified objects.- Parameters:
a
- an action to add/replace- Since:
- 1.548
-
addOrReplaceAction
public boolean addOrReplaceAction(@NonNull Action a)
Add an action, replacing any existing actions of the (exact) same class. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method does not affect transient actions contributed by aTransientActionFactory
Note: this method cannot provide concurrency control due to the backing storage being aCopyOnWriteArrayList
so concurrent calls to any of the mutation methods may produce surprising results though technically consistent from the concurrency contract ofCopyOnWriteArrayList
(we would need some form of transactions or a different backing type).- Parameters:
a
- an action to add/replace- Returns:
true
if this actions changed as a result of the call- Since:
- 2.29
-
removeAction
public boolean removeAction(@Nullable Action a)
Remove an action. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method does not affect transient actions contributed by aTransientActionFactory
Note: this method cannot provide concurrency control due to the backing storage being aCopyOnWriteArrayList
so concurrent calls to any of the mutation methods may produce surprising results though technically consistent from the concurrency contract ofCopyOnWriteArrayList
(we would need some form of transactions or a different backing type).- Parameters:
a
- an action to remove (ifnull
then this will be a no-op)- Returns:
true
if this actions changed as a result of the call- Since:
- 2.29
-
removeActions
public boolean removeActions(@NonNull Class<? extends Action> clazz)
Removes any actions of the specified type. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method does not affect transient actions contributed by aTransientActionFactory
Note: this method cannot provide concurrency control due to the backing storage being aCopyOnWriteArrayList
so concurrent calls to any of the mutation methods may produce surprising results though technically consistent from the concurrency contract ofCopyOnWriteArrayList
(we would need some form of transactions or a different backing type).- Parameters:
clazz
- the type of actions to remove- Returns:
true
if this actions changed as a result of the call- Since:
- 2.29
-
replaceActions
public boolean replaceActions(@NonNull Class<? extends Action> clazz, @NonNull Action a)
Replaces any actions of the specified type by the supplied action. Note: calls togetAllActions()
that happen before calls to this method may not see the update. Note: this method does not affect transient actions contributed by aTransientActionFactory
Note: this method cannot provide concurrency control due to the backing storage being aCopyOnWriteArrayList
so concurrent calls to any of the mutation methods may produce surprising results though technically consistent from the concurrency contract ofCopyOnWriteArrayList
(we would need some form of transactions or a different backing type).- Parameters:
clazz
- the type of actions to replace (note that the action you are replacing this with need not extend this class)a
- the action to replace with- Returns:
true
if this actions changed as a result of the call- Since:
- 2.29
-
getAction
@Deprecated public Action getAction(int index)
Deprecated.No clear purpose, since subclasses may have overriddengetActions()
, and does not considerTransientActionFactory
.
-
getAction
public <T extends Action> T getAction(Class<T> type)
Gets the action (first instance to be found) of a specified type that contributed to this build.- Returns:
- The action or
null
if no such actions exist. - See Also:
getActions(Class)
-
getDynamic
public Object getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
-
doContextMenu
public ModelObjectWithContextMenu.ContextMenu doContextMenu(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response) throws Exception
Description copied from interface:ModelObjectWithContextMenu
Generates the context menu. The typical implementation isreturn new ContextMenu().from(this,request,response);
, which implements the default behaviour. SeeModelObjectWithContextMenu.ContextMenu.from(ModelObjectWithContextMenu, StaplerRequest, StaplerResponse)
for more details of what it does. This should suit most implementations.- Specified by:
doContextMenu
in interfaceModelObjectWithContextMenu
- Throws:
Exception
-
-