home *** CD-ROM | disk | FTP | other *** search
- // EOAssociation.h
- // Enterprise Objects Framework
- // Copyright (c) 1995, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
- #import <AppKit/AppKit.h>
- #import <EOInterface/EODisplayGroup.h>
-
- // An EOAssociation acts as the glue between an object (usually a user
- // interface widget) and the properties of objects managed by one or
- // more displayGroups. When the contents or selection of one of the displayGroups
- // it observes changes, the association updates its object (widget). Similarly,
- // when the association receives an action or delegate message from its object
- // that indicates a change in the selection or value, it passes that change on
- // to the appropriate displayGroup.
- //
- // Associations have one or more named "aspects" that can be bound to object
- // properties. For example, the EOControlAssociation has a "value" aspect
- // that could be bound to the "firstName" property of an employee displayGroup,
- // while the EOPopupAssociation also has an "values" aspect that could be
- // bound to the "departmentName" property of all objects in a department
- // displayGroup.
- //
- // Associations are normally created automatically from connections made
- // in InterfaceBuilder. To create an association programmatically:
- // EOControlAssociation *assoc = [[EOControlAssociation alloc] initWithObject:aField];
- // [assoc bindAspect:@"value" displayGroup:aDisplayGroup key:@"firstName"]
- // // possibly other bindings...
- // [assoc establishConnection]; // assoc is retained by its object
- // [assoc release]; // so we don't need to retain it
- //
- // Associations use the EOObserver mechanism to watch their displayGroups.
- // Because associations inherit from EODelayedObserver, all of the changes
- // notifications from their displayGroups are automatically coalesced, and
- // a single "subjectChanged" message is delivered to each affected association
- // at the end of processing the current event. In subjectChanged the
- // association can callback to its displayGroups and query them as to whether
- // selectionChanged and/or contentsChanged.
- //
-
- @interface EOAssociation : EODelayedObserver <NSCoding>
- {
- id _object;
-
- unsigned _refs:8;
- unsigned _isConnected:1;
- unsigned _extras:7;
- unsigned subclassFlags:16; // for use by subclasses?
-
- // extended ivars used to hold key/displayGroup pairs.
- // Subclasses can add ivars, but not extended ivars.
- }
-
- // implemented by subclasses
- + (NSString *)displayName;
- // the name to be used for the class inside InterfaceBuilder.
- // The default is the class name.
-
- + (BOOL)isUsableWithObject:(id)object;
- // assoc can say whether it can be used with the given source object
- // This may key off of the class of the source, or possibly look at other
- // factors (e.g. for a matrix, what is the type of the cells -- radio, text?)
- // Default returns NO.
-
- + (NSArray *)aspects;
- // returns a list of aspects (sockets) that offered for connection by this
- // association.
- // Default returns an empty array.
-
- + (NSArray *)aspectSignatures;
- // Should return an array corresponding to the aspects array containing a string mask
- // identifying the types of properties the positionally corresponding aspect can
- // be connected to.
- // Types are: "A" (attribute), "1" (to-one relationship), "M" (to-many relationship).
- // E.g., the signature "1M" indicates the aspect can be bound to a to-one or to-many
- // relationship.
- // The signature "" indicates the aspect can be bound to a DisplayGroup without
- // specifying a key (@"" is used as the key in the call to bindAspect:...).
- // Default implementation returns an array of "A1M" of the length of aspects.
-
- + (NSString *)primaryAspect;
- // the name of the "primary" (or default) aspect. Usually "value"
- // This is the default selected in the connect inspector when
- // first connecting an association in IB.
- // Default returns nil
-
- + (NSArray *)objectKeysTaken;
- // returns a list of features of the control that are taken over by the
- // association (examples: "target", "delegate"). These keys will be dimmed
- // out in the IB connect inspector, indicating that the developer cannot
- // use them when using this association.
-
- + (NSArray *)associationClassesSuperseded;
- // Should return a list of associations that this association supercedes.
- // That is, if this association is applicable for a given object
- // then the returned associations will be ommitted from the list
- // of associations in IB for the object. For example, EOPopupAssociation
- // overrides EOControlAssociation since for popups, the PopupAssociation
- // is always more appropriate.
-
- - initWithObject:object;
- // Designated initializer. Sets up association, but does not activate it.
- // establishConnection must be called to actually activate the association.
-
- - initWithCoder:(NSCoder *)coder;
- // Default implementation unarchives the key/destination pairs and then
- // calls initWithObject:
- - (void)encodeWithCoder:(NSCoder *)coder;
-
- - (void)establishConnection;
- // Activates the association after initWithObject: or initWithCoder:.
- // Default implementation subscribes for change notification on the
- // destination displayGroups. Subclasses should override to set self
- // as target or delegate of object.
- // The nib file unarchiving calls this automatically for associations
- // read in from a nib file.
- // Once the connection is established the association becomes "owned" by
- // its object (its retain count is bumped) and will automatically have
- // its breakConnection method called when the object is dealloced.
-
- - (void)dealloc;
- // this will call breakConnection to unsubscribe from all destinations
- // being observed
-
- - (void)breakConnection;
- // removes the association as an observer from it destination and
- // breaks it connection to the parent (causing the retain count to drop).
- // Subclasses may want to override this to unhook delegate connections
- // in the associations object.
-
- - (id)object;
- // Returns the object (typically a UI control) managed by the association.
-
- - (void)bindAspect:(NSString *)name displayGroup:(EODisplayGroup *)dest key:(NSString *)key;
- // Set the destination for an aspect. Binding can be eliminated
- // by binding to nil destination.
- // bindAspect: can only be called *before* calling establishConnection.
- // Once the association has been connected, its bindings cannot be changed.
-
- - (EODisplayGroup *)displayGroupForAspect:(NSString *)name;
- - (NSString *)displayGroupKeyForAspect:(NSString *)name;
-
- - (BOOL)canBindAspect:(NSString *)name displayGroup:(EODisplayGroup *)displayGroup key:(NSString *)key;
- // See if this aspect can be bound to the given destination. Could
- // be used to disable certain aspects in inspector if destination is of wrong type.
- // Default implementation returns YES.
-
- // Key methods for association to interact with the displayGroup
- - (BOOL)endEditing;
- // called by displayGroup to tell association to push uncommitted edit.
- // returns NO if validation failure (and calls assocation:failedToValidate:...)
- // Default implementation returns YES.
-
- - (void)subjectChanged;
- // Called to tell association that something in its world has changed.
- // It should call back its displayGroups to determine what to actually changed
- // (selection, object contents, etc).
- // Default implementation does nothing
-
- + (NSArray *)associationClassesForObject:(id)object;
- // called on root class to return an array of association classes suitable
- // for use with the given source. This is turn calls "usableWithObject:" to
- // all registered association classes.
- @end
-
-
- @interface EOAssociation (EOExtras)
- // Useful methods for use by subclasses
- // Calls the object pointed to by the aspect to get info
- - (id)valueForAspect:(NSString *)name;
- // retrieves value for key of aspect as destination.
- - (BOOL)setValue:value forAspect:(NSString *)name;
- - (BOOL)shouldEndEditingForAspect:(NSString *)aspectName invalidInput:(NSString *)string errorDescription:(NSString *)errorDescription;
- // usually called by subclasses in response to validation failure from
- // an NSFormatter (control:didFailToFormatString:errorDescription:)
- // Passes message to displayGroup to determine whether association should
- // allow use to end editing.
-
- - (id)valueForAspect:(NSString *)name atIndex:(unsigned)index;
- // retrieves value for key of aspect as destination.
- - (BOOL)setValue:value forAspect:(NSString *)name atIndex:(unsigned)index;
- - (BOOL)shouldEndEditingForAspect:(NSString *)aspectName invalidInput:(NSString *)string errorDescription:(NSString *)errorDescription index:(unsigned)index;
-
- - (void)copyMatchingBindingsFromAssociation:(EOAssociation *)other;
- // makes bindings for all of the aspects in the receive that match
- // those in other.
- @end
-
-