-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCOCollection.h
More file actions
166 lines (143 loc) · 5.16 KB
/
Copy pathCOCollection.h
File metadata and controls
166 lines (143 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
Copyright (C) 2011 Quentin Mathe
Date: December 2011
License: MIT (see COPYING)
*/
#import <Foundation/Foundation.h>
#import <EtoileFoundation/EtoileFoundation.h>
#import <CoreObject/COObject.h>
/**
* @group Object Collection and Organization
* @abstract COCollection is a abstract class that provides a common API to
* various concrete collection subclasses such as COGroup or COContainer.
*
* COCollection represents a mutable collection, but subclasses can be immutable.
*
* The collection content is stored in the property returned by -contentKey.
* If the content property is not 'objects', -contentKey must be overriden.
*
* COCollection adopts the collection protocols. Which means you can mutate
* COCollection subclass instances using ETCollectionMutation methods such
* as -addObject:, -insertObject:atIndex:, -removeObject:atIndex:, -removeObject:
* etc. In addition, the class provides -addObjects:.
*
* Every time the collection is mutated, COCollection posts a
* ETSourceDidUpdateNotification (in addition the usual Key-Value-Observing
* notifications).<br />
* If you override ETCollectionMutation primitive methods in a COCollection
* subclass, you must call -didUpdate in the new implementation (to ensure
* ETSourceDidUpdateNotification is posted).
*/
@interface COCollection : COObject <ETCollection, ETCollectionMutation>
/** @taskunit Metamodel */
/**
* Returns a multivalued, ordered and persistent property.
*
* You can use this method to easily describe your collection content in a way
* that matches the superclass contraints.
*
* The returned property can be customized, then inserted into the entity built
* with +newEntityDescription in your subclass.
*
* Name and type must not be nil.
*
* Both type and opposite must be entity description names such as
* <em>Anonymous.NSObject</em> or <em>NSObject</em>.<br />
* The <em>Anonymous</em> prefix is optional. Most entity description names
* don't require a prefix, because they don't belong to a package description
* but are just registered at runtime directly, and belong to this Anonymous
* package as a result.
*
* Can be overriden to change the constraints applying to the property.
*/
+ (ETPropertyDescription *)contentPropertyDescriptionWithName: (NSString *)aName
type: (NSString *)aType
opposite: (NSString *)oppositeType;
/**
* <override-never />
* Returns UTI type for the collection elements.
*
* For inserting a new object in the collection, you can use this method to
* know the object class to instantiate.
*
* The returned UTI depends on -[ETPropertyDescription type] for the content
* property description (looked up using -contentKey).<br />
* To customize the type, you must edit the receiver entity description.
*
* See also -[ETController currentObjectType] in EtoileUI.
*/
@property (nonatomic, readonly) ETUTI *objectType;
/**
* <override-never />
* Returns whether the collection is ordered.
*
* The returned value is controlled by -[ETPropertyDescription isOrdered] for
* the content property description (looked up using -contentKey).
*/
@property (nonatomic, readonly, getter=isOrdered) BOOL ordered;
/** @taskunit Content Access */
/**
* <override-dummy />
* Returns the property name that holds the collection content.
*
* This method is used by COCollection to implement ETCollection and
* ETCollectionMutation protocol methods. Subclasses must thereby return a
* valid key, other the collection API won't behave correctly.
*
* For example, -[ETCollectionMutation insertObjects:atIndexes:hints:]
* implementation uses the content key to retrieve the content collection.
*
* By default, returns <em>objects</em>.
*/
@property (nonatomic, readonly) NSString *contentKey;
/** @taskunit Collection Mutation Additions */
/**
* Adds all the given objects to the receiver content.
*/
- (void)addObjects: (NSArray *)anArray;
/**
* Posts ETSourceDidUpdateNotification.
*
* You must invoke this method every time the collection is changed.
* For example, when you override
* -[ETCollectionMutation insertObjects:atIndexes:hints:].
*
* EtoileUI relies on this notification to reload the UI transparently.
*/
- (void)didUpdate;
/** @taskunit Object Matching */
/**
* Returns the first object whose identifier matches.
*
* The search is shallow, in other words limited to the objects in the receiver
* content.
*
* See -[COObject identifier].
*/
- (id)objectForIdentifier: (NSString *)anId;
@end
/**
* @group Object Collection and Organization
*/
@interface COObject (COCollectionTypeQuerying)
/**
* Returns whether the receiver is a group or not.
*/
@property (nonatomic, readonly) BOOL isGroup;
/**
* Returns whether the receiver is a tag or not.
*
* A tag is group that belongs to -[COEditingContext tagGroup].
*/
@property (nonatomic, readonly) BOOL isTag;
/**
* Returns whether the receiver is a container or not.
*/
@property (nonatomic, readonly) BOOL isContainer;
/**
* Returns whether the receiver is a library or not.
*
* A library is a container.
*/
@property (nonatomic, readonly) BOOL isLibrary;
@end