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
ContributionManagers.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new contribution manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an action as a contribution item to this manager.voidadd(IContributionItem item) Adds a contribution item to this manager.protected booleanallowItem(IContributionItem itemToAdd) This method allows subclasses ofContributionManagerto prevent certain items in the contributions list.voidappendToGroup(String groupName, IAction action) Adds a contribution item for the given action at the end of the group with the given name.voidappendToGroup(String groupName, IContributionItem item) Adds a contribution item to this manager at the end of the group with the given name.protected voidInternal 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.TheContributionManagerimplementation of this method declared onIContributionManagerreturns the current overrides.intgetSize()Return the number of contributions in this manager.protected booleanReturns whether this contribution manager contains dynamic items.intReturns the index of the item with the given id.protected intindexOf(IContributionItem item) Returns the index of the object in the internal structure.voidinsert(int index, IContributionItem item) Insert the item at the given index.voidinsertAfter(String ID, IAction action) Inserts a contribution item for the given action after the item with the given id.voidinsertAfter(String ID, IContributionItem item) Inserts a contribution item after the item with the given id.voidinsertBefore(String ID, IAction action) Inserts a contribution item for the given action before the item with the given id.voidinsertBefore(String ID, IContributionItem item) Inserts a contribution item before the item with the given id.protected voidinternalSetItems(IContributionItem[] items) An internal method for setting the order of the contribution items.booleanisDirty()Returns whether the list of contributions has recently changed and has yet to be reflected in the corresponding widgets.booleanisEmpty()Returns whether this manager has any contribution items.protected voiditemAdded(IContributionItem item) The given item was added to the list of contributions.protected voiditemRemoved(IContributionItem item) The given item was removed from the list of contributions.voidMarks this contribution manager as dirty.voidprependToGroup(String groupName, IAction action) Adds a contribution item for the given action at the beginning of the group with the given name.voidprependToGroup(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.voidRemoves all contribution items from this manager.booleanreplaceItem(String identifier, IContributionItem replacementItem) Replaces the item of the given identifier with another contribution item.protected voidsetDirty(boolean dirty) Sets whether this manager is dirty.voidsetOverrides(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, waitMethods 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:IContributionManagerAdds an action as a contribution item to this manager. Equivalent toadd(new ActionContributionItem(action)).- Specified by:
addin interfaceIContributionManager- Parameters:
action- the action, this cannot benull
-
add
Description copied from interface:IContributionManagerAdds a contribution item to this manager.- Specified by:
addin interfaceIContributionManager- Parameters:
item- the contribution item, this cannot benull
-
appendToGroup
Description copied from interface:IContributionManagerAdds 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:
appendToGroupin interfaceIContributionManager- Parameters:
groupName- the name of the groupaction- the action
-
appendToGroup
Description copied from interface:IContributionManagerAdds a contribution item to this manager at the end of the group with the given name.- Specified by:
appendToGroupin interfaceIContributionManager- Parameters:
groupName- the name of the groupitem- the contribution item
-
allowItem
This method allows subclasses ofContributionManagerto prevent certain items in the contributions list.ContributionManagerwill 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:
trueif the addition should be allowed;falseotherwise. 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:IContributionManagerFinds the contribution item with the given id.- Specified by:
findin interfaceIContributionManager- Parameters:
id- the contribution item id- Returns:
- the contribution item, or
nullif no item with the given id can be found
-
getItems
Description copied from interface:IContributionManagerReturns all contribution items known to this manager.- Specified by:
getItemsin 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
TheContributionManagerimplementation of this method declared onIContributionManagerreturns the current overrides. If there is no overrides it lazily creates one which overrides no item state.- Specified by:
getOverridesin 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:
trueif this manager contains dynamic items, andfalseotherwise
-
indexOf
Returns the index of the item with the given id.- Parameters:
id- The id of the item whose index is requested.- Returns:
intthe 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:IContributionManagerInserts a contribution item for the given action after the item with the given id. Equivalent toinsertAfter(id,new ActionContributionItem(action)).- Specified by:
insertAfterin interfaceIContributionManager- Parameters:
ID- the contribution item idaction- the action to insert
-
insertAfter
Description copied from interface:IContributionManagerInserts a contribution item after the item with the given id.- Specified by:
insertAfterin interfaceIContributionManager- Parameters:
ID- the contribution item iditem- the contribution item to insert
-
insertBefore
Description copied from interface:IContributionManagerInserts a contribution item for the given action before the item with the given id. Equivalent toinsertBefore(id,new ActionContributionItem(action)).- Specified by:
insertBeforein interfaceIContributionManager- Parameters:
ID- the contribution item idaction- the action to insert
-
insertBefore
Description copied from interface:IContributionManagerInserts a contribution item before the item with the given id.- Specified by:
insertBeforein interfaceIContributionManager- Parameters:
ID- the contribution item iditem- the contribution item to insert
-
isDirty
public boolean isDirty()Description copied from interface:IContributionManagerReturns whether the list of contributions has recently changed and has yet to be reflected in the corresponding widgets.- Specified by:
isDirtyin interfaceIContributionManager- Returns:
trueif this manager is dirty, andfalseif it is up-to-date
-
isEmpty
public boolean isEmpty()Description copied from interface:IContributionManagerReturns whether this manager has any contribution items.- Specified by:
isEmptyin interfaceIContributionManager- Returns:
trueif there are no items, andfalseotherwise
-
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:IContributionManagerMarks this contribution manager as dirty.- Specified by:
markDirtyin interfaceIContributionManager
-
prependToGroup
Description copied from interface:IContributionManagerAdds 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:
prependToGroupin interfaceIContributionManager- Parameters:
groupName- the name of the groupaction- the action
-
prependToGroup
Description copied from interface:IContributionManagerAdds a contribution item to this manager at the beginning of the group with the given name.- Specified by:
prependToGroupin interfaceIContributionManager- Parameters:
groupName- the name of the groupitem- the contribution item
-
remove
Description copied from interface:IContributionManagerRemoves and returns the contribution item with the given id from this manager. Returnsnullif this manager has no contribution items with the given id.- Specified by:
removein interfaceIContributionManager- Parameters:
ID- the contribution item id- Returns:
- the item that was found and removed, or
nullif none
-
remove
Description copied from interface:IContributionManagerRemoves the given contribution item from the contribution items known to this manager.- Specified by:
removein interfaceIContributionManager- Parameters:
item- the contribution item- Returns:
- the
itemparameter if the item was removed, andnullif it was not found
-
removeAll
public void removeAll()Description copied from interface:IContributionManagerRemoves all contribution items from this manager.Note: The items will not get disposed.
- Specified by:
removeAllin 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. Useremoveif that is what you want to do.- Returns:
trueif 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-trueif this manager is dirty, andfalseif 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
-