Annotation of Examples/EnterpriseObjects/SHLExamples/Delegation/EOFDelegateDatabaseCategory.m, revision 1.1.1.1

1.1       root        1: /*--------------------------------------------------------------------------
                      2:  *
                      3:  *     You may freely copy, distribute, and reuse the code in this example.
                      4:  *     SHL Systemhouse disclaims any warranty of any kind, expressed or  
                      5:  *     implied, as to its fitness for any particular use.
                      6:  *
                      7:  *
                      8:  *     Database
                      9:  *
                     10:  *     Category Of:    EOFDelegate
                     11:  *
                     12:  *     Conforms To:    None
                     13:  *
                     14:  *     Declared In:    EOFDelegateDatabaseCategory.h
                     15:  *
                     16:  *
                     17:  *------------------------------------------------------------------------*/
                     18: #import "EOFDelegateDatabaseCategory.h"
                     19: 
                     20: 
                     21: 
                     22: 
                     23: @implementation EOFDelegate (Database)
                     24: 
                     25: /*--------------------------------------------------------------------------
                     26:  *     EODatabaseChannel Delegate Methods
                     27:  *------------------------------------------------------------------------*/
                     28: - databaseChannel:channel willInsertObject:object
                     29: {
                     30:     // Invoked from -insertObject: to tell the delegate that an object will
                     31:     // be inserted. The delegate may return the object, a substitute, or nil
                     32:     // to prevent insertion.
                     33:        
                     34:        id      result = object;
                     35:        
                     36:        [[NXApp delegate] announce:channel 
                     37:                selector:_cmd 
                     38:                with:[NSArray arrayWithObject:object]];
                     39: 
                     40:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                     41:                {
                     42:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                     43:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                     44:                        {
                     45:                        case NX_ALERTALTERNATE:
                     46:                                result = nil;
                     47:                                break;
                     48:                        case NX_ALERTDEFAULT:
                     49:                        default:
                     50:                                result = object;
                     51:                                break;
                     52:                        }
                     53:                }
                     54:        
                     55:        return result;
                     56: }
                     57: 
                     58: 
                     59: - (void)databaseChannel:channel didInsertObject:object
                     60: {
                     61:     // Invoked from -insertObject: to tell the delegate that 
                     62:     // an object was inserted.
                     63: 
                     64:        [[NXApp delegate] announce:channel 
                     65:                selector:_cmd 
                     66:                with:[NSArray arrayWithObject:object]];
                     67: }
                     68: 
                     69: 
                     70: - databaseChannel:channel willDeleteObject:object
                     71: {
                     72:     // Invoked from -deleteObject: to tell the delegate that an object will
                     73:     // be deleted.  The delegate may return the object, a substitute, or nil
                     74:     // to prevent deletion.
                     75:        
                     76:        id      result = object;
                     77:        
                     78:        [[NXApp delegate] announce:channel 
                     79:                selector:_cmd 
                     80:                with:[NSArray arrayWithObject:object]];
                     81:        
                     82:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                     83:                {
                     84:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                     85:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                     86:                        {
                     87:                        case NX_ALERTALTERNATE:
                     88:                                result = nil;
                     89:                                break;
                     90:                        case NX_ALERTDEFAULT:
                     91:                        default:
                     92:                                result = object;
                     93:                                break;
                     94:                        }
                     95:                }
                     96:        
                     97:        return result;
                     98: }
                     99: 
                    100: 
                    101: - (void)databaseChannel:channel didDeleteObject:object
                    102: {
                    103:     // Invoked from -deleteObject: to tell the delegate that 
                    104:     // an object was deleted.
                    105: 
                    106:        [[NXApp delegate] announce:channel 
                    107:                selector:_cmd 
                    108:                with:[NSArray arrayWithObject:object]];
                    109: }
                    110: 
                    111: 
                    112: - databaseChannel:channel willUpdateObject:object
                    113: {
                    114:     // Invoked from -updateObject: to tell the delegate that an object will
                    115:     // be updated.  The delegate may return the object, a substitute, or nil
                    116:     // to prevent updating.
                    117:        
                    118:        id      result = object;
                    119:        
                    120:        [[NXApp delegate] announce:channel 
                    121:                selector:_cmd 
                    122:                with:[NSArray arrayWithObject:object]];
                    123:        
                    124:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                    125:                {
                    126:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                    127:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                    128:                        {
                    129:                        case NX_ALERTALTERNATE:
                    130:                                result = nil;
                    131:                                break;
                    132:                        case NX_ALERTDEFAULT:
                    133:                        default:
                    134:                                result = object;
                    135:                                break;
                    136:                        }
                    137:                }
                    138:        
                    139:        return result;
                    140: }
                    141: 
                    142: 
                    143: - (void)databaseChannel:channel didUpdateObject:object
                    144: {
                    145:     // Invoked from -updateObject: to tell the delegate that 
                    146:     // an object was updated.
                    147: 
                    148:        [[NXApp delegate] announce:channel 
                    149:                selector:_cmd 
                    150:                with:[NSArray arrayWithObject:object]];
                    151: }
                    152: 
                    153: 
                    154: - (NSDictionary *)databaseChannel:channel
                    155:     willRefetchObject:object
                    156:     fromSnapshot:(NSDictionary *)snapshot
                    157: {
                    158:     // Invoked whenever an object that was previously fetched is fetched again
                    159:     // and the re-fetched data is different from that in the object.  The
                    160:     // object will be refetched with the dictionary returned by this method,
                    161:     // which may be the snapshot provided or a substitute.  The delegate may
                    162:     // also return nil to prevent the object from being refetched.
                    163:        
                    164:        id      result = object;
                    165:        
                    166:        [[NXApp delegate] announce:channel 
                    167:                selector:_cmd 
                    168:                with:[NSArray arrayWithObjects: object, snapshot, nil]];
                    169:        
                    170:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                    171:                {
                    172:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                    173:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                    174:                        {
                    175:                        case NX_ALERTALTERNATE:
                    176:                                result = nil;
                    177:                                break;
                    178:                        case NX_ALERTDEFAULT:
                    179:                        default:
                    180:                                result = object;
                    181:                                break;
                    182:                        }
                    183:                }
                    184:        
                    185:        return result;
                    186: }
                    187: 
                    188: 
                    189: 
                    190: - (BOOL)databaseChannel:channel
                    191:     willSelectObjectsDescribedByQualifier:(EOQualifier *)qualifier
                    192:     fetchOrder:(NSArray *)fetchOrder
                    193: {
                    194:     // Invoked from -selectObjectsDescribedByQualifier:...  to tell the
                    195:     // delegate that the channel will select objects as specified by
                    196:     // qualifier.  The delegate can modify the qualifier and fetch order.  If
                    197:     // the delegate returns YES the channel will go ahead and select the
                    198:     // object; if the delegate returns NO the channel will abort the select
                    199:     // and return NO.
                    200:        
                    201:        BOOL    result = YES;
                    202:        
                    203:        [[NXApp delegate] announce:channel 
                    204:                selector:_cmd 
                    205:                with:[NSArray arrayWithObjects: qualifier, fetchOrder, nil]];
                    206:        
                    207:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                    208:                {
                    209:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                    210:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                    211:                        {
                    212:                        case NX_ALERTALTERNATE:
                    213:                                result = NO;
                    214:                                break;
                    215:                        case NX_ALERTDEFAULT:
                    216:                        default:
                    217:                                result = YES;
                    218:                                break;
                    219:                        }
                    220:                }
                    221:        
                    222:        return result;
                    223: }
                    224: 
                    225: 
                    226: - (void)databaseChannel:channel
                    227:     didSelectObjectsDescribedByQualifier:(EOQualifier *)qualifier
                    228:     fetchOrder:(NSArray *)fetchOrder
                    229: {
                    230:     // Invoked from -selectObjectsDescribedByQualifier:...  to tell the
                    231:     // delegate that the channel selected objects as specified by qualifier.
                    232: 
                    233:        [[NXApp delegate] announce:channel 
                    234:                selector:_cmd 
                    235:                with:[NSArray arrayWithObjects: qualifier, fetchOrder, nil]];
                    236: }
                    237: 
                    238: 
                    239: - (void)databaseChannel:channel
                    240:     willFetchObjectOfClass:(Class)class
                    241:     withZone:(NSZone *)zone
                    242: {
                    243:     // Invoked from -fetchWithZone: to tell the delegate that 
                    244:     // the channel willfetch the next selected object.
                    245: 
                    246:        [[NXApp delegate] announce:channel 
                    247:                selector:_cmd 
                    248:                with:[NSArray arrayWithObject:class]];
                    249: }
                    250: 
                    251: 
                    252: - (void)databaseChannel:channel didFetchObject:object
                    253: {
                    254:     // Invoked from -fetchWithZone: to tell the delegate that 
                    255:     // the channel fetched the next selected object.
                    256:        
                    257:        [[NXApp delegate] announce:channel 
                    258:                selector:_cmd 
                    259:                with:[NSArray arrayWithObject:object]];
                    260: }
                    261: 
                    262: 
                    263: - (BOOL)databaseChannel:channel willLockObject:object
                    264: {
                    265:     // Invoked from -lockObject: to tell the delegate that object will be
                    266:     // locked using snapshot data to determine whether the database has been
                    267:     // modified.  The delegate may return YES to allow the channel to proceed,
                    268:     // or NO to cause the operation to fail and -lockObject: to return NO.
                    269:        
                    270:        BOOL    result = YES;
                    271:        
                    272:        [[NXApp delegate] announce:channel 
                    273:                selector:_cmd 
                    274:                with:[NSArray arrayWithObject:object]];
                    275:        
                    276:        if ([[NXApp delegate] wantsAlertPanels] == YES)
                    277:                {
                    278:                switch (NXRunAlertPanel ("EODatabaseChannel", 
                    279:                        "%s", "YES", "NO", NULL, sel_getName(_cmd)))
                    280:                        {
                    281:                        case NX_ALERTALTERNATE:
                    282:                                result = NO;
                    283:                                break;
                    284:                        case NX_ALERTDEFAULT:
                    285:                        default:
                    286:                                result = YES;
                    287:                                break;
                    288:                        }
                    289:                }
                    290:        
                    291:        return result;
                    292: }
                    293: 
                    294: 
                    295: - (void)databaseChannel:channel didLockObject:object
                    296: {
                    297:     // Invoked from -lockObject: to tell the delegate that 
                    298:        // object was locked.
                    299: 
                    300:        [[NXApp delegate] announce:channel 
                    301:                selector:_cmd 
                    302:                with:[NSArray arrayWithObject:object]];
                    303: }
                    304: 
                    305: 
                    306: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.