]> err.no Git - sope/blob - sope-core/EOControl/EOArrayDataSource.m
removed NGJavaScript support
[sope] / sope-core / EOControl / EOArrayDataSource.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include <EOControl/EOArrayDataSource.h>
24 #include <EOControl/EOFetchSpecification.h>
25 #include <EOControl/EOSortOrdering.h>
26 #include <EOControl/EOQualifier.h>
27 #include "common.h"
28
29 @interface EODataSource(PostChange)
30 - (void)postDataSourceChangedNotification;
31 @end
32
33 @implementation EOArrayDataSource
34
35 - (id)init {
36   if ((self = [super init])) {
37     self->objects = [[NSMutableArray alloc] init];
38   }
39   return self;
40 }
41 - (void)dealloc {
42   [self->fetchSpecification release];
43   [self->objects            release];
44   [super dealloc];
45 }
46
47 /* accessors */
48
49 - (void)setFetchSpecification:(EOFetchSpecification *)_fspec {
50   if ([self->fetchSpecification isEqual:_fspec])
51     return;
52   
53   [self->fetchSpecification autorelease];
54   self->fetchSpecification = [_fspec copy];
55   
56   [self postDataSourceChangedNotification];
57 }
58 - (EOFetchSpecification *)fetchSpecification {
59   return self->fetchSpecification;
60 }
61
62 - (void)setArray:(NSArray *)_array {
63   [self->objects removeAllObjects];
64   [self->objects addObjectsFromArray:_array];
65 }
66
67 /* fetching */
68
69 - (NSArray *)fetchObjects {
70   NSArray *result;
71   
72   if (self->fetchSpecification == nil) {
73     result = [[self->objects copy] autorelease];
74   }
75   else {
76     EOQualifier *q;
77     NSArray     *sort;
78     
79     q    = [self->fetchSpecification qualifier];
80     sort = [self->fetchSpecification sortOrderings];
81     
82     if (q == nil) {
83       if (sort)
84         result = [self->objects sortedArrayUsingKeyOrderArray:sort];
85       else
86         result = [[self->objects copy] autorelease];
87     }
88     else {
89       result = [self->objects filteredArrayUsingQualifier:q];
90       if (sort) result = [result sortedArrayUsingKeyOrderArray:sort];
91     }
92   }
93   return result;
94 }
95
96 /* operations */
97
98 - (void)deleteObject:(id)_object {
99   [self->objects removeObjectIdenticalTo:_object];
100   [self postDataSourceChangedNotification];
101 }
102
103 - (void)insertObject:(id)_object {
104   [self->objects addObject:_object];
105   [self postDataSourceChangedNotification];
106 }
107
108 - (id)createObject {
109   return [NSMutableDictionary dictionaryWithCapacity:16];
110 }
111
112 @end /* EOArrayDataSource */