[ruleeditor commit] r97 - branches/CPRuleEditor

0 views
Skip to first unread message

codesite...@google.com

unread,
Jan 25, 2009, 2:52:43 PM1/25/09
to psruleedit...@googlegroups.com
Author: caca...@gmail.com
Date: Sun Jan 25 11:36:11 2009
New Revision: 97

Added:
branches/CPRuleEditor/CPExpression_intersectset.j
branches/CPRuleEditor/CPExpression_minusset.j
branches/CPRuleEditor/CPExpression_unionset.j
Modified:
branches/CPRuleEditor/AppController.j
branches/CPRuleEditor/CPComparisonPredicate.j
branches/CPRuleEditor/CPCompoundPredicate.j
branches/CPRuleEditor/CPExpression.j
branches/CPRuleEditor/CPExpression_aggregate.j
branches/CPRuleEditor/CPExpression_assignment.j
branches/CPRuleEditor/CPExpression_constant.j
branches/CPRuleEditor/CPExpression_function.j
branches/CPRuleEditor/CPExpression_keypath.j
branches/CPRuleEditor/CPExpression_operator.j
branches/CPRuleEditor/CPExpression_self.j
branches/CPRuleEditor/CPExpression_variable.j
branches/CPRuleEditor/CPPredicate.j
branches/CPRuleEditor/CPPredicateTest.j
branches/CPRuleEditor/CPRuleEditor.j
branches/CPRuleEditor/CPRuleEditorButtonCell.j
branches/CPRuleEditor/CPRuleEditorPopupButton.j
branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j
branches/CPRuleEditor/CPRuleEditorTextField.j
branches/CPRuleEditor/CPRuleEditorViewSlice.j
branches/CPRuleEditor/CPRuleEditorViewSliceDropSeparator.j
branches/CPRuleEditor/CPRuleEditorViewSliceRow.j
branches/CPRuleEditor/RuleDelegate.j
branches/CPRuleEditor/_CPRuleEditorCache.j
branches/CPRuleEditor/_CPRuleEditorViewSliceHolder.j
branches/CPRuleEditor/criteria.plist
branches/CPRuleEditor/main.j

Log:
update

Modified: branches/CPRuleEditor/AppController.j
==============================================================================
--- branches/CPRuleEditor/AppController.j (original)
+++ branches/CPRuleEditor/AppController.j Sun Jan 25 11:36:11 2009
@@ -1,60 +1,48 @@
+@import <Foundation/CPObject.j>
+@import "CPRuleEditor.j"
+@import "RuleDelegate.j"

-import <Foundation/CPObject.j>
-import "CPRuleEditor.j"
-import "RuleDelegate.j"
-
-
-
-@implementation CPObject (Additions)
-
-- (id)mutableArrayValueForKey:(CPString)key
-{
- return [self valueForKey:key];
-}
-
-@end

@implementation AppController : CPObject
{
+
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
- objj_backtrace_set_enable(true);
- CPLogRegister(CPLogConsole);
-
- var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask],
- contentView = [theWindow contentView];
-
- var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"aà"]
rightExpression:[CPExpression expressionForConstantValue:@"àa"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];

- CPLogConsole("RESULT = "+[pred evaluateWithObject:nil]);
+ CPLogRegister(CPLogConsole);
+
+ var array = [CPArray arrayWithObjects:"a","b","c",nil];
+ var dict = [CPDictionary dictionaryWithObject:array forKey:"array"];
+ var mut = [dict mutableArrayValueForKey:"array"];
+ CPLogConsole("mut = "+ mut );
+
+ var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask],
+ contentView = [theWindow contentView];

- var ruleeditor = [[RuleEditor alloc]
initWithFrame:CGRectMake(0,0,400,200)];
- [ruleeditor setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin |
CPViewHeightSizable];
+ var ruleEditor = [[RuleEditor alloc]
initWithFrame:CGRectMake(0,0,400,200)];
+ [ruleEditor setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin |
CPViewHeightSizable];

var datasource = [[RuleDelegate alloc] init];
- [ruleeditor setDelegate:datasource];
-
- [ruleeditor setBackgroundColor:[CPColor grayColor]];
+ [ruleEditor setDelegate:datasource];

+ [ruleEditor setNestingMode:CPRuleEditorNestingModeSimple];

var aView = [[CPView alloc] initWithFrame:CGRectMake(0,0,50,200)];
[aView setBackgroundColor:[CPColor greenColor]];

var split = [[CPSplitView alloc]
initWithFrame:CGRectMake(0,0,600,400)];
[split addSubview:aView];
- [split addSubview:ruleeditor];
+ [split addSubview:ruleEditor];

[contentView addSubview:split];
- [ruleeditor addRow:self];
+ [ruleEditor addRow:self];
+
[theWindow orderFront:self];

- var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"]
rightExpression:[CPExpression expressionForConstantValue:@"aà"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
-
-
// Uncomment the following line to turn on the standard menu bar.
- //[CPMenu setMenuBarVisible:YES];
+ // [CPMenu setMenuBarVisible:YES];
}

@end

Modified: branches/CPRuleEditor/CPComparisonPredicate.j
==============================================================================
--- branches/CPRuleEditor/CPComparisonPredicate.j (original)
+++ branches/CPRuleEditor/CPComparisonPredicate.j Sun Jan 25 11:36:11 2009
@@ -1,12 +1,11 @@

-import <Foundation/CPArray.j>
-import <Foundation/CPEnumerator.j>
-import <Foundation/CPNull.j>
-import <Foundation/CPString.j>
-import "CPPredicate.j"
-import "CPExpression.j"
-import "CPExpression_operator.j"
-
+@import <Foundation/CPArray.j>
+@import <Foundation/CPNull.j>
+@import <Foundation/CPString.j>
+@import <Foundation/CPEnumerator.j>
+@import "CPPredicate.j"
+@import "CPExpression.j"
+@import "CPExpression_operator.j"

CPDirectPredicateModifier = 0;
CPAllPredicateModifier = 1;
@@ -24,6 +23,8 @@
CPEndsWithPredicateOperatorType = 9;
CPInPredicateOperatorType = 10;
CPCustomSelectorPredicateOperatorType = 11;
+CPContainsPredicateOperatorType = 12;
+CPBetweenPredicateOperatorType = 13;

CPCaseInsensitivePredicateOption = 1;
CPDiacriticInsensitivePredicateOption = 2;
@@ -31,98 +32,113 @@
var CPComparisonPredicateModifier;
var CPPredicateOperatorType;

