Important: The information in this document is obsolete and should not be used for new development.
(informal protocol)
Package | com.apple.cocoa.application |
Companion guide |
A toolbar item with a valid target and action is enabled by default. To allow a toolbar item to be disabled in certain situations, a toolbar item’s target can implement the validateToolbarItem
method.
Note: NSToolbarItem’s validate
method calls this method only if the item’s target has a valid action defined on its target and if the item is not a custom view item. If you want to validate a custom view item, then you have to subclass NSToolbarItem and override validate
.
If this method is implemented and returns false
, NSToolbar will disable theItem; returning true
causes theItem to be enabled.
public abstract boolean validateToolbarItem
(NSToolbarItem theItem)
NSToolbar only calls this method for image items.
If the receiver is the target
for the actions of multiple toolbar items, it’s necessary to determine which toolbar item theItem refers to by testing the itemIdentifier
.
public boolean validateToolbarItem (NSToolbarItem toolbarItem) { |
boolean enable = false; |
if (toolbarItem.itemIdentifier().equals(SaveDocToolbarItemIdentifier)) { |
// We will return true (save item is enabled) |
// only when the document is dirty and needs saving. |
enable = this.isDocumentEdited(); |
} else if (toolbarItem.itemIdentifier().equals(NSToolbarItem.PrintItemIdentifier)) { |
enable = true; |
} |
return enable; |
} |
validateVisibleItems
(NSToolbar)validate
(NSToolbarItem)target
(NSToolbarItem)action
(NSToolbarItem)name
(NSSelector)© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)