Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
- - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
- - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
- - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
- - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
- myObject=[NodeObject new];
- myObject =[node copy]; // node != nil is checked before
- - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
- return item; }
- #import "OutlineController.h"
- @implementation OutlineController {
- }
- //
- // All items are of type Hierarchy !
- //
- - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
- NSInteger result=0;
- id kValue=[item anObject];
- if (!item) {
- result = [[delegate dictDataSource] count];
- }
- else {
- if ( [kValue isKindOfClass:[NSDictionary class]] ||
- [kValue isKindOfClass:[NSArray class]]) result=[kValue count];
- }
- NSLog(@"nbr of childs %ld",(long)result);
- return result;
- }
- - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
- BOOL result=NO;
- id kValue=[item anObject];
- if (!item) {
- result = [[delegate dictDataSource] count] > 0 ? YES:NO;
- }
- else {
- if ( [kValue isKindOfClass:[NSDictionary class]] ||
- [kValue isKindOfClass:[NSArray class]]) result=YES;
- }
- NSLog(@"expandable %d",result);
- return result;
- }
- //
- // The only place items are created is here !
- //
- - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
- id oneObject;
- Hierarchy *hchy;
- //
- // the root is always of type dictionary, and we take the keys as "index"
- if ( !item ) {
- hchy = [Hierarchy new];
- [hchy setComesFromDict:[delegate dictDataSource]];
- [hchy setKey:[[[hchy comesFromDict] allKeys ] objectAtIndex:index] ];
- oneObject =[[hchy comesFromDict] valueForKey:[hchy key]];
- [hchy setAnObject:oneObject];
- }
- else {
- hchy = [item copy] ;
- if ([[hchy anObject] isKindOfClass:[NSDictionary class] ]) {
- // Case: item comes from dictionary.
- // ( if item is expandable, outlineview will ask for item of index here.
- // only dictionary or arrays are expandable )
- [hchy setKey:[[[hchy anObject] allKeys] objectAtIndex:index]];
- oneObject =[[hchy anObject] valueForKey:[hchy key]];
- [hchy setAnObject:oneObject];
- } else
- {
- if ([[hchy anObject] isKindOfClass:[NSArray class] ]) {
- // Case: item comes from anArray
- // fetching array element
- [hchy setComesFromDict:Nil];
- oneObject =[[hchy anObject] objectAtIndex:index];
- [hchy setAnObject:oneObject];
- [hchy setKey:[NSString stringWithFormat:@"%ld",(long)index]];
- }else
- { // Case: Item is a value
- //
- NSLog(@"single KV pair : %@",[hchy key]);
- ;
- }
- }
- }
- if ( [[hchy anObject] isKindOfClass:[NSArray class] ] ||
- [[hchy anObject] isKindOfClass:[NSDictionary class] ] ) {
- [hchy setValueText:@""];
- [hchy setIsHeader:YES];
- } else
- {
- [hchy setValueText:[hchy anObject]];
- }
- return hchy;
- }
- - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
- return item;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement