//////////////////////////////////////////////////////////////////////////////// // // 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.controls { import flash.events.KeyboardEvent; import flash.filesystem.File; import mx.controls.dataGridClasses.DataGridColumn; import mx.controls.fileSystemClasses.FileSystemControlHelper; import mx.controls.fileSystemClasses.FileSystemDataGridNameColumnRenderer; import mx.core.ClassFactory; import mx.core.IUITextField; import mx.core.ScrollPolicy; import mx.core.mx_internal; import mx.events.ListEvent; import mx.formatters.DateFormatter; use namespace mx_internal; //-------------------------------------- // Events //-------------------------------------- /** * Dispatched when the selected directory displayed by this control * changes for any reason. * * @eventType mx.events.FileEvent.DIRECTORY_CHANGE * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ [Event(name="directoryChange", type="mx.events.FileEvent")] /** * Dispatched when the user tries to change * the directory displayed by this control. * *
The user can try to change the directory * by double-clicking a subdirectory, * by pressing Enter or Ctrl-Down when a subdirectory is selected, * by pressing Ctrl-Up when the control isn't displaying * the COMPUTER directory, * by pressing Ctrl-Left when there is a previous directory * in the history list to navigate back to, * or by pressing Ctrl-Right when there is a next directory * in the history list to navigate forward to.
* *This event is cancelable.
* If you call event.preventDefault()
,
* the directory is not changed.
After the directory
property has changed
* and the dataProvider
contains File instances
* for the items in the new directory,
* the directoryChange
event is dispatched.
directoryIcon="@Embed(source='directoryIcon.jpg');"
*
* @default TreeNodeIcon
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name="directoryIcon", type="Class", format="EmbeddedFile", inherit="no")]
/**
* Specifies the icon that indicates a file.
* The default icon is located in the Assets.swf file.
* In MXML, you can use the following syntax to set this property:
* fileIcon="@Embed(source='fileIcon.jpg');"
*
* @default TreeNodeIcon
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name="fileIcon", type="Class", format="EmbeddedFile", inherit="no")]
//--------------------------------------
// Other metadata
//--------------------------------------
[IconFile("FileSystemDataGrid.png")]
[ResourceBundle("aircontrols")]
/**
* The FileSystemDataGrid control lets you display the contents of a
* single file system directory in a data grid format.
*
* The information displayed for each item consists of its name
* (with optional generic icon), type, size, creation date,
* and modification date.
* To do this, FileSystemDataGrid automatically creates five columns
* (DataGridColumn instances) -- nameColumn
, typeColumn
,
* sizeColumn
, creationDateColumn
,
* and modificationDateColumn
-- and sets
* the columns
property to an array of these five instances.
* Each column instance is automatically configured to have an
* appropriate labelFunction
,
* sortCompareFunction
, etc.
* If you don't want all five columns, or if you want to change the
* order, reset the columns
property.
* If you want to customize a column, such as by changing its
* labelFunction
, simply reassign that property
* on the appropriate column object.
To change the displayed data, rather than using the dataProvider
property,
* you set the directory
property.
* The control then automatically populates the dataProvider
* property by enumerating the contents of that directory.
* You should not set the dataProvider
yourself.
You set the directory
property to a File instance,
* as the following example shows:
<mx:FileSystemDataGrid directory="{File.desktopDirectory}"/>* *
You can set the enumerationMode
property to specify
* whether to show files, subdirectories, or both.
* There are three ways to show both: directories first,
* files first, or intermixed.
You can set the extensions
property
* to filter the displayed items so that only files
* with the specified extensions appear.
* The showHidden
property determines whether the control
* displays files and subdirectories that the operating system
* normally hides.
* You can specify an additional filterFunction
* to perform custom filtering, and a nameCompareFunction
* to perform custom sorting.
Because AIR does not support file system notifications,
* this control does not automatically refresh if a file or
* subdirectory is created, deleted, moved, or renamed;
* in other words, it can display an out-of-date view of the file system.
* However, you can call refresh()
to re-enumerate
* the current directory
.
* You could, for example, choose to do this when you have
* performed a file operation that you know causes the control's
* view to become out-of-date, or when the user deactivates
* and reactivates your application.
You can use the showIcons
property
* to show or hide icons, and the showExtensions
* property to show or hide file extensions.
The control provides two methods, findItem()
* and findIndex()
, which you can use to search the
* displayed files and subdirectories to find the one
* with a specified nativePath
.
Two properties, selectedPath
* and selectedPaths
, work similarly
* to selectedItem
and selectedItems
* or selectedIndex
and selectedIndices
,
* but let you specify the selection via nativePath
* strings.
* These are very useful if you need to display a directory
* with particular items preselected, since in this case
* you don't yet have the File items that the control will create
* when it enumerates the directory, and you don't know what
* their indices will be.
The control allows the user to navigate to other directories
* using the mouse or keyboard.
* The user can try to change the directory
* by double-clicking a subdirectory,
* by pressing Enter or Ctrl-Down when a subdirectory is selected,
* by pressing Ctrl-Up when the control isn't displaying
* the COMPUTER directory, by pressing Ctrl-Left when there is
* a "previous" directory to navigate back to, or by pressing Ctrl-Right
* when there is a "next" directory to navigate forward to.
* If the user attempts to change the directory being displayed,
* the control dispatches a cancelable directoryChanging
event.
* If you don't cancel this event by calling
* event.preventDefault()
, the control displays the
* contents of the new directory and the directory
* property changes.
* Whenever the directory
property changes, for any reason,
* the controls dispatches a directoryChange
event
* to let you know.
In order to support "Up" and "Down" controls, the FileSystemList
* has canNavigateUp
and canNavigateDown
* properties and navigateUp()
and navigateDown()
* methods. There is also a navigateTo()
for navigating
* to an arbitrary directory.
The control keeps track of the directories to which the user
* has navigated, in order to make it easy for you to support
* "Back" and "Forward" controls.
* For more information, see the backHistory
,
* forwardHistory
, canNavigateBack
,
* and canNavigateForward
properties, and the
* navigateBack()
and navigateForward()
methods.
Note: The icons displayed for each item are generic file and directory
* icons which you can set using the fileIcon
* and directoryIcon
styles.
* Flex's list-based controls currently support displaying
* only embedded icons, not icons read at runtime.
* Therefore the actual file system icons displayed in the operating system
* are not displayed in a FileSystemDataGrid, even though they are
* accessible in AIR via the icon
property of a File.
The <mx:FileSystemDataGrid>
tag inherits all of the tag
* attributes of its superclass and adds the following tag attributes:
* <mx:FileSystemDataGrid * Properties * dateFormatString="" * directory="null" * enumerationMode="directoriesFirst" * extensions="null" * filterFunction="null" * nameCompareFunction="null" * selectedPath="null" * selectedPaths="null" * showExtensions="true" * showHidden="false" * showIcons="true" * * Styles * directoryIcon="TreeNodeIcon" * fileIcon="TreeNodeIcon" * * Events * directoryChange="No default" * directoryChanging="No default" * fileChoose="No default" * /> ** * @see flash.filesystem.File * * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public class FileSystemDataGrid extends DataGrid { include "../core/Version.as"; //-------------------------------------------------------------------------- // // Class constants // //-------------------------------------------------------------------------- /** * @copy mx.controls.FileSystemList#COMPUTER * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public static const COMPUTER:File = FileSystemControlHelper.COMPUTER; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function FileSystemDataGrid() { super(); helper = new FileSystemControlHelper(this, false); doubleClickEnabled = true; horizontalScrollPolicy = ScrollPolicy.AUTO; iconFunction = helper.fileIconFunction; addEventListener(ListEvent.ITEM_DOUBLE_CLICK, itemDoubleClickHandler); dateFormatter.formatString = dateFormatString; // Set the initial dataProvider by enumerating the root directories. directory = COMPUTER; } //-------------------------------------------------------------------------- // // Variables // //-------------------------------------------------------------------------- /** * @private * An undocumented class that implements functionality * shared by various file system components. */ mx_internal var helper:FileSystemControlHelper; /** * The DateFormatter object used to format the dates * in the Created and Modified columns. * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ mx_internal var dateFormatter:DateFormatter = new DateFormatter(); //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- //---------------------------------- // backHistory //---------------------------------- [Bindable("historyChanged")] /** * An Array of File objects representing directories * to which the user can navigate backward. * *
The first item in this Array is the next directory backward * in the history list. * The last item is the directory furthest backward * in the history list.
* *This Array may contain a null
item, which represents
* the non-existent directory whose contents are root directories
* such as C:\ and D:\ on Microsoft Windows.
The following example shows how to use this property * along with the FileSystemHistoryButton control * to implement a back button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Back" * enabled="{fileSystemViewer.canNavigateBack}" * dataProvider="{fileSystemViewer.backHistory}" * click="fileSystemViewer.navigateBack();" * itemClick="fileSystemViewer.navigateBack(event.index);"/>* * @default [] * * @see #canNavigateBack * @see #navigateBack() * @see mx.controls.FileSystemHistoryButton * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get backHistory():Array { return helper.backHistory; } //---------------------------------- // canNavigateBack //---------------------------------- [Bindable("historyChanged")] /** * A flag which is
true
if there is at least one directory
* in the history list to which the user can navigate backward.
*
* The following example shows how to use this property * along with the FileSystemHistoryButton control * to implement a back button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Back" * enabled="{fileSystemViewer.canNavigateBack}" * dataProvider="{fileSystemViewer.backHistory}" * click="fileSystemViewer.navigateBack();" * itemClick="fileSystemViewer.navigateBack(event.index);"/>* * @default false * * @see #backHistory * @see #navigateBack() * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get canNavigateBack():Boolean { return helper.canNavigateBack; } //---------------------------------- // canNavigateDown //---------------------------------- [Bindable("change")] [Bindable("directoryChanged")] /** * A flag which is
true
if the user can navigate down
* into a selected directory.
* This flag is false
when there is no selected item
* or when the selected item is a file rather than a directory.
*
* The following example shows how to use this property * along with the Button control:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:Button label="Open" * enabled="{fileSystemViewer.canNavigateDown}" * click="fileSystemViewer.navigateDown();"/>* * @default false * * @see #navigateDown() * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get canNavigateDown():Boolean { return helper.canNavigateDown; } //---------------------------------- // canNavigateForward //---------------------------------- [Bindable("historyChanged")] /** * A flag which is
true
if there is at least one directory
* in the history list to which the user can navigate forward.
*
* The following example shows how to use this property * along with the FileSystemHistoryButton control * to implement a forward button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Forward" * enabled="{fileSystemViewer.canNavigateForward}" * dataProvider="{fileSystemViewer.forwardHistory}" * click="fileSystemViewer.navigateForward();" * itemClick="fileSystemViewer.navigateForward(event.index);"/>* * @default false * * @see #forwardHistory * @see #navigateForward() * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get canNavigateForward():Boolean { return helper.canNavigateForward; } //---------------------------------- // canNavigateUp //---------------------------------- [Bindable("directoryChanged")] /** * A flag which is
true
if the user can navigate up
* to a parent directory.
* This flag is only false
when this control is
* displaying the root directories such as C:\ and D:\ on Microsoft Windows.
* (This is the case in which the directory
* property is COMPUTER
.)
*
* The following example shows how to use this property * along with the Button control:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:Button label="Up" * enabled="{fileSystemViewer.canNavigateUp}" * click="fileSystemViewer.navigateUp();"/>* * @default false * * @see #navigateUp() * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get canNavigateUp():Boolean { return helper.canNavigateUp; } //---------------------------------- // creationDateColumn //---------------------------------- /** * The DataGridColumn representing the Created column. * The FileSystemDataGrid control automatically creates this column. * *
You can set properties such as
* creationDateColumn.width
to customize this column.
* To remove this column entirely, or to change the column order,
* set the columns
property to an array such as
* [ nameColumn, modificationDateColumn, sizeColumn ]
.
formatString
* of an internal DateFormatter that this control creates.
*
* @see mx.formatters.DateFormatter#formatString
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get dateFormatString():String
{
return _dateFormatString;
}
/**
* @private
*/
public function set dateFormatString(value:String):void
{
dateFormatStringOverride = value;
_dateFormatString = value != null ?
value :
resourceManager.getString(
"aircontrols",
"fileSystemDataGrid_dateFormatString");
dateFormatter.formatString = _dateFormatString != null ?
_dateFormatString :
"";
invalidateList();
}
//----------------------------------
// directory
//----------------------------------
[Bindable("directoryChanged")]
/**
* @copy mx.controls.FileSystemList#directory
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get directory():File
{
return helper.directory;
}
/**
* @private
*/
public function set directory(value:File):void
{
helper.directory = value;
}
//----------------------------------
// enumerationMode
//----------------------------------
/**
* @copy mx.controls.FileSystemList#enumerationMode
*
* @default FileSystemEnumerationMode.DIRECTORIES_FIRST
*
* @see mx.controls.FileSystemEnumerationMode
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get enumerationMode():String
{
return helper.enumerationMode;
}
/**
* @private
*/
public function set enumerationMode(value:String):void
{
helper.enumerationMode = value;
}
//----------------------------------
// extensions
//----------------------------------
/**
* @copy mx.controls.FileSystemList#extensions
*
* @default null
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get extensions():Array /* of String */
{
return helper.extensions;
}
/**
* @private
*/
public function set extensions(value:Array /* of String */):void
{
helper.extensions = value;
}
//----------------------------------
// filterFunction
//----------------------------------
/**
* @copy mx.controls.FileSystemList#filterFunction
*
* @default null
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get filterFunction():Function
{
return helper.filterFunction;
}
/**
* @private
*/
public function set filterFunction(value:Function):void
{
helper.filterFunction = value;
}
//----------------------------------
// forwardHistory
//----------------------------------
[Bindable("historyChanged")]
/**
* An Array of File objects representing directories
* to which the user can navigate forward.
*
* The first item in this Array is the next directory forward * in the history list. * The last item is the directory furthest forward * in the history list.
* *This Array may contain a null
item, which represents
* the non-existent directory whose contents are root directories
* such as C:\ and D:\ on Windows.
The following example shows how to use this property * along with the FileSystemHistoryButton control to implement a forward button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Forward" * enabled="{fileSystemViewer.canNavigateForward}" * dataProvider="{fileSystemViewer.forwardHistory}" * click="fileSystemViewer.navigateForward();" * itemClick="fileSystemViewer.navigateForward(event.index);"/>* * @default [] * * @see mx.controls.FileSystemHistoryButton * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get forwardHistory():Array { return helper.forwardHistory; } //---------------------------------- // modificationDateColumn //---------------------------------- /** * The DataGridColumn representing the Modified column. * The FileSystemDataGrid control automatically creates this column. * *
You can set properties such as
* modificationDateColumn.width
to customize this column.
* To remove this column entirely, or to change the column order,
* set the columns
property to an array such as
* [ nameColumn, modificationDateColumn, sizeColumn ]
.
You can set properties such as nameColumn.width
* to customize this column.
* To remove this column entirely, or to change the column order,
* set the columns
property to an array such as
* [ nameColumn, modificationDateColumn, sizeColumn ]
.
You can set properties such as sizeColumn.width
* to customize this column.
* To remove this column entirely, or to change the column order,
* set the columns
property to an array such as
* [ nameColumn, modificationDateColumn, sizeColumn ]
.
You can set properties such as typeColumn.width
* to customize this column.
* To remove this column entirely, or to change the column order,
* set the columns
property to an array such as
* [ nameColumn, modificationDateColumn, sizeColumn ]
.
If a subdirectory is not selected, this method does nothing.
* *When this method returns, the directory
property
* contains the File instance for the new directory.
* The dataProvider
property is temporarily
* null
until the new directory has been enumerated.
* After the enumeration, the dataProvider
property
* contains an ArrayCollection of File instances
* for the new directory's contents.
The following example shows how to use this method * along with the Button control to create an open button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:Button label="Open" * enabled="{fileSystemViewer.canNavigateDown}" * click="fileSystemViewer.navigateDown();"/>* * @see #canNavigateDown * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function navigateDown():void { helper.navigateDown(); } /** * Changes this control to display the contents of the next directory * up in the hierarchy. * *
If this control is currently displaying root directories * (such as C: and D: on Microsoft Windows), this method does nothing.
* *When this method returns, the directory
property
* contains the File instance for the new directory.
* The dataProvider
property is temporarily
* null
until the new directory has been enumerated.
* After the enumeration, the dataProvider
property
* contains an ArrayCollection of File instances
* for the new directory's contents.
The following example shows how to use this property * along with the Button control to create an up button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:Button label="Up" * enabled="{fileSystemViewer.canNavigateUp}" * click="fileSystemViewer.navigateUp();"/>* * @see #canNavigateUp * * @langversion 3.0 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function navigateUp():void { helper.navigateUp(); } /** * Changes this control to display the contents of a previously-visited * directory in the
backHistory
array.
*
* If the backHistory
array is empty, or if you specify
* an index that is not in that array, then this method does nothing.
When this method returns, the directory
property
* contains the File instance for the new directory.
* The dataProvider
property is temporarily
* null
until the new directory has been enumerated.
* After the enumeration, the dataProvider
property
* contains an ArrayCollection of File instances
* for the new directory's contents.
The history list is left unchanged. However, the current index
* into it changes, which affects the backHistory
* and forwardHistory
properties.
* They have new values as soon as this method returns.
The following example shows how to use this method * along with the FileSystemHistoryButton control to create a back button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Back" * enabled="{fileSystemViewer.canNavigateBack}" * dataProvider="{fileSystemViewer.backHistory}" * click="fileSystemViewer.navigateBack();" * itemClick="fileSystemViewer.navigateBack(event.index);"/>* * @param index The index in the
backHistory
array
* to navigate to.
* The default is 0, indicating the directory that is "closest back".
*
* @see #backHistory
* @see #canNavigateBack
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function navigateBack(index:int = 0):void
{
helper.navigateBack(index);
}
/**
* Changes this control to display the contents of a previously-visited
* directory in the forwardHistory
array.
*
* If the forwardHistory
array is empty, or if you specify
* an index that is not in that array, then this method does nothing.
When this method returns, the directory
property
* contains the File instance for the new directory.
* The dataProvider
property is temporarily
* null
until the new directory has been enumerated.
* After the enumeration, the dataProvider
property
* contains an ArrayCollection of File instances
* for the new directory's contents.
The history list is left unchanged. However, the current index
* into it changes, which affects the backHistory
* and forwardHistory
properties.
* They have new values as soon as this method returns.
The following example shows how to use this method * along with the FileSystemHistoryButton control to create a forward button:
* ** <mx:FileSystemDataGrid id="fileSystemViewer" directory="{File.desktopDirectory}"/> * <mx:FileSystemHistoryButton label="Forward" * enabled="{fileSystemViewer.canNavigateForward}" * dataProvider="{fileSystemViewer.forwardHistory}" * click="fileSystemViewer.navigateForward();" * itemClick="fileSystemViewer.navigateForward(event.index);"/>* * @param index The index in the
forwardHistory
array
* to navigate to.
* The default is 0, indicating the directory that is "closest forward".
*
* @see #canNavigateForward
* @see #forwardHistory
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function navigateForward(index:int = 0):void
{
helper.navigateForward(index);
}
/**
* @copy mx.controls.FileSystemList#navigateTo()
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function navigateTo(directory:File):void
{
helper.navigateTo(directory);
}
/**
* @copy mx.controls.FileSystemList#refresh()
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function refresh():void
{
helper.refresh();
}
/**
* @copy mx.controls.FileSystemList#clear()
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function clear():void
{
helper.clear();
}
/**
* @private
*/
public function resetHistory(dir:File):void
{
helper.resetHistory(dir);
}
/**
* @private
*/
private function nameSortCompareFunction(item1:File, item2:File):int
{
return helper.directoryEnumeration.fileCompareFunction(item1, item2);
}
/**
* @private
*/
private function typeLabelFunction(item:File,
column:DataGridColumn = null):String
{
// If item is a directory, return "Folder".
if (item.isDirectory)
{
return resourceManager.getString(
"aircontrols", "fileSystemDataGrid_typeFolder");
}
// If item is a file without an extension, return "File".
var extension:String = item.extension;
if (!extension || extension == "")
{
return resourceManager.getString(
"aircontrols", "fileSystemDataGrid_typeFileWithoutExtension");
}
// If item is a file with an extension, return a String like "TXT File".
return resourceManager.getString(
"aircontrols", "fileSystemDataGrid_typeFileWithExtension",
[ extension.toUpperCase() ]);
}
/**
* @private
*/
private function typeSortCompareFunction(item1:File, item2:File):int
{
var typeLabel1:String = typeLabelFunction(item1, null).toUpperCase();
var typeLabel2:String = typeLabelFunction(item2, null).toUpperCase();
if (typeLabel1 < typeLabel2)
return -1;
if (typeLabel1 > typeLabel2)
return 1;
return 0;
}
/**
* @private
*/
private function sizeLabelFunction(item:File,
column:DataGridColumn = null):String
{
var label:String;
if (!item.exists) // item may have been deleted
return "";
try
{
if (item.isDirectory)
{
label = resourceManager.getString(
"aircontrols", "fileSystemDataGrid_sizeFolder");
}
else if (sizeDisplayMode == FileSystemSizeDisplayMode.KILOBYTES)
{
var kb:int = Math.ceil(item.size / 1024);
label = resourceManager.getString(
"aircontrols", "fileSystemDataGrid_sizeKilobytes",
[ kb ]);
}
else if (sizeDisplayMode == FileSystemSizeDisplayMode.BYTES)
{
label = resourceManager.getString(
"aircontrols", "fileSystemDataGrid_sizeBytes",
[ item.size ]);
}
}
catch(e:Error)
{
// item.size throws a File I/O Error for some files,
// such as /etc/master.passwd and /etc/sudoers on a Mac
label = resourceManager.getString(
"aircontrols", "fileSystemDataGrid_sizeFolder");
}
return label;
}
/**
* @private
*/
private function sizeSortCompareFunction(item1:File, item2:File):int
{
var size1:Number;
try
{
size1 = item1.isDirectory ? 0 : item1.size;
}
catch(e1:Error)
{
// item.size throws a File I/O Error for some files,
// such as /etc/master.passwd and /etc/sudoers on a Mac
size1 = 0;
}
var size2:Number;
try
{
size2 = item2.isDirectory ? 0 : item2.size;
}
catch(e2:Error)
{
size2 = 0;
}
if (size1 < size2)
return -1;
if (size1 > size2)
return 1;
return 0;
}
/**
* @private
*/
private function creationDateLabelFunction(
item:File, column:DataGridColumn = null):String
{
if (!item.exists) // item may have been deleted
return "";
var s:String;
try
{
s = dateFormatter.format(item.creationDate);
}
catch (e:Error)
{
// a bad alias on mac will not have a valid creation date
s = "";
}
return s;
}
/**
* @private
*/
private function modificationDateLabelFunction(
item:File, column:DataGridColumn = null):String
{
if (!item.exists) // item may have been deleted
return "";
var s:String;
try
{
s = dateFormatter.format(item.modificationDate);
}
catch (e:Error)
{
// a bad alias on mac will not have a valid mod date
s = "";
}
return s;
}
/**
* @private
*/
private function determineWidthToDisplay(s:String):Number
{
return measureText(s).width + 13;
}
//--------------------------------------------------------------------------
//
// Overridden event handlers
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function keyDownHandler(event:KeyboardEvent):void
{
if (helper.handleKeyDown(event))
return;
super.keyDownHandler(event);
}
//--------------------------------------------------------------------------
//
// Event handlers
//
//--------------------------------------------------------------------------
/**
* @private
*/
protected function itemDoubleClickHandler(event:ListEvent):void
{
helper.itemDoubleClickHandler(event);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Helper classes
//
////////////////////////////////////////////////////////////////////////////////
import flash.display.DisplayObject;
import flash.filesystem.File;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.FileSystemDataGrid;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.controls.listClasses.ListBase;
import mx.core.IDataRenderer;
import mx.core.IFlexDisplayObject;
import mx.core.mx_internal;
import mx.core.UIComponent;
import mx.core.UITextField;
import mx.events.FlexEvent;
import mx.core.IUITextField;
////////////////////////////////////////////////////////////////////////////////
//
// Helper class: CustomDataGridColumn
//
////////////////////////////////////////////////////////////////////////////////
/**
* @private
*/
class CustomDataGridColumn extends DataGridColumn
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*
* @langversion 3.0
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function CustomDataGridColumn(columnName:String = null)
{
super(columnName);
}
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override public function itemToDataTip(data:Object):String
{
return labelFunction(data);
}
}