Package org.eclipse.jface.action
Class ContributionManager
java.lang.Object
org.eclipse.jface.action.ContributionManager
- All Implemented Interfaces:
IContributionManager
- Direct Known Subclasses:
CoolBarManager
,CoolBarToTrimManager
,MenuManager
,StatusLineManager
,ToolBarManager
Abstract base class for all contribution managers, and standard
implementation of
IContributionManager
. This class provides
functionality common across the specific managers defined by this framework.
This class maintains a list of contribution items and a dirty flag, both as
internal state. In addition to providing implementations of most
IContributionManager
methods, this class automatically
coalesces adjacent separators, hides beginning and ending separators, and
deals with dynamically changing sets of contributions. When the set of
contributions does change dynamically, the changes are propagated to the
control via the update
method, which subclasses must
implement.
Note: A ContributionItem
cannot be shared between different
ContributionManager
s.
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new contribution manager. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an action as a contribution item to this manager.void
add
(IContributionItem item) Adds a contribution item to this manager.protected boolean
allowItem
(IContributionItem itemToAdd) This method allows subclasses ofContributionManager
to prevent certain items in the contributions list.void
appendToGroup
(String groupName, IAction action) Adds a contribution item for the given action at the end of the group with the given name.void
appendToGroup
(String groupName, IContributionItem item) Adds a contribution item to this manager at the end of the group with the given name.protected void
Internal debug method for printing statistics about this manager toSystem.out
.Finds the contribution item with the given id.getItems()
Returns all contribution items known to this manager.TheContributionManager
implementation of this method declared onIContributionManager
returns the current overrides.int
getSize()
Return the number of contributions in this manager.protected boolean
Returns whether this contribution manager contains dynamic items.int
Returns the index of the item with the given id.protected int
indexOf
(IContributionItem item) Returns the index of the object in the internal structure.void
insert
(int index, IContributionItem item) Insert the item at the given index.void
insertAfter
(String ID, IAction action) Inserts a contribution item for the given action after the item with the given id.void
insertAfter
(String ID, IContributionItem item) Inserts a contribution item after the item with the given id.void
insertBefore
(String ID, IAction action) Inserts a contribution item for the given action before the item with the given id.void
insertBefore
(String ID, IContributionItem item) Inserts a contribution item before the item with the given id.protected void
internalSetItems
(IContributionItem[] items) An internal method for setting the order of the contribution items.boolean
isDirty()
Returns whether the list of contributions has recently changed and has yet to be reflected in the corresponding widgets.boolean
isEmpty()
Returns whether this manager has any contribution items.protected void
itemAdded
(IContributionItem item) The given item was added to the list of contributions.protected void
itemRemoved
(IContributionItem item) The given item was removed from the list of contributions.void
Marks this contribution manager as dirty.void
prependToGroup
(String groupName, IAction action) Adds a contribution item for the given action at the beginning of the group with the given name.void
prependToGroup
(String groupName, IContributionItem item) Adds a contribution item to this manager at the beginning of the group with the given name.Removes and returns the contribution item with the given id from this manager.remove
(IContributionItem item) Removes the given contribution item from the contribution items known to this manager.void
Removes all contribution items from this manager.boolean
replaceItem
(String identifier, IContributionItem replacementItem) Replaces the item of the given identifier with another contribution item.protected void
setDirty
(boolean dirty) Sets whether this manager is dirty.void
setOverrides
(IContributionManagerOverrides newOverrides) Sets the overrides for this contribution managerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jface.action.IContributionManager
update
-
Constructor Details
-
ContributionManager
protected ContributionManager()Creates a new contribution manager.
-
-
Method Details
-
add
Description copied from interface:IContributionManager
Adds an action as a contribution item to this manager. Equivalent toadd(new ActionContributionItem(action))
.- Specified by:
add
in interfaceIContributionManager
- Parameters:
action
- the action, this cannot benull
-
add
Description copied from interface:IContributionManager
Adds a contribution item to this manager.- Specified by:
add
in interfaceIContributionManager
- Parameters:
item
- the contribution item, this cannot benull
-
appendToGroup
Description copied from interface:IContributionManager
Adds a contribution item for the given action at the end of the group with the given name. Equivalent toappendToGroup(groupName,new ActionContributionItem(action))
.- Specified by:
appendToGroup
in interfaceIContributionManager
- Parameters:
groupName
- the name of the groupaction
- the action
-
appendToGroup
Description copied from interface:IContributionManager
Adds a contribution item to this manager at the end of the group with the given name.- Specified by:
appendToGroup
in interfaceIContributionManager
- Parameters:
groupName
- the name of the groupitem
- the contribution item
-
allowItem
This method allows subclasses ofContributionManager
to prevent certain items in the contributions list.ContributionManager
will either block or allow an addition based on the result of this method call. This can be used to prevent duplication, for example.- Parameters:
itemToAdd
- The contribution item to be added; may benull
.- Returns:
true
if the addition should be allowed;false
otherwise. The default implementation allows all items.- Since:
- 3.0
-
dumpStatistics
protected void dumpStatistics()Internal debug method for printing statistics about this manager toSystem.out
. -
find
Description copied from interface:IContributionManager
Finds the contribution item with the given id.- Specified by:
find
in interfaceIContributionManager
- Parameters:
id
- the contribution item id- Returns:
- the contribution item, or
null
if no item with the given id can be found
-
getItems
Description copied from interface:IContributionManager
Returns all contribution items known to this manager.- Specified by:
getItems
in interfaceIContributionManager
- Returns:
- a list of contribution items
-
getSize
public int getSize()Return the number of contributions in this manager.- Returns:
- the number of contributions in this manager
- Since:
- 3.3
-
getOverrides
TheContributionManager
implementation of this method declared onIContributionManager
returns the current overrides. If there is no overrides it lazily creates one which overrides no item state.- Specified by:
getOverrides
in interfaceIContributionManager
- Returns:
- the overrides for the items of this manager
- Since:
- 2.0
-
hasDynamicItems
protected boolean hasDynamicItems()Returns whether this contribution manager contains dynamic items. A dynamic contribution item contributes items conditionally, dependent on some internal state.- Returns:
true
if this manager contains dynamic items, andfalse
otherwise
-
indexOf
Returns the index of the item with the given id.- Parameters:
id
- The id of the item whose index is requested.- Returns:
int
the index or -1 if the item is not found
-
indexOf
Returns the index of the object in the internal structure. This is different fromindexOf(String id)
since some contribution items may not have an id.- Parameters:
item
- The contribution item- Returns:
- the index, or -1 if the item is not found
- Since:
- 3.0
-
insert
Insert the item at the given index.- Parameters:
index
- The index to be used for insertionitem
- The item to be inserted
-
insertAfter
Description copied from interface:IContributionManager
Inserts a contribution item for the given action after the item with the given id. Equivalent toinsertAfter(id,new ActionContributionItem(action))
.- Specified by:
insertAfter
in interfaceIContributionManager
- Parameters:
ID
- the contribution item idaction
- the action to insert
-
insertAfter
Description copied from interface:IContributionManager
Inserts a contribution item after the item with the given id.- Specified by:
insertAfter
in interfaceIContributionManager
- Parameters:
ID
- the contribution item iditem
- the contribution item to insert
-
insertBefore
Description copied from interface:IContributionManager
Inserts a contribution item for the given action before the item with the given id. Equivalent toinsertBefore(id,new ActionContributionItem(action))
.- Specified by:
insertBefore
in interfaceIContributionManager
- Parameters:
ID
- the contribution item idaction
- the action to insert
-
insertBefore
Description copied from interface:IContributionManager
Inserts a contribution item before the item with the given id.- Specified by:
insertBefore
in interfaceIContributionManager
- Parameters:
ID
- the contribution item iditem
- the contribution item to insert
-
isDirty
public boolean isDirty()Description copied from interface:IContributionManager
Returns whether the list of contributions has recently changed and has yet to be reflected in the corresponding widgets.- Specified by:
isDirty
in interfaceIContributionManager
- Returns:
true
if this manager is dirty, andfalse
if it is up-to-date
-
isEmpty
public boolean isEmpty()Description copied from interface:IContributionManager
Returns whether this manager has any contribution items.- Specified by:
isEmpty
in interfaceIContributionManager
- Returns:
true
if there are no items, andfalse
otherwise
-
itemAdded
The given item was added to the list of contributions. Marks the manager as dirty and updates the number of dynamic items, and the memento.- Parameters:
item
- the item to be added
-
itemRemoved
The given item was removed from the list of contributions. Marks the manager as dirty and updates the number of dynamic items.- Parameters:
item
- remove given parent from list of contributions
-
markDirty
public void markDirty()Description copied from interface:IContributionManager
Marks this contribution manager as dirty.- Specified by:
markDirty
in interfaceIContributionManager
-
prependToGroup
Description copied from interface:IContributionManager
Adds a contribution item for the given action at the beginning of the group with the given name. Equivalent toprependToGroup(groupName,new ActionContributionItem(action))
.- Specified by:
prependToGroup
in interfaceIContributionManager
- Parameters:
groupName
- the name of the groupaction
- the action
-
prependToGroup
Description copied from interface:IContributionManager
Adds a contribution item to this manager at the beginning of the group with the given name.- Specified by:
prependToGroup
in interfaceIContributionManager
- Parameters:
groupName
- the name of the groupitem
- the contribution item
-
remove
Description copied from interface:IContributionManager
Removes and returns the contribution item with the given id from this manager. Returnsnull
if this manager has no contribution items with the given id.- Specified by:
remove
in interfaceIContributionManager
- Parameters:
ID
- the contribution item id- Returns:
- the item that was found and removed, or
null
if none
-
remove
Description copied from interface:IContributionManager
Removes the given contribution item from the contribution items known to this manager.- Specified by:
remove
in interfaceIContributionManager
- Parameters:
item
- the contribution item- Returns:
- the
item
parameter if the item was removed, andnull
if it was not found
-
removeAll
public void removeAll()Description copied from interface:IContributionManager
Removes all contribution items from this manager.Note: The items will not get disposed.
- Specified by:
removeAll
in interfaceIContributionManager
-
replaceItem
Replaces the item of the given identifier with another contribution item. This can be used, for example, to replace large contribution items with placeholders to avoid memory leaks. If the identifier cannot be found in the current list of items, then this does nothing. If multiple occurrences are found, then the replacement items is put in the first position and the other positions are removed.- Parameters:
identifier
- The identifier to look for in the list of contributions; should not benull
.replacementItem
- The contribution item to replace the old item; must not benull
. Useremove
if that is what you want to do.- Returns:
true
if the given identifier can be;- Since:
- 3.0
-
setDirty
protected void setDirty(boolean dirty) Sets whether this manager is dirty. When dirty, the list of contributions is not accurately reflected in the corresponding widgets.- Parameters:
dirty
-true
if this manager is dirty, andfalse
if it is up-to-date
-
setOverrides
Sets the overrides for this contribution manager- Parameters:
newOverrides
- the overrides for the items of this manager- Since:
- 2.0
-
internalSetItems
An internal method for setting the order of the contribution items.- Parameters:
items
- the contribution items in the specified order- Since:
- 3.0
-