From b03718f53f91352cc20cceb48738711e1b57e868 Mon Sep 17 00:00:00 2001 From: Olivier Gutknecht Date: Sun, 17 May 2009 12:20:41 +0200 Subject: [PATCH] Move attributes to array controller, cleanup abstract node hierarchy --- Casserole.xcodeproj/project.pbxproj | 4 + English.lproj/Node.xib | 144 ++++++++++------------ core/KCAbstractNode.h | 44 ++++--- core/KCAbstractNode.m | 118 ++++++++++--------- core/KCNode.h | 6 +- core/KCNode.m | 60 +++++++++- core/KCRegistration.h | 2 +- gui/KCCookbookController.m | 36 +++--- gui/KCCookbooksController.m | 8 +- gui/KCMainWindowController.m | 11 +- gui/KCNodeController.m | 177 +--------------------------- 11 files changed, 251 insertions(+), 359 deletions(-) diff --git a/Casserole.xcodeproj/project.pbxproj b/Casserole.xcodeproj/project.pbxproj index 0cf7fd0..0cc6c90 100644 --- a/Casserole.xcodeproj/project.pbxproj +++ b/Casserole.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 776B00FC0FB6180F00F0EC94 /* KCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 776B00FB0FB6180F00F0EC94 /* KCViewController.m */; }; 776B01620FB626EE00F0EC94 /* KCValueTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 776B01610FB626EE00F0EC94 /* KCValueTransformers.m */; }; 776BFEB30FB5F59700F0EC94 /* KCRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = 776BFEB20FB5F59700F0EC94 /* KCRegistration.m */; }; + 777DECD70FBFA5410095EB25 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 777DECD60FBFA5410095EB25 /* QuartzCore.framework */; }; 778EF94C0FB23EDD00FE49FC /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 778EF94B0FB23EDD00FE49FC /* MainWindow.xib */; }; 778EFA300FB2563200FE49FC /* KCAbstractNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 778EFA2F0FB2563200FE49FC /* KCAbstractNode.m */; }; 779EF7BA0FB7391D000C014B /* Casserole.icns in Resources */ = {isa = PBXBuildFile; fileRef = 779EF7B90FB7391D000C014B /* Casserole.icns */; }; @@ -104,6 +105,7 @@ 776B01610FB626EE00F0EC94 /* KCValueTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KCValueTransformers.m; sourceTree = ""; }; 776BFEB10FB5F59700F0EC94 /* KCRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KCRegistration.h; sourceTree = ""; }; 776BFEB20FB5F59700F0EC94 /* KCRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KCRegistration.m; sourceTree = ""; }; + 777DECD60FBFA5410095EB25 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = ""; }; 778EF9470FB23EB200FE49FC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainWindow.xib; sourceTree = ""; }; 778EFA2E0FB2563200FE49FC /* KCAbstractNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KCAbstractNode.h; sourceTree = ""; }; 778EFA2F0FB2563200FE49FC /* KCAbstractNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KCAbstractNode.m; sourceTree = ""; }; @@ -143,6 +145,7 @@ files = ( 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 774DD65E0FBB2140004C03A2 /* JSON.framework in Frameworks */, + 777DECD70FBFA5410095EB25 /* QuartzCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -162,6 +165,7 @@ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( + 777DECD60FBFA5410095EB25 /* QuartzCore.framework */, 774DD65D0FBB2140004C03A2 /* JSON.framework */, 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, ); diff --git a/English.lproj/Node.xib b/English.lproj/Node.xib index 307563f..d763414 100644 --- a/English.lproj/Node.xib +++ b/English.lproj/Node.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -81,17 +81,11 @@ 268 {{57, 511}, {561, 17}} - - 5.000000e+00 - 4.000000e+00 - 2.000000e+00 - - YES 68288064 272630784 - test1.ftnx.net + test1.example.com @@ -547,49 +541,10 @@ children isLeaf - - - YES - key - value - - YES - YES - YES - YES - YES - - YES - - key - YES - compare: - - - YES - key - value - YES - - - contentArray: attributes - - - - - - contentArray: attributes - contentArray - attributes - 2 - - - 30 - view @@ -598,22 +553,6 @@ 39 - - - contentDictionary: node.attributes - - - - - - contentDictionary: node.attributes - contentDictionary - node.attributes - 2 - - - 48 - value: node.attributes.recipes @@ -671,12 +610,60 @@ 58 - - dataSource - + + contentArray: node.chefAttributes + + + + + contentArray: node.chefAttributes + contentArray + node.chefAttributes + 2 + + + 61 + + + + value: arrangedObjects.nodeTitle + + + + + + value: arrangedObjects.nodeTitle + value + arrangedObjects.nodeTitle + 2 + + + 62 + + + + value: arrangedObjects.nodeValue + + + + + + value: arrangedObjects.nodeValue + value + arrangedObjects.nodeValue + 2 + - 60 + 63 + + + + outlineView + + + + 77 @@ -714,11 +701,11 @@ YES - + @@ -807,6 +794,11 @@ + + 29 + + + 20 @@ -872,16 +864,6 @@ - - 29 - - - - - 47 - - - @@ -920,9 +902,9 @@ 3.IBPluginDependency 4.IBPluginDependency 4.IBViewIntegration.shadowBlurRadius + 4.IBViewIntegration.shadowColor 4.IBViewIntegration.shadowOffsetHeight 4.IBViewIntegration.shadowOffsetWidth - 47.IBPluginDependency 5.IBPluginDependency 9.IBPluginDependency @@ -960,11 +942,11 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -987,7 +969,7 @@ - 60 + 87 diff --git a/core/KCAbstractNode.h b/core/KCAbstractNode.h index 3a5661e..6a292da 100644 --- a/core/KCAbstractNode.h +++ b/core/KCAbstractNode.h @@ -12,20 +12,18 @@ @class KCViewController; @interface KCAbstractNode : NSObject { - KCAbstractNode *_parent; - NSString *_nodeTitle; - NSString *_nodeValue; - NSMutableArray *_children; - KCChefConnection *_connection; - BOOL _isLeaf; + KCAbstractNode *parent; + NSString *nodeTitle; + NSString *nodeValue; + NSMutableArray *children; + BOOL isLeaf; } -@property(copy) NSString *nodeValue; -@property(copy) NSString *nodeTitle; -@property(copy) NSMutableArray *children; -@property(assign) KCAbstractNode *parent; -@property(assign) BOOL isLeaf; -@property(assign) KCChefConnection *connection; +@property(copy) NSString *nodeValue; +@property(copy) NSString *nodeTitle; +@property(copy) NSMutableArray *children; +@property(assign) KCAbstractNode *parent; +@property(assign) BOOL isLeaf; -(void)addObject:(id)o; @@ -35,13 +33,27 @@ @end -@interface KCNodesProxy : KCAbstractNode +@interface KCAttributeNode : KCAbstractNode { + NSString *nodeType; +} +@property(assign) NSString *nodeType; @end -@interface KCViewControllerNode : KCAbstractNode { - KCViewController *viewController; +@interface KCChefNode : KCAbstractNode { + KCChefConnection *connection; +} + +@property(assign) KCChefConnection *connection; + +@end + +@interface KCNodesProxy : KCChefNode +@end + +@interface KCViewControllerNode : KCChefNode { + KCViewController *viewController; } -@property(assign) KCViewController *viewController; +@property(assign) KCViewController *viewController; @end diff --git a/core/KCAbstractNode.m b/core/KCAbstractNode.m index f099bf7..e05a5d7 100644 --- a/core/KCAbstractNode.m +++ b/core/KCAbstractNode.m @@ -10,14 +10,17 @@ #import "KCChefConnection.h" #import "KCViewController.h" +@implementation KCAttributeNode +@synthesize nodeType; +@end + @implementation KCAbstractNode -@synthesize nodeValue = _nodeValue; -@synthesize nodeTitle = _nodeTitle; -@synthesize parent = _parent; -@synthesize connection = _connection; -@dynamic isLeaf; -@dynamic children; +@synthesize nodeValue; +@synthesize nodeTitle; +@synthesize parent; +@dynamic isLeaf; +@dynamic children; - (NSString*)iconName { @@ -30,80 +33,83 @@ - (void)refresh:(id)sender - (NSString*)description { - return _nodeTitle; + return nodeTitle; } -- (void)setIsLeaf:(BOOL)flag; +- (void)setIsLeaf:(BOOL)flag; { - _isLeaf = flag; - if (_isLeaf) - self.children = [NSMutableArray arrayWithObject:self]; + isLeaf = flag; + if (isLeaf) + self.children = [NSMutableArray arrayWithObject:self]; else - self.children = [NSMutableArray array]; + self.children = [NSMutableArray array]; } -- (BOOL)isLeaf; +- (BOOL)isLeaf; { - return _isLeaf; + return isLeaf; } -- (NSMutableArray *)children; +- (NSMutableArray *)children; { - return _children; + return children; } -- (void)setChildren:(NSMutableArray *)newChildren; +- (void)setChildren:(NSMutableArray *)newChildren; { - if (_children == newChildren) - return; - [_children release]; - _children = [newChildren mutableCopy]; + if (children == newChildren) + return; + [children release]; + children = [newChildren mutableCopy]; } -- (NSUInteger)countOfChildren; +- (NSUInteger)countOfChildren; { if (self.isLeaf) - return 0; - return [self.children count]; + return 0; + return [self.children count]; } - (void)addObject:(id)object { if (self.isLeaf) - return; - [self.children insertObject:object atIndex:[self countOfChildren]]; + return; + [self.children insertObject:object atIndex:[self countOfChildren]]; } -- (void)insertObject:(id)object inChildrenAtIndex:(NSUInteger)index; +- (void)insertObject:(id)object inChildrenAtIndex:(NSUInteger)index; { if (self.isLeaf) - return; - [self.children insertObject:object atIndex:index]; + return; + [self.children insertObject:object atIndex:index]; } -- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index; +- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index; { if (self.isLeaf) - return; - [self.children removeObjectAtIndex:index]; + return; + [self.children removeObjectAtIndex:index]; } -- (id)objectInChildrenAtIndex:(NSUInteger)index; +- (id)objectInChildrenAtIndex:(NSUInteger)index; { if (self.isLeaf) - return nil; - return [self.children objectAtIndex:index]; + return nil; + return [self.children objectAtIndex:index]; } -- (void)replaceObjectInChildrenAtIndex:(NSUInteger)index withObject:(id)object; +- (void)replaceObjectInChildrenAtIndex:(NSUInteger)index withObject:(id)object; { if (self.isLeaf) - return; - [self.children replaceObjectAtIndex:index withObject:object]; + return; + [self.children replaceObjectAtIndex:index withObject:object]; } @end +@implementation KCChefNode +@synthesize connection; +@end @implementation KCViewControllerNode @synthesize viewController; @@ -132,53 +138,53 @@ -(NSString*)iconName return NSImageNameNetwork; } -- (void)setIsLeaf:(BOOL)flag; +- (void)setIsLeaf:(BOOL)flag; { return; } -- (BOOL)isLeaf; +- (BOOL)isLeaf; { - return NO; + return NO; } -- (NSMutableArray *)children; +- (NSMutableArray *)children; { - return self.connection.nodes; + return self.connection.nodes; } -- (void)setChildren:(NSMutableArray *)newChildren; +- (void)setChildren:(NSMutableArray *)newChildren; { - return; + return; } -- (NSUInteger)countOfChildren; +- (NSUInteger)countOfChildren; { - return [self.connection.nodes count]; + return [self.connection.nodes count]; } - (void)addObject:(id)object { - return; + return; } -- (void)insertObject:(id)object inChildrenAtIndex:(NSUInteger)index; +- (void)insertObject:(id)object inChildrenAtIndex:(NSUInteger)index; { - return; + return; } -- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index; +- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index; { - return; + return; } -- (id)objectInChildrenAtIndex:(NSUInteger)index; +- (id)objectInChildrenAtIndex:(NSUInteger)index; { - return [_connection.nodes objectAtIndex:index]; + return [connection.nodes objectAtIndex:index]; } -- (void)replaceObjectInChildrenAtIndex:(NSUInteger)index withObject:(id)object; +- (void)replaceObjectInChildrenAtIndex:(NSUInteger)index withObject:(id)object; { - return; + return; } @end diff --git a/core/KCNode.h b/core/KCNode.h index e271f07..d1f84da 100644 --- a/core/KCNode.h +++ b/core/KCNode.h @@ -9,12 +9,16 @@ #import #import "KCAbstractNode.h" -@interface KCNode : KCAbstractNode { +@interface KCNode : KCChefNode { NSDictionary* attributes; + NSMutableArray* chefAttributes; } @property (retain) NSDictionary* attributes; +@property (retain) NSMutableArray* chefAttributes; -(void)refresh:(id)sender; +-(NSMutableArray*)nodeTreeFromDictionary:(NSDictionary*)d; +-(NSMutableArray*)nodeTreeFromArray:(NSArray*)array; @end diff --git a/core/KCNode.m b/core/KCNode.m index ee05992..b2fc180 100644 --- a/core/KCNode.m +++ b/core/KCNode.m @@ -13,6 +13,7 @@ @implementation KCNode @synthesize attributes; +@synthesize chefAttributes; - (BOOL)isLeaf; { @@ -31,13 +32,70 @@ - (void)observeValueForKeyPath:(NSString *)keyPath [a runModal]; } else { - if ([op.result isKindOfClass:[NSDictionary class]]) + if ([op.result isKindOfClass:[NSDictionary class]]) { [self setAttributes:(NSDictionary*)op.result]; + [self setChefAttributes:[self nodeTreeFromDictionary:[(NSDictionary*)op.result objectForKey:@"attributes"]]]; + } } } } +-(NSMutableArray*)nodeTreeFromDictionary:(NSDictionary*)d +{ + NSMutableArray* result = [NSMutableArray array]; + NSArray* keys = [[d allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; + for (NSString* key in keys) + { + KCAttributeNode* n = [[KCAttributeNode alloc] init]; + [n setNodeTitle:key]; + id value = [d objectForKey:key]; + if ([value isKindOfClass:[NSArray class]]) { + n.nodeType = @"Array"; + [n setIsLeaf:false]; + [n setChildren:[self nodeTreeFromArray:value]]; + } + if ([value isKindOfClass:[NSDictionary class]]) { + n.nodeType = @"Dictionary"; + [n setIsLeaf:false]; + [n setChildren:[self nodeTreeFromDictionary:value]]; + } + else { + n.nodeType = [value className]; + [n setIsLeaf:true]; + n.nodeValue = [value description]; + } + [result addObject:n]; + } + return result; +} + +-(NSMutableArray*)nodeTreeFromArray:(NSArray*)array +{ + NSMutableArray* result = [NSMutableArray array]; + for (id value in array) + { + KCAttributeNode* n = [[KCAttributeNode alloc] init]; + [n setNodeTitle:@""]; + if ([value isKindOfClass:[NSArray class]]) { + n.nodeType = @"Array"; + [n setIsLeaf:false]; + [n setChildren:[self nodeTreeFromArray:value]]; + } + if ([value isKindOfClass:[NSDictionary class]]) { + n.nodeType = @"Dictionary"; + [n setIsLeaf:false]; + [n setChildren:[self nodeTreeFromDictionary:value]]; + } + else { + n.nodeType = [value className]; + [n setIsLeaf:true]; + n.nodeValue = [value description]; + } + } + return result; +} + -(void)refresh:(id)sender { NSOperationQueue* queue = [(KCApplicationDelegate*)[NSApp delegate] queue]; diff --git a/core/KCRegistration.h b/core/KCRegistration.h index acd19c2..36bf42e 100644 --- a/core/KCRegistration.h +++ b/core/KCRegistration.h @@ -10,7 +10,7 @@ #import "KCAbstractNode.h" -@interface KCRegistration : KCAbstractNode { +@interface KCRegistration : KCChefNode { NSDictionary* content; } diff --git a/gui/KCCookbookController.m b/gui/KCCookbookController.m index 5337345..2e55402 100644 --- a/gui/KCCookbookController.m +++ b/gui/KCCookbookController.m @@ -17,72 +17,72 @@ @implementation KCCookbookController - (void)awakeFromNib { NSMutableArray* a = [NSMutableArray array]; - KCAbstractNode *node; - KCAbstractNode *child; - node = [[KCAbstractNode alloc] init]; + KCChefNode *node; + KCChefNode *child; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Attributes"]; [node setIsLeaf:false]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"apache.rb"]; [child setIsLeaf:true]; [node addObject:child]; [a addObject:node]; - node = [[KCAbstractNode alloc] init]; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Definitions"]; [node setIsLeaf:false]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"apache_module.rb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"web_app.rb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"apache_site.rb"]; [child setIsLeaf:true]; [node addObject:child]; [a addObject:node]; - node = [[KCAbstractNode alloc] init]; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Recipes"]; [node setIsLeaf:false]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"default.rb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"mod_dir.rb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"mod_headers.rb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"mod_proxy.rb"]; [child setIsLeaf:true]; [node addObject:child]; [a addObject:node]; - node = [[KCAbstractNode alloc] init]; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Templates"]; [node setIsLeaf:false]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"apache2.conf.erb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"ports.conf.erb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"web_app.conf.erb"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"default_site.erb"]; [child setIsLeaf:true]; [node addObject:child]; diff --git a/gui/KCCookbooksController.m b/gui/KCCookbooksController.m index e4af44e..9a73d02 100644 --- a/gui/KCCookbooksController.m +++ b/gui/KCCookbooksController.m @@ -16,16 +16,16 @@ @implementation KCCookbooksController - (void)awakeFromNib { NSMutableArray* a = [NSMutableArray array]; - KCAbstractNode *node; - node = [[KCAbstractNode alloc] init]; + KCChefNode *node; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"CouchDB"]; [node setIsLeaf:true]; [a addObject:node]; - node = [[KCAbstractNode alloc] init]; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Apache"]; [node setIsLeaf:true]; [a addObject:node]; - node = [[KCAbstractNode alloc] init]; + node = [[KCChefNode alloc] init]; [node setNodeTitle:@"Passenger"]; [node setIsLeaf:true]; [a addObject:node]; diff --git a/gui/KCMainWindowController.m b/gui/KCMainWindowController.m index 8fa175e..a76e5c9 100644 --- a/gui/KCMainWindowController.m +++ b/gui/KCMainWindowController.m @@ -51,7 +51,7 @@ - (void)awakeFromNib NSMutableArray* a = [NSMutableArray array]; KCViewControllerNode *viewNode; - KCAbstractNode *child; + KCChefNode *child; KCNodesProxy *nodeProxy; viewNode = [[KCViewControllerNode alloc] init]; @@ -67,7 +67,7 @@ - (void)awakeFromNib viewNode = [[KCViewControllerNode alloc] init]; viewNode.viewController = cookbooksController; [viewNode setIsLeaf:false]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"Apache2"]; [child setIsLeaf:true]; [viewNode addObject:child]; @@ -82,11 +82,11 @@ - (void)awakeFromNib ((KCViewControllerNode*)viewNode).viewController = searchController; [viewNode setIsLeaf:true]; - /* child = [[KCAbstractNode alloc] init]; + /* child = [[KCChefNode alloc] init]; [child setNodeTitle:@"Rails nodes"]; [child setIsLeaf:true]; [node addObject:child]; - child = [[KCAbstractNode alloc] init]; + child = [[KCChefNode alloc] init]; [child setNodeTitle:@"Ubuntu nodes"]; [child setIsLeaf:true]; [node addObject:child];*/ @@ -116,6 +116,7 @@ - (void)setupViewControllers nodeController = [[KCNodeController alloc] initWithNibName:@"Node" bundle:nil]; nodeController.chefConnection = self.chefConnection; nodeController.windowController = self; + [nodeController setCanSearch:true]; [nodeController setTitle:@"Node"]; cookbooksController = [[KCCookbooksController alloc] initWithNibName:@"Cookbooks" bundle:nil]; @@ -152,7 +153,7 @@ - (void)switchView:(KCViewController*)view - (void)changeItemView { NSArray *selection = [sourceController selectedObjects]; - KCAbstractNode *node = [selection objectAtIndex:0]; + KCChefNode *node = [selection objectAtIndex:0]; NSString *title = [node nodeTitle]; if ([currentViewController view] != nil) diff --git a/gui/KCNodeController.m b/gui/KCNodeController.m index 4fa5256..9a59697 100644 --- a/gui/KCNodeController.m +++ b/gui/KCNodeController.m @@ -8,6 +8,7 @@ #import "KCNodeController.h" #import "KCAbstractNode.h" +#import @implementation KCNodeController @@ -17,182 +18,6 @@ @implementation KCNodeController @synthesize attributes; @synthesize node; --(void)awakeFromNib -{ - [self setName:@"test1.ftnx.net"]; - [self setRecipes:@"vim,emacs,passenger,couchdb"]; - [self setTags:@"cloud1,production,load-balanced"]; - -#if 0 - NSMutableArray* a = [NSMutableArray array]; - KCAbstractNode *n; - KCAbstractNode *child; - n= [[KCAbstractNode alloc] init]; - [n setNodeTitle:@"platform"]; - [n setNodeValue:@"ubuntu"]; - [n setIsLeaf:true]; - [a addObject:n]; - - n = [[KCAbstractNode alloc] init]; - [n setNodeTitle:@"activemq"]; - [n setIsLeaf:false]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"gid"]; - [child setNodeValue:@"992"]; - [child setIsLeaf:true]; - [n addObject:child]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"version"]; - [child setNodeValue:@"5.1.0"]; - [child setIsLeaf:true]; - [n addObject:child]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"mirror_url"]; - [child setNodeValue:@"http://apache.osuosl.org/activemq"]; - [child setIsLeaf:true]; - [n addObject:child]; - - [a addObject:n]; - - - n = [[KCAbstractNode alloc] init]; - [n setNodeTitle:@"kernel"]; - [n setIsLeaf:false]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"machine"]; - [child setNodeValue:@"i686"]; - [child setIsLeaf:true]; - [n addObject:child]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"name"]; - [child setNodeValue:@"Linux"]; - [child setIsLeaf:true]; - [n addObject:child]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"version"]; - [child setNodeValue:@"#42-Ubuntu SMP Fri Apr 17 02:48:10 UTC 2009"]; - [child setIsLeaf:true]; - [n addObject:child]; - - child = [[KCAbstractNode alloc] init]; - [child setNodeTitle:@"release"]; - [child setNodeValue:@"2.6.28-11-server"]; - [child setIsLeaf:true]; - [n addObject:child]; - - [a addObject:n]; - [self setAttributes:a]; -#endif - - -} - -/* Required methods - */ - -- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item -{ - // NSLog(@"outlineView:child:ofItem:%d %@",index,item); - if (item==nil) - { - NSDictionary* item = [self.node.attributes objectForKey:@"attributes"]; - NSArray* a = [[item allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; - NSString* key = [a objectAtIndex:index]; - NSArray* couple = [NSArray arrayWithObjects:key, [item objectForKey:key], nil]; - CFRetain(couple); - return couple; - } - else if ([item isKindOfClass:[NSArray class]]) - { - NSDictionary* value = [item objectAtIndex:1]; - - NSArray* a = [value allKeys]; - NSString* key = [a objectAtIndex:index]; - NSArray* couple = [NSArray arrayWithObjects:key, [value objectForKey:key], nil]; - CFRetain(couple); - return couple; - } - else if ([item isKindOfClass:[NSDictionary class]]) - { - return [item objectForKey:[[item allKeys] objectAtIndex:index]]; - } - return nil; -} - -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item -{ - // NSLog(@"outlineView:isItemExpandable:%@",[item class]); - if (![item isKindOfClass:[NSArray class]]) - return false; - if ([[item objectAtIndex:1] isKindOfClass:[NSDictionary class]]) - { - if ([[item objectAtIndex:1] count] > 0) - return true; - } - return false; -} - -- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item -{ - // NSLog(@"outlineView:numberOfChildrenOfItem:%@",[item class]); - if (item==nil) - return [[self.node.attributes objectForKey:@"attributes"] count]; - else if (![item isKindOfClass:[NSArray class]]) - return 0; - - // NSLog(@" outlineView:numberOfChildrenOfItem:%d",[item count]); - if ([[item objectAtIndex:1] isKindOfClass:[NSDictionary class]]) - return [[item objectAtIndex:1] count]; - - return 0; - -} - -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ - // NSLog(@"outlineView:objectValueForTableColumn:%@ byItem %@",[tableColumn identifier],[item class]); - if ([item isKindOfClass:[NSArray class]]) - // NSLog(@" %d",[item count]); - - if (item==nil) - return @""; - if ([item isKindOfClass:[NSString class]]) - { - return item; - } - else if ([item isKindOfClass:[NSDictionary class]]) - { - if ([[tableColumn identifier] isEqualToString:@"key"]) - return [item objectForKey:@"key"]; - else - return [item objectForKey:@"value"]; - } - else if ([item isKindOfClass:[NSArray class]]) - { - if ([item count]<2) - return [item description]; - if ([[tableColumn identifier] isEqualToString:@"key"]) - return [item objectAtIndex:0]; - else { - if ([[item objectAtIndex:1] isKindOfClass:[NSDictionary class]]) - return @""; - // return [NSString stringWithFormat:@"%d items",[[item objectAtIndex:1] count]]; - if ([[item objectAtIndex:1] isKindOfClass:[NSArray class]]) - return [[item objectAtIndex:1] componentsJoinedByString:@","]; - else - return [item objectAtIndex:1]; - } - } - else - return [item description]; -} - -(NSString*)iconName { return [node iconName];