+@implementation CPString (Compare)
+
+- (CPComparisonResult)compare:(CPString)aString options:(int)aMask
range:(CPRange)range
+{
+ if (range.location + range.length > [self length])
+ [CPException raise:CPRangeException reason:"Range exceeds the
length of the receiver"]; // should raise in cocoa but doesn't
+
+ var lhs = [self substringWithRange:range],
+ rhs = aString;
+
+ return [lhs compare:rhs options:aMask];
+}
+
+@end
+
@implementation CPComparisonPredicate : CPPredicate
{
CPExpression _left;
CPExpression _right;

- var _modifier;
- var _type;
- var _options;
- var _customSelector;
-
+ CPComparisonPredicateModifier _modifier;
+ CPPredicateOperatorType _type;
+ unsigned int _options;
+ SEL _customSelector;
}

- (id)initWithLeftExpression:(CPExpression)left
rightExpression:(CPExpression)right
modifier:(CPComparisonPredicateModifier)modifier
type:(CPPredicateOperatorType)type options:(unsigned)options
{
- _left = left;
- _right = right;
- _modifier = modifier;
- _type = type;
-
- if(type == CPMatchesPredicateOperatorType
- || type == CPLikePredicateOperatorType
- || type == CPBeginsWithPredicateOperatorType
- || type == CPEndsWithPredicateOperatorType
- || type == CPInPredicateOperatorType)
- _options = options;
- else
- _options = 0;
+ _left = left;
+ _right = right;
+ _modifier = modifier;
+ _type = type;
+ _options = options;
+
+ if (type != CPMatchesPredicateOperatorType &&
+ type != CPLikePredicateOperatorType &&
+ type != CPBeginsWithPredicateOperatorType &&
+ type != CPEndsWithPredicateOperatorType &&
+ type != CPInPredicateOperatorType)
+ _options = 0;

- _customSelector = 0;
- return self;
+ _customSelector = 0;
+
+ return self;
}

- (id)initWithLeftExpression:(CPExpression)left
rightExpression:(CPExpression)right customSelector:(SEL)selector
{
- _left = left;
- _right = right;
- _modifier = CPDirectPredicateModifier;
- _type = CPCustomSelectorPredicateOperatorType;
- _options = 0;
- _customSelector = selector;
- return self;
+ _left = left;
+ _right = right;
+ _modifier = CPDirectPredicateModifier;
+ _type = CPCustomSelectorPredicateOperatorType;
+ _options = 0;
+ _customSelector = selector;
+
+ return self;
}

- (id)initWithCoder:(CPCoder)coder
{
- // UNIMPLEMENTED
- return self;
+ // UNIMPLEMENTED
+ return self;
}

- (void)encodeWithCoder:(CPCoder)coder
{
- // UNIMPLEMENTED
+ // UNIMPLEMENTED
}

+ (CPPredicate)predicateWithLeftExpression:(CPExpression)left
rightExpression:(CPExpression)right
modifier:(CPComparisonPredicateModifier)modifier type:(int)type
options:(unsigned)options
{
- return [[self alloc] initWithLeftExpression:left rightExpression:right
modifier:modifier type:type options:options];
+ return [[self alloc] initWithLeftExpression:left rightExpression:right
modifier:modifier type:type options:options];
}

+ (CPPredicate)predicateWithLeftExpression:(CPExpression)left
rightExpression:(CPExpression)right customSelector:(SEL)selector
{
- return [[self alloc] initWithLeftExpression:left rightExpression:right
customSelector:selector];
+ return [[self alloc] initWithLeftExpression:left rightExpression:right
customSelector:selector];
}

- (CPString)predicateFormat
{
- var modifier;
- var operator;
- var options;
+ var modifier;

- switch(_modifier)
- {
+ switch (_modifier)
+ {
case CPDirectPredicateModifier:
modifier = "";
- break;
+ break;

- case CPAllPredicateModifier:
- modifier = "ALL ";
- break;
-
- case CPAnyPredicateModifier:
- modifier = "ANY ";
- break;
-
- default:
- modifier = "";
- break;
- }
+ case CPAllPredicateModifier:
+ modifier = "ALL ";
+ break;
+
+ case CPAnyPredicateModifier:
+ modifier = "ANY ";
+ break;
+
+ default:
+ modifier = "";
+ break;
+ }

+ var options;
+
switch (_options)
{
- case CPCaseInsensitivePredicateOption:
+ case CPCaseInsensitivePredicateOption:
options = "[c]";
break;

@@ -139,192 +155,189 @@
break;
}

- switch(_type){
-
- case CPLessThanPredicateOperatorType:
- operator = "<";
- break;
+ var operator;

- case CPLessThanOrEqualToPredicateOperatorType:
- operator = "<=";
- break;
+ switch (_type)
+ {
+ case CPLessThanPredicateOperatorType:
+ operator = "<";
+ break;

- case CPGreaterThanPredicateOperatorType:
- operator = ">";
- break;
+ case CPLessThanOrEqualToPredicateOperatorType:
+ operator = "<=";
+ break;

- case CPGreaterThanOrEqualToPredicateOperatorType:
- operator = ">=";
- break;
+ case CPGreaterThanPredicateOperatorType:
+ operator = ">";
+ break;

- case CPEqualToPredicateOperatorType:
- operator = "==";
- break;
+ case CPGreaterThanOrEqualToPredicateOperatorType:
+ operator = ">=";
+ break;

- case CPNotEqualToPredicateOperatorType:
- operator = "!=";
- break;
+ case CPEqualToPredicateOperatorType:
+ operator = "==";
+ break;

- case CPMatchesPredicateOperatorType:
- operator = "MATCHES";
- break;
+ case CPNotEqualToPredicateOperatorType:
+ operator = "!=";
+ break;

- case CPLikePredicateOperatorType:
- operator = "LIKE";
- break;
+ case CPMatchesPredicateOperatorType:
+ operator = "MATCHES";
+ break;

- case CPBeginsWithPredicateOperatorType:
- operator = "BEGINSWITH";
- break;
+ case CPLikePredicateOperatorType:
+ operator = "LIKE";
+ break;

- case CPEndsWithPredicateOperatorType:
- operator = "ENDSWITH";
- break;
+ case CPBeginsWithPredicateOperatorType:
+ operator = "BEGINSWITH";
+ break;

- case CPInPredicateOperatorType:
- operator = "IN";
- break;
+ case CPEndsWithPredicateOperatorType:
+ operator = "ENDSWITH";
+ break;

- // FIX, not right
- case CPCustomSelectorPredicateOperatorType:
- operator = [CPString
stringWithFormat:@"%s",CPStringFromSelector(_customSelector)];
- break;
+ case CPInPredicateOperatorType:
+ operator = "IN";
+ break;

- }
+ // FIX, not right
+ case CPCustomSelectorPredicateOperatorType:
+ operator = CPStringFromSelector(_customSelector);
+ break;
+ }

- return [CPString stringWithFormat:@"%s%s %s%s %s",modifier,[_left
description],operator,options,[_right description]];
+ return [CPString stringWithFormat:@"%s%s %s%s %s",modifier,[_left
description],operator,options,[_right description]];

}

- (CPPredicate)predicateWithSubstitutionVariables:(CPDictionary)variables
{
- var left = [_left _expressionWithSubstitutionVariables:variables];
- var right = [_left _expressionWithSubstitutionVariables:variables];
+ var left = [_left _expressionWithSubstitutionVariables:variables];
+ var right = [_right _expressionWithSubstitutionVariables:variables];

- if(_type != CPCustomSelectorPredicateOperatorType)
- return [CPComparisonPredicate predicateWithLeftExpression:left
rightExpression:right modifier:_modifier type:_type options:_options];
- else
- return [CPComparisonPredicate predicateWithLeftExpression:left
rightExpression:right customSelector:_customSelector];
+ if (_type != CPCustomSelectorPredicateOperatorType)
+ return [CPComparisonPredicate predicateWithLeftExpression:left
rightExpression:right modifier:_modifier type:_type options:_options];
+ else
+ return [CPComparisonPredicate predicateWithLeftExpression:left
rightExpression:right customSelector:_customSelector];
}

- (CPExpression)leftExpression
{
- return _left;
+ return _left;
}

- (CPExpression)rightExpression
{
- return _right;
+ return _right;
}

- (CPPredicateOperatorType)predicateOperatorType
{
- return _type;
+ return _type;
}

- (CPComparisonPredicateModifier)comparisonPredicateModifier
{
- return _modifier;
+ return _modifier;
}

- (unsigned)options
{
- return _options;
+ return _options;
}

- (SEL)customSelector
{
- return _customSelector;
+ return _customSelector;
}

- (BOOL)_evaluateValue:leftResult rightValue:rightResult
{
-var CPDiacriticInsensitiveSearch = 128;
-
- var leftIsNil = (leftResult == nil || [leftResult isEqual:[CPNull null]]);
- var rightIsNil = (rightResult == nil || [rightResult isEqual:[CPNull
null]]);
+ var CPDiacriticInsensitiveSearch = 128; // this has to be declared in
CPString rather than here
+
+ var leftIsNil = (leftResult == nil || [leftResult isEqual:[CPNull
null]]);
+ var rightIsNil = (rightResult == nil || [rightResult isEqual:[CPNull
null]]);

if (leftIsNil || rightIsNil)
- return ((leftIsNil == rightIsNil)
- && (_type == CPEqualToPredicateOperatorType
- || _type == CPLessThanOrEqualToPredicateOperatorType
- || _type == CPGreaterThanOrEqualToPredicateOperatorType));
+ return ((leftIsNil == rightIsNil) &&
+ (_type == CPEqualToPredicateOperatorType ||
+ _type == CPLessThanOrEqualToPredicateOperatorType ||
+ _type == CPGreaterThanOrEqualToPredicateOperatorType));

var string_compare_options = 0;

- // left and right should be casted first [CAST()] following 10.5 rules.
- switch(_type){
-
- case CPLessThanPredicateOperatorType:
- return ([leftResult compare:rightResult] == CPOrderedAscending);
+ // left and right should be casted first [CAST()] following 10.5 rules.
+ switch (_type)
+ {
+ case CPLessThanPredicateOperatorType:
+ return ([leftResult compare:rightResult] ==
CPOrderedAscending);

- case CPLessThanOrEqualToPredicateOperatorType:
- return ([leftResult compare:rightResult] != CPOrderedDescending);
+ case CPLessThanOrEqualToPredicateOperatorType:
+ return ([leftResult compare:rightResult] !=
CPOrderedDescending);

- case CPGreaterThanPredicateOperatorType:
- return ([leftResult compare:rightResult] == CPOrderedDescending);
+ case CPGreaterThanPredicateOperatorType:
+ return ([leftResult compare:rightResult] ==
CPOrderedDescending);

- case CPGreaterThanOrEqualToPredicateOperatorType:
- return ([leftResult compare:rightResult] != CPOrderedAscending);
+ case CPGreaterThanOrEqualToPredicateOperatorType:
+ return ([leftResult compare:rightResult] !=
CPOrderedAscending);

- case CPEqualToPredicateOperatorType:
- return [leftResult isEqual:rightResult];
+ case CPEqualToPredicateOperatorType:
+ return [leftResult isEqual:rightResult];

- case CPNotEqualToPredicateOperatorType:
- return (![leftResult isEqual:rightResult]);
+ case CPNotEqualToPredicateOperatorType:
+ return (![leftResult isEqual:rightResult]);

- case CPMatchesPredicateOperatorType:
- if(_options & CPDiacriticInsensitivePredicateOption)
+ case CPMatchesPredicateOperatorType:
+ if (_options & CPDiacriticInsensitivePredicateOption)
{
- leftResult = _stripDiacritics(leftResult);
- rightResult = _stripDiacritics(rightResult);
+ leftResult = _stripDiacritics(leftResult);
+ rightResult = _stripDiacritics(rightResult);
}

- var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
- var reg = new RegExp(rightResult,commut);
- return reg.test(leftResult);
+ var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
+ var reg = new RegExp(rightResult,commut);
+ return reg.test(leftResult);

- case CPLikePredicateOperatorType:
- if(_options & CPDiacriticInsensitivePredicateOption)
+ case CPLikePredicateOperatorType:
+ if (_options & CPDiacriticInsensitivePredicateOption)
{
- leftResult = _stripDiacritics(leftResult);
- rightResult = _stripDiacritics(rightResult);
+ leftResult = _stripDiacritics(leftResult);
+ rightResult = _stripDiacritics(rightResult);
}
- var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
- var like_pattern = escape_regex(rightResult);
- var reg = new RegExp(like_pattern,commut);
- return reg.test(leftResult);
-
- case CPBeginsWithPredicateOperatorType:
- var range = CPMakeRange(0,[rightResult length]);
- if (_options & CPCaseInsensitivePredicateOption) string_compare_options
|= CPCaseInsensitiveSearch;
- if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;
-
- return ([leftResult compare:rightResult options:string_compare_options
range:range] == CPOrderedSame);
-
- case CPEndsWithPredicateOperatorType:
- var range = CPMakeRange([leftResult length] - [rightResult
length],[rightResult length]);
- if (_options & CPCaseInsensitivePredicateOption) string_compare_options
|= CPCaseInsensitiveSearch;
- if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;
+ var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
+ var like_pattern = escape_regex(rightResult);
+ var reg = new RegExp(like_pattern,commut);
+ return reg.test(leftResult);
+
+ case CPBeginsWithPredicateOperatorType:
+ var range = CPMakeRange(0,[rightResult length]);
+ if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
+ if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;
+
+ return ([leftResult compare:rightResult
options:string_compare_options range:range] == CPOrderedSame);
+
+ case CPEndsWithPredicateOperatorType:
+ var range = CPMakeRange([leftResult length] - [rightResult
length],[rightResult length]);
+ if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
+ if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

- return ([leftResult compare:rightResult options:string_compare_options
range:range] == CPOrderedSame);
+ return ([leftResult compare:rightResult
options:string_compare_options range:range] == CPOrderedSame);

- case CPInPredicateOperatorType: // UNTESTED
+ case CPInPredicateOperatorType:
// Handle special case where rightResult is a collection and
leftResult an element of it.
if (![rightResult isKindOfClass: [CPString class]])
{
- var e;
- var value;
-
if (![rightResult respondsToSelector:
@selector(objectEnumerator)])
- [CPException raise: CPInvalidArgumentException reason:
@"The right hand side for an IN operator must be a collection"];
+ [CPException raise:CPInvalidArgumentException
reason:@"The right hand side for an IN operator must be a collection"];

- e = [rightResult objectEnumerator];
+ var e = [rightResult objectEnumerator],
+ value;
while (value = [e nextObject])
- {
if ([value isEqual:leftResult])
return YES;
- }

return NO;
}
@@ -332,92 +345,86 @@
if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

- return ([rightResult rangeOfString: leftResult options:
string_compare_options].location != CPNotFound);
+ return ([rightResult rangeOfString:leftResult
options:string_compare_options].location != CPNotFound);

- case CPCustomSelectorPredicateOperatorType:
- return [leftResult performSelector:_customSelector
withObject:rightResult];
+ case CPCustomSelectorPredicateOperatorType:
+ return [leftResult performSelector:_customSelector
withObject:rightResult];

- default:
- return NO;
- }
+ default:
+ return NO;
+ }
}

- (BOOL)evaluateWithObject:(id)object
substitutionVariables:(CPDictionary)variables
{
- var p = [self predicateWithSubstitutionVariables:variables];
- return [p evaluateWithObject:object];
+ var p = [self predicateWithSubstitutionVariables:variables];
+ return [p evaluateWithObject:object];
}

- (BOOL)evaluateWithObject:(id)object
{
- var leftValue = [_left expressionValueWithObject:object context:nil];
- var rightValue = [_right expressionValueWithObject:object context:nil];
+ var leftValue = [_left expressionValueWithObject:object context:nil];
+ var rightValue = [_right expressionValueWithObject:object context:nil];
+
+ if (_modifier == CPDirectPredicateModifier)
+ return [self _evaluateValue:leftValue rightValue:rightValue];
+ else
+ {
+ if (![leftValue respondsToSelector:@selector(objectEnumerator)])
+ [CPException raise:CPInvalidArgumentException reason:@"The
left hand side for an ALL or ANY operator must be either a CPArray or a
CPSet"];

- if(_modifier == CPDirectPredicateModifier)
- return [self _evaluateValue:leftValue rightValue:rightValue];
- else
-{
- var result = (_modifier == CPAllPredicateModifier);
- var e;
- var value;
-
- if (![leftValue respondsToSelector: @selector(objectEnumerator)])
- [CPException raise:CPInvalidArgumentException reason:@"The left hand
side for an ALL or ANY operator must be either an CPArray or an CPSet"];
-
- e = [leftValue objectEnumerator];
- while (value = [e nextObject])
- {
- var eval = [self _evaluateValue:leftValue rightValue:rightValue];
- if (eval != result)
- return eval;
- }
+ var e = [leftValue objectEnumerator],
+ result = (_modifier == CPAllPredicateModifier),
+ value;
+
+ while (value = [e nextObject])
+ {
+ var eval = [self _evaluateValue:value rightValue:rightValue];
+ if (eval != result)
+ return eval;
+ }

- return result;
- }
+ return result;
+ }
}

@end

-function _stripDiacritics(str)
+var _stripDiacritics = function _stripDiacritics(str)
{
-var buffer = "";
+ var output = "";

var diacritics =
[[192,198],[224,230],[231,231],[232,235],[236,239],[242,246],[249,252]];
var normalized = [65,97,99,101,105,111,117];

for (var indexSource = 0; indexSource < [str length]; indexSource++)
{
- var code = str.charCodeAt(indexSource);
+ var code = str.charCodeAt(indexSource);

- for (var i = 0; i < diacritics.length; i++)
- {
- var drange = diacritics[i];
-
- if(code >= drange[0] && code <= drange[1])
- {
- CPLogConsole(str.charAt(indexSource) + " ; old code = "+code+" ; new
= "+ normalized[i]);
- code = normalized[i];
- break;
- }
- }
-
- buffer += String.fromCharCode(code);
- }
-
+ for (var i = 0; i < diacritics.length; i++)
+ {
+ var drange = diacritics[i];
+
+ if (code >= drange[0] && code <= drange[1])
+ {
+ code = normalized[i];
+ break;
+ }
+ }

-return buffer;
+ output += String.fromCharCode(code);
+ }
+
+ return output;
}

-function escape_regex(str)
+var escape_regex = function escape_regex(str)
{
-
var regexchar = ['(',')','{','}','.','*','+','?','|','^','$'];
var replace = ['\(','\)','\{','\}','\.','.*','\+','.?','\|','\^','\$'];

- for (var i = 0; i < regexchar.length; i++)
- str = str.replace(regexchar[i], replace[i]);
- CPLogConsole(str);
+ for (var i = 0; i < regexchar.length; i++)
+ str = str.replace(regexchar[i], replace[i]);
+
return str;
}
-
-

Modified: branches/CPRuleEditor/CPCompoundPredicate.j
==============================================================================
--- branches/CPRuleEditor/CPCompoundPredicate.j (original)
+++ branches/CPRuleEditor/CPCompoundPredicate.j Sun Jan 25 11:36:11 2009
@@ -1,6 +1,6 @@
-import "CPPredicate.j"
-import <Foundation/CPArray.j>
-import <Foundation/CPString.j>
+@import "CPPredicate.j"
+@import <Foundation/CPArray.j>
+@import <Foundation/CPString.j>

CPNotPredicateType = 0;
CPAndPredicateType = 1;
@@ -17,7 +17,7 @@

- (id)initWithType:(CPCompoundPredicateType)type
subpredicates:(CPArray)predicates
{
- _type=type;
+ _type = type;
_predicates = predicates;
return self;
}
@@ -39,35 +39,38 @@

- (CPPredicate)predicateWithSubstitutionVariables:(CPDictionary)variables
{
- var subp = [CPArray array];
- var i;
- for (i =0; i < [subp count]; i++){
- var p = [subp objectAtIndex:i];
- var sp = [p predicateWithSubstitutionVariables:variables];
- [subp addObject:sp];
- }
- return [[CPCompoundPredicate alloc] initWithType:_type
subpredicates:subp];
+ var subp = [CPArray array],
+ i;
+
+ for (i =0; i < [subp count]; i++)
+ {
+ var p = [subp objectAtIndex:i];
+ var sp = [p predicateWithSubstitutionVariables:variables];
+ [subp addObject:sp];
+ }
+ return [[CPCompoundPredicate alloc] initWithType:_type
subpredicates:subp];
}

- (CPString)predicateFormat
{
- var result = [CPString string];
- var args = [CPArray array];
- var i,count = [_predicates count];
+ var result = [CPString string],
+ args = [CPArray array],
+ count = [_predicates count],
+ i;

- for(i = 0;i < count;i++)
+ for (i = 0;i < count;i++)
{
- var subpredicate = [_predicates objectAtIndex:i];
- var precedence = [subpredicate predicateFormat];
+ var subpredicate = [_predicates objectAtIndex:i],
+ precedence = [subpredicate predicateFormat];

- if([subpredicate isKindOfClass:[CPCompoundPredicate class]])
- if([subpredicate compoundPredicateType] != _type)
+ if ([subpredicate isKindOfClass:[CPCompoundPredicate class]] &&
+ [subpredicate compoundPredicateType] != _type)
precedence = [CPString stringWithFormat:@"(%s)",precedence];

[args addObject:precedence];
}

- switch(_type)
+ switch (_type)
{
case CPNotPredicateType:
result = result + [CPString stringWithFormat:@"NOT %s",[args
objectAtIndex:0]];
@@ -97,27 +100,28 @@

- (BOOL)evaluateWithObject:(id)object
{
- var result = NO;
- var i,count = [_predicates count];
+ var result = NO,
+ count = [_predicates count],
+ i;

- for(i = 0;i < count;i++)
+ for (i = 0;i < count;i++)
{
var predicate = [_predicates objectAtIndex:i];

- switch(_type)
+ switch (_type)
{
case CPNotPredicateType:
return ![predicate evaluateWithObject:object];

case CPAndPredicateType:
- if(i == 0)
+ if (i == 0)
result = [predicate evaluateWithObject:object];
else
result = result && [predicate evaluateWithObject:object];
break;

case CPOrPredicateType:
- if([predicate evaluateWithObject:object])
+ if ([predicate evaluateWithObject:object])
return YES;
break;
}

Modified: branches/CPRuleEditor/CPExpression.j
==============================================================================
--- branches/CPRuleEditor/CPExpression.j (original)
+++ branches/CPRuleEditor/CPExpression.j Sun Jan 25 11:36:11 2009
@@ -1,9 +1,9 @@

-import <Foundation/CPString.j>
-import <Foundation/CPArray.j>
-import <Foundation/CPKeyValueCoding.j>
-import <Foundation/CPDictionary.j>
-import <Foundation/CPCoder.j>
+@import <Foundation/CPString.j>
+@import <Foundation/CPArray.j>
+@import <Foundation/CPKeyValueCoding.j>
+@import <Foundation/CPDictionary.j>
+@import <Foundation/CPCoder.j>

CPConstantValueExpressionType = 0;
CPEvaluatedObjectExpressionType = 1;
@@ -11,6 +11,10 @@
CPKeyPathExpressionType = 3;
CPFunctionExpressionType = 4;
CPAggregateExpressionType = 5;
+CPSubqueryExpressionType = 6;
+CPUnionSetExpressionType = 7;
+CPIntersectSetExpressionType = 8;
+CPMinusSetExpressionType = 9;

@implementation CPExpression : CPObject
{
@@ -26,7 +30,6 @@
- (id)initWithCoder:(CPCoder)coder
{
// IMPLEMENTED BY CONCRETE SUBCLASSES
- return self;
}

- (void)encodeWithCoder:(CPCoder)coder
@@ -61,8 +64,8 @@

var selector = CPSelectorFromString(function_name);

- if (![expression_function respondsToSelector:selector])
- [CPException raise: CPInvalidArgumentException reason: [CPString
stringWithFormat:@"Unknown function implementation: %s", function_name]];
+ if (![expression_function respondsToSelector:selector])
+ [CPException raise: CPInvalidArgumentException reason:@"Unknown
function implementation: " + function_name];

[expression_function setSelector:selector];

@@ -71,7 +74,27 @@

+ (CPExpression)expressionForAggregate:(CPArray)collection
{
- return [[CPExpression_aggregate alloc] initWithAggregate:collection];
+ return [[CPExpression_aggregate alloc] initWithAggregate:collection];
+}
+
++ (CPExpression)expressionForSubquery:(CPExpression)expression
usingIteratorVariable:(CPString)variable predicate:(id)predicate
+{
+ return nil; // UNIMPLEMENTED
+}
+
++ (CPExpression)expressionForUnionSet:(CPExpression)left
with:(CPExpression)right
+{
+ return [[CPExpression_unionset alloc] initWithLeft:left right:right];
+}
+
++ (CPExpression)expressionForIntersectSetSet:(CPExpression)left
with:(CPExpression)right
+{
+ return [[CPExpression_intersectset alloc] initWithLeft:left
right:right];
+}
+
++ (CPExpression)expressionForMinusSet:(CPExpression)left
with:(CPExpression)right
+{
+ return [[CPExpression_minusset alloc] initWithLeft:left right:right];
}

- (int)expressionType
@@ -129,9 +152,12 @@

@end

-import "CPExpression_aggregate.j"
-import "CPExpression_constant.j"
-import "CPExpression_self.j"
-import "CPExpression_variable.j"
-import "CPExpression_keypath.j"
-import "CPExpression_function.j"
+@import "CPExpression_constant.j"
+@import "CPExpression_self.j"
+@import "CPExpression_variable.j"
+@import "CPExpression_keypath.j"
+@import "CPExpression_function.j"
+@import "CPExpression_aggregate.j"
+@import "CPExpression_unionset.j"
+@import "CPExpression_intersectset.j"
+@import "CPExpression_minusset.j"

Modified: branches/CPRuleEditor/CPExpression_aggregate.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_aggregate.j (original)
+++ branches/CPRuleEditor/CPExpression_aggregate.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@

-import "CPExpression.j"
-import <Foundation/CPArray.j>
-import <Foundation/CPString.j>
+@import "CPExpression.j"
+@import <Foundation/CPArray.j>
+@import <Foundation/CPString.j>

@implementation CPExpression_aggregate : CPExpression
{
@@ -28,7 +28,7 @@

- (void)encodeWithCoder:(CPCoder)coder
{
- [coder encodeObject:_aggregate forKey:@"CPExpressionAggregate"]; //
subexpressions must be NSCoding compliant.
+ [coder encodeObject:_aggregate forKey:@"CPExpressionAggregate"]; //
subexpressions must be CPCoding compliant.
}

- (id)collection
@@ -38,55 +38,56 @@

- (CPExpression)rightExpression
{
- if([_aggregate count] > 0)
- return [_aggregate lastObject];
+ if ([_aggregate count] > 0)
+ return [_aggregate lastObject];

- return nil;
+ return nil;
}

- (CPExpression)leftExpression
{
- if([_aggregate count] > 0)
- return [_aggregate objectAtIndex:0];
+ if ([_aggregate count] > 0)
+ return [_aggregate objectAtIndex:0];

- return nil;
+ return nil;
}

- (id)expressionValueWithObject:(id)object context:(CPDictionary)context
{
- var eval_array = [CPArray array];
+ var eval_array = [CPArray array],
+ collection = [_aggregate objectEnumerator],
+ exp;
+
+ while (exp = [collection nextObject])
+ {
+ var eval = [exp expressionValueWithObject:object context:context];
+ if (eval != nil)[eval_array addObject:eval];
+ }

- var collection = [_aggregate objectEnumerator];
- var exp;
- while (exp = [collection nextObject]) {
- var eval = [exp expressionValueWithObject:object context:context];
- if(eval != nil)[eval_array addObject:eval];
- }
-
- return eval_array;
+ return eval_array;
}

- (CPString)description
{
var i,
- count = [_aggregate count];
-
- var result = "{";
+ count = [_aggregate count],
+ result = "{";

- for(i = 0;i < count;i++)
+ for (i = 0;i < count;i++)
result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate
objectAtIndex:i] description], (i + 1 < count) ? @", " : @""];

result = result + "}";
+
return result;
}

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- var subst_array = [CPArray array];
- var i,
- count = [_aggregate count];
+ var subst_array = [CPArray array],
+ count = [_aggregate count],
+ i;

- for(i = 0; i < count; i++)
+ for (i = 0; i < count; i++)
[subst_array addObject:[[_aggregate objectAtIndex:i]
_expressionWithSubstitutionVariables:variables]];

return [CPExpression expressionForAggregate:subst_array];

Modified: branches/CPRuleEditor/CPExpression_assignment.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_assignment.j (original)
+++ branches/CPRuleEditor/CPExpression_assignment.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@

-import "CPExpression.j"
-import "CPExpression_operator.j"
-import <Foundation/CPString.j>
+@import "CPExpression.j"
+@import "CPExpression_operator.j"
+@import <Foundation/CPString.j>


@implementation CPExpression_assignment: CPExpression
@@ -14,6 +14,7 @@
{
_variable = variable;
_expression = expression;
+
return self;
}


Modified: branches/CPRuleEditor/CPExpression_constant.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_constant.j (original)
+++ branches/CPRuleEditor/CPExpression_constant.j Sun Jan 25 11:36:11 2009
@@ -1,6 +1,6 @@

-import "CPExpression.j"
-import <Foundation/CPDictionary.j>
+@import "CPExpression.j"
+@import <Foundation/CPDictionary.j>

@implementation CPExpression_constant : CPExpression
{
@@ -22,8 +22,8 @@

- (void)encodeWithCoder:(CPCoder)coder
{
-if([_value respondsToSelector:@selector(encodeOject:forKey:)])
- [coder encodeObject:_value forKey:@"CPExpressionConstantValue"];
+ if ([_value respondsToSelector:@selector(encodeOject:forKey:)])
+ [coder encodeObject:_value forKey:@"CPExpressionConstantValue"];
}

- (id)constantValue
@@ -38,12 +38,12 @@

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- return self;
+ return self;
}

- (CPString)description
{
- if([_value isKindOfClass:[CPString class]])
+ if ([_value isKindOfClass:[CPString class]])
return [CPString stringWithFormat:@"\"%s\"",_value];
else
return [_value description];

Modified: branches/CPRuleEditor/CPExpression_function.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_function.j (original)
+++ branches/CPRuleEditor/CPExpression_function.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@
-import "CPExpression.j"
-import <Foundation/CPString.j>
-import <Foundation/CPArray.j>
-import <Foundation/CPDictionary.j>
+@import "CPExpression.j"
+@import <Foundation/CPString.j>
+@import <Foundation/CPArray.j>
+@import <Foundation/CPDictionary.j>

@implementation CPExpression_function : CPExpression
{
@@ -9,16 +9,23 @@
SEL _selector;
CPArray _arguments;
int _argc;
+ CPInvocation _invocation;
}

- (void)setSelector:(SEL)selector
{
_selector = selector;
+ /*
+ var signature = [CPExpression_function
methodSignatureForSelector:selector];
+ _invocation = [CPInvocation invocationWithMethodSignature:signature];
+ [_invocation setSelector:_selector];
+ [_invocation setTarget:self];
+ */
}

- (id)initWithName:(CPString)name arguments:(CPArray)arguments
{
- [super initWithExpressionType:CPFunctionExpressionType];
+ [super initWithExpressionType:CPFunctionExpressionType];

_name = name;
_arguments = arguments;
@@ -28,8 +35,8 @@

- (id)initWithCoder:(CPCoder)coder
{
- var name = [coder decodeObjectForKey:@"CPExpressionFunctionName"];
- var arguments = [coder
decodeObjectForKey:@"CPExpressionFunctionArguments"];
+ var name = [coder decodeObjectForKey:@"CPExpressionFunctionName"],
+ arguments = [coder
decodeObjectForKey:@"CPExpressionFunctionArguments"];

return [self initWithName:name arguments:arguments];
}
@@ -52,43 +59,43 @@

- (id)expressionValueWithObject:(id)object context:(CPDictionary)context
{
- var subst_args = [CPArray array];
- var i;
+ var eval_args = [CPArray array],
+ i;

for (i = 0; i < _argc; i++)
- [subst_args addObject: [[_arguments objectAtIndex: i]
expressionValueWithObject:object context:context]];
-
-
- return [self performSelector: _selector withObject: subst_args];
+ {
+ var arg = [[_arguments objectAtIndex:i]
expressionValueWithObject:object context:context];
+ if(arg != nil) [eval_args addObject:arg];
+ }

+ return [self performSelector:_selector withObject:eval_args];
}

- (CPString)description
-{
- var i;
-
- var result = [CPString stringWithFormat:@"%s(", _name];
+{
+ var result = [CPString stringWithFormat:@"%s(", _name],
+ i;

- for(i = 0; i < _argc; i++){
+ for (i = 0; i < _argc; i++){
result = result + [CPString stringWithFormat:@"%s%s", [_arguments
objectAtIndex:i] , (i+1<_argc) ? ", " : ""];
}

result = result + ")";

- return result;
+ return result ;
}

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- var array = [CPArray array];
- var i;
+ var array = [CPArray array],
+ i;

- for(i = 0; i < _argc; i++)
+ for (i = 0; i < _argc; i++)
[array addObject:[[_arguments objectAtIndex:i]
_expressionWithSubstitutionVariables:variables]];

- return [CPExpression expressionForFunction:_name arguments:array];
-
+ return [CPExpression expressionForFunction:_name arguments:array];
}
+
/*
10.5 documentation for expressionForFunction:arguments:

@@ -113,8 +120,11 @@

- (CPNumber)average:(CPArray)parameters
{
- var i;
- var sum = 0.0;
+ if(_argc < 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var i,
+ sum = 0.0;

for (i = 0; i < _argc; i++)
{
@@ -125,8 +135,11 @@

- (CPNumber)sum:(CPArray)parameters
{
- var i;
- var sum = 0.0;
+ if(_argc < 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var i,
+ sum = 0.0;

for (i = 0; i < _argc; i++)
{
@@ -137,17 +150,20 @@

- (CPNumber)count:(CPArray)parameters
{
- if (_argc != 1) // raise
- return CPNotFound;
-
+ if(_argc < 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
return [CPNumber numberWithUnsignedInt: [[parameters objectAtIndex: 0]
count]];
}

- (CPNumber)min:(CPArray)parameters
{
- var i;
- var min = 0.0;
- var cur;
+ if(_argc < 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var i,
+ min = 0.0,
+ cur;

if (_argc > 0)
{
@@ -167,114 +183,163 @@

- (CPNumber)max:(CPArray)parameters
{
- var i;
- var max = 0.0;
- var cur;
+ if(_argc < 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var i,
+ max = 0.0,
+ cur;

if (_argc > 0)
- {
max = [[parameters objectAtIndex: 0] doubleValue];
- }
-
+
for (i = 1; i < _argc; i++)
{
cur = [[parameters objectAtIndex: i] doubleValue];
if (max < cur)
- {
- max = cur;
- }
- }
+ max = cur;
+ }
return [CPNumber numberWithDouble: max];
}
-/*
-- (CPNumber)median:(CPArray)parameters
-{
-}
-- (CPNumber)mode:(CPArray)parameters
-{
-}
-- (CPNumber)stddev:(CPArray)parameters
-{
-}
+
- (CPNumber)add:to:(CPArray)parameters
{
- var left = [parameters objectAtIndex: 0];
- var right = [parameters objectAtIndex: 1];
+ if(_argc != 2)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var left = [parameters objectAtIndex: 0],
+ right = [parameters objectAtIndex: 1];

return [CPNumber numberWithDouble: [left doubleValue] + [right
doubleValue]];
}

- (CPNumber)from:subtract:(CPArray)parameters
{
- var left = [parameters objectAtIndex: 0];
- var right = [parameters objectAtIndex: 1];
+ if(_argc != 2)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var left = [parameters objectAtIndex: 0],
+ right = [parameters objectAtIndex: 1];

return [CPNumber numberWithDouble: [left doubleValue] - [right
doubleValue]];
}

- (CPNumber)multiply:by:(CPArray)parameters
{
- var left = [parameters objectAtIndex: 0];
- var right = [parameters objectAtIndex: 1];
+ if(_argc != 2)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];

+ var left = [parameters objectAtIndex: 0],
+ right = [parameters objectAtIndex: 1];
+
return [CPNumber numberWithDouble: [left doubleValue] * [right
doubleValue]];
-
}

- (CPNumber)divide:by:(CPArray)parameters
{
- var left = [parameters objectAtIndex: 0];
- var right = [parameters objectAtIndex: 1];
+ if(_argc != 2)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var left = [parameters objectAtIndex: 0],
+ right = [parameters objectAtIndex: 1];

return [CPNumber numberWithDouble: [left doubleValue] / [right
doubleValue]];
}

-- (CPNumber)modulus:by:(CPArray)parameters
-{
-}
- (CPNumber)sqrt:(CPArray)parameters
{
- var num = [[parameters objectAtIndex: 0] doubleValue];
+ if(_argc != 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];

- return [CPNumber numberWithDouble: num * num];
+ var num = [[parameters objectAtIndex: 0] doubleValue];

+ return [CPNumber numberWithDouble: Math.sqrt(num)];
}

-- (CPNumber)log:(CPArray)parameters
+- (CPNumber)abs:(CPArray)parameters
{
+ if(_argc != 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var num = [[parameters objectAtIndex: 0] doubleValue];
+
+ return [CPNumber numberWithDouble:Math.abs(num)];
}
-- (CPNumber)ln:(CPArray)parameters
+
+- (CPDate)now
{
+ return [CPDate date];
}
-- (CPNumber)raise:to:(CPArray)parameters
+
+- (CPNumber)ln:(CPArray)parameters
{
+ if(_argc != 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var num = [[parameters objectAtIndex: 0] doubleValue];
+
+ return [CPNumber numberWithDouble:Math.log(num)];
}
+
- (CPNumber)exp:(CPArray)parameters
{
+ if(_argc != 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var num = [[parameters objectAtIndex: 0] doubleValue];
+
+ return [CPNumber numberWithDouble:Math.exp(num)];
}
+
- (CPNumber)ceiling:(CPArray)parameters
{
-}
-- (CPNumber)abs:(CPArray)parameters
-{
+ if(_argc != 1)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
var num = [[parameters objectAtIndex: 0] doubleValue];
- var abs = (num > 0) ? num : (-1) * num;

- return [NSNumber numberWithDouble:abs];
+ return [CPNumber numberWithDouble:Math.ceil(num)];
}

-- (CPNumber)trunc:(CPArray)parameters
+- (CPNumber)random
{
+ return [CPNumber numberWithDouble:Math.random()];
}
-- (CPNumber)random
+
+- (CPNumber)modulus:by:(CPArray)parameters
{
+ if(_argc != 2)
+ [CPException raise:CPInvalidArgumentException reason:"Invalid number
of parameters"];
+
+ var left = [parameters objectAtIndex: 0],
+ right = [parameters objectAtIndex: 1];
+
+ return [CPNumber numberWithInt:([left intValue] % [right intValue])];
}
-- (CPNumber)random:(CPArray)parameters
+
+
+/*
+- (CPNumber)median:(CPArray)parameters
+{
+}
+- (CPNumber)mode:(CPArray)parameters
{
}
-- (CPNumber)now
+- (CPNumber)stddev:(CPArray)parameters
+{
+}
+- (CPNumber)log:(CPArray)parameters
+{
+}
+- (CPNumber)raise:to:(CPArray)parameters
+{
+}
+
+- (CPNumber)trunc:(CPArray)parameters
+{
+}
+- (CPNumber)random:(CPArray)parameters
{
- return [CPDate date];
}

// These functions are generated when parsing

Added: branches/CPRuleEditor/CPExpression_intersectset.j
==============================================================================
--- (empty file)
+++ branches/CPRuleEditor/CPExpression_intersectset.j Sun Jan 25 11:36:11
2009
@@ -0,0 +1,48 @@
+@import "CPExpression.j"
+
+@implementation CPExpression_intersectset : CPExpression
+{
+ CPExpression _left;
+ CPExpression _right;
+}
+
+- (id)initWithLeft:(CPExpression)left right:(CPExpression)right
+{
+ [super initWithExpressionType:CPIntersectSetExpressionType];
+ _left = left ;
+ _right = right;
+
+ return self;
+}
+
+- (id)expressionValueWithObject:object context:(CPDictionary)context
+{
+ var right = [_right expressionValueWithObject:object context:context];
+ if (![right respondsToSelector: @selector(objectEnumerator)])
+ [CPException raise:CPInvalidArgumentException reason:@"The right
expression for a CPIntersectSetExpressionType expression must be either a
CPArray, CPDictionary or CPSet"];
+
+ var left = [_left expressionValueWithObject:object context:context];
+ if (![left isKindOfClass:[CPSet set]])
+ [CPException raise:CPInvalidArgumentException reason:@"The left
expression for a CPIntersectSetExpressionType expression must a CPSet"];
+
+ var set = [CPSet setWithSet:left],
+ e = [right objectEnumerator],
+ item;
+
+ while (item = [e nextObject])
+ if([left containsObject:item])[set addObject:item];
+
+ return [CPExpression expressionForConstantValue:set];
+}
+
+- (CPExpression )_expressionWithSubstitutionVariables:(CPDictionary
)variables
+{
+ return self;
+}
+
+- (CPString )description
+{
+ return [_left description] +" INTERSECT "+ [_right description];
+}
+
+@end

Modified: branches/CPRuleEditor/CPExpression_keypath.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_keypath.j (original)
+++ branches/CPRuleEditor/CPExpression_keypath.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@

-import "CPExpression.j"
-import <Foundation/CPString.j>
-import <Foundation/CPKeyValueCoding.j>
+@import "CPExpression.j"
+@import <Foundation/CPString.j>
+@import <Foundation/CPKeyValueCoding.j>

@implementation CPExpression_keypath : CPExpression
{
@@ -38,7 +38,7 @@

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- return self;
+ return self;
}

- (CPString)description

Added: branches/CPRuleEditor/CPExpression_minusset.j
==============================================================================
--- (empty file)
+++ branches/CPRuleEditor/CPExpression_minusset.j Sun Jan 25 11:36:11 2009
@@ -0,0 +1,44 @@
+@import "CPExpression.j"
+
+@implementation CPExpression_minusset : CPExpression
+
+- (id)initWithLeft:(CPExpression)left right:(CPExpression)right
+{
+ [super initWithExpressionType:CPMinusSetExpressionType];
+ _left = left ;
+ _right = right;
+
+ return self;
+}
+
+-(id)expressionValueWithObject:object context:(CPDictionary)context
+{
+ var right = [_right expressionValueWithObject:object context:context];
+ if (![right respondsToSelector: @selector(objectEnumerator)])
+ [CPException raise:CPInvalidArgumentException reason:@"The right
expression for a CPIntersectSetExpressionType expression must be either a
CPArray, CPDictionary or CPSet"];
+
+ var left = [_left expressionValueWithObject:object context:context];
+ if (![left isKindOfClass:[CPSet set]])
+ [CPException raise:CPInvalidArgumentException reason:@"The left
expression for a CPIntersectSetExpressionType expression must a CPSet"];
+
+ var set = [CPSet setWithSet:left],
+ e = [right objectEnumerator],
+ item;
+
+ while (item = [e nextObject])
+ [set removeObject:item];
+
+ return [CPExpression expressionForConstantValue:set];
+}
+
+- (CPExpression )_expressionWithSubstitutionVariables:(CPDictionary
)variables
+{
+ return self;
+}
+
+- (CPString )description
+{
+ return [_left description] +" MINUS "+ [_right description];
+}
+
+@end

Modified: branches/CPRuleEditor/CPExpression_operator.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_operator.j (original)
+++ branches/CPRuleEditor/CPExpression_operator.j Sun Jan 25 11:36:11 2009
@@ -1,21 +1,21 @@

-import "CPExpression.j"
-import <Foundation/CPArray.j>
-import <Foundation/CPString.j>
-import <Foundation/CPDictionary.j>
-
- var CPExpressionOperatorNegate = "CPExpressionOperatorNegate";
- var CPExpressionOperatorAdd = "CPExpressionOperatorAdd";
- var CPExpressionOperatorSubtract = "CPExpressionOperatorSubtract";
- var CPExpressionOperatorMultiply = "CPExpressionOperatorMultiply";
- var CPExpressionOperatorDivide = "CPExpressionOperatorDivide";
- var CPExpressionOperatorExp = "CPExpressionOperatorExp";
- var CPExpressionOperatorAssign = "CPExpressionOperatorAssign";
- var CPExpressionOperatorKeypath = "CPExpressionOperatorKeypath";
- var CPExpressionOperatorIndex = "CPExpressionOperatorIndex";
- var CPExpressionOperatorIndexFirst = "CPExpressionOperatorIndexFirst";
- var CPExpressionOperatorIndexLast = "CPExpressionOperatorIndexLast";
- var CPExpressionOperatorIndexSize = "CPExpressionOperatorIndexSize";
+@import "CPExpression.j"
+@import <Foundation/CPArray.j>
+@import <Foundation/CPString.j>
+@import <Foundation/CPDictionary.j>
+
+var CPExpressionOperatorNegate = "CPExpressionOperatorNegate";
+var CPExpressionOperatorAdd = "CPExpressionOperatorAdd";
+var CPExpressionOperatorSubtract = "CPExpressionOperatorSubtract";
+var CPExpressionOperatorMultiply = "CPExpressionOperatorMultiply";
+var CPExpressionOperatorDivide = "CPExpressionOperatorDivide";
+var CPExpressionOperatorExp = "CPExpressionOperatorExp";
+var CPExpressionOperatorAssign = "CPExpressionOperatorAssign";
+var CPExpressionOperatorKeypath = "CPExpressionOperatorKeypath";
+var CPExpressionOperatorIndex = "CPExpressionOperatorIndex";
+var CPExpressionOperatorIndexFirst = "CPExpressionOperatorIndexFirst";
+var CPExpressionOperatorIndexLast = "CPExpressionOperatorIndexLast";
+var CPExpressionOperatorIndexSize = "CPExpressionOperatorIndexSize";

@implementation CPExpression_operator : CPExpression
{
@@ -42,23 +42,23 @@

- (CPString)description
{
- var result = [CPString string];
- var args = [CPArray array];
- var i,
- count = [_arguments count];
+ var result = [CPString string],
+ args = [CPArray array],
+ count = [_arguments count],
+ i;

- for(i = 0; i < count; i++)
+ for (i = 0; i < count; i++)
{
var check = [_arguments objectAtIndex:i];
var precedence = [check description];

if ([check isKindOfClass:[CPExpression_operator class]])
- precedence = [CPString stringWithFormat:@"(%@)", precedence];
+ precedence = [CPString stringWithFormat:@"(%@)", precedence];

[args addObject:precedence];
}

- switch(_operator)
+ switch (_operator)
{
case CPExpressionOperatorNegate : result = result + [CPString
stringWithFormat:@"-%@", [args objectAtIndex:0]];
break;
@@ -102,12 +102,12 @@

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- var array = [CPArray array];
- var i,
- count = [_arguments count];
+ var array = [CPArray array],
+ count = [_arguments count],
+ i;

- for(i = 0; i < count; i++)
- [array addObject:[[_arguments objectAtIndex:i]
_expressionWithSubstitutionVariables:variables]];
+ for (i = 0; i < count; i++)
+ [array addObject:[[_arguments objectAtIndex:i]
_expressionWithSubstitutionVariables:variables]];

return [CPExpression_operator expressionForOperator:_operator
arguments:array];
}

Modified: branches/CPRuleEditor/CPExpression_self.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_self.j (original)
+++ branches/CPRuleEditor/CPExpression_self.j Sun Jan 25 11:36:11 2009
@@ -1,15 +1,15 @@

-import "CPExpression.j"
-import <Foundation/CPString.j>
-import <Foundation/CPDictionary.j>
-import <Foundation/CPCoder.j>
+@import "CPExpression.j"
+@import <Foundation/CPString.j>
+@import <Foundation/CPDictionary.j>
+@import <Foundation/CPCoder.j>

@implementation CPExpression_self : CPExpression{}

- (id)init
{
- [super initWithExpressionType:CPEvaluatedObjectExpressionType];
- return self;
+ [super initWithExpressionType:CPEvaluatedObjectExpressionType];
+ return self;
}

- (id)initWithCoder:(CPCoder)coder
@@ -20,19 +20,20 @@
- (void)encodeWithCoder:(CPCoder)coder
{
}
+
- (id)expressionValueWithObject:object context:(CPDictionary)context
{
- return object;
+ return object;
}

-
(CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
- return self;
+ return self;
}

- (CPString)description
{
- return @"SELF";
+ return @"SELF";
}

@end

Added: branches/CPRuleEditor/CPExpression_unionset.j
==============================================================================
--- (empty file)
+++ branches/CPRuleEditor/CPExpression_unionset.j Sun Jan 25 11:36:11 2009
@@ -0,0 +1,44 @@
+@import "CPExpression.j"
+
+@implementation CPExpression_unionset
+
+- (id)initWithLeft:(CPExpression)left right:(CPExpression)right
+{
+ [super initWithExpressionType:CPUnionSetExpressionType];
+ _left = left;
+ _right = right;
+
+ return self;
+}
+
+-(id)expressionValueWithObject:object context:(CPDictionary )context
+{
+ var right = [_right expressionValueWithObject:object context:context];
+ if (![right respondsToSelector: @selector(objectEnumerator)])
+ [CPException raise:CPInvalidArgumentException reason:@"The right
expression for a CPIntersectSetExpressionType expression must be either a
CPArray, CPDictionary or CPSet"];
+
+ var left = [_left expressionValueWithObject:object context:context];
+ if (![left isKindOfClass:[CPSet set]])
+ [CPException raise:CPInvalidArgumentException reason:@"The left
expression for a CPIntersectSetExpressionType expression must a CPSet"];
+
+ var unionset = [CPSet setWithSet:left],
+ e = [right objectEnumerator],
+ item;
+
+ while (item = [e nextObject])
+ [unionset addObject:item];
+
+ return [CPExpression expressionForConstantValue:unionset];
+}
+
+- (CPExpression )_expressionWithSubstitutionVariables:(CPDictionary
)variables
+{
+ return self;
+}
+
+- (CPString )description
+{
+ return [_left description] +" UNION "+ [_right description];
+}
+
+@end

Modified: branches/CPRuleEditor/CPExpression_variable.j
==============================================================================
--- branches/CPRuleEditor/CPExpression_variable.j (original)
+++ branches/CPRuleEditor/CPExpression_variable.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@

-import "CPExpression.j"
-import <Foundation/CPString.j>
-import <Foundation/CPDictionary.j>
+@import "CPExpression.j"
+@import <Foundation/CPString.j>
+@import <Foundation/CPDictionary.j>

@implementation CPExpression_variable : CPExpression
{
@@ -33,7 +33,7 @@

- (id)expressionValueWithObject:object context:(CPDictionary)context
{
- return [context objectForKey: _variable];
+ return [context objectForKey:_variable];
}

- (CPString)description
@@ -46,7 +46,7 @@
var aconstant = [variables objectForKey:_variable];

if (aconstant != nil)
- return [CPExpression expressionForConstantValue:aconstant];
+ return [CPExpression expressionForConstantValue:aconstant];

return self;
}

Modified: branches/CPRuleEditor/CPPredicate.j
==============================================================================
--- branches/CPRuleEditor/CPPredicate.j (original)
+++ branches/CPRuleEditor/CPPredicate.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@

-import <Foundation/CPValue.j>
-import <Foundation/CPArray.j>
-import <Foundation/CPNull.j>
+@import <Foundation/CPValue.j>
+@import <Foundation/CPArray.j>
+@import <Foundation/CPNull.j>

@implementation CPPredicate : CPObject
{
@@ -35,16 +35,19 @@
+ (CPPredicate) predicateWithFormat: (CPString) format, ...
{
// UNIMPLEMENTED
+ return nil;
}

+ (CPPredicate) predicateWithFormat: (CPString)format argumentArray:
(CPArray)args
{
// UNIMPLEMENTED
+ return nil;
}

+ (CPPredicate) predicateWithFormat: (CPString)format arguments:
(va_list)args
{
// UNIMPLEMENTED
+ return nil;
}

@end
@@ -76,38 +79,41 @@

- (CPArray)filteredArrayUsingPredicate:(CPPredicate)predicate
{
- var i,count = [self count];
- var result = [CPArray array];
-
- for(i = 0;i < count;i++){
- var object = [self objectAtIndex:i];
-
- if([predicate evaluateWithObject:object])
- [result addObject:object];
- }
+ var count = [self count],
+ result = [CPArray array],
+ i;
+
+ for (i = 0;i < count;i++)
+ {
+ var object = [self objectAtIndex:i];
+
+ if ([predicate evaluateWithObject:object])
+ [result addObject:object];
+ }

- return result;
+ return result;
}

- (void)filterUsingPredicate:(CPPredicate)predicate
{
- var count = [self count];
-
- while(--count >= 0){
- var check=[self objectAtIndex:count];
+ var count = [self count];

- if(![predicate evaluateWithObject:check])
- [self removeObjectAtIndex:count];
- }
+ while (--count >= 0)
+ {
+ var check = [self objectAtIndex:count];
+
+ if (![predicate evaluateWithObject:check])
+ [self removeObjectAtIndex:count];
+ }
}

@end


-import "CPCompoundPredicate.j"
-import "CPComparisonPredicate.j"
-import "CPExpression.j"
-
-import "CPExpression_operator.j"
-import "CPExpression_aggregate.j"
-import "CPExpression_assignment.j"
+@import "CPCompoundPredicate.j"
+@import "CPComparisonPredicate.j"
+@import "CPExpression.j"
+
+@import "CPExpression_operator.j"
+@import "CPExpression_aggregate.j"
+@import "CPExpression_assignment.j"

Modified: branches/CPRuleEditor/CPPredicateTest.j
==============================================================================
--- branches/CPRuleEditor/CPPredicateTest.j (original)
+++ branches/CPRuleEditor/CPPredicateTest.j Sun Jan 25 11:36:11 2009
@@ -1,10 +1,39 @@
-import <Foundation/Foundation.j>
-import "CPPredicate.j"
+@import <Foundation/Foundation.j>
+@import "CPPredicate.j"

@implementation CPPredicateTest : OJTestCase
+{
+ CPDictionary dict;
+}
+
+- (id)init
+{
+ self = [super init];
+ if (self != nil)
+ {
+ var d,
+ objects;
+
+ dict = [[CPDictionary alloc] init];
+ [dict setObject: @"A Title" forKey:@"title"];
+
+ var keys = [CPArray
arrayWithObjects:@"Name",@"Age",@"Children",nil];
+ objects = [CPArray arrayWithObjects:@"John",[CPNumber
numberWithInt:34],[CPArray arrayWithObjects:@"Kid1", @"Kid2", nil],nil];
+
+ d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
+ [dict setObject:d forKey:@"Record1"];
+
+ objects = [CPArray arrayWithObjects:@"Mary",[CPNumber
numberWithInt:30],[CPArray arrayWithObjects:@"Kid1", @"Girl1", nil],nil];

--(void)testExpressionsInitialization{
+ d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
+ [dict setObject:d forKey:@"Record2"];
+
+ }
+ return self;
+}

+- (void)testExpressionsInit
+{
var expression_keypath = [CPExpression expressionForKeyPath:@"name"];
[self assertNotNull:expression_keypath message:"Expression should not
be nil"];

@@ -14,7 +43,7 @@
var expression_num = [CPExpression
expressionForConstantValue:[CPNumber numberWithInt:1]];
[self assertNotNull:expression_num message:"Expression should not be
nil"];

- var expression_collection = [CPExpression
expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d",nil]];
+ var expression_collection = [CPExpression
expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d",nil]];
[self assertNotNull:expression_collection message:"Expression should
not be nil"];

var expression_var = [CPExpression expressionForVariable:@"variable"];
@@ -29,8 +58,8 @@
var expression_aggregate = [CPExpression
expressionForAggregate:[CPArray
arrayWithObjects:expression_str,expression_num,expression_function,nil]];
[self assertNotNull:expression_aggregate message:"Expression should
not be nil"];

-// var expression_subquery = [CPExpression
expressionForSubquery:expression_collection usingIteratorVariable:@"self"
predicate:[CPPredicate predicateWithValue:YES]];
-// [self assertNotNull:expression_subquery message:"Expression should
not be nil"];
+ var expression_subquery = [CPExpression
expressionForSubquery:expression_collection usingIteratorVariable:@"self"
predicate:[CPPredicate predicateWithValue:YES]];
+ [self assertNotNull:expression_subquery message:"Expression should not
be nil"];

var set = [CPSet setWithObjects:@"a",@"b",@"d",nil];
var array = [CPArray arrayWithObjects:@"a",@"b",@"d",nil];
@@ -43,40 +72,114 @@

var expression_minusset = [CPExpression expressionForMinusSet:set
with:array];
[self assertNotNull:expression_minusset message:"Expression should not
be nil"];
+}
+
+-(void)testFunctionExpression
+{
+ var function_exp = [CPExpression expressionForFunction:"sum:"
arguments:[CPArray arrayWithObjects:[CPExpression
expressionForConstantValue:1],[CPExpression
expressionForConstantValue:2],[CPExpression
expressionForConstantValue:3],nil]];

+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:function_exp rightExpression:[CPExpression
expressionForConstantValue:3] modifier:CPDirectPredicateModifier
type:CPGreaterThanPredicateOperatorType options:0];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:[pred
description] + " should be true"];
}

-- (void)testOptions
+-(void)testVariableExpression
{
- var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"]
rightExpression:[CPExpression expressionForConstantValue:@"aà"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
+ var variable_exp = [CPExpression expressionForVariable:@"variable"];
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"]
rightExpression:variable_exp modifier:CPDirectPredicateModifier
type:CPGreaterThanPredicateOperatorType options:0];

- [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
-
- pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"aB"]
rightExpression:[CPExpression expressionForConstantValue:@"Ab"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:1];
+ var variables = [CPDictionary dictionaryWithObject:20
forKey:@"variable"];
+
+ [self assertTrue:[pred evaluateWithObject:dict
substitutionVariables:variables] message:"'"+ [pred description] + "'
should be true"];
+}

+- (void)testOptions
+{
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"]
rightExpression:[CPExpression expressionForConstantValue:@"aà"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
[self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
-

+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"aB"]
rightExpression:[CPExpression expressionForConstantValue:@"Ab"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:1];
+ [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
}

--(void)testOperators{
- var predicate_match = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:"Farenight
451"] rightExpression:[CPExpression expressionForConstantValue:"(F|
g)\\w+\\s\\d{3}"] modifier:CPDirectPredicateModifier
type:CPMatchesPredicateOperatorType options:2];
+-(void)testModifier
+{
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression
expressionForKeyPath:@"Record2.Children"] rightExpression:[CPExpression
expressionForConstantValue:@"Gi"] modifier:CPAnyPredicateModifier
type:CPBeginsWithPredicateOperatorType options:0];
+ [self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred
description] + "' should be true"];
+
+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression
expressionForKeyPath:@"Record1.Children"] rightExpression:[CPExpression
expressionForConstantValue:@"Kid"] modifier:CPAllPredicateModifier
type:CPBeginsWithPredicateOperatorType options:0];
+ [self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred
description] + "' should be true"];
+}

- [self assertTrue:[predicate_match evaluateWithObject:nil] message:"/"+
[predicate_match description] + "/ should be true"];
+-(void)testOperators
+{
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:"Farenight
451"] rightExpression:[CPExpression expressionForConstantValue:"(F|
g)\\w+\\s\\d{3}"] modifier:CPDirectPredicateModifier
type:CPMatchesPredicateOperatorType options:2];
+ [self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred
description] + "' should be true"];

pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"b"]
rightExpression:[CPExpression expressionForConstantValue:@"[a-c]"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:1];
-
- [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
-
+ [self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred
description] + "' should be true"];

pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"Aa"]
rightExpression:[CPExpression expressionForConstantValue:@"ab"]
modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType
options:0];
-
- [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
+ [self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred
description] + "' should be true"];

pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"Ac"]
rightExpression:[CPExpression expressionForConstantValue:@"ab"]
modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType
options:2];
+ [self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred
description] + "' should be true"];
+
+}
+
+-(void)testCompoundPredicate
+{
+ var predOne = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Name"]
rightExpression:[CPExpression expressionForConstantValue:@"J"]
modifier:CPDirectPredicateModifier type:CPBeginsWithPredicateOperatorType
options:0];
+
+ var predTwo = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"]
rightExpression:[CPExpression expressionForConstantValue:[CPNumber
numberWithInt:40]] modifier:CPDirectPredicateModifier
type:CPLessThanPredicateOperatorType options:0];
+
+ var pred = [[CPCompoundPredicate alloc]
initWithType:CPAndPredicateType subpredicates:[CPArray
arrayWithObjects:predOne,predTwo,nil]];
+
+ [self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred
description] + "' should be true"];
+}
+
+-(void)testPredicateParsing
+{
+ var predicate;
+// TEST STRING
+ predicate = [CPPredicate predicateWithFormat: @"%K == %@",
@"Record1.Name", @"John"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"%K MATCHES[c] %@",
@"Record1.Name", @"john"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"%K BEGINSWITH %@",
@"Record1.Name", @"Jo"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"(%K == %@) AND (%K
== %@)", @"Record1.Name", @"John", @"Record2.Name", @"Mary"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+// TEST integer
+ predicate = [CPPredicate predicateWithFormat: @"%K == %d",
@"Record1.Age", 34];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"%K < %d",
@"Record1.Age", 40];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"%K BETWEEN %@",
@"Record1.Age", [CPArray arrayWithObjects:[CPNumber numberWithInt: 20],
[CPNumber numberWithInt:40], nil]];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"(%K == %d) OR (%K
== %d)", @"Record1.Age", 34, @"Record2.Age", 34];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+// TEST float
+ predicate = [CPPredicate predicateWithFormat: @"%K < %f",
@"Record1.Age", 40.5];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
+
+ predicate = [CPPredicate predicateWithFormat: @"%f > %K", 40.5,
@"Record1.Age"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];

- [self assertTrue:[pred evaluateWithObject:nil] message:" should be
true"];
+// TEST Aggregate
+ predicate = [CPPredicate predicateWithFormat: @"%@ IN %K", @"Kid1",
@"Record1.Children"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];

+ predicate = [CPPredicate predicateWithFormat: @"Any %K == %@",
@"Record2.Children", @"Girl1"];
+ [self assertTrue:[predicate evaluateWithObject:dict]
message:[predicate description] + " should be true"];
}

@end

Modified: branches/CPRuleEditor/CPRuleEditor.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditor.j (original)
+++ branches/CPRuleEditor/CPRuleEditor.j Sun Jan 25 11:36:11 2009
@@ -5,11 +5,12 @@



-import "CPPredicate.j"
-import "_CPRuleEditorCache.j"
-import "_CPRuleEditorViewSliceHolder.j"
-import "_CPRuleEditorViewUnboundRowHolder.j"
-import "CPRuleEditorViewSliceDropSeparator.j"
+@import "CPPredicate.j"
+@import "_CPRuleEditorCache.j"
+@import "_CPRuleEditorViewSliceHolder.j"
+@import "_CPRuleEditorViewUnboundRowHolder.j"
+@import "CPRuleEditorViewSliceDropSeparator.j"
+@import "CPRuleEditorViewSliceRow.j"

CPRuleEditorPredicateLeftExpression
= "CPRuleEditorPredicateLeftExpression";
CPRuleEditorPredicateRightExpression
= "CPRuleEditorPredicateRightExpression";
@@ -34,10 +35,11 @@

var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType";

-var itemsContext = @"items";
-var valuesContext = @"values";
-var subrowsContext = @"subrows_array";
-var boundArrayContext = @"bound_array";
+ itemsContext = "items";
+ valuesContext = "values";
+ subrowsContext = "subrows_array";
+ boundArrayContext = "bound_array";
+

@implementation RuleEditor : CPView
{
@@ -45,18 +47,17 @@
var elideUpdating = 1;
var lastAlternateKeyValue = 1;
var extendedDelegateCalls = 1;
- var editable = YES;
+ var editable = 1;
var settingSize = 1;
var suppressKeyDown = 1;
var dropWasSuccessful = 1;
- var delegateWantsValidation = YES;
+ var delegateWantsValidation = 1;
var disallowEmpty = 1;
var lastDrewWithFRAppearance = 1;
var allowsEmptyCompoundRows = 1;
var dropChangedRowCount = 1;
var reserved = 20;

- CALayer _rootLayer;
Class _rowClass;

CPIndexSet _draggingRows;
@@ -101,13 +102,6 @@

}

-- (void)windowWillClose:(CPNotification)window
-{
- var observationInfo = [self observationInfo];
- var binders = [observationInfo
valueForKeyPath:@"_observances._observer._observer"];
- [binders
makeObjectsPerformSelector:@selector(releaseConnectionWithSynchronizePeerBinders:)
withObject:YES];
-}
-
- (BOOL)isFlipped
{
return YES;
@@ -167,12 +161,6 @@
{
self = [super initWithFrame:frame];
if (self != nil) {
- _rootLayer = [CALayer layer];
-
- [self setWantsLayer:YES];
- [self setLayer:_rootLayer];
- [_rootLayer setNeedsDisplay];
-
[self _initRuleEditorShared];
}
return self;
@@ -191,7 +179,9 @@
_lastRow = 0;
editable = 1;
delegateWantsValidation = 1;
-
+ allowsEmptyCompoundRows = 0;
+ disallowEmpty = 0;
+
_rowClass = [CPDictionary class];
_itemsKeyPath = @"criteria";
_subrowsArrayKeyPath = @"subrows";
@@ -199,6 +189,8 @@
_valuesKeyPath = @"displayValues";
_boundArrayKeyPath = @"boundArray";

+ _sliceHeight = 25;
+
_dropLineView = [self _createSliceDropSeparator];

_slicesHolder = [[RuleEditorViewSliceHolder alloc] initWithFrame:[self
bounds]];
@@ -208,6 +200,7 @@

_boundArrayOwner = [[RuleEditorViewUnboundRowHolder alloc] init];
[_boundArrayOwner addObserver:self forKeyPath:_boundArrayKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:boundArrayContext];
+
[self registerForDraggedTypes:[CPArray
arrayWithObjects:CPRuleEditorItemPBoardType,nil]];

var center = [CPNotificationCenter defaultCenter];
@@ -349,7 +342,7 @@

- (void)setDelegate:(id)newDelegate
{
- if(_ruleDelegate != newDelegate){
+ if (_ruleDelegate != newDelegate){

var nc = [CPNotificationCenter defaultCenter];

@@ -385,7 +378,7 @@

- (BOOL)_shouldHideSubtractButtonForSlice:(id)slice
{
- if (disallowEmpty == NO) return NO;
+ if (disallowEmpty == 0) return NO;

switch (_nestingMode)
{
@@ -395,7 +388,7 @@
return ([slice rowIndex] == 0);
break;
case CPRuleEditorNestingModeList:
- return ([self numberOfRows]==1);
+ return ([self numberOfRows] == 1);
break;
case CPRuleEditorNestingModeSingle:
return YES;
@@ -421,36 +414,44 @@

- (id)_searchCacheForRowObject:(id)rowObject
{
- for(var cache in _rowCache)
- if([cache rowObject] == rowObject)
+ var i;
+ for (i = 0; i < [_rowCache count]; i++)
+ {
+ var cache = _rowCache[i];
+ if ([cache rowObject] == rowObject)
return cache;
-
+ }
+
return nil;
}

- (int)_rowIndexForRowObject:(id)rowobject
{
- if(rowobject == _boundArrayOwner) return -1;
+ if (rowobject == _boundArrayOwner) return -1;

return [[self _searchCacheForRowObject:rowobject] rowIndex]; // Pas bon
car le rowIndex du row cache n'est pas synchro avec la position dans
_rowCache.
}

- (int)parentRowForRow:(int)rowIndex
{
- if(rowIndex < 0 || rowIndex > [self numberOfRows])
- [CPException raise:CPRangeException format:@"row %d is out of
range",rowIndex];
-
+ if (rowIndex < 0 || rowIndex > [self numberOfRows])
+ [CPException raise:CPRangeException reason:@"row %d is out of
range",rowIndex];

var targetObject = [[self _rowCacheForIndex:rowIndex] rowObject];
-
+CPLogConsole("rowTypeForRow0"+[self rowTypeForRow:0]);
var current_index;
for (current_index = 0; current_index < rowIndex; current_index ++){
- if([self rowTypeForRow:current_index] == CPRuleEditorRowTypeCompound){
+ if ([self rowTypeForRow:current_index] == CPRuleEditorRowTypeCompound)
+ {
var candidate = [[self _rowCacheForIndex:current_index] rowObject];
var subObjects = [self _subrowObjectsOfObject:candidate];

- if([subObjects indexOfObjectIdenticalTo:targetObject] != CPNotFound)
- return current_index;
+ for(var i = 0;i< [subObjects count];i++)
+ {
+ var obj = [subObjects objectAtIndex:i];
+ if(obj === targetObject)
+ return current_index;
+ }
}
}
return -1;
@@ -458,7 +459,7 @@

- (CPMutableArray)_subrowObjectsOfObject:(id)object
{
- if(object == _boundArrayOwner)
+ if (object === _boundArrayOwner)
return [object mutableArrayValueForKey:_boundArrayKeyPath];
else
return [object mutableArrayValueForKey:_subrowsArrayKeyPath];
@@ -468,9 +469,9 @@
- (CPIndexSet)subrowIndexesForRow:(int)rowIndex
{
var object;
- if(rowIndex == -1)
+ if (rowIndex == -1)
object = _boundArrayOwner;
- else if(rowIndex<[self numberOfRows])
+ else if (rowIndex<[self numberOfRows])
object = [[self _rowCacheForIndex:rowIndex] rowObject];
else [CPException raise:CPRangeException format:@"row(%d) is greater than
the number of rows",rowIndex];

@@ -479,17 +480,17 @@

var indexes = [CPMutableIndexSet indexSet];
var i;
- for (i=rowIndex+1; i<[self numberOfRows]; i++) {
+ for (i = rowIndex+1; i<[self numberOfRows]; i++) {
var candidate = [[self _rowCacheForIndex:i] rowObject];
var indexInSubrows = [subobjects indexOfObjectIdenticalTo:candidate];

- if(indexInSubrows != CPNotFound){
+ if (indexInSubrows != CPNotFound){
[indexes addIndex:i];
objectsCount --;
// [buffer removeObjectAtIndex:indexInSubrows];
- if([self rowTypeForRow:i]==CPRuleEditorRowTypeCompound)i+=[[self
subrowIndexesForRow:i] count];
+ if ([self rowTypeForRow:i] == CPRuleEditorRowTypeCompound)i+=[[self
subrowIndexesForRow:i] count];
}
- if(objectsCount==0) break;
+ if (objectsCount == 0) break;
}
return indexes;
}
@@ -504,7 +505,7 @@
var parentIndex = [self parentRowForRow:current_index];
var subrowsIndexes = [self subrowIndexesForRow:parentIndex];

- if([subrowsIndexes count]==1 && [subrowsIndexes
firstIndex]==current_index)
+ if ([subrowsIndexes count]==1 && [subrowsIndexes
firstIndex]==current_index)
{
[childlessParents addIndex:parentIndex];
var moreChildless = [self
_childlessParentsIfSlicesWereDeletedAtIndexes:[CPIndexSet
indexSetWithIndex:parentIndex]];
@@ -544,6 +545,7 @@
// (id)-[RuleEditor _childlessParentsIfSlicesWereDeletedAtIndexes:]
// (void)-[RuleEditor removeRowsAtIndexes:includeSubrows:]
// (void)-[RuleEditor _updatePredicate]
+

var rowindex = [slice rowIndex];
[self removeRowsAtIndexes:[CPIndexSet indexSetWithIndex:rowindex]
includeSubrows:YES];
@@ -560,29 +562,31 @@

- (void)removeRowsAtIndexes:(CPIndexSet)indexes
includeSubrows:(BOOL)include
{
- if([indexes count]==0) return;
+ if ([indexes count]==0) return;

var current_index = [indexes firstIndex];

var parentRowIndex = [self parentRowForRow:current_index];
var parentRowObject;

- if(parentRowIndex == -1)
+ if (parentRowIndex == -1)
parentRowObject = _boundArrayOwner;
else
parentRowObject = [[self _rowCacheForIndex:parentRowIndex] rowObject];

- var subrows = [self _subrowObjectsOfObject:parentRowObject];
+ var _subrows = [self _subrowObjectsOfObject:parentRowObject];

var childsIndexes = [CPMutableIndexSet indexSet];

while (current_index != CPNotFound) {
+
var rowObject = [[self _rowCacheForIndex:current_index] rowObject];

- var relativeChildIndex = [subrows indexOfObjectIdenticalTo:rowObject];
- if(relativeChildIndex != CPNotFound)[childsIndexes
addIndex:relativeChildIndex];
+ var relativeChildIndex = [_subrows indexOfObjectIdenticalTo:rowObject];
+
+ if (relativeChildIndex != CPNotFound)[childsIndexes
addIndex:relativeChildIndex];

- if(include && [self rowTypeForRow:current_index] ==
CPRuleEditorRowTypeCompound)
+ if (include && [self rowTypeForRow:current_index] ==
CPRuleEditorRowTypeCompound)
{
var more_childs = [self subrowIndexesForRow:current_index];
[self removeRowsAtIndexes:more_childs includeSubrows:include];
@@ -591,18 +595,12 @@
current_index = [indexes indexGreaterThanIndex:current_index];
}

- [subrows removeObjectsAtIndexes:childsIndexes];
-}
-
-- (void)addObserver:(CPObject)anObserver forKeyPath:(CPString)keyPath
options:(CPKeyValueObservingOptions)options context:(void)context
-{
- CPLogConsole(@"addObserver:" + anObserver +" keypath: " + keyPath + "
options:" + options);
- [super addObserver:anObserver forKeyPath:keyPath options:options
context:context];
+ [_subrows removeObjectsAtIndexes:childsIndexes];
}

- (void)_setBoundDataSource:(id)datasource withKeyPath:(CPString)keyPath
options:(CPDictionary)options
{
- if(_boundArrayOwner)
+ if (_boundArrayOwner)
[_boundArrayOwner removeObserver:self forKeyPath:_boundArrayKeyPath];

[self setBoundArrayKeyPath:keyPath];
@@ -614,7 +612,7 @@

[_boundArrayOwner addObserver:self forKeyPath:_boundArrayKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:boundArrayContext];

- if([boundRows count]>0)
+ if ([boundRows count]>0)
[[self _subrowObjectsOfObject:_boundArrayOwner] insertObjects:boundRows
atIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [boundRows
count])]];

}
@@ -629,19 +627,21 @@

var relativeIndex = (type == CPRuleEditorRowTypeSimple) ? rowIndex :
rowIndex - [self parentRowForRow:rowIndex] -1;

- while((numItems = [self _queryNumberOfChildrenOfItem:item
withRowType:type]) > 0){
+ while ((numItems = [self _queryNumberOfChildrenOfItem:item
withRowType:type]) > 0){

var itemAndValue = [CPDictionary dictionary];

var childIndex = (firstItemAdded)?0:(relativeIndex % numItems);

var child = [self _queryChild:childIndex ofItem:item withRowType:type];
+
[itemAndValue setObject:child forKey:@"item"];

var value = [self _queryValueForItem:child inRow:rowIndex];
[itemAndValue setObject:value forKey:@"value"];
-
+
[itemsAndValues addObject:itemAndValue];
+
firstItemAdded = YES;
item = child;
}
@@ -656,7 +656,7 @@
var rowIndexEvent = [slice rowIndex];
var rowTypeEvent = [self rowTypeForRow:rowIndexEvent];

- var parentRowIndex = (rowTypeEvent==CPRuleEditorRowTypeCompound)?
rowIndexEvent:[self parentRowForRow:rowIndexEvent];
+ var parentRowIndex = (rowTypeEvent == CPRuleEditorRowTypeCompound)?
rowIndexEvent:[self parentRowForRow:rowIndexEvent];

[self insertRowAtIndex:rowIndexEvent + 1 withType:type
asSubrowOfRow:parentRowIndex animate:YES];
// [self _reconfigureSubviewsAnimate:YES];
@@ -666,12 +666,13 @@

- (void)addRow:(id)sender
{
+CPLogConsole(_cmd);
var parentRowIndex, rowtype;
var numberOfRows = [self numberOfRows];

switch (_nestingMode){
case CPRuleEditorNestingModeSimple:
- rowtype =
(numberOfRows==0)?CPRuleEditorRowTypeCompound:CPRuleEditorRowTypeSimple;
+ rowtype = (numberOfRows ==
0)?CPRuleEditorRowTypeCompound:CPRuleEditorRowTypeSimple;
parentRowIndex = (numberOfRows == 0) ? -1 : 0;
break;
case CPRuleEditorNestingModeList:
@@ -679,7 +680,7 @@
parentRowIndex = -1;
break;
case CPRuleEditorNestingModeSingle:
- if(numberOfRows > 0) return;
+ if (numberOfRows > 0) return;
rowtype = CPRuleEditorRowTypeSimple;
parentRowIndex = -1;
break;
@@ -689,7 +690,7 @@
break;
default:
[CPException raise:CPInvalidArgumentException format:@"Not supported
CPRuleEditorNestingMode %d",_nestingMode];
- // Compound mode:
parentRowIndex=(lastRowType==CPRuleEditorRowTypeCompound)?lastRow :[self
parentRowForRow:lastRow]; break;
+ // Compound mode: parentRowIndex=(lastRowType ==
CPRuleEditorRowTypeCompound)?lastRow :[self parentRowForRow:lastRow]; break;
}

[self insertRowAtIndex:numberOfRows withType:rowtype
asSubrowOfRow:parentRowIndex animate:YES];
@@ -697,33 +698,22 @@

- (void)insertRowAtIndex:(int)insertIndex withType:(unsigned int)rowtype
asSubrowOfRow:(int)parentRowIndex animate:(BOOL)animate
{
+CPLogConsole(_cmd);

- var rowObject = [self _insertNewRowAtIndex:insertIndex ofType:rowtype
withParentRow:parentRowIndex];
+ var newObject = [self _insertNewRowAtIndex:insertIndex ofType:rowtype
withParentRow:parentRowIndex];

- if(rowtype == CPRuleEditorRowTypeCompound && ![self
_allowsEmptyCompoundRows])
+ if (rowtype == CPRuleEditorRowTypeCompound && ![self
_allowsEmptyCompoundRows])
{
var subrow = [self _insertNewRowAtIndex:insertIndex+1
ofType:CPRuleEditorRowTypeSimple withParentRow:insertIndex];
- [[rowObject valueForKey:_subrowsArrayKeyPath] insertObject:subrow
atIndex:0];
+ [[newObject valueForKey:_subrowsArrayKeyPath] insertObject:subrow
atIndex:0];
}

- var subrowsObjects;
- var parentRowObject = (parentRowIndex == -1)?_boundArrayOwner:[[self
_rowCacheForIndex:parentRowIndex] rowObject];
-
- switch (_nestingMode)
- {
- case CPRuleEditorNestingModeSimple:
- subrowsObjects = [self _subrowObjectsOfObject:parentRowObject];
- break;
- case CPRuleEditorNestingModeList:
- subrowsObjects = [self _subrowObjectsOfObject:_boundArrayOwner];
- break;
- default:
- subrowsObjects = [self _subrowObjectsOfObject:parentRowObject];
- break;
- }
-
- [subrowsObjects insertObject:rowObject
atIndex:insertIndex-parentRowIndex-1];
- CPLogConsole("subrowsObjects" + [subrowsObjects description]);
+ var parentRowObject = (parentRowIndex == -1 || _nestingMode ==
CPRuleEditorNestingModeList)?_boundArrayOwner:[[self
_rowCacheForIndex:parentRowIndex] rowObject];
+CPLogConsole([_boundArrayOwner
mutableArrayValueForKey:_boundArrayKeyPath]);
+ var subrowsObjects = [self _subrowObjectsOfObject:parentRowObject];
+
+ [subrowsObjects insertObject:newObject
atIndex:insertIndex-parentRowIndex-1];
+
}

- (id)_insertNewRowAtIndex:(int)insertIndex
ofType:(CPRuleEditorRowType)rowtype withParentRow:(int)parentRowIndex
@@ -743,59 +733,60 @@

- (void)_startObservingRowObjectsRecursively:(id)rowObjects
{
- for(var rowObject in rowObjects)
+ var i;
+ for (i =0;i <[rowObjects count];i++)
{
+ var rowObject = rowObjects[i];
[rowObject addObserver:self forKeyPath:_itemsKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:itemsContext];
[rowObject addObserver:self forKeyPath:_valuesKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:valuesContext];
[rowObject addObserver:self forKeyPath:_subrowsArrayKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:subrowsContext];

var subrows = [self _subrowObjectsOfObject:rowObject];
- [self _startObservingRowObjectsRecursively:subrows];
+ if([subrows count]>0)[self _startObservingRowObjectsRecursively:subrows];
}
-
// ORIG IMPL : calls +keyPathsForValuesAffectingValueForKey: for all keys
}

- (void)_stopObservingRowObjectsRecursively:(id)rowObjects
{
- for(var rowObject in rowObjects)
+ var i;
+ for (i =0;i <[rowObjects count];i++)
{
+ var rowObject = rowObjects[i];
[rowObject removeObserver:self forKeyPath:_itemsKeyPath];
[rowObject removeObserver:self forKeyPath:_valuesKeyPath];
[rowObject removeObserver:self forKeyPath:_subrowsArrayKeyPath];

var subrows = [rowObject objectForKey:_subrowsArrayKeyPath];
- [self _stopObservingRowObjectsRecursively:subrows];
+ if([subrows count]>0)[self _stopObservingRowObjectsRecursively:subrows];
}
-
}

- (void)observeValueForKeyPath:(CPString)keypath ofObject:(id)object
change:(CPDictionary)change context:(void)context
{
- CPLogConsole(_cmd);

- CPLogConsole([CPString stringWithFormat:"KVO CHANGE %@ of %@ in
context %d Change:%d\nOld:%@\nNew:%@",keypath,[object
className],context,[[change objectForKey:CPKeyValueChangeKindKey]
intValue],[change objectForKey:CPKeyValueChangeOldKey],[change
objectForKey:CPKeyValueChangeNewKey]]);
- var changeKind = [[change objectForKey:CPKeyValueChangeKindKey] intValue];
+ CPLogConsole([CPString stringWithFormat:"KVO CHANGE %@ of %@ in
context %@ Change:%d Old:%@ New:%@",keypath,[object
className],context,[[change objectForKey:CPKeyValueChangeKindKey]
intValue],[[change objectForKey:CPKeyValueChangeOldKey]
description],[[change objectForKey:CPKeyValueChangeNewKey] description]]);
+
+ var changeKind = [[change objectForKey:CPKeyValueChangeKindKey]
intValue] ;
var changeNewValue = [change objectForKey:CPKeyValueChangeNewKey];
var changeOldValue = [change objectForKey:CPKeyValueChangeOldKey];
var newRows;
var oldRows;

- if(context == boundArrayContext){
-
- if(changeKind==CPKeyValueChangeSetting)
+ if (context == boundArrayContext){
+ if (changeKind == CPKeyValueChangeSetting)
{
newRows = changeNewValue;
oldRows = changeOldValue;
}
- else if(changeKind==CPKeyValueChangeInsertion)
+ else if (changeKind == CPKeyValueChangeInsertion)
{
newRows = [self _subrowObjectsOfObject:object];
oldRows = [CPMutableArray arrayWithArray:newRows];
var newInsert = changeNewValue;
[oldRows removeObjectsInArray:newInsert];
}
- else if(changeKind==CPKeyValueChangeRemoval)
+ else if (changeKind == CPKeyValueChangeRemoval)
{
newRows = [self _subrowObjectsOfObject:object];
oldRows = [CPMutableArray arrayWithArray:newRows];
@@ -806,21 +797,23 @@

[self _changedRowArray:newRows withOldRowArray:oldRows forParent:object];

- for(var newRow in newRows)
+ var n;
+ for (n=0;n<[newRows count];n++)
{
+ var newRow = newRows[n];
var subnewRows = [self _subrowObjectsOfObject:newRow];
- if([subnewRows count]>0)[self _changedRowArray:subnewRows
withOldRowArray:[CPArray array] forParent:newRow];
+ if ([subnewRows count]>0)[self _changedRowArray:subnewRows
withOldRowArray:[CPArray array] forParent:newRow];
}

[self _reconfigureSubviewsAnimate:NO];
[self reloadPredicate];

- if([newRows count] != [oldRows count])
+ if ([newRows count] != [oldRows count])
[self
_postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification
indexes:[change objectForKey:CPKeyValueChangeIndexesKey]];

- }else if(context == subrowsContext){
+ }else if (context == subrowsContext){

- if(changeKind==CPKeyValueChangeSetting)
+ if (changeKind == CPKeyValueChangeSetting)
{
newRows = changeNewValue;
oldRows = changeOldValue;
@@ -829,13 +822,13 @@
[self _reconfigureSubviewsAnimate:NO];
[self reloadPredicate];

- if([newRows count] != [oldRows count])
+ if ([newRows count] != [oldRows count])
[self
_postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification
indexes:[change objectForKey:CPKeyValueChangeIndexesKey]];
}
}
- else if(context == itemsContext){
+ else if (context == itemsContext){
}
- else if(context == valuesContext){
+ else if (context == valuesContext){
}

// CPLogConsole("============================== END KVO CHANGE
======================================");
@@ -843,20 +836,22 @@
}

- (void)_changedItem:(id)oldItem toItem:(id)newItem inRow:(int)rowIndex
atCriteriaIndex:(int)indexInCriteria
-{
+{CPLogConsole(_cmd);
var criteria = [self criteriaForRow:rowIndex];
var values = [self displayValuesForRow:rowIndex];
var type = [self rowTypeForRow:rowIndex];
-
+CPLogConsole(_cmd);
var itemToAdd = newItem;
var relativeIndexInCriteria = 0;
var num_childs = CPNotFound;
+CPLogConsole(_cmd);
+ var remainingRange = CPMakeRange(0, MIN(indexInCriteria,[criteria
count]));

- var remainingRange = CPMakeRange(0, indexInCriteria);
var finalCriteria = [CPMutableArray arrayWithArray:[criteria
subarrayWithRange:remainingRange]];
- var finalValues = [CPMutableArray arrayWithArray:[values
subarrayWithRange:remainingRange]];

- while(num_childs >0){
+ var finalValues = [CPMutableArray arrayWithArray:[values
subarrayWithRange:remainingRange]];
+CPLogConsole(_cmd);
+ while (num_childs >0){

[finalCriteria addObject:itemToAdd];

@@ -865,18 +860,18 @@

num_childs = [self _queryNumberOfChildrenOfItem:itemToAdd
withRowType:type];

- if(num_childs >0)
+ if (num_childs >0)
itemToAdd = [self _queryChild:0 ofItem:itemToAdd withRowType:type];

relativeIndexInCriteria++;
}
-
+CPLogConsole(_cmd);
var object = [[self _rowCacheForIndex:rowIndex] rowObject];
[object setValue:finalCriteria forKey:_itemsKeyPath];
[object setValue:finalValues forKey:_valuesKeyPath];

[[_slices objectAtIndex:rowIndex] _reconfigureSubviews];
-
+CPLogConsole(_cmd);
[self _postRuleOptionChangedNotification];
}

@@ -889,16 +884,17 @@
var newRowCount = [newRows count];
var oldRowCount = [oldRows count];

- CPLogConsole("\nOldArray:" + oldRowCount + "\nNewArray:" + newRowCount);
-
+ CPLogConsole("OldArray:" + oldRowCount + "NewArray:" + newRowCount);
+CPLogConsole("ROW CACHE"+_rowCache);
var parentCacheindentation;
- if(parentCacheIndex == -1) parentCacheindentation = -1;
+ if (parentCacheIndex == -1) parentCacheindentation = -1;
else
parentCacheindentation = [[self _rowCacheForIndex:parentCacheIndex]
indentation];

[_rowCache removeObjectsInRange:CPMakeRange(parentCacheIndex+1,
oldRowCount)];
var newRowCacheindex;
- for(newRowCacheindex = 0; newRowCacheindex < newRowCount;
newRowCacheindex++){
+ for (newRowCacheindex = 0; newRowCacheindex < newRowCount;
newRowCacheindex++)
+ {
var newCacheIndex = parentCacheIndex+newRowCacheindex+1;
var obj = [newRows objectAtIndex:newRowCacheindex];
var newRowType = [[obj valueForKey:_typeKeyPath] intValue];
@@ -909,16 +905,21 @@
[cache setIndentation:parentCacheindentation + 1];
[_rowCache insertObject:cache atIndex:newCacheIndex];

- if([[obj valueForKey:_itemsKeyPath] count]==0){
+ if ([[obj valueForKey:_itemsKeyPath] count]==0){
var itemsandvalues = [self
_getItemsAndValuesToAddForRow:newRowCacheindex ofType:newRowType];
var newitems = [itemsandvalues valueForKey:@"item"];
var newvalues = [itemsandvalues valueForKey:@"value"];
-
+ CPLogConsole("new Items:"+[newitems description]);
+ [obj willChangeValueForKey:_itemsKeyPath];
[obj setValue:[CPMutableArray arrayWithArray:newitems]
forKey:_itemsKeyPath];
+ [obj didChangeValueForKey:_itemsKeyPath];
+
+ [obj willChangeValueForKey:_valuesKeyPath];
[obj setValue:[CPMutableArray arrayWithArray:newvalues]
forKey:_valuesKeyPath];
+ [obj didChangeValueForKey:_valuesKeyPath];
}
}
-
+CPLogConsole("ROW CACHE"+_rowCache);
var deltaCount = newRowCount - oldRowCount;
var minusCount = MIN(newRowCount,oldRowCount);

@@ -926,27 +927,28 @@
for (n=0; n<minusCount; n++) {
var oldrow = [oldRows objectAtIndex:n];
var newrow = [newRows objectAtIndex:n];
- if(newrow != oldrow) break;
+ if (newrow != oldrow) break;

}

var changePoint = n;
var absDeltaCount = MAX(deltaCount,-deltaCount); // WTF is abs()
function ?

- if(deltaCount>0)
+ if (deltaCount>0)
{
var startIndex = parentCacheIndex + changePoint +1;
var newIndentation = parentCacheindentation + 1;

var newSliceRelativeIndex;
- for(newSliceRelativeIndex = 0 ; newSliceRelativeIndex < absDeltaCount;
newSliceRelativeIndex++)
- {
- var newIndex = startIndex + newSliceRelativeIndex;
+ for (newSliceRelativeIndex = 0 ; newSliceRelativeIndex < absDeltaCount;
newSliceRelativeIndex++)
+ {

+ var newIndex = startIndex + newSliceRelativeIndex;
var newslice = [self _newSlice];
-
+CPLogConsole("newslice"+newslice);
[newslice setRowIndex:newIndex];
[newslice setIndentation:newIndentation];
+
var rowType = [self rowTypeForRow:newIndex];
[newslice _setRowType:rowType];
[newslice _configurePlusButtonByRowType:rowType];
@@ -964,71 +966,82 @@
[_slices makeObjectsPerformSelector:@selector(_updateButtonVisibilities)];
}

-- (RuleEditorViewSliceRow)_newSlice
+- (CPRuleEditorViewSliceRow)_newSlice
{
+CPLogConsole(_cmd);
var sliceRect = CGRectMake(0, 0, [self frame].size.width, 1);
var slice = [self _createNewSliceWithFrame:sliceRect ruleEditorView:self];
- CPLogConsole(@"editable" + editable);
+CPLogConsole(slice);
[slice setEditable:editable];

return slice;
}

-- (RuleEditorViewSliceRow)_createNewSliceWithFrame:(CGRect)frame
ruleEditorView:(RuleEditor)editor
+- (CPRuleEditorViewSliceRow)_createNewSliceWithFrame:(CGRect)frame
ruleEditorView:(CPRuleEditor)editor
{
- var newslice = [[RuleEditorViewSliceRow alloc] initWithFrame:frame
ruleEditorView:editor];
+CPLogConsole(_cmd);
+ var newslice = [[CPRuleEditorViewSliceRow alloc] initWithFrame:frame
ruleEditorView:editor];
+CPLogConsole(newslice);
return newslice;
}

- (void)_reconfigureSubviewsAnimate:(BOOL)animate
{
-
- // [self _updateSliceIndentations];
+CPLogConsole(_cmd);
[self _updateSliceRows];

var viewAnimations = [CPMutableArray array];
var added_slices = [CPMutableArray array];

- for(var slice in _slices)
+ for (var i= 0;i< [_slices count];i++)
{
- var targetRect = [slice _animationTargetRect];
- if(! CPEqualRects([slice frame], targetRect))
+ var aslice = [_slices objectAtIndex:i];
+ var targetRect = [aslice _animationTargetRect];
+ if ([aslice frame] != targetRect)
{
- if([slice superview] == nil){
- var addFrame = CGRectMake(0, ([slice rowIndex])*_sliceHeight, [self
frame].size.width, _sliceHeight);
- if(animate)addFrame.size.height = 1.;
- [slice setFrame:addFrame];
- [slice _reconfigureSubviews];
- [added_slices addObject:slice];
+ if ([aslice superview] == nil)
+ {
+ var addFrame = CGRectMake(0, ([aslice rowIndex])*_sliceHeight, [self
frame].size.width, _sliceHeight);
+ if (animate)addFrame.size.height = 1.;
+ [aslice setFrame:addFrame];
+
+ [aslice _reconfigureSubviews];
+
+ [added_slices addObject:aslice];
}

var animation = [CPDictionary dictionary];
- [animation setObject:slice forKey:CPViewAnimationTargetKey];
- [animation setObject:[CPValue valueWithRect:targetRect]
forKey:CPViewAnimationEndFrameKey];
+ [animation setObject:aslice forKey:"CPViewAnimationTargetKey"];
+ [animation setObject:[CPValue valueWithJSObject:targetRect]
forKey:"CPViewAnimationEndFrameKey"];

[viewAnimations insertObject:animation atIndex:0];
}
}

- for(var added_slice in added_slices)
- [_slicesHolder addSubview:added_slice positioned:CPWindowBelow
relativeTo:nil];
-
- if(animate)
- {
-
- for (var anim in viewAnimations)
- {
- var endFrame = [[anim valueforKey:CPViewAnimationEndFrameKey] rectValue];
- var target = [anim valueforKey:CPViewAnimationTargetKey];
- [[target layer] setFrame:endFrame];
+ for (var j= 0;j< [added_slices count];j++)
+ {
+ var added_slice = [added_slices objectAtIndex:j];
+ [added_slice setNeedsDisplay:YES];
+ [_slicesHolder addSubview:added_slice positioned:CPWindowBelow
relativeTo:nil];

- }
+ CPLogConsole("holer:"+CPStringFromRect([_slicesHolder
frame])+"slice"+CPStringFromRect([added_slice frame]));
+ }

+ if (animate)
+ {
+ for (var k= 0;k< [viewAnimations count];k++)
+ {
+ var anime = [viewAnimations objectAtIndex:k];
+ var endFrame = [[anim valueforKey:"CPViewAnimationEndFrameKey"]
JSObject];
+ var target = [anim valueforKey:"CPViewAnimationTargetKey"];
+ [[target _layer] setFrame:endFrame];
+ }
}
/*
[[_slices objectAtIndex:_lastRow] setNeedsDisplay:YES];
_lastRow = [self numberOfRows] -1;
*/
+CPLogConsole(_cmd);
}

- (void)_updateSliceRows
@@ -1036,7 +1049,8 @@
var width = [self frame].size.width;
var i;

- for (i = 0; i < [self numberOfRows]; i++) {
+ for (i = 0; i < [self numberOfRows]; i++)
+ {
var slice = [_slices objectAtIndex:i];
[slice setRowIndex:i];
var targetRect = CGRectMake(0., i*_sliceHeight, width, _sliceHeight);
@@ -1055,7 +1069,7 @@
{
var rowcache = [self _rowCacheForIndex:index];

- if(rowcache){
+ if (rowcache){
var values = [[rowcache rowObject]
mutableArrayValueForKey:_itemsKeyPath];
return values;
}
@@ -1067,7 +1081,7 @@
{
var rowcache = [self _rowCacheForIndex:index];

- if(rowcache){
+ if (rowcache){
var values = [[rowcache rowObject]
mutableArrayValueForKey:_valuesKeyPath];
return values;
}
@@ -1079,7 +1093,7 @@
{
var rowcache = [self _rowCacheForIndex:index];

- if(rowcache){
+ if (rowcache){
var rowobject = [rowcache rowObject];
return [[rowobject valueForKey:_typeKeyPath] intValue];
}
@@ -1106,10 +1120,10 @@
var subindexes = [self subrowIndexesForRow:-1];

var current_index = [subindexes firstIndex];
- while(current_index!=CPNotFound)
+ while (current_index!=CPNotFound)
{
var subpredicate = [self predicateForRow:current_index];
- if(subpredicate)[subpredicates addObject:subpredicate];
+ if (subpredicate)[subpredicates addObject:subpredicate];
current_index = [subindexes indexGreaterThanIndex:current_index];
}

@@ -1129,7 +1143,7 @@

- (CPPredicate)predicateForRow:(int)row
{
- if(delegateWantsValidation)
+ if (delegateWantsValidation)
{
var predicatePartsForCriterion =
@selector(ruleEditor:predicatePartsForCriterion:withDisplayValue:inRow:);
var displayValueForCriterion =
@selector(ruleEditor:predicatePartsForCriterion:withDisplayValue:inRow:);
@@ -1158,21 +1172,21 @@
var displayValue = [self _queryValueForItem:item inRow:row]; // A voir.
On peut aussi prendre la valeur affichée dans le row cache.

var predpart = [_ruleDelegate ruleEditor:self
predicatePartsForCriterion:item withDisplayValue:displayValue inRow:row];
- if(predpart)[predicateParts setValuesForKeysWithDictionary:predpart];
+ if (predpart)[predicateParts setValuesForKeysWithDictionary:predpart];
}

- if([self rowTypeForRow:row] == CPRuleEditorRowTypeCompound)
+ if ([self rowTypeForRow:row] == CPRuleEditorRowTypeCompound)
{

var subpredicates = [CPMutableArray array];
var subrowsIndexes = [self subrowIndexesForRow:row];

- if([subrowsIndexes count] == 0) return nil;
+ if ([subrowsIndexes count] == 0) return nil;

var current_index = [subrowsIndexes firstIndex];
while (current_index != CPNotFound) {
var subpredicate = [self predicateForRow:current_index];
- if(subpredicate)[subpredicates addObject:subpredicate];
+ if (subpredicate)[subpredicates addObject:subpredicate];
current_index = [subrowsIndexes indexGreaterThanIndex:current_index];
}

@@ -1210,7 +1224,7 @@

if (!lhs){ CPLogConsole(@"missing left expression in predicate parts
dictionary"); return NULL;}
if (!rhs){ CPLogConsole(@"missing right expression in predicate parts
dictionary"); return NULL;}
- if (selector==0 && !operator){ CPLogConsole(@"missing operator type while
no selector in predicate parts dictionary"); return NULL;}
+ if (selector == 0 && !operator){ CPLogConsole(@"missing operator type
while no selector in predicate parts dictionary"); return NULL;}

if (!modifier) CPLogConsole(@"missing modifier in predicate parts
dictionary. Setting default: CPDirectPredicateModifier");
if (!options) CPLogConsole(@"missing options in predicate parts
dictionary. Setting default: CPCaseInsensitivePredicateOption");
@@ -1221,7 +1235,7 @@
var error;
try
{
- if(selector != 0)
+ if (selector != 0)
predicate = [CPComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
@@ -1260,7 +1274,8 @@

- (CPColor)_sliceLastBottomBorderColor
{
- return [CPColor controlShadowColor];
+ // return [CPColor controlShadowColor];
+ return [CPColor blackColor];
}

- (CPString)_toolTipForAddCompoundRowButton
@@ -1287,7 +1302,7 @@
{
var current_index = [indexes firstIndex];

- while(current_index !=CPNotFound){
+ while (current_index !=CPNotFound){
var subindexes = [self subrowIndexesForRow:index];
[self _updateSliceIndentationAtIndex:current_index
toIndentation:indentation+1 withIndexSet:subindexes];
current_index = [indexes indexGreaterThanIndex:current_index];
@@ -1308,27 +1323,39 @@

- (CPArray)_selectedSlices
{
- var _selectedSlices = [CPMutableArray array];
-
- for (slice in _slices)
- if([slice _isSelected])[_selectedSlices addObject:slice];
+ var _selectedSlices = [CPMutableArray array],
+ i;

+ for (i = 0; i<[_slices count]; i++)
+ {
+ var slice = _slices[i];
+ if ([slice _isSelected])[_selectedSlices addObject:slice];
+ }
return _selectedSlices;
}

- (int)_lastSelectedSliceIndex
{
var lastIndex = -1;
-
- for (var slice in _slices)
- if([slice _isLastSelected])return [slice rowIndex];
+ var i;
+
+ for (i = 0; i < [_slices count]; i++)
+ {
+ var slice = _slices[i];
+ if ([slice _isLastSelected])return [slice rowIndex];
+ }

return CPNotFound;
}

- (void)_deselectAll
{
- for (var slice in _slices){
+ var i;
+
+ for (i = 0; i < [_slices count]; i++)
+ {
+ var slice = _slices[i];
+
[slice _setSelected:NO];
[slice _setLastSelected:NO];
}
@@ -1338,9 +1365,9 @@
{
var modifierFlags = [event modifierFlags];

- if(modifierFlags & CPCommandKeyMask && [slice _rowType] ==
CPRuleEditorRowTypeSimple){
+ if (modifierFlags & CPCommandKeyMask && [slice _rowType] ==
CPRuleEditorRowTypeSimple){
[slice _setSelected:![slice _isSelected]];
- if(![slice _isSelected])[slice _setLastSelected:YES];
+ if (![slice _isSelected])[slice _setLastSelected:YES];
[slice setNeedsDisplay:YES];
}else{
[self _deselectAll];
@@ -1365,9 +1392,13 @@
{
var selectedRowIndexes = [CPMutableIndexSet indexSet];

- for(var slice in _slices)
- if([slice _isSelected])[selectedRowIndexes addIndex:[slice rowIndex]];
-
+ var i;
+ for (i = 0; i < [_slices count]; i++)
+ {
+ var slice = _slices[i];
+ if ([slice _isSelected])[selectedRowIndexes addIndex:[slice
rowIndex]];
+ }
+
return selectedRowIndexes;
}

@@ -1390,7 +1421,8 @@
/* MISC */
- (void)drawInContext:(CGContext)context
{
- CGContextSetFillColor(context, [CPColor grayColor]);
+CPLogConsole(_cmd);
+ CGContextSetFillColor(context, [CPColor redColor]);
CGContextFillRect(context, [self bounds]);

[self _drawSliceBackgroundsWithClipRect:rect];
@@ -1423,7 +1455,7 @@

- (void)bind:(CPString)binding toObject:(id)observableController
withKeyPath:(CPString)keyPath options:(CPDictionary)options
{
- if([binding isEqualToString:@"rows"])
+ if ([binding isEqualToString:@"rows"])
[self _setBoundDataSource:observableController withKeyPath:keyPath
options:options];
}

@@ -1461,11 +1493,15 @@

- (CPIndexSet)_selectedSliceIndices
{
- var selectedIndices = [CPMutableIndexSet indexSet];
-
- for (var slice in _slices)
- if([slice _isSelected])[selectedIndices addIndex:[slice rowIndex]];
-
+ var selectedIndices = [CPMutableIndexSet indexSet],
+ i;
+
+ for (i = 0; i < [_slices count]; i++)
+ {
+ var slice = _slices[i];
+ if ([slice _isSelected])[selectedIndices addIndex:[slice
rowIndex]];
+ }
+
return selectedIndices;
}

@@ -1485,14 +1521,13 @@
var point = [self convertPoint:[event locationInWindow] fromView:nil];
var view = [self hitTest:point];
CPLogConsole(@"Drag from %@",CPStringFromPoint(point));
- if([self _dragShouldBeginFromMouseDown:view])
+ if ([self _dragShouldBeginFromMouseDown:view])
[self _performDragForSlice:view withEvent:event];
}

- (BOOL)_dragShouldBeginFromMouseDown:(CPView)view
{
- return (editable
- && [view isKindOfClass:[RuleEditorViewSliceRow class]]);
+ return (editable && [view isKindOfClass:[CPRuleEditorViewSliceRow
class]]);
}

- (BOOL)_performDragForSlice:(id)slice withEvent:(CPEvent)event
@@ -1503,12 +1538,12 @@
var mainRowIndex = [slice rowIndex];
var draggingRows = [CPMutableIndexSet indexSetWithIndex:mainRowIndex];
var selected_indices = [self _selectedSliceIndices];
- if([selected_indices containsIndex:mainRowIndex])[draggingRows
addIndexes:selected_indices];
+ if ([selected_indices containsIndex:mainRowIndex])[draggingRows
addIndexes:selected_indices];

_draggingRows = [self _includeSubslicesForSlicesAtIndexes:draggingRows];

var pasteboard = [CPPasteboard pasteboardWithName: CPDragPboard];
- [pasteboard declareTypes: [CPArray arrayWithObjects:
CPRuleEditorItemPBoardType, nil] owner: self];
+ [pasteboard declareTypes:[CPArray arrayWithObjects:
CPRuleEditorItemPBoardType, nil] owner: self];


var dragImage = [self _dragImageForIndices:_draggingRows];
@@ -1544,7 +1579,7 @@
return dragImage;
}

-- (void)_rightMouseDownOnSlice:(RuleEditorViewSlice)slice
withEvent:(CPEvent)event
+- (void)_rightMouseDownOnSlice:(CPRuleEditorViewSlice)slice
withEvent:(CPEvent)event
{
}

@@ -1598,7 +1633,7 @@

- (CPDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
- if(isLocal) return CPDragOperationMove;
+ if (isLocal) return CPDragOperationMove;
return CPDragOperationNone;
}

@@ -1608,13 +1643,13 @@
var y = point.y + _sliceHeight /2;
var indexOfDropLine = floor(y / _sliceHeight);

- if(indexOfDropLine < 0 || indexOfDropLine > [self numberOfRows])
+ if (indexOfDropLine < 0 || indexOfDropLine > [self numberOfRows])
return CPDragOperationNone;

var current_index = [_draggingRows firstIndex];
while (current_index != CPNotFound) {

- if(indexOfDropLine == 0 || indexOfDropLine == current_index ||
indexOfDropLine == current_index + 1)
+ if (indexOfDropLine == 0 || indexOfDropLine == current_index ||
indexOfDropLine == current_index + 1)
{
[self _clearDropLine];
return CPDragOperationNone;
@@ -1770,4 +1805,4 @@

@end

-import "CPRuleEditorViewSliceRow.j"
+

Modified: branches/CPRuleEditor/CPRuleEditorButtonCell.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorButtonCell.j (original)
+++ branches/CPRuleEditor/CPRuleEditorButtonCell.j Sun Jan 25 11:36:11 2009
@@ -4,7 +4,7 @@
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2007 by
Steve Nygard.
*/

-@implementation RuleEditorButtonCell : CPButton
+@implementation CPRuleEditorButtonCell : CPButtonCell
{
}

@@ -31,8 +31,8 @@

- (void)drawInteriorWithFrame:(CGRect)cellFrame inView:(CPView)controlView
{
- cellFrame.origin.x -=2;
- cellFrame.size.width +=4;
+ cellFrame.origin.x -= 2;
+ cellFrame.size.width += 4;
[super drawInteriorWithFrame:cellFrame inView:controlView];
}


Modified: branches/CPRuleEditor/CPRuleEditorPopupButton.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorPopupButton.j (original)
+++ branches/CPRuleEditor/CPRuleEditorPopupButton.j Sun Jan 25 11:36:11 2009
@@ -5,26 +5,9 @@
*/


-@implementation RuleEditorPopupButton : CPPopUpButton
+@implementation CPRuleEditorPopupButton : CPPopUpButton
{
}

-/*
-+ (void)initialize
-{
-}
-*/
-
-+ (Class)cellClass
-{
- return [RuleEditorPopupButtonCell class];
-}
-
-/*
-
-- (void)sizeToFit
-{
-}
-*/
@end


Modified: branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j (original)
+++ branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j Sun Jan 25 11:36:11
2009
@@ -5,7 +5,7 @@
*/


-@implementation RuleEditorPopupButtonCell : CPPopUpButtonCell
+@implementation CPRuleEditorPopupButtonCell : CPPopUpButtonCell
{
}

@@ -28,17 +28,10 @@

- (BOOL)trackMouse:(CPEvent)theEvent inRect:(CGRect)cellFrame
ofView:(CPView)controlView untilMouseUp:(BOOL)untilMouseUp
{
- var editable = [self sliceIsEditable];
- if(!editable)
+ if (![self sliceIsEditable])
return NO;

return [super trackMouse:theEvent inRect:cellFrame ofView:controlView
untilMouseUp:untilMouseUp];
-}
-
-- (CGRect)drawingRectForBounds:(CGRect)theRect
-{
- theRect.size.height -=5;
- return theRect;
}

- (unsigned int)arrowPosition

Modified: branches/CPRuleEditor/CPRuleEditorTextField.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorTextField.j (original)
+++ branches/CPRuleEditor/CPRuleEditorTextField.j Sun Jan 25 11:36:11 2009
@@ -6,29 +6,35 @@
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

-@implementation RuleEditorTextField : CPTextField
+@implementation CPRuleEditorTextField : CPTextField
+{
+}

- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self != nil) {
- [[self cell] setControlSize:CPMiniControlSize];
- [[self cell] setBordered:NO];
- [[self cell] setEditable:NO];
- [[self cell] setDrawsBackground:NO];
- [[self cell] setFont:[CPFont fontWithName:@"LuciaGrande"
size:11.]];
+ CPLogConsole(_cmd);
+ // [self setControlSize:CPMiniControlSize];
+ CPLogConsole(_cmd);
+ [self setBordered:NO];
+ CPLogConsole(_cmd);
+ [self setEditable:NO];
+ [self setDrawsBackground:NO];
+ CPLogConsole(_cmd);
+ // [self setFont:[CPFont fontWithName:@"LuciaGrande" size:11.]];

}
return self;
}

-
+/*
- (id)hitTest:(CPPoint)point
{
- if(!CPPointInRect(point, [self frame]))
+ if (!CPPointInRect(point, [self frame]))
return nil;

return [self superview];
}
-
+*/
@end

Modified: branches/CPRuleEditor/CPRuleEditorViewSlice.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorViewSlice.j (original)
+++ branches/CPRuleEditor/CPRuleEditorViewSlice.j Sun Jan 25 11:36:11 2009
@@ -4,20 +4,17 @@
*/


-@implementation RuleEditorViewSlice : CPView
+@implementation CPRuleEditorViewSlice : CPView
{
- CALayer _rootLayer;
CPRuleEditor _ruleEditor;
CPColor _backgroundColor;
int _indentation;
CGRect _animationTargetRect;

- struct {
- unsigned int selected:1;
- unsigned int lastSelected:1;
- unsigned int hideNonPartDrawing:1;
- unsigned int reserved:29;
- } _flags;
+ BOOL selected;
+ BOOL lastSelected;
+ unsigned int hideNonPartDrawing;
+ unsigned int reserved;

int _rowIndex;

@@ -32,7 +29,7 @@
{
self = [super initWithCoder:coder];
if (self != nil) {
- [self setBackgroundColor:[CPColor blueColor]]
+ [self setBackgroundColor:[CPColor grayColor]];
}
return self;
}
@@ -44,46 +41,42 @@

- (id)initWithFrame:(CGRect)frame ruleEditorView:(id)editor
{
- if(self = [super initWithFrame:frame]){
+ if (self = [super initWithFrame:frame]){

_ruleEditor = editor;
-
- _rootLayer = [CALayer layer];
- [self setWantsLayer:YES];
- [self setLayer:_rootLayer];
- [_rootLayer setBounds:[self bounds]];
- [_rootLayer setDelegate:self];
- [_rootLayer setNeedsDisplay];
- [_rootLayer setBackgroundColor:[CPColor redColor]];
+ selected = NO;
+ lastSelected = NO;
+ [self setBackgroundColor:[CPColor grayColor]];
+
}
return self;
}

- (void)_setHideNonPartDrawing:(BOOL)value
{
- _flags.hideNonPartDrawing = value;
+ hideNonPartDrawing = value;
}

- (void)_setLastSelected:(BOOL)value
{
- _flags.lastSelected = value;
+ lastSelected = value;
}

- (BOOL)_isLastSelected
{
- return _flags.lastSelected;
+ return lastSelected;
}

- (void)_setSelected:(BOOL)value
{
- _flags.selected = value;
+ selected = value;
}

- (BOOL)_isSelected
{
- return _flags.selected;
+ return selected;
}
-
+/*
- (CPColor)backgroundColor
{
return _backgroundColor ;
@@ -91,10 +84,10 @@

- (void)setBackgroundColor:(CPColor)color
{
- if(_backgroundColor != color)
+ if (_backgroundColor != color)
_backgroundColor = color;
}
-
+*/
- (int)indentation
{
return _indentation;
@@ -124,24 +117,38 @@
{
return _animationTargetRect;
}
-
--(void)drawRect:(CGRect)rect
-{
- if([self _isSelected])
+/*
+-(void)drawRect:(CPRect)rect{
+ if ([self _isSelected])
{
var isKey = [[self window] isKeyWindow];
+
[(isKey) ? [_ruleEditor _selectedActiveRowColor]:[_ruleEditor
_selectedInactiveRowColor] set];
CPRectFill(rect);
}
+
+ var drawrect = CGRectMake(0, 0, [self frame].size.width, 1);
+
+ CPLogConsole([_ruleEditor _sliceLastBottomBorderColor]);
+ CPLogConsole([_ruleEditor _sliceBottomBorderColor]);
+
+ if([self rowIndex] == [_ruleEditor numberOfRows] - 1)
+ [[_ruleEditor _sliceLastBottomBorderColor] set];
+ else
+ [[_ruleEditor _sliceBottomBorderColor] set];

- var drawrect = NSMakeRect(0, 0, [self frame].size.width, 1);
- [(_rowIndex == [_ruleEditor numberOfRows]-1) ? [_ruleEditor
_sliceLastBottomBorderColor]:[_ruleEditor _sliceBottomBorderColor] set];
- CPRectFill(drawrect);
+

+ CPLogConsole(_cmd);
+
drawrect.origin.y += [self frame].size.height -1;
[[_ruleEditor _sliceTopBorderColor] set];
- CPRectFill(drawrect);
+
+ CPLogConsole(_cmd);
+
+
}
+*/

- (void)mouseDown:(CPEvent)theEvent
{

Modified: branches/CPRuleEditor/CPRuleEditorViewSliceDropSeparator.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorViewSliceDropSeparator.j (original)
+++ branches/CPRuleEditor/CPRuleEditorViewSliceDropSeparator.j Sun Jan 25
11:36:11 2009
@@ -29,7 +29,7 @@

- (void)drawInContext:(CGContext)context
{
- CGContextSetFillColor(context, [CPColor lightGrayColor]);
+ CGContextSetFillColor(context, [CPColor redColor]);
CGContextFillRect(context, [self bounds]);
}


Modified: branches/CPRuleEditor/CPRuleEditorViewSliceRow.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorViewSliceRow.j (original)
+++ branches/CPRuleEditor/CPRuleEditorViewSliceRow.j Sun Jan 25 11:36:11
2009
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Pear, Inc. All rights reserved.
*/

+
+@import "CPRuleEditorViewSlice.j"
+
+@import "CPRuleEditor.j"
+// @import "CPRuleEditorButtonCell.j"
+@import "CPRuleEditorPopupButton.j"
+@import "CPRuleEditorTextField.j"
+
var CPImageNameAddTemplate = @"CPImageNameAddTemplate";
var CPImageNameRemoveTemplate = @"CPImageNameRemoveTemplate";
var CONTROL_HEIGHT = 18.;

-import "CPRuleEditorViewSlice.j"
-
-import "CPRuleEditor.j"
-import "CPRuleEditorButtonCell.j"
-import "CPRuleEditorPopupButton.j"
-import "CPRuleEditorTextField.j"
-
-@implementation RuleEditorViewSliceRow : RuleEditorViewSlice
+@implementation CPRuleEditorViewSliceRow : CPRuleEditorViewSlice
{
-
CPMutableArray _ruleOptionViews;
CPMutableArray _ruleOptionFrames;
CPMutableArray _correspondingRuleItems;
@@ -25,16 +25,15 @@
CPButton _subtractButton;
int _rowType;
int _plusButtonRowType;
- BOOL editable = YES;
+ BOOL editable;

id _sliceRowReserved;
}

- (id)initWithFrame:(CGRect)frame ruleEditorView:(id)editor
{
- if(self = [super initWithFrame:frame ruleEditorView:editor])
+ if (self = [super initWithFrame:frame ruleEditorView:editor])
{
-
[self _initShared];
}
return self;
@@ -46,56 +45,53 @@
_ruleOptionFrames = [[CPMutableArray alloc] init];
_ruleOptionInitialViewFrames = [[CPMutableArray alloc] init];
_ruleOptionViews = [[CPMutableArray alloc] init];
-
+ editable = 1;
_addButton = [self _createAddRowButton];
_subtractButton = [self _createDeleteRowButton];

- [_addButton setToolTip:[_ruleEditor _toolTipForAddSimpleRowButton]];
- [_subtractButton setToolTip:[_ruleEditor _toolTipForDeleteRowButton]];
+// [_addButton setToolTip:[_ruleEditor _toolTipForAddSimpleRowButton]];
+// [_subtractButton setToolTip:[_ruleEditor _toolTipForDeleteRowButton]];

var sliceFrame = [self frame];

- var _buttonframe = CGRectMake(sliceFrame.size.width - CONTROL_HEIGHT -
[self _rowButtonsRightHorizontalPadding],([_ruleEditor rowHeight]
-CONTROL_HEIGHT)/2,CONTROL_HEIGHT,CONTROL_HEIGHT);
+ var _buttonframe = CGRectMake(sliceFrame.size.width - CONTROL_HEIGHT -
[self _rowButtonsRightHorizontalPadding],([_ruleEditor rowHeight] -
CONTROL_HEIGHT)/2,CONTROL_HEIGHT,CONTROL_HEIGHT);
[_addButton setFrame:_buttonframe];
+
_buttonframe.origin.x -= CONTROL_HEIGHT + [self
_rowButtonsInterviewHorizontalPadding];
[_subtractButton setFrame:_buttonframe];
-
[self setAutoresizingMask:CPViewWidthSizable & CPViewMinXMargin];

- if([_ruleEditor isEditable])
+ if ([_ruleEditor isEditable])
{
[self addSubview:_addButton];
[self addSubview:_subtractButton];
}
+
}

- (CPButton )_createAddRowButton
{
- var button = [[CPButton alloc] init];
-
- var buttoncell = [[RuleEditorButtonCell alloc] init];
- [button setCell:buttoncell];
-
- var plus_image = [CPImage imageNamed:CPImageNameAddTemplate];
-
+ var button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
+ [button setBezelStyle:CPRoundRectBezelStyle];
+ [button setImagePosition:CPImageOnly];
+ var plus_image = [[CPImage alloc]
initWithContentsOfFile:"CPImageNameAddTemplate.tiff" size:CGSizeMake(8,
8)];
[button setImage:plus_image];
+
[button setAction:@selector(_addOption:)];
[button setTarget:self];
[button setAutoresizingMask:CPViewMaxXMargin];
-
+ [button sizeToFit];
+
return button;
}

- (CPButton )_createDeleteRowButton
{
- var button = [[CPButton alloc] init];
-
- var buttoncell = [[RuleEditorButtonCell alloc] init];
- [button setCell:buttoncell];
-
- var minus_image = [CPImage imageNamed:CPImageNameRemoveTemplate];
-
+ var button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
+ [button setImagePosition:CPImageOnly];
+ var minus_image = [[CPImage alloc]
initWithContentsOfFile:"CPImageNameRemoveTemplate.tiff" size:CGSizeMake(8,
8)];
[button setImage:minus_image];
+
[button setAction:@selector(_deleteOption:)];
[button setTarget:self];
[button setAutoresizingMask:CPViewMaxXMargin];
@@ -105,26 +101,26 @@

- (CPMenuItem )_createMenuItemWithTitle:(CPString )title
{
- var loc_title = CPLocalizedStringFromTable(title,[_ruleEditor
formattingStringsFilename],nil);
- return [[CPMenuItem alloc] initWithTitle:loc_title action:0
keyEquivalent:@""];
+ //var loc_title = CPLocalizedStringFromTable(title,[_ruleEditor
formattingStringsFilename],nil);
+ return [[CPMenuItem alloc] initWithTitle:title action:0
keyEquivalent:@""];
}

- (CPPopUpButton )_createPopUpButtonWithItems:(CPArray )itemsArray
selectedItemIndex:(int)index
-{
+{CPLogConsole([itemsArray description] );
// [RuleEditorViewSliceRow _minimumVerticalPopupPadding]
- var item;

- var popup = [[RuleEditorPopupButton alloc] init];
+ var popup = [[CPRuleEditorPopupButton alloc]
initWithFrame:CGRectMakeZero()];
+ var menu = [[CPMenu alloc] initWithTitle:@""];
+
+ [popup setFrame:CPMakeRect(0, ([_ruleEditor rowHeight] - [popup
frame].size.height)/2, 100, CONTROL_HEIGHT)];

- [popup setFrame:NSMakeRect(0, ([_ruleEditor rowHeight] - [popup
frame].size.height)/2, CONTROL_HEIGHT, 40)];
- var menu = [[CPMenu alloc] init];
+ for (var i=0;i<[itemsArray count];i++)
+ [menu addItem:[itemsArray objectAtIndex:i]];

- for (var item in itemsArray)
- [menu addItem:item];

[popup setMenu:menu];
[popup selectItemAtIndex:index];
- [popup sizeToFit];
+// [popup sizeToFit]; UNIMPLEMENTED ?

return popup;
}
@@ -134,11 +130,11 @@
return [CPMenuItem separatorItem];
}

-- (CPTextField )_createStaticTextFieldWithStringValue:(CPString )text
+- (CPRuleEditorTextField)_createStaticTextFieldWithStringValue:(CPString
)text
{
- var textField = [[RuleEditorTextField alloc] initWithFrame:NSMakeRect(0,
0, 0, CONTROL_HEIGHT)];
- var loc_text = CPLocalizedStringFromTable(text,[_ruleEditor
formattingStringsFilename],nil);
- [textField setStringValue:loc_text];
+ var textField = [[CPRuleEditorTextField alloc]
initWithFrame:CPMakeRect(0, 0, 0, CONTROL_HEIGHT)];
+ // var loc_text = CPLocalizedStringFromTable(text,[_ruleEditor
formattingStringsFilename],nil);
+ [textField setStringValue:text];
[textField sizeToFit];

return textField;
@@ -146,24 +142,30 @@

- (void)_addOption:(id)sender
{
- if([self rowIndex]==[_ruleEditor numberOfRows]-1) [self
setNeedsDisplay:YES];
+CPLogConsole(_cmd);
+ if ([self rowIndex] == [_ruleEditor numberOfRows]-1) [self
setNeedsDisplay:YES];
[_ruleEditor _addOptionFromSlice:self ofRowType:_plusButtonRowType];
}

- (void)_deleteOption:(id)sender
{
+CPLogConsole(_cmd);
[_ruleEditor _deleteSlice:self];
}

-- (void)_ruleOptionPopupChangedAction:(CPMenuItem )sender
+- (void)_ruleOptionPopupChangedAction:(CPMenuItem )popup
{
+CPLogConsole(sender);
+// HACK BUG
+var sender = [popup selectedItem];
var layoutdict = [sender representedObject];
+CPLogConsole(_cmd);
var newItem = [layoutdict objectForKey:@"item"];
var indexInCriteria = [[layoutdict objectForKey:@"indexInCriteria"]
intValue];
-
+CPLogConsole(_cmd);
var oldItem = [_correspondingRuleItems objectAtIndex:indexInCriteria];
-
- if(newItem != oldItem)
+CPLogConsole(_cmd);
+ if (newItem != oldItem)
{
[_correspondingRuleItems replaceObjectAtIndex:indexInCriteria
withObject:newItem];
[_ruleEditor _changedItem:oldItem toItem:newItem inRow:[self rowIndex]
atCriteriaIndex:indexInCriteria];
@@ -189,7 +191,7 @@
}

- (void)_reconfigureSubviews
-{
+{CPLogConsole(_cmd);
var numItems;
var currentItem = nil;
var optionView = nil;
@@ -200,12 +202,12 @@

[self _emptyRulePartSubviews];
[_correspondingRuleItems removeAllObjects];
-
- while( (numItems = [_ruleEditor _queryNumberOfChildrenOfItem:currentItem
withRowType:rowtype]) >0){

- var isCustomRightControl = NO;
- var isStaticTextField = NO;
- var isPopupMenu = NO;
+ while ( (numItems = [_ruleEditor _queryNumberOfChildrenOfItem:currentItem
withRowType:rowtype]) >0){
+
+ var isCustomRightControl = false;
+ var isStaticTextField = false;
+ var isPopupMenu = false;
var isMultiValue = numItems > 1;
var selectedMenuItemIndex =0;

@@ -215,17 +217,18 @@
var selectedItem = nil;

var childIndex;
- for (childIndex = 0; childIndex < numItems; childIndex++) {
+ for (childIndex = 0; childIndex < numItems; childIndex++)
+ {
var childItem = [_ruleEditor _queryChild:childIndex ofItem:currentItem
withRowType:rowtype];
current_display_value = [_ruleEditor _queryValueForItem:childItem
inRow:[self rowIndex]];

- if(isMultiValue)
+ if (isMultiValue)
{
var menuItem;

- if([current_display_value isKindOfClass:[CPString class]])
+ if ([current_display_value isKindOfClass:[CPString class]])
menuItem = [self _createMenuItemWithTitle:current_display_value];
- else if([current_display_value isKindOfClass:[CPMenuItem class]])
+ else if ([current_display_value isKindOfClass:[CPMenuItem class]])
menuItem = current_display_value;
else
[CPException raise:CPGenericException format:@"Display value must
be a string or a menu item"];
@@ -239,9 +242,9 @@
[menuItem setTag:indexInCriteria];

[itemsArray addObject:menuItem];
- isPopupMenu = YES;
-
- if((childIndex == numItems - 1 && selectedItem == nil)
+ isPopupMenu = true;
+
+ if ((childIndex == numItems - 1 && selectedItem == nil)
|| ([current_display_value isEqual:display_value_cached])
|| ([current_display_value isKindOfClass:[CPView class]]
&& [[current_display_value objectValue]
isEqualTo:[display_value_cached objectValue]]))
@@ -250,58 +253,62 @@
}

}
- else if([current_display_value isKindOfClass:[CPString class]])
+ else if ([current_display_value isKindOfClass:[CPString class]])
{
- isStaticTextField = YES;
+ isStaticTextField = true;
selectedItem = childItem; selectedMenuItemIndex =0;
}
- else if([current_display_value isKindOfClass:[CPControl class]])
+ else if ([current_display_value isKindOfClass:[CPControl class]])
{
- isCustomRightControl = YES;
+ isCustomRightControl = true;
selectedItem = childItem; selectedMenuItemIndex =0;
} else
- [CPException raise:CPGenericException format:@"Display value must be a
string or a custom control"];
+ [CPException raise:CPGenericException reason:@"Display value must be a
string or a custom control"];

}

- if(isPopupMenu)
+ if (isPopupMenu)
{
optionView = [self _createPopUpButtonWithItems:itemsArray
selectedItemIndex:selectedMenuItemIndex];
}
- else if(isStaticTextField)
+ else if (isStaticTextField)
{
optionView = [self
_createStaticTextFieldWithStringValue:[current_display_value description]];
}
- else if(isCustomRightControl)
+ else if (isCustomRightControl)
{
optionView = display_value_cached;
- [optionView setFrame:NSMakeRect(0, 0, 150, CONTROL_HEIGHT)];
- if([optionView respondsToSelector:@selector(cell)])
- [[optionView cell] setEditable:_sliceRowFlags.editable];
+ [optionView setFrame:CPMakeRect(0, 0, 150, CONTROL_HEIGHT)];
+ if ([optionView respondsToSelector:@selector(cell)])
+ [[optionView cell] setEditable:editable];
}

[_ruleOptionViews addObject:optionView];
- var rectValue = [CPValue valueWithRect:[optionView frame]];

- if(rectValue)
+ var rectValue = [CPValue valueWithJSObject:[optionView frame]];
+ CPLogConsole([optionView className]+" = "+CPStringFromRect([optionView
frame]));
+ if (rectValue)
[_ruleOptionInitialViewFrames addObject:rectValue];

[_correspondingRuleItems addObject:selectedItem];
currentItem = selectedItem;
indexInCriteria++;
}
+

[self _relayoutSubviewsWidthChanged:NO];
}

- (void)_relayoutSubviewsWidthChanged:(BOOL)changedWidth
{
- if(changedWidth){
+
+ if (changedWidth)
+ {
var _addButtonOrigin = [self frame].size.width - [_addButton
frame].size.width - [self _rowButtonsRightHorizontalPadding];
- [_addButton setFrameOrigin:NSMakePoint(_addButtonOrigin, [_addButton
frame].origin.y)];
+ [_addButton setFrameOrigin:CPMakePoint(_addButtonOrigin, [_addButton
frame].origin.y)];

var _substractButtonOrigin = _addButtonOrigin - [_subtractButton
frame].size.width - [self _rowButtonsInterviewHorizontalPadding];
- [_subtractButton setFrameOrigin:NSMakePoint(_substractButtonOrigin,
[_addButton frame].origin.y) ];
+ [_subtractButton setFrameOrigin:CPMakePoint(_substractButtonOrigin,
[_addButton frame].origin.y) ];
}

[_ruleOptionFrames removeAllObjects];
@@ -312,23 +319,28 @@
var _ruleOptionView;
while (_ruleOptionView = [collection nextObject])
{
- var shouldAddView = ([_ruleOptionView superview]==nil);
- if(changedWidth || shouldAddView)
+ var shouldAddView = ([_ruleOptionView superview] == nil);
+ if (changedWidth || shouldAddView)
{
var optionFrame = [_ruleOptionView frame];
- optionFrame.origin = NSMakePoint(optionViewOriginX, ([_ruleEditor
rowHeight] - optionFrame.size.height)/2);
+ optionFrame.origin = CPMakePoint(optionViewOriginX, ([_ruleEditor
rowHeight] - optionFrame.size.height)/2);
+ CPLogConsole([_ruleEditor rowHeight]+" - "+optionFrame.size.height);
var optionFrameEnd = MIN(optionFrame.origin.x +
optionFrame.size.width,[_subtractButton frame].origin.x - [self
_rowButtonsLeftHorizontalPadding]);
+
optionFrame.size.width = optionFrameEnd - optionFrame.origin.x;

[_ruleOptionView setFrame:optionFrame];
+ CPLogConsole([_ruleOptionView className]+"
= "+CPStringFromRect(optionFrame));
[_ruleOptionView setAutoresizingMask:CPViewMinYMargin &
CPViewMinXMargin ];

- if(shouldAddView)[self addSubview:_ruleOptionView];
+ if (shouldAddView)[self addSubview:_ruleOptionView];

- [_ruleOptionFrames addObject:[CPValue valueWithRect:optionFrame]];
+ [_ruleOptionFrames addObject:[CPValue valueWithJSObject:optionFrame]];
optionViewOriginX += optionFrame.size.width + [self
_interviewHorizontalPadding];
+
}
}
+
}

- (void)_updateButtonVisibilities
@@ -359,7 +371,8 @@
[self _setRowTypeToAddFromPlusButton:plusButtonType];
}

-- (unsigned int)_rowType{
+- (unsigned int)_rowType
+{
return _rowType;
}

@@ -370,12 +383,12 @@

- (BOOL)isEditable
{
- return _sliceRowFlags.editable;
+ return editable;
}

- (void)setEditable:(BOOL)value
{
- _sliceRowFlags.editable = value;
+ editable = value;
// [RuleEditorViewSliceRow _updateEnabledStateForSubviews];
// [RuleEditorViewSliceRow _updateButtonVisibilities];

@@ -447,6 +460,10 @@
// Ou alors avec _correspondingRuleItems
}

+-(void)drawRect:(CPRect)rect
+{
+ [super drawRect:rect];
+}
/*
- (BOOL)_dropsIndentWhenImmediatelyBelow
{

Modified: branches/CPRuleEditor/RuleDelegate.j
==============================================================================
--- branches/CPRuleEditor/RuleDelegate.j (original)
+++ branches/CPRuleEditor/RuleDelegate.j Sun Jan 25 11:36:11 2009
@@ -1,6 +1,6 @@

-import <Foundation/Foundation.j>
-import "CPRuleEditor.j"
+@import <Foundation/Foundation.j>
+@import "CPRuleEditor.j"

var CPRuleEditorPredicateKeys = new
Array(CPRuleEditorPredicateLeftExpression,CPRuleEditorPredicateRightExpression,CPRuleEditorPredicateComparisonModifier,CPRuleEditorPredicateOptions,CPRuleEditorPredicateOperatorType,CPRuleEditorPredicateCustomSelector,CPRuleEditorPredicateCompoundType);

@@ -11,7 +11,7 @@

var request = [CPURLRequest requestWithURL:url];
var data = [CPURLConnection sendSynchronousRequest:request
returningResponse:NULL error:NULL];
- if(data)
+ if (data)
{
var dict = [CPPropertyListSerialization propertyListFromData:data
format:CPPropertyListXMLFormat_v1_0 errorDescription:NULL];
return dict;
@@ -29,7 +29,7 @@

var request = [CPURLRequest requestWithURL:url];
var data = [CPURLConnection sendSynchronousRequest:request
returningResponse:NULL error:NULL];
- if(data)
+ if (data)
{
var array = [CPPropertyListSerialization propertyListFromData:data
format:CPPropertyListXMLFormat_v1_0 errorDescription:NULL];
return array;
@@ -62,7 +62,7 @@
- (int)ruleEditor:(RuleEditor )editor
numberOfChildrenForCriterion:(id)criterion
withRowType:(CPRuleEditorRowType)rowType
{
var childs;
- if(criterion)
+ if (criterion)
childs = [criterion objectForKey:@"criteria"];
else
childs = [rows valueForKeyPath:(rowType == CPRuleEditorRowTypeSimple) ?
@"rootChildren.subrows" : @"rootHeaders.subrows"];
@@ -75,7 +75,7 @@
{
var childs;

- if(criterion)
+ if (criterion)
childs = [criterion objectForKey:@"criteria"];
else
childs = [rows valueForKeyPath:(rowType == CPRuleEditorRowTypeSimple) ?
@"rootChildren.subrows" : @"rootHeaders.subrows"];
@@ -94,15 +94,15 @@

var custom_control_class = [criterion
objectForKey:@"CPRuleEditorCustomControlClass"];

- if(custom_control_class != nil)
+ if (custom_control_class != nil)
{
var viewkey = [CPString stringWithFormat:@"view_%d", row];

var view = [criterion objectForKey:viewkey];
- if(view == nil)
+ if (view == nil)
{
var custom_class = CPClassFromString(custom_control_class);
- view = [[custom_class alloc] initWithFrame:CGZeroRect];
+ view = [[custom_class alloc] initWithFrame:CGRectMakeZero()];

[criterion setObject:view forKey:viewkey];
}
@@ -115,30 +115,31 @@

- (CPDictionary)ruleEditor:(RuleEditor)editor
predicatePartsForCriterion:(id)criterion withDisplayValue:(id)value
inRow:(int)row
{
-
+CPLogConsole(_cmd);
var predicatePartsForCriterion = [CPDictionary dictionary];

- if([editor rowTypeForRow:row] == CPRuleEditorRowTypeCompound)
+ if ([editor rowTypeForRow:row] == CPRuleEditorRowTypeCompound)
{
var compound_type = [criterion
objectForKey:CPRuleEditorPredicateCompoundType];
- if(compound_type)[predicatePartsForCriterion setObject:compound_type
forKey:CPRuleEditorPredicateCompoundType];
+ if (compound_type)[predicatePartsForCriterion setObject:compound_type
forKey:CPRuleEditorPredicateCompoundType];
return predicatePartsForCriterion;
}

var i;
- for (i=0 ;i< 7;i++){
+ for (i = 0 ;i< 7;i++)
+ {
var key = CPRuleEditorPredicateKeys[i];
var predicatePart = nil ;

- if([key isEqualToString:CPRuleEditorPredicateLeftExpression])
+ if ([key isEqualToString:CPRuleEditorPredicateLeftExpression])
{
var str = [criterion objectForKey:key];
- if(str) predicatePart = [CPExpression expressionForKeyPath:str];
+ if (str) predicatePart = [CPExpression expressionForKeyPath:str];
}
else if ([key isEqualToString:CPRuleEditorPredicateRightExpression])
{
var transformedValue;
- if([criterion objectForKey:@"CPRuleEditorCustomControlClass"] != nil)
+ if ([criterion objectForKey:@"CPRuleEditorCustomControlClass"] != nil)
transformedValue = ([value isKindOfClass:[CPView class]]) ? [value
objectValue]:value;
else
transformedValue = [criterion objectForKey:key];
@@ -147,21 +148,21 @@
else if ([key isEqualToString:CPRuleEditorPredicateOperatorType])
{
var operator = [criterion objectForKey:key];
- if(operator) predicatePart = operator;
+ if (operator) predicatePart = operator;
}
else if ([key isEqualToString:CPRuleEditorPredicateCustomSelector])
{
var selector = [criterion objectForKey:key];
- if(selector) predicatePart = selector;
+ if (selector) predicatePart = selector;
}
else if ([key isEqualToString:CPRuleEditorPredicateOptions])
{
var options = [criterion objectForKey:key];
- if(options) predicatePart = options;
+ if (options) predicatePart = options;
}
else continue;

- if(predicatePart)[predicatePartsForCriterion setObject:predicatePart
forKey:key];
+ if (predicatePart)[predicatePartsForCriterion setObject:predicatePart
forKey:key];
}
return predicatePartsForCriterion;
}

Modified: branches/CPRuleEditor/_CPRuleEditorCache.j
==============================================================================
--- branches/CPRuleEditor/_CPRuleEditorCache.j (original)
+++ branches/CPRuleEditor/_CPRuleEditorCache.j Sun Jan 25 11:36:11 2009
@@ -10,6 +10,7 @@
int rowIndex;
int indentation;
}
+
-(CPString)description
{
return [CPString stringWithFormat:@"<%@ object:%p rowIndex:%d
indentation:%d>",[self className] , rowObject,rowIndex,indentation];
@@ -48,7 +49,4 @@
indentation = value;
}

-
-
-@end
-
+@end
\ No newline at end of file

Modified: branches/CPRuleEditor/_CPRuleEditorViewSliceHolder.j
==============================================================================
--- branches/CPRuleEditor/_CPRuleEditorViewSliceHolder.j (original)
+++ branches/CPRuleEditor/_CPRuleEditorViewSliceHolder.j Sun Jan 25
11:36:11 2009
@@ -6,14 +6,17 @@

@implementation RuleEditorViewSliceHolder : CPView
{
+
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
- if (self != nil) {
- [self setBackgroundColor:[CPColor redColor]]
-}
+ if (self != nil)
+ {
+ [self setBackgroundColor:[CPColor lightGrayColor]];
+
+ }
return self;
}

@@ -27,9 +30,9 @@
return YES;
}

-- (void)drawRect:(CGRect)rect
+-(void)drawRect:(CPRect)rect
{
- [[self superview] drawRect:rect];
+[[self superview] drawRect:rect];
}

@end

Modified: branches/CPRuleEditor/criteria.plist
==============================================================================
--- branches/CPRuleEditor/criteria.plist (original)
+++ branches/CPRuleEditor/criteria.plist Sun Jan 25 11:36:11 2009
@@ -40,6 +40,49 @@
<array>
<dict>
<key>NSRuleEditorPredicateLeftExpression</key>
+ <string>name</string>
+ <key>criteria</key>
+ <array>
+ <dict>
+ <key>NSRuleEditorPredicateComparisonModifier</key>
+ <integer>0</integer>
+ <key>NSRuleEditorPredicateOperatorType</key>
+ <integer>6</integer>
+ <key>NSRuleEditorPredicateOptions</key>
+ <integer>0</integer>
+ <key>criteria</key>
+ <array>
+ <dict>
+ <key>CPRuleEditorCustomControlClass</key>
+ <string>CPTextField</string>
+ </dict>
+ </array>
+ <key>valeur</key>
+ <string>CPBeginsWithPredicateOperatorType</string>
+ </dict>
+ <dict>
+ <key>NSRuleEditorPredicateComparisonModifier</key>
+ <integer>0</integer>
+ <key>NSRuleEditorPredicateOperatorType</key>
+ <integer>6</integer>
+ <key>NSRuleEditorPredicateOptions</key>
+ <integer>0</integer>
+ <key>criteria</key>
+ <array>
+ <dict>
+ <key>CPRuleEditorCustomControlClass</key>
+ <string>CPTextField</string>
+ </dict>
+ </array>
+ <key>valeur</key>
+ <string>CPBeginsWithPredicateOperatorType</string>
+ </dict>
+ </array>
+ <key>valeur</key>
+ <string>name</string>
+ </dict>
+ <dict>
+ <key>NSRuleEditorPredicateLeftExpression</key>
<string>age</string>
<key>criteria</key>
<array>
@@ -60,7 +103,7 @@
</dict>
</array>
<key>valeur</key>
- <string>NSLessThanPredicateOperatorType</string>
+ <string>CPLessThanPredicateOperatorType</string>
</dict>
<dict>
<key>NSRuleEditorPredicateComparisonModifier</key>

Modified: branches/CPRuleEditor/main.j
==============================================================================
--- branches/CPRuleEditor/main.j (original)
+++ branches/CPRuleEditor/main.j Sun Jan 25 11:36:11 2009
@@ -1,7 +1,7 @@
-import <Foundation/Foundation.j>
-import <AppKit/AppKit.j>
+@import <Foundation/Foundation.j>
+@import <AppKit/AppKit.j>

-import "AppController.j"
+@import "AppController.j"

@implementation CPString (description)

Reply all
Reply to author
Forward
0 new messages