Skip to content

Instantly share code, notes, and snippets.

@joachimhs
Created November 22, 2011 22:51
Show Gist options
  • Save joachimhs/1387307 to your computer and use it in GitHub Desktop.
Save joachimhs/1387307 to your computer and use it in GitHub Desktop.
Objective-J CPOutlineView
/*
* AppController.j
* nibapptest
*
* Created by You on November 20, 2011.
* Copyright 2011, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPOutlineView.j>
@import "TreeStructure.j"
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
@outlet CPOutlineView myOutletView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
[theWindow setFullPlatformWindow:YES];
[myOutletView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
[myOutletView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
}
- (void)sendAsynchRequest
{
var request = [[CPURLRequest alloc] initWithURL:@"http://localhost:8081/instrumentationMenu"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:@"{\"getInstrumentationMenu\":\"instrumentationMenu\",\"includeCharts\":true}"];
[request setValue:"5" forHTTPHeaderField:@"Content-Length"];
[request setValue:"text/plain;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
var urlConnection = [CPURLConnection connectionWithRequest:request delegate:self];
[urlConnection start];
/*[CPJSONPConnection sendRequest:request callback:"aCallbackParameter" delegate:self];*/
}
- (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.
CPLog("CPURLConnection didReceiveData");
var jsObject = [data objectFromJSON];
CPLog(jsObject.instrumentationMenu.length);
CPLog(jsObject.instrumentationMenu[0].guiPath);
var tree = [[TreeStructure alloc] init];
[tree updateItems:jsObject];
[myOutletView setDataSource:tree];
}
- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
{
//This method is called if the request fails for any reason.
CPLog("didFailWithError");
}
- (IBAction)sayHello:(id)aSender
{
CPLog("Sending Request to Server");
[self sendAsynchRequest];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment