Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
  2. - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
  3. - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
  4. - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  5.  
  6. - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  7.  
  8. myObject=[NodeObject new];
  9.  
  10. myObject =[node copy]; // node != nil is checked before
  11.  
  12. - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
  13. return item; }
  14.  
  15. #import "OutlineController.h"
  16.  
  17. @implementation OutlineController {
  18.  
  19. }
  20.  
  21.  
  22. //
  23. // All items are of type Hierarchy !
  24. //
  25.  
  26. - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
  27. NSInteger result=0;
  28. id kValue=[item anObject];
  29.  
  30. if (!item) {
  31. result = [[delegate dictDataSource] count];
  32. }
  33. else {
  34. if ( [kValue isKindOfClass:[NSDictionary class]] ||
  35. [kValue isKindOfClass:[NSArray class]]) result=[kValue count];
  36. }
  37.  
  38. NSLog(@"nbr of childs %ld",(long)result);
  39. return result;
  40. }
  41.  
  42.  
  43.  
  44. - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
  45. BOOL result=NO;
  46. id kValue=[item anObject];
  47.  
  48. if (!item) {
  49. result = [[delegate dictDataSource] count] > 0 ? YES:NO;
  50. }
  51. else {
  52. if ( [kValue isKindOfClass:[NSDictionary class]] ||
  53. [kValue isKindOfClass:[NSArray class]]) result=YES;
  54. }
  55. NSLog(@"expandable %d",result);
  56. return result;
  57. }
  58.  
  59.  
  60. //
  61. // The only place items are created is here !
  62. //
  63. - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
  64. id oneObject;
  65. Hierarchy *hchy;
  66.  
  67. //
  68. // the root is always of type dictionary, and we take the keys as "index"
  69. if ( !item ) {
  70. hchy = [Hierarchy new];
  71. [hchy setComesFromDict:[delegate dictDataSource]];
  72. [hchy setKey:[[[hchy comesFromDict] allKeys ] objectAtIndex:index] ];
  73. oneObject =[[hchy comesFromDict] valueForKey:[hchy key]];
  74. [hchy setAnObject:oneObject];
  75. }
  76. else {
  77. hchy = [item copy] ;
  78.  
  79. if ([[hchy anObject] isKindOfClass:[NSDictionary class] ]) {
  80. // Case: item comes from dictionary.
  81. // ( if item is expandable, outlineview will ask for item of index here.
  82. // only dictionary or arrays are expandable )
  83.  
  84. [hchy setKey:[[[hchy anObject] allKeys] objectAtIndex:index]];
  85. oneObject =[[hchy anObject] valueForKey:[hchy key]];
  86. [hchy setAnObject:oneObject];
  87. } else
  88. {
  89. if ([[hchy anObject] isKindOfClass:[NSArray class] ]) {
  90. // Case: item comes from anArray
  91. // fetching array element
  92. [hchy setComesFromDict:Nil];
  93. oneObject =[[hchy anObject] objectAtIndex:index];
  94. [hchy setAnObject:oneObject];
  95.  
  96. [hchy setKey:[NSString stringWithFormat:@"%ld",(long)index]];
  97. }else
  98. { // Case: Item is a value
  99. //
  100. NSLog(@"single KV pair : %@",[hchy key]);
  101. ;
  102. }
  103. }
  104. }
  105.  
  106. if ( [[hchy anObject] isKindOfClass:[NSArray class] ] ||
  107. [[hchy anObject] isKindOfClass:[NSDictionary class] ] ) {
  108. [hchy setValueText:@""];
  109. [hchy setIsHeader:YES];
  110. } else
  111. {
  112. [hchy setValueText:[hchy anObject]];
  113. }
  114. return hchy;
  115. }
  116.  
  117. - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
  118.  
  119. return item;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement