-
-
Save chandlerkent/262671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import <Foundation/CPObject.j> | |
@import <AppKit/CPOutlineView.j> | |
@implementation SourceListController : CPObject | |
{ | |
CPOutlineView outlineView; | |
CPView owner; | |
CPDictionary items; | |
AOURLConnection dataConnection; | |
id delegate; | |
} | |
- (id)initWithOwner:(CPView)anOwner delegate:(id)aDelegate | |
{ | |
if (self = [super init]) | |
{ | |
delegate = aDelegate; | |
owner = anOwner; | |
outlineView = [[CPOutlineView alloc] initWithFrame:[owner bounds]]; | |
var textColumn = [[CPTableColumn alloc] initWithIdentifier:@"TextColumn"]; | |
[textColumn setMaxWidth:500.0]; | |
[outlineView setHeaderView:nil]; | |
[outlineView setCornerView:nil]; | |
[outlineView addTableColumn:textColumn]; | |
[outlineView setOutlineTableColumn:textColumn]; | |
//[outlineView setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[mainBundle pathForResource:@"toolbar_bg.png"]]]]; | |
[owner addSubview:outlineView]; | |
[self loadData]; | |
//[outlineView setDataSource:self]; | |
} | |
return self; | |
} | |
- (void)loadData | |
{ | |
dataConnection = [[AOURLConnection alloc] initWithURL:@"resourcelist" method:@"GET" content:null delegate:self]; | |
} | |
- (void)connection:(CPURLConnection) dataConnection didReceiveData:(CPString)data | |
{ | |
var result = CPJSObjectCreateWithJSON(data); | |
//if(result.error == null) | |
//{ | |
console.log(result); | |
items = [CPDictionary dictionaryWithJSObject:result recursively:YES]; | |
console.log(items); | |
[outlineView setDataSource:self]; | |
[outlineView reloadData]; | |
//} | |
} | |
- (id)outlineView:(CPOutlineView)outlineView child:(int)index ofItem:(id)item | |
{ | |
CPLog("outlineView:%@ child:%@ ofItem:%@", outlineView, index, item); | |
if (item === nil) | |
{ | |
var values = [items objectForKey:'root']; | |
var children = [values objectForKey:@"children"]; | |
var childID = [children objectForKey:index]; | |
//keys = [values allKeys]; | |
//console.log([keys objectAtIndex:index]); | |
return [childID]; | |
} | |
else | |
{ | |
//console.log('item: '+item); | |
//console.log(index); | |
var values = [items objectForKey:item]; | |
var children = [values objectForKey:@"children"]; | |
var childID = [children objectForKey:index]; | |
//keys = [values allKeys]; | |
//console.log([keys objectAtIndex:index]); | |
return [childID]; | |
} | |
} | |
- (BOOL)outlineView:(CPOutlineView)outlineView isItemExpandable:(id)item | |
{ | |
CPLog("outlineView:%@ isItemExpandable:%@", outlineView, item); | |
var values = [items objectForKey:item]; | |
if([values objectForKey:@"children"]) | |
{ | |
console.log(true); | |
return true; | |
} | |
else | |
{ | |
console.log(false); | |
return false; | |
} | |
} | |
- (int)outlineView:(CPOutlineView)outlineView numberOfChildrenOfItem:(id)item | |
{ | |
CPLog("outlineView:%@ numberOfChildrenOfItem:%@", outlineView, item); | |
if (item === nil) | |
{ | |
var values = [items objectForKey:'root']; | |
var children = [values objectForKey:@"children"]; | |
return [children count]; | |
} | |
else | |
{ | |
var values = [items objectForKey:item]; | |
var children = [values objectForKey:@"children"]; | |
console.log([children count]); | |
return [children count]; | |
} | |
} | |
- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item | |
{ | |
CPLog("outlineView:%@ objectValueForTableColumn:%@ byItem:%@", outlineView, tableColumn, item); | |
//value = [items objectForKey:item]; | |
var view = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)]; | |
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)]; | |
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:[mainBundle pathForResource:@"guest.jpg"]]]; | |
[view addSubview:imageView]; | |
//return [[items objectForKey:item] objectForKey:@"name"]; | |
return view; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment