Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created December 31, 2010 14:35
Show Gist options
  • Save jlebrech/761054 to your computer and use it in GitHub Desktop.
Save jlebrech/761054 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@implementation ProjectsView : CPView
{
CPTableView projectsTable;
CPArray projects;
}
- (id)initWithFrame:(CPRect)frame
{
self = [super initWithFrame:frame];
if (self){
// create the CPTableView
projectsTable = [[CPTableView alloc] initWithFrame:[self bounds]];
[projectsTable setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable | CPViewMinXMargin | CPViewMinYMargin ];
[projectsTable setUsesAlternatingRowBackgroundColors:YES];
[projectsTable setAlternatingRowBackgroundColors:[CPArray arrayWithObjects:[CPColor whiteColor],[CPColor redColor]]];
var headerColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"button-bezel-center.png"]]];
[[projectsTable cornerView] setBackgroundColor:headerColor];
// add the first column
var column = [[CPTableColumn alloc] initWithIdentifier:@"Project"];
[[column headerView] setStringValue:"Project Name"];
[[column headerView] setBackgroundColor:headerColor];
[column setWidth:200.0];
[projectsTable addTableColumn:column];
var request = [CPURLRequest requestWithURL:"/listprojects"] ;
var projectConnection = [CPURLConnection connectionWithRequest:request delegate:self] ;
[projectsTable setDataSource:self];
[self addSubview:projectsTable];
}
return self;
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
return [[projects objectAtIndex:row] count];
}
// CPTableView datasource methods
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return 100;
}
- (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data
{
//This method is called when a connection receives a response. in a
//multi-part request, this method will (eventually) be called multiple times,
//once for each part in the response.
projects = JSON.parse(data);
[projectsTable reloadData];
}
- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
{
//This method is called if the request fails for any reason.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment