home *** CD-ROM | disk | FTP | other *** search
- // EODisplayGroup.h
- // Enterprise Objects Framework
- // Copyright (c)1993, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
-
- @class EOAssociation;
-
-
- // EODisplayGroup holds a set of objects and a selection for display and
- // editing in the user interface. EOAssociations "observe" displayGroups
- // and push the values of the displayGroups objects into UI controls.
-
- @interface EODisplayGroup : NSObject <NSCoding>
- {
- @private
- EODataSource *_dataSource;
- NSMutableArray *_allObjects;
- NSMutableArray *_displayedObjects;
- id _delegate;
- NSArray *_selection;
- struct {
- unsigned selectsFirstObjectAfterFetch:1;
- unsigned didChangeContents:1;
- unsigned didChangeSelection:1;
- unsigned autoFetch:1;
- unsigned haveFetched:1;
- unsigned validateImmediately:1;
- unsigned optimisticRefresh:1;
- unsigned _reserved:25;
- } _flags;
-
- // Used for debugging.
- NSArray *_sortOrdering;
- EOQualifier *_qualifier;
- NSArray *_localKeys; // For IB inspector
- NSMutableArray *_selectedObjects;
- EOAssociation *_editingAssociation;
- id _observerNotificationBeginProxy;
- id _observerNotificationEndProxy;
- int _updatedObjectIndex;
- void *_reserved;
- }
-
- - init;
- // primitive initializer
-
- - (void)setDataSource:(EODataSource *)dataSource;
- - (EODataSource *)dataSource;
- // get/set the displayGroup's dataSource.
-
- - (id)delegate;
- - (void)setDelegate:(id)aDelegate;
- // get/set the displayGroup's delegate.
-
- - (NSArray *)allObjects;
- // Returns all data-bearing objects accessible through the displayGroup.
- - (NSArray *)displayedObjects;
- // Sorted and filtered subset of allObjects that are displayed by the associations
- // for this DisplayGroup.
- - (void)setObjectArray:(NSArray *)array;
- // Set "allObjects" array for this DisplayGroup.
- // Attempts to maintain the same set of selected objects from before the set.
- // The array is automatically sorted and filtered via updateDisplayedObjects.
- // The associations for the DisplayGroup are notified of the change in objects to
- // update the UI.
- // Note that adding and removing objects via setObjectArray: does not result in a
- // insert or delete operation being sent to the dataSource; the set merely affects the UI.
-
-
- // selection is always in terms of the displayedObjects, not allObjects
- - (NSArray *)selectionIndexes;
- // Returns the selection as an array of NSNumbers.
-
- - (BOOL)setSelectionIndexes:(NSArray *)selection;
- // Sets the selection as an array of NSNumbers. The displayGroup sends
- // -isDiscardAllowed to all its detail displayGroups, as a change in
- // selection will cause detail displayGroups to change their data source.
- // If any displayGroup returns NO the selection is NOT changed and NO is
- // returned. If an association attempts to change the selection and
- // fails, the association should reset its selection by asking the
- // displayGroup for the current selection. Returns YES on success, NO on
- // failure.
-
- - (NSArray *)selectedObjects;
- // Returns the selected objects.
- - (id)selectedObject;
- // the first selected object, or nil if no selection
-
- - (BOOL)selectObjectsIdenticalTo:(NSArray *)objectSelection;
- // selects matching objects if any, or clears selection
-
- - (BOOL)selectObjectsIdenticalTo:(NSArray *)objectSelection selectFirstOnNoMatch:(BOOL)selectFirstOnNoMatch;
- // if selectFirstOnNoMatch==NO, will attempt to maintain
- // previous selection indexes if no match.
-
- - (BOOL)selectNext;
- // This convenience method increments the selection. If incrementing
- // the selection would set the selection beyond the end of the array
- // then the selection is set to 0. If the previous selection was a
- // multiple selection then the selection is set to the next record
- // after the first item in the previous selection. This method (and
- // it's cover selectNext:) are useful for user interfaces that don't
- // have widgets to directly control the selection. Does not redisplay.
-
- - (BOOL)selectPrevious;
- // This convenience method decrements the selection. If decrementing
- // the selection would set the selection before the start of the array
- // then the selection is set to the last object. If the previous
- // selection was a multiple selection then the selection is set to the
- // previous record before the first item in the previous selection.
- // This method (and it's cover selectPrevious:) are useful for user
- // interfaces that don't have widgets to directly control the selection.
- // Does not redisplay.
-
- - (BOOL)clearSelection;
- // Clears the selection. Shortcut for sending -setSelection:with an
- // empty array. Doesn't redisplay.
-
- - (void)redisplay;
- // Sends -contentsDidChange to all the associations.
-
- - (BOOL)fetch;
- // Sends -endEditing to the the editing association. Sends -displayGroupWillFetch:
- // to the delegate. If the delegate agrees, sends fetchObjects calls [self setObjectArray:]
- // with the results, sends -displayGroupDidFetch:to the delegate.
- // Returns YES on success, NO on failure.
-
- - (BOOL)deleteObjectAtIndex:(unsigned)anIndex;
- // Sends -displayGroup:willDeleteObject:to the delegate. If the delegate
- // agrees, deletes the object, then sends -displayGroup:didDeleteObject:to
- // the delegate. If the selection can change -selectionDidChange is sent
- // to the associations. Finally -contentsDidChange is always sent to the
- // associations. Returns YES on success, NO on failure.
-
- - (BOOL)deleteSelection;
- // Iterates over the selection, sending -deleteObjectAtIndex:to self for
- // each object in the selection. Aborts the delete and return NO if
- // any -deleteObjectAtIndex:message returns NO. Returns YES if all
- // objects are successfully deleted.
-
- - (id)insertObjectAtIndex:(unsigned)anIndex;
- // Asks the data source to create a new object using the createObject
- // method. The calls insertObject:atIndex:.
-
- - (void)insertObject:newObject atIndex:(unsigned)anIndex;
- // The newObject should be of an appropriate class for the displayGroup's
- // data source. A new object can be allocated using the data source's
- // createObject method.
-
- - (EOAssociation *)editingAssociation;
- // the association, if any, currently editing a value vended by this displayGroup
-
- - (NSArray *)observingAssociations;
- // returns an array of all EOAssociations observing this DisplayGroup.
- // (just filters the result of [EOObserverCenter observersForObject:self];
-
- - (BOOL)endEditing;
- // This method is invoked whenever the displayGroup needs to force an end
- // to text editing. It's invoked from -saveToObjects.
- // Returnd no if the editingAssociation refuses to end editing (e.g.
- // validation failure).
-
- - (void)setSortOrdering:(NSArray *)keySortOrderArray;
- - (NSArray *)sortOrdering;
- // an EOSortOrder array to be applied to all records upon fetch.
- // [displayGroup updateDisplayedObjects] must be called after
- // calling setSortOrdering: in order to apply the sort.
-
- - (void)setQualifier:(EOQualifier *)qualifier;
- - (EOQualifier *)qualifier;
- // an EOQualifier use to filter allObjects to the displayedObjects subset.
- // [displayGroup updateDisplayedObjects] must be called after
- // calling setQualifier: in order to apply the filter.
-
- - (void)updateDisplayedObjects;
- // resorts and filters the allObjects array to created an updated displayedObjects
- // subset. Updates the display accordingly.
-
- - (void)setSelectsFirstObjectAfterFetch:(BOOL)yn;
- - (BOOL)selectsFirstObjectAfterFetch;
- // Set/return the selection policy after fetching. If YES and nothing
- // was selected before the fetch then the first object will be selected.
- // If YES and there was a previous selection the displayGroup will attempt
- // to maintain that selection after the fetch. If NO the displayGroup will
- // not alter the selection. The default is YES.
-
- - (void)setValidatesChangesImmediately:(BOOL)yn;
- - (BOOL)validatesChangesImmediately;
-
- - (void)setFetchesOnLoad:(BOOL)yn;
- - (BOOL)fetchesOnLoad;
-
- - (void)setUsesOptimisticRefresh:(BOOL)yn;
- - (BOOL)usesOptimisticRefresh;
- // When objects change in the EOEditingContext for an EODisplayGroup,
- // by default the DisplayGroup refreshes all associations, even if
- // none of its objects are in the EOEditingContext's notification change list.
- // This "pessimistic" refresh is sometimes necessary because associations may
- // display derived values (via key paths or business methods) that depend on
- // objects other than those being displayed. However, if for a particular UI,
- // no such derived data is being displayed, usesOptimisticRefresh can be set
- // to instruct the EODisplayGroup to refresh only if one of its objects
- // were updated. The default is NO.
-
- - (NSArray *)localKeys;
- - (void)setLocalKeys:(NSArray *)newKeySet;
- // Keys declared by the user in the inspector in IB.
-
- @end
-
-
- @interface EODisplayGroup (EOAssociationInteraction)
-
- // find out what changed
- - (BOOL)selectionChanged;
- - (BOOL)contentsChanged;
- - (int)updatedObjectIndex;
- // When contentsChanged is set, if only one object was changed,
- // the index of the changed object is returned. If more than
- // one object was changed, -1 is returned. Associations can use this
- // information to optimize redisplay.
-
- // get values from the displayGroup for display
- - (id)valueForKey:(NSString *)key object:(id)object;
- // the primitive for the following two methods. This could
- // call the edit context to get buffered edits (?) or call a
- // delegate to allow displayGroup computed values.
-
- - (id)selectedObjectValueForKey:(NSString *)key;
- - (id)valueForObjectAtIndex:(unsigned)index key:(NSString *)key;
-
- // push user changes to the displayGroup.
- - (BOOL)setValue:(id)value forObject:(id)eo key:(NSString *)key;
- // the primitive for the following three methods. This could call
- // the EC to push buffered edits, or allow the delegate to save special
- // values for special keys.
- // The method will invoke all available validation protocols, and present
- // errors according to the displayGroups error handling policy.
- // A return value of YES indicates, in a UI context, that the user
- // can leave the field.
- - (BOOL)setSelectedObjectValue:value forKey:(NSString *)key;
- - (BOOL)setValue:(id)value forObjectAtIndex:(unsigned)index key:(NSString *)key;
- // returns YES if the user can leave the field
-
- // Allow displayGroup to handle local validation failures
- - (BOOL)association:(EOAssociation *)association failedToValidateValue:(NSString *)value forKey:(NSString *)key object:(id)eo errorDescription:(NSString *)errorDescription;
- // returns YES if association should allow user to leave the field.
- // DisplayGroup will decide how to handle error and how to present message.
-
- - (void)associationDidBeginEditing:(EOAssociation *)association;
- // called by association to tell displayGroup of pending UI changes. (e.g. dirty the
- // document).
- - (void)associationDidEndEditing:(EOAssociation *)association;
-
- @end
-
- // EOEditingContext EOEditors methods
- @interface EODisplayGroup (EOEditors)
- - (BOOL)editorHasChangesForEditingContext:(EOEditingContext *)editingContext;
- // Called by the EOEditingContext to determine if we have uncommitted edits.
- // Returns YES if [self editingAssociation] != nil
-
- - (void)editingContextWillSaveChanges:(EOEditingContext *)editingContext;
- // If [self endEditing] returns NO, raise an exception.
-
- @end
-
-
- // EOEditingContext EOMessageHandler methods
- @interface EODisplayGroup (EOMessageHandlers)
- - (void)editingContext:(EOEditingContext *)editingContext presentErrorMessage:(NSString *)message;
- // Presents alert panel
-
- @end
-
-
-
- // These methods are simple convienience methods to facilitate target/action
- // connections in InterfaceBuilder.
- @interface EODisplayGroup (EODisplayGroupTargetAction)
-
- - (void)selectNext:sender;
- // This is a target-action cover for -selectNext. Also sends
- // -redisplay after changing the selection.
-
- - (void)selectPrevious:sender;
- // This is a target-action cover for -selectPrevious. Also sends
- // -redisplay after changing the selection.
-
- - (void)fetch:sender;
- // This is a target-action cover for -fetch.
-
- - (void)insert:sender;
- // Inserts an object after the selected object, or, if nothing is
- // selected, at the end of the array.
-
- - (void)delete:(id)sender;
- // This is a target-action cover for -deleteObjectAtIndex:. Deletes the
- // first selected object, or, if nothing is selected the last object.
-
- @end
-
-
- // This optional protocol describes the methods a delegate of the
- // EODisplayGroup may implement.
- @interface NSObject (EODisplayGroupDelegate)
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldRedisplayForEditingContextChangeNotification:(NSNotification *)notification;
- // Sent when the EODisplayGroup receives an EOObjectsChangedInEditingContextNotification.
- // By default, all associations are refreshed (i.e. a redisplay is performed).
- // Delegate can override by looking at changes in notification userInfo and decide
- // whether to refresh.
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldRefetchForInvalidatedAllObjectsNotification:(NSNotification *)notification;
- // Sent when the EODisplayGroup receives an EOInvalidatedAllObjectsInStoreNotification
- // from its EOEditingContext. By default, the DisplayGroup discards any pending
- // changes from its associations and refetches its data from the dataSource.
- // Delegate can override and prevent the refetch.
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldChangeSelectionToIndexes:(NSArray *)newIndexes;
- - (void)displayGroupDidChangeSelection:(EODisplayGroup *)displayGroup;
- // Sent when the selection changes.
-
- - (BOOL)displayGroupShouldFetch:(EODisplayGroup *)displayGroup;
- // Informs the delegate that the displayGroup is about to fetch. If the
- // delegate returns no the fetch fails; if the delegate returns YES
- // the fetch proceeds.
-
- - (void)displayGroup:(EODisplayGroup *)displayGroup didFetchObjects:(NSArray *)objects;
- // Informs the delegate that the displayGroup has fetched object.
-
- - (NSArray *)displayGroup:(EODisplayGroup *)displayGroup displayArrayForObjects:(NSArray *)objects;
- // If the delegate implements this method, it is responsible returning a sorted and
- // filtered version of the given array. If the delegate does not implement this method
- // and a sortOrdering and/or qualifier has been on the DisplayGroup, the displayGroup
- // will filter the object using [objects filteredArrayUsingQualifier:[self qualifier]]
- // and then sort them using [objects sortedArrayUsingKeyOrderArray:[self sortOrdering]];
-
- - (void)displayGroup:(EODisplayGroup *)displayGroup didSetValue:(id)value forObject:(id)eo key:(NSString *)key;
-
- - (void)displayGroup:(EODisplayGroup *)displayGroup createObjectFailedForDataSource:dataSource;
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldInsertObject:object atIndex:(unsigned)newIndex;
- // If the delegate returns NO object is released and not inserted.
-
- - (void)displayGroup:(EODisplayGroup *)displayGroup didInsertObject:object;
- // Informs the delegate that the displayGroup has inserted object.
-
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldDeleteObject:object;
- // If the delegate returns NO object is not deleted.
-
- - (void)displayGroup:(EODisplayGroup *)displayGroup didDeleteObject:object;
- // Informs the delegate that the displayGroup has deleted object.
-
- - (void)displayGroupDidChangeDataSource:(EODisplayGroup *)displayGroup;
- // indicates that setDataSource: was called and the current dataSource
- // has been changed.
-
- - (BOOL)displayGroup:(EODisplayGroup *)displayGroup shouldDisplayAlertWithTitle:(NSString *)title message:(NSString *)message;
- // Called before the DisplayGroup will call NSRunAlertPanel(). Delegate can intercept
- // and supress alert or present it in another way.
-
- @end
-
-