diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as index 90cf4b78ef..feadb86e21 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as +++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as @@ -35,9 +35,12 @@ internal class MXRoyaleClasses import mx.containers.beads.ApplicationLayout; ApplicationLayout; import mx.containers.beads.BoxLayout; BoxLayout; import mx.containers.ControlBar; ControlBar; - import mx.containers.Panel; Panel; + import mx.containers.Panel; Panel; import mx.controls.ToolTip; ToolTip; import mx.controls.beads.ToolTipBead; ToolTipBead; + import mx.collections.SortField; SortField; + import mx.collections.Sort; Sort; + import mx.effects.IEffectInstance; IEffectInstance; import mx.events.EffectEvent; EffectEvent; import mx.graphics.Stroke; Stroke; diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISort.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISort.as index 217900c275..ed8b5cd34b 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISort.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISort.as @@ -1,353 +1,353 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package mx.collections -{ - - /** - * The ISort interface defines the interface for classes that - * provide the sorting information required to sort the - * data of a collection view. - * - * @see mx.collections.ICollectionView - * @see mx.collections.ISortField - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ -public interface ISort -{ - //-------------------------------------------------------------------------- - // - // Properties - // - //-------------------------------------------------------------------------- - - /** - * The method used to compare items when sorting. - * If you specify this property, Flex ignores any - * compareFunction properties that you specify in the - * ISortField objects that you use in this class. - * - *

The compare function must have the following signature:

- * - *

-     *
-     *     function [name](a:Object, b:Object, fields:Array = null):int
-     *
-     *  
- * - *

This function must return the following value: - *

- *

To return to the internal comparision function, set this value to - * null.

- *

- * The fields array specifies the object fields - * to compare. - * Typically the algorithm will compare properties until the field list is - * exhausted or a non-zero value can be returned. - * For example:

- * - *

-     *    function myCompare(a:Object, b:Object, fields:Array = null):int
-     *    {
-     *        var result:int = 0;
-     *        var i:int = 0;
-     *        var propList:Array = fields ? fields : internalPropList;
-     *        var len:int = propList.length;
-     *        var propName:String;
-     *        while (result == 0 && (i < len))
-     *        {
-     *            propName = propList[i];
-     *            result = compareValues(a[propName], b[propName]);
-     *            i++;
-     *        }
-     *        return result;
-     *    }
-     *
-     *    function compareValues(a:Object, b:Object):int
-     *    {
-     *        if (a == null && b == null)
-     *            return 0;
-     *
-     *        if (a == null)
-     *          return 1;
-     *
-     *        if (b == null)
-     *           return -1;
-     *
-     *        if (a < b)
-     *            return -1;
-     *
-     *        if (a > b)
-     *            return 1;
-     *
-     *        return 0;
-     *    }
-     *  
- * - *

The default value is an internal compare function that can perform - * a string, numeric, or date comparison in ascending or descending order. - * Specify your own function only if you need a need a custom - * comparison algorithm. This is normally only the case if a calculated - * field is used in a display.

- * - *

Alternatively you can specify separate compare functions for each - * sort field by using the ISortField class - * compareFunction property; This way you can use the default - * comparison for some fields and a custom comparison for others.

- * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function get compareFunction():Function; - - /** - * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor - * argument instead. - */ - function set compareFunction(value:Function):void; - - /** - * An Array of ISortField objects that - * specifies the fields to compare. - * The order of the ISortField objects in the array determines - * field priority order when sorting. - * The default sort comparator checks the sort fields in array - * order until it determinines a sort order for the two - * fields being compared. - * - * @default null - * - * @see ISortField - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function get fields():Array; - - /** - * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor - * argument instead. - */ - function set fields(value:Array):void; - - /** - * Indicates if the sort should be unique. - * Unique sorts fail if any value or combined value specified by the - * fields listed in the fields property result in an indeterminate or - * non-unique sort order; that is, if two or more items have identical - * sort field values. An error is thrown if the sort is not unique. - * The sorting logic uses this unique property value only if sort - * field(s) are specified explicitly. If no sort fields are specified - * explicitly, no error is thrown even when there are identical value - * elements. - * - * @default false - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function get unique():Boolean; - - /** - * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor - * argument instead. - */ - function set unique(value:Boolean):void; - - //-------------------------------------------------------------------------- - // - // Methods - // - //-------------------------------------------------------------------------- - - /** - * Finds the specified object within the specified array (or the insertion - * point if asked for), returning the index if found or -1 if not. - * The ListCollectionView class findxxx() - * methods use this method to find the requested item; as a general rule, - * it is easier to use these functions, and not findItem() - * to find data in ListCollectionView-based objects. - * You call the findItem() method directly when writing a - * class that supports sorting, such as a new ICollectionView - * implementation. - * The input items array need to be sorted before calling this function. - * Otherwise this function will not be able to find the specified value - * properly. - * - * @param items the Array within which to search. - * @param values Object containing the properties to look for (or - * the object to search for, itself). - * The object must consist of field name/value pairs, where - * the field names are names of fields specified by the - * fields property, in the same order they - * are used in that property. - * You do not have to specify all of the fields from the - * fields property, but you - * cannot skip any in the order. - * Therefore, if the fields - * properity lists three fields, you can specify its first - * and second fields in this parameter, but you cannot - * specify only the first and third fields. - * @param mode String containing the type of find to perform. - * Valid values are: - * - * - * - * - * - * - * - * - * - * - * - * - * - *
ANY_INDEX_MODEReturn any position that - * is valid for the values.
FIRST_INDEX_MODEReturn the position - * where the first occurrance of the values is found.
LAST_INDEX_MODEReturn the position where the - * last ocurrance of the specified values is found. - *
- * @param returnInsertionIndex If the method does not find an item - * identified by the values parameter, - * and this parameter is true the - * findItem() - * method returns the insertion point for the values, - * that is the point in the sorted order where you - * should insert the item. - * @param compareFunction a comparator function to use to find the item. - * If you do not specify this parameter or , or if you - * provide a null value, - * findItem() function uses the - * compare function determined by the ISort - * instance's compareFunction property, - * passing in the array of fields determined - * by the values object and the current - * SortFields. - * - * If you provide a non-null value, findItem() - * function uses it as the compare function. - * - * The signature of the function passed as - * compareFunction must be as follows: - * function myCompareFunction(a:Object, b:Object):int. - * Note that there is no third argument unlike the - * compare function for ISort.compareFunction() - * property. - * @return int The index in the array of the found item. - * If the returnInsertionIndex parameter is - * false and the item is not found, returns -1. - * If the returnInsertionIndex parameter is - * true and the item is not found, returns - * the index of the point in the sorted array where the - * values would be inserted. - * - * @throws SortError If there are any parameter errors, - * the find critieria is not compatible with the sort - * or the comparator function for the sort can not be determined. - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function findItem( - items:Array, - values:Object, - mode:String, - returnInsertionIndex:Boolean = false, - compareFunction:Function = null):int; - - /** - * Return whether the specified property is used to control the sort. - * The function cannot determine a definitive answer if the sort uses a - * custom comparator; it always returns true in this case. - * - * @param property The name of the field to test. - * @return Whether the property value might affect the sort outcome. - * If the sort uses the default compareFunction, returns - * true if the - * property parameter specifies a sort field. - * If the sort or any ISortField uses a custom comparator, - * there's no way to know, so return true. - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function propertyAffectsSort(property:String):Boolean; - - /** - * Goes through the fields array and calls - * reverse() on each of the ISortField objects in - * the array. If the field was descending now it is ascending, - * and vice versa. - * - *

Note: an ICollectionView does not automatically - * update when the objects in the fields array are modified; - * call its refresh() method to update the view.

- * - *

Note: a future release of Apache Flex SDK will change the signature - * of this function to return a reversed clone of this Sort instance. See - * FLEX-34853.

- * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function reverse():void; - - /** - * Apply the current sort to the specified array (not a copy). - * To prevent the array from being modified, create a copy - * use the copy in the items parameter. - * - *

Flex ICollectionView implementations call the - * sort method automatically and ensure that the sort is - * performed on a copy of the underlying data.

- * - * @param items Array of items to sort. - * - * @langversion 3.0 - * @playerversion Flash 9 - * @playerversion AIR 1.1 - * @productversion Flex 4.5 - */ - function sort(items:Array):void; -} -} +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package mx.collections +{ + + /** + * The ISort interface defines the interface for classes that + * provide the sorting information required to sort the + * data of a collection view. + * + * @see mx.collections.ICollectionView + * @see mx.collections.ISortField + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ +public interface ISort +{ + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + /** + * The method used to compare items when sorting. + * If you specify this property, Flex ignores any + * compareFunction properties that you specify in the + * ISortField objects that you use in this class. + * + *

The compare function must have the following signature:

+ * + *

+     *
+     *     function [name](a:Object, b:Object, fields:Array = null):int
+     *
+     *  
+ * + *

This function must return the following value: + *

+ *

To return to the internal comparision function, set this value to + * null.

+ *

+ * The fields array specifies the object fields + * to compare. + * Typically the algorithm will compare properties until the field list is + * exhausted or a non-zero value can be returned. + * For example:

+ * + *

+     *    function myCompare(a:Object, b:Object, fields:Array = null):int
+     *    {
+     *        var result:int = 0;
+     *        var i:int = 0;
+     *        var propList:Array = fields ? fields : internalPropList;
+     *        var len:int = propList.length;
+     *        var propName:String;
+     *        while (result == 0 && (i < len))
+     *        {
+     *            propName = propList[i];
+     *            result = compareValues(a[propName], b[propName]);
+     *            i++;
+     *        }
+     *        return result;
+     *    }
+     *
+     *    function compareValues(a:Object, b:Object):int
+     *    {
+     *        if (a == null && b == null)
+     *            return 0;
+     *
+     *        if (a == null)
+     *          return 1;
+     *
+     *        if (b == null)
+     *           return -1;
+     *
+     *        if (a < b)
+     *            return -1;
+     *
+     *        if (a > b)
+     *            return 1;
+     *
+     *        return 0;
+     *    }
+     *  
+ * + *

The default value is an internal compare function that can perform + * a string, numeric, or date comparison in ascending or descending order. + * Specify your own function only if you need a need a custom + * comparison algorithm. This is normally only the case if a calculated + * field is used in a display.

+ * + *

Alternatively you can specify separate compare functions for each + * sort field by using the ISortField class + * compareFunction property; This way you can use the default + * comparison for some fields and a custom comparison for others.

+ * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + //function get compareFunction():Function; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + //function set compareFunction(value:Function):void; + + /** + * An Array of ISortField objects that + * specifies the fields to compare. + * The order of the ISortField objects in the array determines + * field priority order when sorting. + * The default sort comparator checks the sort fields in array + * order until it determinines a sort order for the two + * fields being compared. + * + * @default null + * + * @see ISortField + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + function get fields():Array; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + function set fields(value:Array):void; + + /** + * Indicates if the sort should be unique. + * Unique sorts fail if any value or combined value specified by the + * fields listed in the fields property result in an indeterminate or + * non-unique sort order; that is, if two or more items have identical + * sort field values. An error is thrown if the sort is not unique. + * The sorting logic uses this unique property value only if sort + * field(s) are specified explicitly. If no sort fields are specified + * explicitly, no error is thrown even when there are identical value + * elements. + * + * @default false + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function get unique():Boolean; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + // function set unique(value:Boolean):void; + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * Finds the specified object within the specified array (or the insertion + * point if asked for), returning the index if found or -1 if not. + * The ListCollectionView class findxxx() + * methods use this method to find the requested item; as a general rule, + * it is easier to use these functions, and not findItem() + * to find data in ListCollectionView-based objects. + * You call the findItem() method directly when writing a + * class that supports sorting, such as a new ICollectionView + * implementation. + * The input items array need to be sorted before calling this function. + * Otherwise this function will not be able to find the specified value + * properly. + * + * @param items the Array within which to search. + * @param values Object containing the properties to look for (or + * the object to search for, itself). + * The object must consist of field name/value pairs, where + * the field names are names of fields specified by the + * fields property, in the same order they + * are used in that property. + * You do not have to specify all of the fields from the + * fields property, but you + * cannot skip any in the order. + * Therefore, if the fields + * properity lists three fields, you can specify its first + * and second fields in this parameter, but you cannot + * specify only the first and third fields. + * @param mode String containing the type of find to perform. + * Valid values are: + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ANY_INDEX_MODEReturn any position that + * is valid for the values.
FIRST_INDEX_MODEReturn the position + * where the first occurrance of the values is found.
LAST_INDEX_MODEReturn the position where the + * last ocurrance of the specified values is found. + *
+ * @param returnInsertionIndex If the method does not find an item + * identified by the values parameter, + * and this parameter is true the + * findItem() + * method returns the insertion point for the values, + * that is the point in the sorted order where you + * should insert the item. + * @param compareFunction a comparator function to use to find the item. + * If you do not specify this parameter or , or if you + * provide a null value, + * findItem() function uses the + * compare function determined by the ISort + * instance's compareFunction property, + * passing in the array of fields determined + * by the values object and the current + * SortFields. + * + * If you provide a non-null value, findItem() + * function uses it as the compare function. + * + * The signature of the function passed as + * compareFunction must be as follows: + * function myCompareFunction(a:Object, b:Object):int. + * Note that there is no third argument unlike the + * compare function for ISort.compareFunction() + * property. + * @return int The index in the array of the found item. + * If the returnInsertionIndex parameter is + * false and the item is not found, returns -1. + * If the returnInsertionIndex parameter is + * true and the item is not found, returns + * the index of the point in the sorted array where the + * values would be inserted. + * + * @throws SortError If there are any parameter errors, + * the find critieria is not compatible with the sort + * or the comparator function for the sort can not be determined. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* function findItem( + items:Array, + values:Object, + mode:String, + returnInsertionIndex:Boolean = false, + compareFunction:Function = null):int; */ + + /** + * Return whether the specified property is used to control the sort. + * The function cannot determine a definitive answer if the sort uses a + * custom comparator; it always returns true in this case. + * + * @param property The name of the field to test. + * @return Whether the property value might affect the sort outcome. + * If the sort uses the default compareFunction, returns + * true if the + * property parameter specifies a sort field. + * If the sort or any ISortField uses a custom comparator, + * there's no way to know, so return true. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* function propertyAffectsSort(property:String):Boolean; */ + + /** + * Goes through the fields array and calls + * reverse() on each of the ISortField objects in + * the array. If the field was descending now it is ascending, + * and vice versa. + * + *

Note: an ICollectionView does not automatically + * update when the objects in the fields array are modified; + * call its refresh() method to update the view.

+ * + *

Note: a future release of Apache Flex SDK will change the signature + * of this function to return a reversed clone of this Sort instance. See + * FLEX-34853.

+ * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* function reverse():void; */ + + /** + * Apply the current sort to the specified array (not a copy). + * To prevent the array from being modified, create a copy + * use the copy in the items parameter. + * + *

Flex ICollectionView implementations call the + * sort method automatically and ensure that the sort is + * performed on a copy of the underlying data.

+ * + * @param items Array of items to sort. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* function sort(items:Array):void; */ +} +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISortField.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISortField.as new file mode 100644 index 0000000000..bd516972a9 --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ISortField.as @@ -0,0 +1,272 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package mx.collections +{ +/** + * The ISortField interface defines the interface for classes that + * are used with ISort classes, to provide the sorting information + * required to sort the specific fields or property in a collection view. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ +public interface ISortField + { + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + /** + * This helper property is used internally by the findItem() + * and sort() methods. Other uses of this property are not + * supported. + * Returns -1 if this ISortField shouldn't be used by the Sort + * class to sort the field (there is no compareFunction or no name). Otherwise, returns a bitmask of sort options. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function get arraySortOnOptions():int; + + /** + * The function that compares two items during a sort of items for the + * associated collection. If you specify a compareFunction + * property in an ISort object, Flex ignores any + * compareFunction properties of the ISort's ISortField + * objects. + *

The compare function must have the following signature:

+ * + *

function myCompare(a:Object, b:Object):int

+ * + *

This function returns the following values:

+ * + * + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function get compareFunction():Function; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + // function set compareFunction(c:Function):void; + + /** + * Specifies whether this field should be sorted in descending + * order. + * + *

The default value is false (ascending).

+ * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function get descending():Boolean; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + // function set descending(value:Boolean):void; + + /** + * The name of the field to be sorted. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + function get name():String; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + function set name(n:String):void; + + /** + * Specifies that if the field being sorted contains numeric + * (number/int/uint) values, or string representations of numeric values, + * the comparator use a numeric comparison. + *

+ * This property is used by SortField class in case custom compare + * function is not provided. + *

+ *

+ * If this property is true, the built-in numeric compare + * function is used. Each of data items is cast to a + * Number() function before the comparison. + *

+ *

+ * If this property is false, the built-in string compare + * function is used. Each of data items is cast to a + * String() function before the comparison. + *

+ *

+ * If this property is null, the first data item + * is introspected to see if it is a number or string and the sort + * proceeds based on that introspection. + *

+ * + * @default null + * + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + function get numeric():Object; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + function set numeric(value:Object):void; + + + /** + * Specifies what compare type will be used for the sortField. This overrides the default + * behavior. + * + * @default null + * + * @langversion 3.0 + * @playerversion Flash 11.8 + * @playerversion AIR 3.8 + * @productversion Royale 0.9.4 + */ + // function get sortCompareType():String; + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + // function set sortCompareType(value:String):void; + + + /** + * True if this ISortField uses a custom comparator function. + * + * @see @compareFunction + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function get usingCustomCompareFunction():Boolean; + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * A helper function called by the Sort class to set the + * default comparison function to perform a comparison based on + * one of three things: whether or not a custom compare function has + * been set, the data type for the specified field or the the value of the + * numeric property. If the the numeric property is true, + * then a numeric comparison will be performed when sorting. + * + * @param obj The object that contains the data. If the field name has + * been set with the name property, then the name will be used to access + * the data value from this object. Otherwise the object itself will + * be used as the data value. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function initializeDefaultCompareFunction(obj:Object):void; + + /** + * Reverse the criteria for this sort field. + * If the field was sorted in descending order, for example, sort it + * in ascending order. + * + *

NOTE: An ICollectionView does not automatically + * update when the ISortFields are modified; call its + * refresh() method to update the view.

+ * + *

Note: a future release of Apache Flex SDK will change the signature + * of this function to return a reversed clone of this SortField instance. + * See FLEX-34853 for more details.

+ * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + // function reverse():void; + + + /** + * This changes the internal compare function used by the SortField based + * on the value of sortCompareType. + * + * @deprecated A future release of Apache Flex SDK will remove this function in favour of + * making ISortField instances immutable. + * + * @return true for successfully matched or false for failure to match the sortCompareType. + * + * @langversion 3.0 + * @playerversion Flash 11.8 + * @playerversion AIR 3.8 + * @productversion Royale 0.9.4 + */ + // function updateSortCompareType():Boolean; + + /** + * Returns true if the object has the field required by this ISortField instance. + * In the case of ComplexSortField, returns true if the object has a field with + * an identical name to the first part of the namePath. + * + * @return true if the object has the field required by this ISortField instance. + * + * @langversion 3.0 + * @playerversion Flash 11.8 + * @playerversion AIR 3.8 + * @productversion Royale 0.9.4 + */ + // function objectHasSortField(object:Object):Boolean; +} +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/Sort.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/Sort.as new file mode 100644 index 0000000000..39dc1f28d0 --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/Sort.as @@ -0,0 +1,227 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package mx.collections +{ + + /* + import flash.events.Event; + import flash.events.EventDispatcher; */ + + import org.apache.royale.events.Event; + import org.apache.royale.events.EventDispatcher; + + //import mx.collections.errors.SortError; + import mx.core.mx_internal; + /* import mx.resources.IResourceManager; + import mx.resources.ResourceManager */; + import mx.utils.ObjectUtil; + + use namespace mx_internal; + + [DefaultProperty("fields")] +[ResourceBundle("collections")] +/* [Alternative(replacement="spark.collections.Sort", since="4.5")] + */ +/** + * Provides the sorting information required to establish a sort on an + * existing view (ICollectionView interface or class that + * implements the interface). After you assign a Sort instance to the view's + * sort property, you must call the view's + * refresh() method to apply the sort criteria. + * + *

Typically the sort is defined for collections of complex items, that is + * collections in which the sort is performed on one or more properties of + * the objects in the collection. + * The following example shows this use:

+ *

+ *     var col:ICollectionView = new ArrayCollection();
+ *     // In the real world, the collection would have more than one item.
+ *     col.addItem({first:"Anders", last:"Dickerson"});
+ *
+ *     // Create the Sort instance.
+ *     var sort:ISort = new Sort();
+ *
+ *     // Set the sort field; sort on the last name first, first name second.
+ *     // Both fields are case-insensitive.
+ *     sort.fields = [new SortField("last",true), new SortField("first",true)];
+ *       // Assign the Sort object to the view.
+ *     col.sort = sort;
+ *
+ *     // Apply the sort to the collection.
+ *     col.refresh();
+ *  
+ * + *

There are situations in which the collection contains simple items, + * like String, Date, Boolean, etc. + * In this case, apply the sort to the simple type directly. + * When constructing a sort for simple items, use a single sort field, + * and specify a null name (first) parameter + * in the SortField object constructor. + * For example: + *


+ *     var col:ICollectionView = new ArrayCollection();
+ *     col.addItem("California");
+ *     col.addItem("Arizona");
+ *     var sort:Sort = new Sort();
+ *
+ *     // There is only one sort field, so use a null
+ *     // first parameter.
+ *     sort.fields = [new SortField(null, true)];
+ *     col.sort = sort;
+ *     col.refresh();
+ *  
+ *

+ * + *

The Flex implementations of the ICollectionView interface + * retrieve all items from a remote location before executing a sort. + * If you use paging with a sorted list, apply the sort to the remote + * collection before you retrieve the data. + *

+ * + *

By default this Sort class does not provide correct language specific + * sorting for strings. For this type of sorting please see the + * spark.collections.Sort and + * spark.collections.SortField classes.

+ * + * Note: to prevent problems like + * FLEX-34853 + * it is recommended to use SortField + * instances as immutable objects (by not changing their state). + * + * @mxml + * + *

The <mx:Sort> tag has the following attributes:

+ * + *
+ *  <mx:Sort
+ *  Properties
+ *  compareFunction="Internal compare function"
+ *  fields="null"
+ *  unique="false | true"
+ *  />
+ *  
+ * + *

In case items have inconsistent data types or items have complex data + * types, the use of the default built-in compare functions is not recommended. + * Inconsistent sorting results may occur in such cases. To avoid such problem, + * provide a custom compare function and/or make the item types consistent.

+ * + *

Just like any other AdvancedStyleClient-based classes, + * the Sort and SortField classes do not have a + * parent-child relationship in terms of event handling. Locale changes in a + * Sort instance are not dispatched to its SortField + * instances automatically. The only exceptional case is the internal default + * SortField instance used when no explicit fields are provided. + * In this case, the internal default SortField instance follows + * the locale style that the owner Sort instance has.

+ * + * @see mx.collections.ICollectionView + * @see ISortField + * @see spark.collections.Sort + * @see spark.collections.SortField + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + * @royalesuppresspublicvarwarning + */ +public class Sort extends EventDispatcher implements ISort +{ + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructor. + * + *

Creates a new Sort with no fields set and no custom comparator.

+ * + * @param fields An Array of ISortField objects that + * specifies the fields to compare. + * @param customCompareFunction Use a custom function to compare the + * objects in the collection to which this sort will be applied. + * @param unique Indicates if the sort should be unique. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function Sort(fields:Array = null, customCompareFunction:Function = null, unique:Boolean = false) + { + super(); + + this.fields = fields; + + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + + //---------------------------------- + // fields + //---------------------------------- + + /** + * @private + * Storage for the fields property. + */ + private var _fields:Array; + + [Inspectable(category="General", arrayType="mx.collections.ISortField")] + [Bindable("fieldsChanged")] + + /** + * @inheritDoc + * + * @default null + * + * @see SortField + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function get fields():Array + { + return _fields; + } + + /** + * @private + */ + public function set fields(value:Array):void + { + _fields = value; + + dispatchEvent(new Event("fieldsChanged")); + } + +} +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/SortField.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/SortField.as new file mode 100644 index 0000000000..ad1e419a94 --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/SortField.as @@ -0,0 +1,855 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package mx.collections +{ + + +/* + import flash.events.Event; + import flash.events.EventDispatcher; */ + + import org.apache.royale.events.Event; + import org.apache.royale.events.EventDispatcher; + + // import mx.collections.errors.SortError; + import mx.core.mx_internal; +/* import mx.resources.IResourceManager; */ //commented + + /* import mx.resources.ResourceManager; */ //commented + import mx.utils.ObjectUtil; + + [ResourceBundle("collections")] +/* [Alternative(replacement="spark.collections.SortField", since="4.5")] + */ +/** + * Provides the sorting information required to establish a sort on a field + * or property in a collection view. + * + * The SortField class is meant to be used with the Sort class. + * + * Typically the sort is defined for collections of complex items, that is + * items in which the sort is performed on properties of those objects. + * As in the following example: + * + *

+ *     var col:ICollectionView = new ArrayCollection();
+ *     col.addItem({first:"Anders", last:"Dickerson"});
+ *     var sort:Sort = new Sort();
+ *     sort.fields = [new SortField("first", true)];
+ *     col.sort = sort;
+ *  
+ * + * There are situations in which the collection contains simple items, like + * String, Date, Boolean, etc. + * In this case, sorting should be applied to the simple type directly. + * When constructing a sort for this situation only a single sort field is + * required and should not have a name specified. + * For example: + * + *

+ *     var col:ICollectionView = new ArrayCollection();
+ *     col.addItem("California");
+ *     col.addItem("Arizona");
+ *     var sort:Sort = new Sort();
+ *     sort.fields = [new SortField(null, true)];
+ *     col.sort = sort;
+ *  
+ * + *

By default the comparison provided by the SortField class does + * not provide correct language specific + * sorting for strings. For this type of sorting please see the + * spark.collections.Sort and + * spark.collections.SortField classes.

+ * + * Note: to prevent problems like + * FLEX-34853 + * it is recommended to use SortField + * instances as immutable objects (by not changing their state). + * + * @mxml + * + *

The <mx:SortField> tag has the following attributes:

+ * + *
+ *  <mx:SortField
+ *  Properties
+ *  caseInsensitive="false"
+ *  compareFunction="Internal compare function"
+ *  descending="false"
+ *  name="null"
+ *  numeric="null"
+ *  />
+ *  
+ * + * @see mx.collections.ICollectionView + * @see mx.collections.Sort + * @see spark.collections.Sort + * @see spark.collections.SortField + + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ +public class SortField extends EventDispatcher implements ISortField +{ + /* include "../core/Version.as"; */ + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructor. + * + * @param name The name of the property that this field uses for + * comparison. + * If the object is a simple type, pass null. + * @param caseInsensitive When sorting strings, tells the comparator + * whether to ignore the case of the values. + * @param descending Tells the comparator whether to arrange items in + * descending order. + * @param numeric Tells the comparator whether to compare sort items as + * numbers, instead of alphabetically. + * @param sortCompareType Gives an indication to SortField which of the + * default compare functions to use. + * @param customCompareFunction Use a custom function to compare the + * objects based on this SortField. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function SortField(name:String = null, + caseInsensitive:Boolean = false, + descending:Boolean = false, + numeric:Object = null, + sortCompareType:String = null, + customCompareFunction:Function = null) + { + super(); + + _name = name; + _caseInsensitive = caseInsensitive; + // _descending = descending; + _numeric = numeric; + // _sortCompareType = sortCompareType; + + /* if(customCompareFunction != null) + { + compareFunction = customCompareFunction; + } + else if (updateSortCompareType() == false) + { + _compareFunction = stringCompare; + } */ + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + /** + * @private + * Used for accessing localized Error messages. + */ + /* private var resourceManager:IResourceManager = + ResourceManager.getInstance(); */ + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //--------------------------------- + // arraySortOnOptions + //--------------------------------- + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function get arraySortOnOptions():int + { + if (usingCustomCompareFunction + || name == null + || _compareFunction == xmlCompare + || _compareFunction == dateCompare) + { + return -1; + } + var options:int = 0; + if (caseInsensitive) options |= Array.CASEINSENSITIVE; + if (descending) options |= Array.DESCENDING; + if (numeric == true || _compareFunction == numericCompare) options |= Array.NUMERIC; + return options; + } */ + + //--------------------------------- + // caseInsensitive + //--------------------------------- + + /** + * @private + * Storage for the caseInsensitive property. + */ + private var _caseInsensitive:Boolean; + + [Inspectable(category="General")] + [Bindable("caseInsensitiveChanged")] + + /** + * Specifies whether the sort for this field should be case insensitive. + * + * @default false + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function get caseInsensitive():Boolean + { + return _caseInsensitive; + } + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + mx_internal function setCaseInsensitive(value:Boolean):void + { + if (value != _caseInsensitive) + { + _caseInsensitive = value; + dispatchEvent(new Event("caseInsensitiveChanged")); + } + } + + //--------------------------------- + // compareFunction + //--------------------------------- + + /** + * @private + * Storage for the compareFunction property. + */ + /* private var _compareFunction:Function; + + [Inspectable(category="General")] */ + + /** + * The function that compares two items during a sort of items for the + * associated collection. If you specify a compareFunction + * property in an ISort object, Flex ignores any + * compareFunction properties of the ISort's + * SortField objects. + * + *

The compare function must have the following signature:

+ * + *

function myCompare(a:Object, b:Object):int

+ * + *

This function must return the following values:

+ * + * + * + *

The default value is an internal compare function that can perform + * a string, numeric, or date comparison in ascending or descending order, + * with case-sensitive or case-insensitive string comparisons. + * Specify your own function only if you need a need a custom comparison + * algorithm. This is normally only the case if a calculated field is + * used in a display.

+ * + * Note if you need language-specific sorting then consider using the + * spark.collections.SortField class. + * + * @see spark.collections.SortField + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function get compareFunction():Function + { + return _compareFunction; + } */ + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + /* public function set compareFunction(c:Function):void + { + _compareFunction = c; + _usingCustomCompareFunction = (c != null); + } */ + + //--------------------------------- + // descending + //--------------------------------- + + /** + * @private + * Storage for the descending property. + */ + /* private var _descending:Boolean; + + [Inspectable(category="General")] + [Bindable("descendingChanged")] */ + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function get descending():Boolean + { + return _descending; + } */ + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + /* public function set descending(value:Boolean):void + { + if (_descending != value) + { + _descending = value; + dispatchEvent(new Event("descendingChanged")); + } + } */ + + //--------------------------------- + // name + //--------------------------------- + + /** + * @private + * Storage for the name property. + */ + private var _name:String; + + [Inspectable(category="General")] + [Bindable("nameChanged")] + + /** + * @inheritDoc + * + * @default null + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function get name():String + { + return _name; + } + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + public function set name(n:String):void + { + _name = n; + dispatchEvent(new Event("nameChanged")); + } + + //--------------------------------- + // numeric + //--------------------------------- + + /** + * @private + * Storage for the numeric property. + */ + private var _numeric:Object; + + [Inspectable(category="General")] + [Bindable("numericChanged")] + + /** + * @inheritDoc + * + * @default null + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + public function get numeric():Object + { + return _numeric; + } + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + public function set numeric(value:Object):void + { + if (_numeric != value) + { + _numeric = value; + dispatchEvent(new Event("numericChanged")); + } + } + + + //--------------------------------- + // sortCompareType + //--------------------------------- + + /** + * @private + */ + /* private var _sortCompareType:String = null; */ + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 11.8 + * @playerversion AIR 3.8 + * @productversion Royale 0.9.4 + */ + /* [Bindable("sortCompareTypeChanged")] + public function get sortCompareType():String + { + return _sortCompareType; + } */ + + /** + * @deprecated A future release of Apache Flex SDK will remove this function. Please use the constructor + * argument instead. + */ + /* public function set sortCompareType(value:String):void + { + if (_sortCompareType != value) + { + _sortCompareType = value; + dispatchEvent(new Event("sortCompareTypeChanged")); + } + + updateSortCompareType(); + } */ + + + //--------------------------------- + // usingCustomCompareFunction + //--------------------------------- + + /* private var _usingCustomCompareFunction:Boolean; */ + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function get usingCustomCompareFunction():Boolean + { + return _usingCustomCompareFunction; + } */ + + //-------------------------------------------------------------------------- + // + // Overridden Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + * A pretty printer for SortField that lists the sort fields and their + * options. + */ + /* override public function toString():String + { + return ""; + } */ + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function initializeDefaultCompareFunction(obj:Object):void + { + // if the compare function is not already set then we can set it + if (!usingCustomCompareFunction) + { + if (_sortCompareType) + { + //Attempt to set the compare function based on the sortCompareType + if (updateSortCompareType() == true) + { + return; + } + } + + if (numeric == true) + _compareFunction = numericCompare; + else if (caseInsensitive || numeric == false) + _compareFunction = stringCompare; + else + { + // we need to introspect the data a little bit + var value:Object; + if (_name) + { + value = getSortFieldValue(obj); + } + //this needs to be an == null check because !value will return true + //where value == 0 or value == false + if (value == null) + { + value = obj; + } + + var typ:String = typeof(value); + switch (typ) + { + case "string": + _compareFunction = stringCompare; + break; + case "object": + if (value is Date) + { + _compareFunction = dateCompare; + } + else + { + _compareFunction = stringCompare; + var test:String; + try + { + test = value.toString(); + } + catch(error2:Error) + { + } + if (!test || test == "[object Object]") + { + _compareFunction = nullCompare; + } + } + break; + case "xml": + _compareFunction = xmlCompare; + break; + case "boolean": + case "number": + _compareFunction = numericCompare; + break; + } + } // else + } // if + } */ + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* public function reverse():void + { + descending = !descending; + } */ + + + /** + * @inheritDoc + * + * @langversion 3.0 + * @playerversion Flash 11.8 + * @playerversion AIR 3.8 + * @productversion Royale 0.9.4 + */ + /* public function updateSortCompareType():Boolean + { + if (!_sortCompareType) + { + return false; + } + + + //Lookup the sortCompareType by its SortFieldCompareTypes value and set the associated compare method. + switch(_sortCompareType) + { + case SortFieldCompareTypes.DATE: + { + _compareFunction = dateCompare; + + return true; + } + + case SortFieldCompareTypes.NULL: + { + _compareFunction = nullCompare; + + return true; + } + + case SortFieldCompareTypes.NUMERIC: + { + _compareFunction = numericCompare; + + return true; + } + + case SortFieldCompareTypes.STRING: + { + _compareFunction = stringCompare; + + return true; + } + + case SortFieldCompareTypes.XML: + { + _compareFunction = xmlCompare; + + return true; + } + } + + + return false; + } + + + public function objectHasSortField(object:Object):Boolean + { + return getSortFieldValue(object) !== undefined; + } */ + + + //-------------------------------------------------------------------------- + // + // Protected Methods + // + //-------------------------------------------------------------------------- + + /* protected function getSortFieldValue(obj:Object):* + { + var result:* = undefined; + + try + { + result = obj[_name]; + } + catch(error:Error) + { + } + + return result; + } */ + + //-------------------------------------------------------------------------- + // + // Private Methods + // + //-------------------------------------------------------------------------- + + /* private function nullCompare(a:Object, b:Object):int + { + var left:Object; + var right:Object; + + var found:Boolean = false; + + // return 0 (ie equal) if both are null + if (a == null && b == null) + { + return 0; + } + + // we need to introspect the data a little bit + if (_name) + { + left = getSortFieldValue(a); + right = getSortFieldValue(b); + } + + // return 0 (ie equal) if both are null + if (left == null && right == null) + return 0; + + if (left == null && !_name) + left = a; + + if (right == null && !_name) + right = b; + + + var typeLeft:String = typeof(left); + var typeRight:String = typeof(right); + + + if (typeLeft == "string" || typeRight == "string") + { + found = true; + _compareFunction = stringCompare; + } + else if (typeLeft == "object" || typeRight == "object") + { + if (left is Date || right is Date) + { + found = true; + _compareFunction = dateCompare; + } + } + else if (typeLeft == "xml" || typeRight == "xml") + { + found = true; + _compareFunction = xmlCompare; + } + else if (typeLeft == "number" || typeRight == "number" + || typeLeft == "boolean" || typeRight == "boolean") + { + found = true; + _compareFunction = numericCompare; + } + + if (found) + { + return _compareFunction(left, right); + } + else + { + var message:String = ""; + resourceManager.getString( + "collections", "noComparatorSortField", [ name ]); + throw new SortError(message); + } + } */ + + /** + * Pull the numbers from the objects and call the implementation. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* private function numericCompare(a:Object, b:Object):int + { + var fa:Number = _name == null ? Number(a) : Number(getSortFieldValue(a)); + var fb:Number = _name == null ? Number(b) : Number(getSortFieldValue(b)); + + return ObjectUtil.numericCompare(fa, fb); + } */ + + /** + * Pull the date objects from the values and compare them. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* private function dateCompare(a:Object, b:Object):int + { + var fa:Date = _name == null ? a as Date : getSortFieldValue(a) as Date; + var fb:Date = _name == null ? b as Date : getSortFieldValue(b) as Date; + + return ObjectUtil.dateCompare(fa, fb); + } */ + + /** + * Pull the strings from the objects and call the implementation. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* protected function stringCompare(a:Object, b:Object):int + { + var fa:String = _name == null ? String(a) : String(getSortFieldValue(a)); + var fb:String = _name == null ? String(b) : String(getSortFieldValue(b)); + + return ObjectUtil.stringCompare(fa, fb, _caseInsensitive); + } */ + + /** + * Pull the values out fo the XML object, then compare + * using the string or numeric comparator depending + * on the numeric flag. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.4 + */ + /* protected function xmlCompare(a:Object, b:Object):int + { + var sa:String = _name == null ? a.toString() : getSortFieldValue(a).toString(); + var sb:String = _name == null ? b.toString() : getSortFieldValue(b).toString(); + + if (numeric == true) + { + return ObjectUtil.numericCompare(parseFloat(sa), parseFloat(sb)); + } + else + { + return ObjectUtil.stringCompare(sa, sb, _caseInsensitive); + } + } */ +} +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/error/SortError.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/error/SortError.as new file mode 100644 index 0000000000..fd82dc8c6c --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/error/SortError.as @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package mx.collections.errors +{ + +/** + * This error is thrown when a Sort class is not configured properly; + * for example, if the find criteria are invalid. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Flex 3 + */ +public class SortError extends Error +{ + /* include "../../core/Version.as"; */ + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructor. + * + * @param message A message providing information about the error cause. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Flex 3 + */ + public function SortError(message:String) + { + super(message); + } +} + +}