00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INCLUDED_SM2DGRAPHVIEW_H
00009 #import <SM2DGraphView/SM2DGraphView.h>
00010 #endif
00011 #ifndef INCLUDED_SM2DPIECHARTVIEW_H
00012 #import <SM2DGraphView/SMPieChartView.h>
00013 #endif
00014 #ifndef INCLUDED_NIBMANAGER_H
00015 #import "NIBManager.h"
00016 #endif
00017 #ifndef INCLUDED_NIBMANAGERHANDLER_H
00018 #import "NIBManagerHandler.h"
00019 #endif
00020 #ifndef INCLUDED_NIBCONTROLLER_H
00021 #import "NIBController.h"
00022 #endif
00023 #ifndef INCLUDED_NIBCALLBACK_H
00024 #import "NIBCallback.h"
00025 #endif
00026 #ifndef INCLUDED_AZWINDOW_H
00027 #import "AZWindow.h"
00028 #endif
00029 #ifndef INCLUDED_AZTEXTFIELD_H
00030 #import "AZTextField.h"
00031 #endif
00032 #ifndef INCLUDED_AZVIEW_H
00033 #import "AZView.h"
00034 #endif
00035 #ifndef INCLUDED_AZSCROLLVIEW_H
00036 #import "AZScrollView.h"
00037 #endif
00038 #ifndef INCLUDED_METADATAPARSER_H
00039 #import "MetadataParser.h"
00040 #endif
00041 #ifndef INCLUDED_DECORATORPARSER_H
00042 #import "DecoratorParser.h"
00043 #endif
00044 #ifndef INCLUDED_MATRIXCONTROLLER_H
00045 #import "MatrixController.h"
00046 #endif
00047 #ifndef INCLUDED_DYNAMICPOPUPHANDLER_H
00048 #import "DynamicPopUpHandler.h"
00049 #endif
00050 #ifndef INCLUDED_OUTLINEVIEWCONTROLLER_H
00051 #import "OutlineViewController.h"
00052 #endif
00053 #ifndef INCLUDED_OUTLINEVIEWMANAGER_H
00054 #import "OutlineViewManager.h"
00055 #endif
00056 #ifndef INCLUDED_OUTLINEVIEWDELEGATE_H
00057 #import "OutlineViewDelegate.h"
00058 #endif
00059 #ifndef INCLUDED_TOKENFIELDDELEGATE_H
00060 #import "TokenFieldDelegate.h"
00061 #endif
00062 #ifndef INCLUDED_PADDEDFORMATTER_H
00063 #import "PaddedFormatter.h"
00064 #endif
00065
00066
00067 NSString * DEFAULT_BACKING_STORE = @"Logs/DocHandler/DocHandler.xobj";
00068 NSString * DEFAULT_NIB_NAME = @"AozoraBT";
00069 NSString * DEFAULT_RESULT_TYPE_KEY = @"r_object_type";
00070 NSString * DEFAULT_RESULT_DATA_KEY = @"data";
00071
00072
00073 float XADJUST = 20;
00074 float YADJUST = 20;
00075 BOOL PROCESS_DECORATIONS = YES;
00076
00077
00078 @implementation NIBManager
00079
00080
00081 - (id)init {
00082 self = [super init];
00083 if (self) {
00084 main = nil;
00085 path = nil;
00086 tabView = nil;
00087 popupMenu = nil;
00088 callback = nil;
00089 validator = nil;
00090 bounds = nil;
00091 adjustment = nil;
00092 scrolling = YES;
00093 flipped = YES;
00094 decorated = NO;
00095 assumeAll = NO;
00096 displayMode = EMBEDDED;
00097 persistenceMode = DOCUMENT;
00098 name = DEFAULT_NIB_NAME;
00099 backingType = NSXMLStoreType;
00100 backingStore = DEFAULT_BACKING_STORE;
00101 contexts = [[[NSMutableArray alloc] init] retain];
00102 controllers = [[[NSMutableArray alloc] init] retain];
00103 handler = [[[DynamicPopUpHandler alloc] init] retain];
00104
00105 NSPoint myPoint = {XADJUST, YADJUST};
00106 [self setAdjustment:myPoint];
00107 }
00108 return self;
00109 }
00110
00111
00112 - (void)dealloc {
00113 if (path)
00114 [path release];
00115 if (name)
00116 [name release];
00117 if (backingType)
00118 [backingType release];
00119 if (backingStore)
00120 [backingStore release];
00121 if (callback)
00122 [callback release];
00123 if (validator)
00124 [validator release];
00125 if (contexts)
00126 [contexts release];
00127 if (controllers)
00128 [controllers release];
00129 if (handler)
00130 [handler release];
00131 if (bounds)
00132 free(bounds);
00133 if (adjustment)
00134 free(adjustment);
00135 [super dealloc];
00136 }
00137
00138
00139 -(void)awakeFromNib {
00140 }
00141
00142
00143 - (NSString *)name {
00144 return name;
00145 }
00146
00147
00148 - (void)setName:(NSString *)myName {
00149 if (name)
00150 [name release];
00151 name = [[myName stringByExpandingTildeInPath] retain];
00152 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00153 NSLog(@"NIBManager assigning bundle name: %s", [name UTF8String]);
00154 }
00155
00156
00157 - (NSString *)path {
00158 return path;
00159 }
00160
00161
00162 - (void)setPath:(NSString *)myPath {
00163 if (path)
00164 [path release];
00165 path = [[myPath stringByExpandingTildeInPath] retain];
00166 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00167 NSLog(@"NIBManager assigning bundle path: %s", [path UTF8String]);
00168 }
00169
00170
00171 - (NSString *)backingStore {
00172 return backingStore;
00173 }
00174
00175
00176 - (void)setBackingStore:(NSString *)myStore {
00177 if (backingStore)
00178 [backingStore release];
00179 backingStore = [[myStore stringByExpandingTildeInPath] retain];
00180 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00181 NSLog(@"NIBManager assigning CoreData backing store: %s", [backingStore UTF8String]);
00182 }
00183
00184
00185 - (NSString *)backingType {
00186 return backingType;
00187 }
00188
00189
00190 - (void)setBackingType:(NSString *)myType {
00191 if (backingType)
00192 [backingType release];
00193 backingType = myType;
00194 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00195 NSLog(@"NIBManager assigning CoreData backing type: %s", [backingType UTF8String]);
00196 }
00197
00198
00199 - (NSTabView *)tabView {
00200 return tabView;
00201 }
00202
00203
00204 - (void)setTabView:(NSTabView *)myTabs {
00205 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00206 NSLog(@"NIBManager registering NSTabView for displays");
00207 tabView = myTabs;
00208 }
00209
00210
00211 - (NSPopUpButton *)popupMenu {
00212 return popupMenu;
00213 }
00214
00215
00216 - (void)setPopupMenu:(NSPopUpButton *)myMenu {
00217 [self setPopupMenu:myMenu withTarget:self withAction:@selector(onPopUpChange:)];
00218 }
00219
00220
00221 - (void)setPopupMenu:(NSPopUpButton *)myMenu withTarget:(id)target withAction:(SEL)action {
00222 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00223 NSLog(@"NIBManager registering NSPopUpButton for changes");
00224 popupMenu = myMenu;
00225 if ([self isEnabled]) {
00226 [popupMenu setTarget:target];
00227 [popupMenu setAction:action];
00228 }
00229 }
00230
00231
00232 - (NIBCallback *)callback {
00233 return callback;
00234 }
00235
00236
00237 - (void)setCallback:(NIBCallback *)myCallback {
00238 if (myCallback && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00239 NSLog(@"NIBManager assigning callback: %s", [[myCallback description] UTF8String]);
00240 callback = myCallback;
00241 }
00242
00243
00244 - (NIBValidator *)validator {
00245 return validator;
00246 }
00247
00248
00249 - (void)setValidator:(NIBValidator *)myValidator {
00250 if (myValidator && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00251 NSLog(@"NIBManager assigning validator: %s", [[myValidator description] UTF8String]);
00252 validator = myValidator;
00253 }
00254
00255
00256 - (id)main {
00257 return main;
00258 }
00259
00260
00261 - (void)setMain:(id)myMain {
00262 if (myMain && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00263 NSLog(@"NIBManager assigning main: %s", [[myMain description] UTF8String]);
00264 main = myMain;
00265 }
00266
00267
00268 - (DynamicPopUpHandler *)handler {
00269 return handler;
00270 }
00271
00272
00273 - (void)setHandler:(DynamicPopUpHandler *)myHandler {
00274 if (myHandler && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00275 NSLog(@"NIBManager assigning popup handler: %s", [[myHandler description] UTF8String]);
00276 if (handler)
00277 [handler release];
00278 handler = myHandler;
00279 }
00280
00281
00282 -(int)displayMode {
00283 return displayMode;
00284 }
00285
00286
00287 -(void)setDisplayMode:(int)myMode {
00288 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00289 NSLog(@"NIBManager assigning display mode: %s", (myMode == EMBEDDED ? "EMBEDDED" : "WINDOWED"));
00290 displayMode = myMode;
00291 }
00292
00293
00294 -(int)persistenceMode {
00295 return persistenceMode;
00296 }
00297
00298
00299 -(void)setPersistenceMode:(int)myMode {
00300 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00301 NSLog(@"NIBManager assigning persistence mode: %s", (myMode == DOCUMENT ? "DOCUMENT" : "UNIQUE"));
00302 persistenceMode = myMode;
00303 }
00304
00305
00306 -(NSRect *)bounds {
00307 return bounds;
00308 }
00309
00310
00311 -(void)setBounds:(NSRect)myBounds {
00312 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00313 NSLog(@"NIBManager assigning component bounds: [%fx%f] at [%f,%f]", myBounds.size.width, myBounds.size.height, myBounds.origin.x, myBounds.origin.y);
00314 if (!bounds)
00315 bounds = (NSRect *)malloc(sizeof(NSRect));
00316 if (!bounds)
00317 NSLog(@"NIBManager: out of memory");
00318 else
00319 memcpy(bounds, &myBounds, sizeof(NSRect));
00320 }
00321
00322
00323 -(NSPoint *)adjustment {
00324 return adjustment;
00325 }
00326
00327
00328 -(void)setAdjustment:(NSPoint)myAdjustment {
00329 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00330 NSLog(@"NIBManager assigning component adjust: at [%f,%f]", myAdjustment.x, myAdjustment.y);
00331 if (!adjustment)
00332 adjustment = (NSPoint *)malloc(sizeof(NSPoint));
00333 if (!adjustment)
00334 NSLog(@"NIBManager: out of memory");
00335 else {
00336 adjustment->x = myAdjustment.x;
00337 adjustment->y = myAdjustment.y;
00338 }
00339 }
00340
00341
00342 -(BOOL)scrolling {
00343 return scrolling;
00344 }
00345
00346
00347 -(void)setScrolling:(BOOL)isScrolling {
00348 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00349 NSLog(@"NIBManager assigning scrolling views: %s", (isScrolling ? "YES" : "NO"));
00350 scrolling = isScrolling;
00351 }
00352
00353
00354 -(BOOL)decorated {
00355 return decorated;
00356 }
00357
00358
00359 -(void)setDecorated:(BOOL)isDecorated {
00360 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00361 NSLog(@"NIBManager assigning decorating views: %s", (isDecorated ? "YES" : "NO"));
00362 decorated = isDecorated;
00363 }
00364
00365
00366 -(BOOL)flipped {
00367 return flipped;
00368 }
00369
00370
00371 -(void)setFlipped:(BOOL)isFlipped {
00372 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00373 NSLog(@"NIBManager assigning flipped views: %s", (isFlipped ? "YES" : "NO"));
00374 flipped = isFlipped;
00375 }
00376
00377
00378 -(BOOL)assumeAll {
00379 return assumeAll;
00380 }
00381
00382
00383 -(void)setAssumeAll:(BOOL)isAssumed {
00384 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00385 NSLog(@"NIBManager assigning assuming all entities: %s", (isAssumed ? "YES" : "NO"));
00386 assumeAll = isAssumed;
00387 }
00388
00389
00390 - (void)doInitialise:(NSString *)myPath withCallback:(NIBCallback *)myCallback withValidator:(NIBValidator *)myValidator {
00391 [self setValidator:myValidator];
00392 [self doInitialise:myPath withCallback:myCallback];
00393 }
00394
00395
00396 - (void)doInitialise:(NSString *)myPath withCallback:(NIBCallback *)myCallback {
00397 [self setCallback:myCallback];
00398 [self doInitialise:myPath];
00399 }
00400
00401
00402 - (void)doInitialise:(NSString *)myPath {
00403 NSArray * paths;
00404 NIBContext * context;
00405 NSString * actual;
00406 NSString * temp;
00407 int i;
00408 int count = 0;
00409
00410 [self setPath: myPath];
00411 paths = [[[[NSFileManager defaultManager] directoryContentsAtPath:[self path]] retain] sortedArrayUsingSelector:@selector(localizedCompare:)];
00412 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00413 NSLog(@"NIBManager assigning bundle count: %i", [paths count]);
00414 [contexts removeAllObjects];
00415 for (i = 0; i < [paths count]; i++) {
00416 temp = (NSString *) [paths objectAtIndex: i];
00417 actual = [[[self path] stringByAppendingString:@"/"] stringByAppendingString:temp];
00418 if ([actual hasSuffix:@".bundle"]) {
00419 context = [self doCreate:actual withName:temp withTag:count];
00420 if (context) {
00421 [contexts addObject:context];
00422 count++;
00423 }
00424 }
00425 }
00426 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00427 NSLog(@"NIBManager initialisation completed");
00428 }
00429
00430
00431 - (NIBContext *)doCreate:(NSString *)myPath withName:(NSString *)myName withTag:(int)tag {
00432 NIBController * controller;
00433 NIBContext * context = [[[NIBContext alloc] init] retain];
00434 NSBundle * bundle;
00435 NSArray * objects;
00436 NSObject * object;
00437 NSString * identifier;
00438 BOOL found;
00439 int j;
00440
00441 [context setPath:myPath];
00442 [context setName:myName];
00443 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00444 NSLog(@"NIBManager loading bundle at path: %s", [myPath UTF8String]);
00445
00446 bundle = [NSBundle bundleWithPath:myPath];
00447 if (bundle) {
00448 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00449 NSLog(@"NIBManager loading DynamicNIB: %s, bundle version: %s", [myName UTF8String], [[[bundle infoDictionary] objectForKey:@"CFBundleVersion"] UTF8String]);
00450 found = NO;
00451 [context setBundle:bundle];
00452 [context setMetadata:[MetadataParser metadataWithBundle:bundle]];
00453 objects = [self topLevelObjectsFromLoadingBundle:bundle withName:myName withOwner:self];
00454 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00455 NSLog(@"NIBManager found top-level objects: %i", [objects count]);
00456 for (j = 0; !found && j < [objects count]; j++) {
00457 object = [objects objectAtIndex:j];
00458 if ([object isKindOfClass:[NIBController class]]) {
00459 controller = (NIBController *) object;
00460 [controller setModel: [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]];
00461 [controller setManager: self];
00462 found = YES;
00463 }
00464 }
00465 if (!found) {
00466 controller = [self createController];
00467 [controller setModel:[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]];
00468 [controller setManager: self];
00469 [self addController: controller];
00470 for (j = 0; j < [objects count]; j++) {
00471 object = [objects objectAtIndex:j];
00472 identifier = [NIBManager determineIdentifier:object];
00473
00474 if ([object isKindOfClass:[NSPanel class]])
00475 [object retain];
00476 if ([object isKindOfClass:[OutlineViewController class]]) {
00477 [(OutlineViewController *)object setPath:[OutlineViewController determinePath:context]];
00478 [(OutlineViewController *)object doInitialise:self];
00479 [object retain];
00480 }
00481
00482 if (identifier && [object isKindOfClass:[NSMenu class]]) {
00483 [[controller menus] setValue:(NSMenu *)object forKey:identifier];
00484 } else if ([object isKindOfClass:[NSView class]]) {
00485 [controller setWindow:(NSView *)object];
00486 } else if ([object isKindOfClass:[NSObjectController class]]) {
00487 [(NSObjectController *)object setManagedObjectContext:[[NSManagedObjectContext alloc] init]];
00488 [controller addController:(NSObjectController *)object withContext:context];
00489 }
00490 }
00491 }
00492 [controller doInitialiseWith:self];
00493 [controller doInitialise];
00494 [context setController:controller];
00495 [[context getMetadata] setTag:tag];
00496 [self processDecorations:[context getView] forContext:context];
00497 return context;
00498 } else if ([NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE) {
00499 NSLog(@"NIBManager could not load bundle: %s", [myPath UTF8String]);
00500 }
00501 return nil;
00502 }
00503
00504
00505 - (void)processDecorations:(NSView *)aView forContext:(NIBContext *)context {
00506 if (!PROCESS_DECORATIONS)
00507 return;
00508
00509 NSArray * subViews = [NIBManager getComponents:aView];
00510 NSString * bindingName;
00511 id component;
00512 int i;
00513
00514 for (i = 0; i < [subViews count]; i++) {
00515 component = [subViews objectAtIndex:i];
00516 if ([component isKindOfClass:[NSControl class]]) {
00517 bindingName = [NIBManager determineName:component];
00518 if (bindingName && [bindingName length] > 0) {
00519 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00520 NSLog(@"NIBManager checking for decorations for component: %s", [bindingName UTF8String]);
00521 [self processTextDecorations:component forContext:context forBinding:bindingName withParent:aView];
00522 [self processPopUpDecorations:component forContext:context forBinding:bindingName withParent:aView];
00523 [self processValidationDecorations:component forContext:context forBinding:bindingName withParent:aView];
00524 [self processTokenDecorations:component forContext:context forBinding:bindingName withParent:aView];
00525 [self processDatePickerDecorations:component forContext:context forBinding:bindingName withParent:aView];
00526 }
00527 [self processOutlineDecorations:component forContext:context forBinding:bindingName withParent:aView];
00528 } else if ([component isKindOfClass:[NSView class]] && ![component isEqual:aView]) {
00529 [self processDecorations:(NSView *)component forContext:context];
00530 }
00531 }
00532 }
00533
00534
00535 - (void)processTextDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00536 if (![component isKindOfClass:[NSTextField class]])
00537 return;
00538
00539 MetadataParser * parser = [context getMetadata];
00540 NSString * type = [parser getElementType:bindingName];
00541
00542 if ([type isEqualTo:TYPE_PADDED]) {
00543 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00544 NSLog(@"NIBManager adding PaddedFormatter to attribute: %s", [bindingName UTF8String]);
00545 [component setFormatter:[PaddedFormatter formatterWithLength:[parser getElementLength:bindingName]]];
00546 }
00547 if ([type isEqualTo:TYPE_VALIDATOR] && [self validator] && [component isKindOfClass:[AZTextField class]]) {
00548 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00549 NSLog(@"NIBManager adding NIBValidator to attribute: %s", [bindingName UTF8String]);
00550 [component setTarget:[self validator]];
00551
00552 [(AZTextField *)component setChangeAction:@selector(doProcessControl:)];
00553 }
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 }
00564
00565
00566 - (void)processDatePickerDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00567 if (![component isKindOfClass:[NSDatePicker class]])
00568 return;
00569
00570 [(NSDatePicker*)component setDateValue:[NSDate date]];
00571 }
00572
00573
00574 - (void)processPopUpDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00575
00576 NSString *drop = [[context getMetadata] getValue:bindingName];
00577 if ([drop hasPrefix:@"<DYNAMIC_"]) {
00578 NSLog(@" - building dynamic lookup for: %s", [drop UTF8String]);
00579
00580 NSString *parentWidgetName = [drop substringFromIndex:9];
00581 parentWidgetName = [parentWidgetName substringToIndex:[parentWidgetName length]-1];
00582 id parentWidget = [NIBManager getComponentForBinding:parentWidgetName fromParent:parent];
00583 if (parentWidget && [parentWidget isKindOfClass:[NSPopUpButton class]]) {
00584 NSLog(@" - found parent widget %s", [[parentWidget description] UTF8String]);
00585
00586 [parentWidget setTarget:[self handler]];
00587 [parentWidget setAction:@selector(onPopUpChange:)];
00588 [[self handler] addDynamicPopUp:bindingName andContextName:context forPopUp:parentWidgetName];
00589 [[self handler] onPopUpChange:parentWidget];
00590 }
00591 }
00592 }
00593
00594
00595 - (void)processValidationDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00596
00597
00598
00599 if ([[DecoratorParser getDecoratorParser] hasValidator:bindingName forContext:context] && [component respondsToSelector:@selector(setDelegate:)]) {
00600 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00601 NSLog(@" - adding validation delegate...");
00602 [component setDelegate:context];
00603 }
00604
00605
00606
00607
00608 if ([[DecoratorParser getDecoratorParser] hasListValues:bindingName forContext:context]) {
00609
00610 [component removeAllItems];
00611
00612 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00613 NSLog(@" - repopulating component with retrieved list values...");
00614 if ([component isKindOfClass:[NSPopUpButton class]]) {
00615 [(NSPopUpButton *) component addItemsWithTitles:[[DecoratorParser getDecoratorParser] retrieveListValues:bindingName forContext:context]];
00616 } else if ([component isKindOfClass:[NSComboBox class]]) {
00617 [(NSComboBox *) component addItemsWithObjectValues:[[DecoratorParser getDecoratorParser] retrieveListValues:bindingName forContext:context]];
00618 }
00619 }
00620 }
00621
00622
00623 - (void)processTokenDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00624 if (![component isKindOfClass:[NSTokenField class]])
00625 return;
00626 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00627 NSLog(@" - setting delegate for NSTokenField: %s", [bindingName UTF8String]);
00628
00629
00630 NSString * maxValue = [[context getMetadata] getValue:[NSString stringWithFormat:@"%s.max_value", [bindingName UTF8String]]];
00631 NSManagedObject * managedO = [[context getController] getObject:nil];
00632
00633
00634 TokenFieldDelegate *tokenHandler = [[TokenFieldDelegate alloc] init];
00635 [tokenHandler setManagedObject:managedO];
00636 [tokenHandler setKey:bindingName];
00637 if (maxValue)
00638 [tokenHandler setMaxLength:[maxValue intValue]];
00639
00640
00641 [component setDelegate:tokenHandler];
00642
00643
00644 [component bind:@"value" toObject:tokenHandler withKeyPath:bindingName options:[component infoForBinding:@"value"]];
00645
00646
00647 [managedO addObserver:tokenHandler
00648 forKeyPath:bindingName
00649 options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
00650 context:component];
00651 }
00652
00653
00654 - (void)processOutlineDecorations:(id)component forContext:(NIBContext *)context forBinding:(NSString *)bindingName withParent:(NSView *)parent {
00655 if (![component isKindOfClass:[NSOutlineView class]])
00656 return;
00657 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00658 NSLog(@" - setting delegate for NSOutlineView: %s", [bindingName UTF8String]);
00659
00660 MetadataParser * parser = [context getMetadata];
00661 NSString * type = [parser getValue:NIB_TYPE];
00662
00663 if ([type isEqual:TYPE_HIERARCHY]) {
00664 NSString * location = [OutlineViewController determinePath:context];
00665 OutlineViewManager * manager = [[[OutlineViewManager alloc] init] retain];
00666 OutlineViewDelegate * delegate = [[[OutlineViewDelegate alloc] init] retain];
00667 NSManagedObject * managedO = [[context getController] getObject:nil];
00668 NSArray * mappings = [[[parser getLocalizedValue:[MetadataParser createKey:NIB_OUTLINE withOption:@"mappings"]] componentsSeparatedByString:@","] retain];
00669
00670 if (location) {
00671 [context setOutlineManager:manager];
00672 [manager setLabels:[[[parser getLocalizedValue:[MetadataParser createKey:NIB_OUTLINE withOption:@"labels"]] componentsSeparatedByString:@","] retain]];
00673 [manager setIdentifiers:[[[parser getLocalizedValue:[MetadataParser createKey:NIB_OUTLINE withOption:@"identifiers"]] componentsSeparatedByString:@","] retain]];
00674 [manager doInitialise:component withURL:[NSURL fileURLWithPath:location]];
00675 [delegate setManager:manager];
00676 [delegate setManagedObject:managedO];
00677 [delegate setMappings:mappings];
00678 [component setDelegate:delegate];
00679 [component deselectAll:manager];
00680 }
00681 }
00682 }
00683
00684
00685 - (IBAction)doPopUpChange:(id)sender {
00686 if (![self isEnabled])
00687 return;
00688
00689 NSString * selected = [popupMenu titleOfSelectedItem];
00690 NIBContext * context;
00691 int i;
00692
00693 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00694 NSLog(@"NIBManager received change event: %s", [selected UTF8String]);
00695 for (i = 0; i < [self getContextCount]; i++) {
00696 context = [self getContext:i];
00697 if ([selected isEqualTo:[[context getMetadata] getLabel]]) {
00698 if (tabView) {
00699 [tabView selectTabViewItemWithIdentifier:[[context getMetadata] getName]];
00700 } else {
00701 [[context getWindow] makeKeyAndOrderFront:sender];
00702 }
00703 }
00704 }
00705 if ([[self main] respondsToSelector:@selector(doPopUpChange:)])
00706 [[self main] doPopUpChange:sender];
00707 }
00708
00709
00710 - (IBAction)onPopUpChange:(id)sender {
00711 [self performSelectorOnMainThread:@selector(doPopUpChange:)
00712 withObject:sender
00713 waitUntilDone:YES];
00714 }
00715
00716
00717 - (void)doDisplay:(NSString *)type {
00718 [self doDisplay:type withIdentifier:nil];
00719 }
00720
00721
00722 - (void)doDisplay:(NSString *)type withIdentifier:(id)identifier {
00723 NIBContext * context;
00724 NSString * temp;
00725 int i;
00726
00727 for (i = 0; i < [self getContextCount]; i++) {
00728 context = [self getContext:i];
00729 temp = [[context getMetadata] getName];
00730 if ([type isEqualTo:temp]) {
00731 if (tabView) {
00732 [tabView selectTabViewItemWithIdentifier:temp];
00733 } else {
00734 [[context getWindow] makeKeyAndOrderFront:self];
00735 }
00736 }
00737 }
00738 }
00739
00740
00741 - (IBAction)doExecute:(id)sender {
00742 NIBController * controller;
00743 int i;
00744
00745 if (![self isEnabled])
00746 return;
00747 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00748 NSLog(@"NIBManager received execute event...");
00749 for (i = 0; i < [self getControllerCount]; i++) {
00750 controller = [self getController: i];
00751 if ([controller isEnabled])
00752 [controller doExecute: sender];
00753 }
00754 }
00755
00756
00757 - (void)doCallback:(NIBController *)controller withObject:(id)object {
00758 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00759 NSLog(@"NIBManager received callback event...");
00760 if (callback)
00761 [callback doCallback:controller withObject:object];
00762 }
00763
00764
00765 - (void)doBuild:(NSPopUpButton *)popup {
00766 [self doBuild:popup withTarget:self withAction:@selector(onPopUpChange:)];
00767 }
00768
00769
00770 - (void)doBuild:(NSPopUpButton *)popup withTarget:(id)target withAction:(SEL)action {
00771 MetadataParser * parser;
00772 NSString * title;
00773 int i;
00774 int total = [popup numberOfItems];
00775 int count = 0;
00776
00777 for (i = 0; i < [self getContextCount]; i++) {
00778 parser = [[self getContext:i] getMetadata];
00779 title = [parser getLabel];
00780 if (title && [title length] > 0) {
00781 [parser setTag:(total+count)];
00782 [popup addItemWithTitle:title];
00783 [[[popup menu] itemWithTitle:title] setTag:[parser getTag]];
00784 count++;
00785 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00786 NSLog(@"NIBManager added option to NSPopUpButton, title: %s", [title UTF8String]);
00787 } else
00788 NSLog(@"NIBManager found ill-formed NIB at index: %i", i);
00789 }
00790 [self setPopupMenu:popup withTarget:target withAction:action];
00791 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00792 NSLog(@"NIBManager build completed");
00793 }
00794
00795
00796 - (void)doBuild:(NSPopUpButton *)menu withTabs:(NSTabView *)tabs {
00797 [self doBuild:menu withTabs:tabs withTarget:self withAction:@selector(onPopUpChange:)];
00798 }
00799
00800
00801 - (void)doBuild:(NSPopUpButton *)menu withTabs:(NSTabView *)tabs withTarget:(id)target withAction:(SEL)action {
00802 NIBContext * context;
00803 NSString * temp;
00804 NSView * view;
00805 int i;
00806
00807 for (i = 0; i < [self getContextCount]; i++) {
00808 context = [self getContext:i];
00809 view = [context getView];
00810 if (view) {
00811 temp = [[context getMetadata] getName];
00812 if (temp && [temp length] > 0) {
00813 [NIBManager addComponent:view withTabs:tabs withIdentifier:temp];
00814 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00815 NSLog(@"NIBManager added view to NSTabView, name: %s", [temp UTF8String]);
00816 } else
00817 NSLog(@"NIBManager found ill-formed NIB at index: %i", i);
00818 }
00819 }
00820 [self setTabView:tabs];
00821 [self doBuild:menu withTarget:target withAction:action];
00822 }
00823
00824
00825 - (void)doBuildSearch:(NSSearchField *)field withTemplate:(NSMenu *)template withSelector:(SEL)aSelector {
00826 MetadataParser * parser;
00827 NSMenuItem * item;
00828 NSString * title;
00829 int i;
00830
00831 for (i = 0; i < [self getContextCount]; i++) {
00832 parser = [[self getContext:i] getMetadata];
00833 title = [parser getLabelWith:NIB_SEARCH_LABEL];
00834 if (title && [title length] > 0) {
00835 item = [[NSMenuItem alloc] initWithTitle:title
00836 action:aSelector
00837 keyEquivalent:@""];
00838 [item setTag: [parser getTag]];
00839 [template addItem:item];
00840 [item release];
00841 }
00842 }
00843 [[field cell] setSearchMenuTemplate: template];
00844 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_INFO)
00845 NSLog(@"NIBManager searcher build completed");
00846 }
00847
00848
00849 - (NIBController *)createController {
00850 return [[[NIBController alloc] init] retain];
00851 }
00852
00853
00854 - (NIBController *)getController:(int)index {
00855 return (NIBController *) [controllers objectAtIndex: index];
00856 }
00857
00858
00859 - (void)addController:(NIBController *)controller {
00860 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00861 NSLog(@"NIBManager adding NIBController...");
00862 [controllers addObject: controller];
00863 }
00864
00865
00866 - (void)removeController:(NIBController *)controller {
00867 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00868 NSLog(@"NIBManager removing NIBController...");
00869 [controllers removeObject: controller];
00870 }
00871
00872
00873 - (int)getControllerCount {
00874 return [controllers count];
00875 }
00876
00877
00878 - (int)getContextCount {
00879 return [contexts count];
00880 }
00881
00882
00883 - (int)determineTag:(NSString *)type {
00884 MetadataParser * parser;
00885 int i = 0;
00886
00887 for (i = 0; i < [self getContextCount]; i++) {
00888 parser = [[self getContext:i] getMetadata];
00889 if ([[parser getName] isEqualTo:type])
00890 return [parser getTag];
00891 }
00892 return -1;
00893 }
00894
00895
00896 - (BOOL)isEnabled {
00897 return ([contexts count] > 0);
00898 }
00899
00900
00901 - (NIBContext *)getContext:(int)index {
00902 return (NIBContext *) [contexts objectAtIndex:index];
00903 }
00904
00905
00906 - (NIBContext *)getContextFor:(NSString *)type {
00907 NIBContext * context;
00908 int tag = [self determineTag:type];
00909
00910 if ([NIBManagerHandler getLoggingLevel] >= LOGGING_DEBUG)
00911 NSLog(@"NIBManager getting context: %s [%i]", [type UTF8String], tag);
00912 context = (tag >= 0 ? [self getContext:tag] : nil);
00913 if ([self persistenceMode] == UNIQUE) {
00914 context = [self doCreate:[context getPath] withName:[context getName] withTag:[[context getMetadata] getTag]];
00915 }
00916 return context;
00917 }
00918
00919
00920 - (NSArray *)topLevelObjectsFromLoadingNibNamed:(NSString *)myName withOwner:(id)owner {
00921 return [self topLevelObjectsFromLoadingBundle:[NSBundle bundleForClass:[owner class]]
00922 withName:myName
00923 withOwner:owner];
00924 }
00925
00926
00927 - (NSArray *)topLevelObjectsFromLoadingBundle:(NSBundle *)bundle withName:(NSString *)myName withOwner:(id)owner {
00928 NSString * file = nil;
00929
00930 if ([myName hasSuffix:@".bundle"])
00931 myName = [myName substringToIndex: [myName length]-7];
00932 if (bundle)
00933 file = [bundle pathForResource:myName ofType:@"nib"];
00934 if (!file)
00935 file = [bundle pathForResource:[self name] ofType:@"nib"];
00936 if (!file) {
00937 bundle = [NSBundle mainBundle];
00938 file = [bundle pathForResource:myName ofType:@"nib"];
00939 }
00940 if (!file)
00941 file = [bundle pathForResource:[self name] ofType:@"nib"];
00942 if (!file && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00943 NSLog(@"NIBManager unable to load NIB objects from bundle: %s", [myName UTF8String]);
00944 return [self topLevelObjectsFromLoadingBundleNib:bundle
00945 withName:file
00946 withOwner:owner];
00947 }
00948
00949
00950 - (NSArray *)topLevelObjectsFromLoadingBundleNib:(NSBundle *)bundle withName:(NSString *)myName withOwner:(id)owner {
00951 NSMutableArray * topLevelObjects = [NSMutableArray array];
00952 NSDictionary * nameTable = [NSDictionary dictionaryWithObjectsAndKeys:topLevelObjects, @"NSTopLevelObjects", owner, @"NSOwner", nil];
00953
00954 if ([NSBundle loadNibFile:myName
00955 externalNameTable:nameTable
00956 withZone:[owner zone]]) {
00957 [topLevelObjects makeObjectsPerformSelector:@selector(release)];
00958 return topLevelObjects;
00959 }
00960 if (myName && [NIBManagerHandler getLoggingLevel] >= LOGGING_NOTICE)
00961 NSLog(@"NIBManager unable to load NIB objects from file: %s", [myName UTF8String]);
00962 return nil;
00963 }
00964
00965
00980 - (NSArray *)createResultsArrayForDisplay:(NSArray *)resultsArray {
00981
00982 if (!resultsArray || [resultsArray count] == 0) {
00983 return [[NSArray alloc] init];
00984 }
00985
00986
00987
00988 NSString * objectType = [[resultsArray objectAtIndex:0] valueForKey:DEFAULT_RESULT_TYPE_KEY];
00989 int tag = [self determineTag:objectType];
00990 MetadataParser * metadata = [[self getContext:tag] getMetadata];
00991
00992
00993 NSArray * resultIdentifiers = [metadata searchResultIdentifiers];
00994
00995
00996 NSMutableArray * results = [[NSMutableArray alloc] init];
00997
00998 int i, j;
00999 NSDictionary * dictionary;
01000 NSMutableDictionary * newDictionary;
01001
01002
01003 NSString * resultIdentifier;
01004 for (i = 0; i < [resultsArray count]; i++) {
01005 dictionary = [resultsArray objectAtIndex:i];
01006 newDictionary = [[NSMutableDictionary alloc] init];
01007
01008 for (j = 0; j < [resultIdentifiers count]; j++) {
01009 resultIdentifier = [resultIdentifiers objectAtIndex:j];
01010 if(![dictionary objectForKey:[metadata searchResultMetadataName:resultIdentifier]]) {
01011 [newDictionary setObject:@"" forKey:resultIdentifier];
01012 }
01013 else {
01014 [newDictionary setObject:[dictionary objectForKey:[metadata searchResultMetadataName:resultIdentifier]] forKey:resultIdentifier];
01015 }
01016 }
01017
01018 [newDictionary setObject:dictionary forKey:DEFAULT_RESULT_DATA_KEY];
01019
01020 [results addObject:newDictionary];
01021
01022 }
01023 return results;
01024 }
01025
01026
01041 - (NSDictionary *)createResultsDictionaryForDisplay:(NSDictionary *)results {
01042
01043
01044
01045 NSString * objectType = [results valueForKey:DEFAULT_RESULT_TYPE_KEY];
01046 int tag = [self determineTag:objectType];
01047 MetadataParser * metadata = [[self getContext:tag] getMetadata];
01048 NSMutableDictionary * newDictionary = [[[NSMutableDictionary alloc] init] retain];
01049
01050
01051 NSArray * resultIdentifiers = [metadata searchResultIdentifiers];
01052 NSString * resultIdentifier;
01053 int i;
01054
01055
01056 for (i = 0; i < [resultIdentifiers count]; i++) {
01057 resultIdentifier = [resultIdentifiers objectAtIndex:i];
01058 if (![results objectForKey:[metadata searchResultMetadataName:resultIdentifier]]) {
01059 [newDictionary setObject:@"" forKey:resultIdentifier];
01060 } else {
01061 [newDictionary setObject:[results objectForKey:[metadata searchResultMetadataName:resultIdentifier]] forKey:resultIdentifier];
01062 }
01063 }
01064
01065 [newDictionary setObject:results forKey:DEFAULT_RESULT_DATA_KEY];
01066 return newDictionary;
01067 }
01068
01069
01070 +(void)addComponent:(NSView *)component withTabs:(NSTabView *)tabs withIdentifier:(NSString *)identifier {
01071 NSTabViewItem * item = [[NSTabViewItem alloc] initWithIdentifier:identifier];
01072
01073 [item setLabel:identifier];
01074 [tabs addTabViewItem:item];
01075 [NIBManager addComponent:component withTabs:tabs withItem:item];
01076 }
01077
01078
01079 +(void)addComponent:(NSView *)component withTabs:(NSTabView *)tabs withItem:(NSTabViewItem *)item {
01080 component = (NSView *) [NIBManager getContentComponent:component];
01081 [NIBManager originateComponent:component];
01082 [item setView:component];
01083 }
01084
01085
01086 +(void)addAction:(NSView *)view withTarget:(id)target withAction:(SEL)action {
01087 [NIBManager addAction:view withDelegate:nil withTarget:target withAction:action];
01088 }
01089
01090
01091 +(void)addAction:(NSView *)view withDelegate:(id)delegate withTarget:(id)target withAction:(SEL)action {
01092 NSArray * views = [view subviews];
01093 id temp;
01094 int i;
01095
01096 for (i = 0; i < [views count]; i++) {
01097 temp = [views objectAtIndex:i];
01098 if ([temp isKindOfClass:[NSTextField class]]) {
01099 if (delegate) {
01100 [temp setDelegate:delegate];
01101 }
01102 } else if ([temp isKindOfClass:[NSButton class]]) {
01103 if (![temp target] || ![temp action]) {
01104 [temp setTarget:target];
01105 [temp setAction:action];
01106 }
01107 } else if ([temp isKindOfClass:[NSView class]]) {
01108 [NIBManager addAction:(NSView *)temp withDelegate:delegate withTarget:target withAction:action];
01109 }
01110 }
01111 }
01112
01113
01114 +(void)removeComponent:(NSView *)view {
01115 [NIBManager removeComponent:view fromParent:[view superview]];
01116 }
01117
01118
01119 +(void)removeComponent:(NSView *)view fromParent:(NSView *)parent {
01120 NSView * tempView = [[NSView alloc] initWithFrame:NSZeroRect];
01121
01122 [parent replaceSubview:view with:tempView];
01123 [tempView release];
01124 }
01125
01126
01127 +(void)originateComponent:(NSView *)component {
01128 NSPoint point = {0, 0};
01129
01130 if ([component isKindOfClass:[NSScrollView class]])
01131 [[(NSScrollView *)component documentView] scrollPoint:point];
01132 else
01133 [component scrollPoint:point];
01134 }
01135
01136
01137 +(NSView *)makeFlippedView:(NSView *)component {
01138 return [NIBManager makeFlippedView:component withAddition:YES];
01139 }
01140
01141
01142 +(NSView *)makeFlippedView:(NSView *)component withAddition:(BOOL)addition {
01143 if ([component isKindOfClass:[AZView class]])
01144 return component;
01145
01146 AZView * flipped = [[[AZView alloc] init] retain];
01147
01148 [flipped setMenu:[component menu]];
01149 [flipped setFrame:[component frame]];
01150 [flipped setBounds:[component bounds]];
01151 if (addition)
01152 [flipped addSubview:component];
01153 return flipped;
01154 }
01155
01156
01157 +(NSBox *)makeBoxedView:(NSView *)component withTitle:(NSString *)title {
01158 return [NIBManager makeBoxedView:component withTitle:title withFlipped:YES];
01159 }
01160
01161
01162 +(NSBox *)makeBoxedView:(NSView *)component withTitle:(NSString *)title withFlipped:(BOOL)flipped {
01163 NSBox * boxed = [[[NSBox alloc] init] retain];
01164
01165 if (flipped)
01166 [boxed setContentView:[NIBManager makeFlippedView:component withAddition:NO]];
01167 else
01168 [[boxed contentView] setMenu:[component menu]];
01169 [boxed setMenu:[component menu]];
01170 [boxed setTitle:title];
01171 [boxed setAutoresizingMask:[component autoresizingMask]];
01172 return boxed;
01173 }
01174
01175
01176 +(NSScrollView *)makeScrollView:(NSView *)component withFlipped:(BOOL)flipped {
01177 return [NIBManager makeScrollView:component withBounds:[component bounds] withFlipped:flipped];
01178 }
01179
01180
01181 +(NSScrollView *)makeScrollView:(NSView *)component withBounds:(NSRect)bounds withFlipped:(BOOL)flipped {
01182 NSScrollView * scroller = [[[NSScrollView alloc] init] retain];
01183
01184 [scroller setAutohidesScrollers:YES];
01185 [scroller setHasVerticalScroller:YES];
01186 [scroller setHasHorizontalScroller:YES];
01187 [scroller setDocumentView:(flipped ? [NIBManager makeFlippedView:component] : component)];
01188 [scroller setDrawsBackground:NO];
01189 [scroller setFrame:bounds];
01190 [scroller setBounds:bounds];
01191 [scroller setMenu:[component menu]];
01192 [component scrollPoint:bounds.origin];
01193 return scroller;
01194 }
01195
01196
01197 +(NSWindow *)makeWindow:(NSView *)component withTitle:(NSString *)title {
01198 return [NIBManager makeWindow:component withTitle:title withStyle:(NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
01199 }
01200
01201
01202 +(NSWindow *)makeWindow:(NSView *)component withTitle:(NSString *)title withStyle:(unsigned int)style {
01203 NSWindow * window;
01204
01205 if (title)
01206 style = (style | NSTitledWindowMask);
01207 window = [[NSWindow alloc] initWithContentRect:[component bounds] styleMask:style backing:NSBackingStoreBuffered defer:NO];
01208 if (title)
01209 [window setTitle:title];
01210 [window setContentView:component];
01211 [window setContentSize:[component bounds].size];
01212 return window;
01213 }
01214
01215
01216 +(NSPanel *)makePanel:(NSView *)component withTitle:(NSString *)title {
01217 return [NIBManager makePanel:component withTitle:title withStyle:(NSClosableWindowMask)];
01218 }
01219
01220
01221 +(NSPanel *)makePanel:(NSView *)component withTitle:(NSString *)title withStyle:(unsigned int)style {
01222 NSPanel * window;
01223
01224 if (title)
01225 style = (style | NSTitledWindowMask);
01226 window = [[NSPanel alloc] initWithContentRect:[component bounds] styleMask:style backing:NSBackingStoreBuffered defer:NO];
01227 if (title)
01228 [window setTitle:title];
01229 [window setContentView:component];
01230 return window;
01231 }
01232
01233
01234 +(NSWindow *)makeWindow:(NIBContext *)context withView:(NSView *)view withTitle:(NSString *)title {
01235 return [NIBManager makeWindow:context withView:view withTitle:title withStyle:(NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
01236 }
01237
01238
01239 +(NSWindow *)makeWindow:(NIBContext *)context withView:(NSView *)view withTitle:(NSString *)title withStyle:(unsigned int)style {
01240 NSWindow * window = [NIBManager makeWindow:view withTitle:title withStyle:style];
01241 double width = [[context getMetadata] getWidth];
01242 double height = [[context getMetadata] getHeight];
01243
01244 if (width > 0 && height > 0) {
01245 NSSize size = {width, height};
01246 [window setContentSize:size];
01247 }
01248 return window;
01249 }
01250
01251
01252 +(NSPanel *)makePanel:(NIBContext *)context withView:(NSView *)view withTitle:(NSString *)title {
01253 return [NIBManager makePanel:context withView:view withTitle:title withStyle:(NSClosableWindowMask)];
01254 }
01255
01256
01257 +(NSPanel *)makePanel:(NIBContext *)context withView:(NSView *)view withTitle:(NSString *)title withStyle:(unsigned int)style {
01258 NSPanel * window = [NIBManager makePanel:view withTitle:title withStyle:style];
01259 double width = [[context getMetadata] getWidth];
01260 double height = [[context getMetadata] getHeight];
01261
01262 if (width > 0 && height > 0) {
01263 NSSize size = {width, height};
01264 [window setContentSize:size];
01265 }
01266 return window;
01267 }
01268
01269
01270 +(BOOL)makeDirectoryPath:(NSString *)path {
01271 NSFileManager * fileManager = [NSFileManager defaultManager];
01272 BOOL isDirectory = NO;
01273
01274 path = [path stringByExpandingTildeInPath];
01275 if ([fileManager fileExistsAtPath:path isDirectory:&isDirectory])
01276 return isDirectory;
01277
01278 NSMutableArray * components = [NSMutableArray arrayWithArray:[path pathComponents]];
01279 NSString * pathElement;
01280 NSString * dir = @"";
01281 int i;
01282
01283 for (i = 0 ; i < [components count]; i++) {
01284 pathElement = [components objectAtIndex:i];
01285 dir = [dir stringByAppendingPathComponent:pathElement];
01286 if (![fileManager fileExistsAtPath:dir isDirectory:&isDirectory]) {
01287 if (![fileManager createDirectoryAtPath:dir attributes:nil]) {
01288 [dir release];
01289 dir = nil;
01290 return NO;
01291 }
01292 }
01293 }
01294 return YES;
01295 }
01296
01297
01298 +(void)setEnabled:(BOOL)enabled withView:(NSView *)view {
01299 [NIBManager setEnabled:enabled withView:view withFilter:nil];
01300 }
01301
01302
01303 +(void)setEnabled:(BOOL)enabled withView:(NSView *)view withFilter:(NSString *)filter {
01304 NSArray * views = [view subviews];
01305 BOOL matched;
01306 id temp;
01307 int i;
01308
01309 for (i = 0; i < [views count]; i++) {
01310 temp = [views objectAtIndex:i];
01311 matched = (!filter || [filter isEqual:[NIBManager determineEnabled:temp]]);
01312 if ([temp isKindOfClass:[NSControl class]]) {
01313 if (matched)
01314 [temp setEnabled:enabled];
01315 } else if ([temp isKindOfClass:[NSTextView class]]) {
01316 if (matched)
01317 [temp setEditable:enabled];
01318 } else if ([temp isKindOfClass:[NSScrollView class]]) {
01319 [NIBManager setEnabled:enabled withView:[temp documentView] withFilter:(matched ? nil : filter)];
01320 } else if ([temp isKindOfClass:[NSBox class]]) {
01321 [NIBManager setEnabled:enabled withView:[temp contentView] withFilter:(matched ? nil : filter)];
01322 } else if ([temp isKindOfClass:[NSTabView class]]) {
01323 [NIBManager setEnabled:enabled withView:[[temp selectedTabViewItem] view] withFilter:(matched ? nil : filter)];
01324 } else if ([temp isKindOfClass:[NSView class]]) {
01325 [NIBManager setEnabled:enabled withView:temp withFilter:(matched ? nil : filter)];
01326 }
01327 }
01328 }
01329
01330
01331 +(void)setValue:(id)value withKey:(NSString *)key withParent:(NSView *)view {
01332 NSArray * views = [view subviews];
01333 id temp;
01334 int i;
01335
01336 for (i = 0; i < [views count]; i++) {
01337 temp = [views objectAtIndex:i];
01338 if ([temp isKindOfClass:[NSControl class]]) {
01339 if ([[NIBManager determineName:temp] isEqualTo:key])
01340 [temp setStringValue:value];
01341 } else if ([temp isKindOfClass:[NSView class]]) {
01342 [NIBManager setValue:value withKey:key withParent:temp];
01343 }
01344 }
01345 }
01346
01347
01348 +(NSMutableArray *)getComponents:(id)parent {
01349 NSMutableArray * components = [[[NSMutableArray alloc] init] retain];
01350 NSArray * subviews = nil;
01351 int i = 0;
01352
01353 if ([parent isKindOfClass:[NSWindow class]]) {
01354 [components addObjectsFromArray:[NIBManager getComponents:[parent contentView]]];
01355 } else if ([parent isKindOfClass:[NSBox class]]) {
01356 [components addObjectsFromArray:[NIBManager getComponents:[parent contentView]]];
01357 } else if ([parent isKindOfClass:[NSScrollView class]]) {
01358 [components addObjectsFromArray:[NIBManager getComponents:[parent documentView]]];
01359 } else if ([parent isKindOfClass:[NSTabViewItem class]]) {
01360 [components addObjectsFromArray:[NIBManager getComponents:[parent view]]];
01361
01362 } else if ([parent isKindOfClass:[NSControl class]]) {
01363
01364
01365 id target = [parent target];
01366 if ([target isKindOfClass:[NSPanel class]] && [parent action] == @selector(makeKeyAndOrderFront:)) {
01367 [components addObjectsFromArray:[NIBManager getComponents:[target contentView]]];
01368 }
01369 [components addObject:parent];
01370 } else if ([parent isKindOfClass:[NSTextView class]]) {
01371 [components addObject:parent];
01372 } else if ([parent isKindOfClass:[NSTabView class]]) {
01373 subviews = [parent tabViewItems];
01374 } else if ([parent isKindOfClass:[NSView class]]) {
01375
01376 subviews = [parent subviews];
01377 }
01378
01379 for (i = 0; subviews && i < [subviews count]; i++)
01380 [components addObjectsFromArray:[NIBManager getComponents:[subviews objectAtIndex:i]]];
01381 return components;
01382 }
01383
01384
01385 +(id)getComponent:(NSString *)name fromParent:(id)component {
01386 if ([name isEqualTo:[NIBManager determineIdentifier:component]])
01387 return component;
01388
01389 NSArray * subviews = [NIBManager getComponents:component];
01390 NSString * temp;
01391 int i = 0;
01392 id child;
01393
01394 for (i = 0; i < [subviews count]; i++) {
01395 child = [subviews objectAtIndex:i];
01396 temp = [NIBManager determineIdentifier:child];
01397 if (temp && [temp isEqualTo:name])
01398 return child;
01399 }
01400 return nil;
01401 }
01402
01403
01404 +(id)getComponentOrView:(NSString *)name fromParent:(id)component {
01405 if ([name isEqualTo:[NIBManager determineIdentifier:component]])
01406 return component;
01407
01408 NSArray * subviews = [component subviews];
01409 int i = 0;
01410 id child;
01411
01412 for (i = 0; i < [subviews count]; i++) {
01413 child = [NIBManager getComponentOrView:name fromParent:[subviews objectAtIndex:i]];
01414 if (child)
01415 return child;
01416 }
01417 return nil;
01418 }
01419
01420
01421 +(id)getComponentForBinding:(NSString *)bindingName fromParent:(id)component {
01422 NSArray * subviews = [NIBManager getComponents:component];
01423 NSString * temp;
01424 int i = 0;
01425 id child;
01426
01427 for (i = 0; i < [subviews count]; i++) {
01428 child = [subviews objectAtIndex:i];
01429 temp = [NIBManager determineName:child];
01430 if (temp && [temp isEqualTo:bindingName])
01431 return child;
01432 }
01433 return nil;
01434 }
01435
01436
01437 +(id)getContentComponent:(id)component {
01438 if (![component isKindOfClass:[NSScrollView class]])
01439 return component;
01440
01441 id content = [(NSScrollView *)component documentView];
01442
01443 if ([content isKindOfClass:[AZView class]] && [[content subviews] count] == 1)
01444 content = [[content subviews] objectAtIndex:0];
01445 if ([content isKindOfClass:[NSView class]] && [[content subviews] count] == 1)
01446 content = [[content subviews] objectAtIndex:0];
01447
01448 if ([content isKindOfClass:[NSScrollView class]])
01449 return content;
01450 return component;
01451 }
01452
01453
01454 +(id)determineComponent:(id)component {
01455 if (!component)
01456 NSLog(@"NIBManager considering NULL component...");
01457
01458 if ([component isKindOfClass:[MatrixController class]]) {
01459 return [NIBManager determineComponent:[component context]];
01460 } else if ([component isKindOfClass:[NIBContext class]]) {
01461 return [NIBManager determineComponent:[component getView]];
01462 } else if ([component isKindOfClass:[NIBController class]]) {
01463 return [NIBManager determineComponent:[component window]];
01464 } else if ([component isKindOfClass:[NSWindow class]]) {
01465 return [NIBManager determineComponent:[component contentView]];
01466 } else if ([component isKindOfClass:[NSView class]]) {
01467 return component;
01468 } else {
01469 return nil;
01470 }
01471 }
01472
01473
01474 +(NSString *)determineName:(id)component {
01475 NSString * value = nil;
01476
01477 if ([component isKindOfClass:[NSButton class]] && ![component isKindOfClass:[NSPopUpButton class]] && ![component isKindOfClass:[NSComboBox class]])
01478 return [component alternateTitle];
01479 if ([component isKindOfClass:[NSTextView class]])
01480 return [NIBManager determineBinding:@"data" withComponent:component];
01481 value = [NIBManager determineBinding:@"value" withComponent:component];
01482 if (!value)
01483 value = [NIBManager determineBinding:@"selectedValue" withComponent:component];
01484 return value;
01485 }
01486
01487
01488 +(NSString *)determineIdentifier:(id)component {
01489 if ([component isKindOfClass:[NSMenu class]] && [[component delegate] isKindOfClass:[NSObjectController class]])
01490 return [[component delegate] entityName];
01491 return [NIBManager determineBinding:@"toolTip" withComponent:component withOffset:7];
01492 }
01493
01494
01495 +(NSString *)determineEnabled:(id)component {
01496 NSString * value = [NIBManager determineName:component];
01497 return (value ? value : [NIBManager determineBinding:@"enabled" withComponent:component withOffset:7]);
01498 }
01499
01500
01501 +(NSString *)determineBinding:(NSString *)key withComponent:(id)component {
01502 return [NIBManager determineBinding:key withComponent:component withOffset:10];
01503 }
01504
01505
01506 +(NSString *)determineBinding:(NSString *)key withComponent:(id)component withOffset:(int)offset {
01507 NSString * value = [[component infoForBinding:key] objectForKey:NSObservedKeyPathKey];
01508 return (value ? [value substringFromIndex:offset] : nil);
01509 }
01510
01511
01512 @end