Skip to content
Browse files

Updated PagedList to contain more of the paging functionality

Updated the main app to not fetch pages based on IPE
  • Loading branch information...
1 parent a5952a3 commit 53d80d41d79abaf99cab79de6c64d2faab8c6dfd @jamesward committed Mar 31, 2011
View
22 .actionScriptProperties
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<actionScriptProperties analytics="false" mainApplicationPath="DataPaging.mxml" projectUUID="d7f0eb4d-4ff8-4af8-a67e-e0ebc32f2be2" version="10">
+ <compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="bin-debug" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
+ <compilerSourcePath/>
+ <libraryPath defaultLinkType="0">
+ <libraryPathEntry kind="4" path="">
+ <excludedEntries>
+ <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flex.swc" useDefaultLinkType="false"/>
+ <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/core.swc" useDefaultLinkType="false"/>
+ </excludedEntries>
+ </libraryPathEntry>
+ <libraryPathEntry kind="1" linkType="1" path="libs"/>
+ </libraryPath>
+ <sourceAttachmentPath/>
+ </compiler>
+ <applications>
+ <application path="DataPaging.mxml"/>
+ </applications>
+ <modules/>
+ <buildCSSFiles/>
+ <flashCatalyst validateFlashCatalystCompatibility="false"/>
+</actionScriptProperties>
View
2 .flexProperties
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<flexProperties enableServiceManager="false" flexServerFeatures="0" flexServerType="0" toolCompile="true" useServerFlexSDK="false" version="2"/>
View
18 .project
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>DataPaging</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.adobe.flexbuilder.project.flexbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.adobe.flexbuilder.project.flexnature</nature>
+ <nature>com.adobe.flexbuilder.project.actionscriptnature</nature>
+ </natures>
+</projectDescription>
View
3 .settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Tue Mar 22 08:27:23 MDT 2011
+eclipse.preferences.version=1
+encoding/<project>=utf-8
View
0 src/history/history.css → html-template/history/history.css
File renamed without changes.
View
0 src/history/history.js → html-template/history/history.js
File renamed without changes.
View
0 src/history/historyFrame.html → html-template/history/historyFrame.html
File renamed without changes.
View
213 src/DataPaging.html → html-template/index.template.html
@@ -1,108 +1,105 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<!-- saved from url=(0014)about:internet -->
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
- <!--
- Smart developers always View Source.
-
- This application was built using Adobe Flex, an open source framework
- for building rich Internet applications that get delivered via the
- Flash Player or to desktops via Adobe AIR.
-
- Learn more about Flex at http://flex.org
- // -->
- <head>
- <title>DataPaging</title>
- <meta name="google" value="notranslate">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <!-- Include CSS to eliminate any default margins/padding and set the height of the html element and
- the body element to 100%, because Firefox, or any Gecko based browser, interprets percentage as
- the percentage of the height of its parent container, which has to be set explicitly. Fix for
- Firefox 3.6 focus border issues. Initially, don't display flashContent div so it won't show
- if JavaScript disabled.
- -->
- <style type="text/css" media="screen">
- html, body { height:100%; }
- body { margin:0; padding:0; overflow:auto; text-align:center;
- background-color: #ffffff; }
- object:focus { outline:none; }
- #flashContent { display:none; }
- </style>
-
- <!-- Enable Browser History by replacing useBrowserHistory tokens with two hyphens -->
- <!-- BEGIN Browser History required section ${useBrowserHistory}>
- <link rel="stylesheet" type="text/css" href="history/history.css" />
- <script type="text/javascript" src="history/history.js"></script>
- <!${useBrowserHistory} END Browser History required section -->
-
- <script type="text/javascript" src="swfobject.js"></script>
- <script type="text/javascript">
- // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
- var swfVersionStr = "10.1.0";
- // To use express install, set to playerProductInstall.swf, otherwise the empty string.
- var xiSwfUrlStr = "${expressInstallSwf}";
- var flashvars = {};
- var params = {};
- params.quality = "high";
- params.bgcolor = "#ffffff";
- params.allowscriptaccess = "sameDomain";
- params.allowfullscreen = "true";
- var attributes = {};
- attributes.id = "DataPaging";
- attributes.name = "DataPaging";
- attributes.align = "middle";
- swfobject.embedSWF(
- "DataPaging.swf", "flashContent",
- "100%", "100%",
- swfVersionStr, xiSwfUrlStr,
- flashvars, params, attributes);
- // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
- swfobject.createCSS("#flashContent", "display:block;text-align:left;");
- </script>
- </head>
- <body>
- <!-- SWFObject's dynamic embed method replaces this alternative HTML content with Flash content when enough
- JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
- when JavaScript is disabled.
- -->
- <div id="flashContent">
- <p>
- To view this page ensure that Adobe Flash Player version
- 10.1.0 or greater is installed.
- </p>
- <script type="text/javascript">
- var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
- document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
- + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
- </script>
- </div>
-
- <noscript>
- <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="DataPaging">
- <param name="movie" value="DataPaging.swf" />
- <param name="quality" value="high" />
- <param name="bgcolor" value="#ffffff" />
- <param name="allowScriptAccess" value="sameDomain" />
- <param name="allowFullScreen" value="true" />
- <!--[if !IE]>-->
- <object type="application/x-shockwave-flash" data="DataPaging.swf" width="100%" height="100%">
- <param name="quality" value="high" />
- <param name="bgcolor" value="#ffffff" />
- <param name="allowScriptAccess" value="sameDomain" />
- <param name="allowFullScreen" value="true" />
- <!--<![endif]-->
- <!--[if gte IE 6]>-->
- <p>
- Either scripts and active content are not permitted to run or Adobe Flash Player version
- 10.1.0 or greater is not installed.
- </p>
- <!--<![endif]-->
- <a href="http://www.adobe.com/go/getflashplayer">
- <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
- </a>
- <!--[if !IE]>-->
- </object>
- <!--<![endif]-->
- </object>
- </noscript>
- </body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!-- saved from url=(0014)about:internet -->
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+ <!--
+ Smart developers always View Source.
+
+ This application was built using Adobe Flex, an open source framework
+ for building rich Internet applications that get delivered via the
+ Flash Player or to desktops via Adobe AIR.
+
+ Learn more about Flex at http://flex.org
+ // -->
+ <head>
+ <title>${title}</title>
+ <meta name="google" value="notranslate" />
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <!-- Include CSS to eliminate any default margins/padding and set the height of the html element and
+ the body element to 100%, because Firefox, or any Gecko based browser, interprets percentage as
+ the percentage of the height of its parent container, which has to be set explicitly. Fix for
+ Firefox 3.6 focus border issues. Initially, don't display flashContent div so it won't show
+ if JavaScript disabled.
+ -->
+ <style type="text/css" media="screen">
+ html, body { height:100%; }
+ body { margin:0; padding:0; overflow:auto; text-align:center;
+ background-color: ${bgcolor}; }
+ object:focus { outline:none; }
+ #flashContent { display:none; }
+ </style>
+
+ <!-- Enable Browser History by replacing useBrowserHistory tokens with two hyphens -->
+ <!-- BEGIN Browser History required section ${useBrowserHistory}>
+ <link rel="stylesheet" type="text/css" href="history/history.css" />
+ <script type="text/javascript" src="history/history.js"></script>
+ <!${useBrowserHistory} END Browser History required section -->
+
+ <script type="text/javascript" src="swfobject.js"></script>
+ <script type="text/javascript">
+ // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
+ var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";
+ // To use express install, set to playerProductInstall.swf, otherwise the empty string.
+ var xiSwfUrlStr = "${expressInstallSwf}";
+ var flashvars = {};
+ var params = {};
+ params.quality = "high";
+ params.bgcolor = "${bgcolor}";
+ params.allowscriptaccess = "sameDomain";
+ params.allowfullscreen = "true";
+ var attributes = {};
+ attributes.id = "${application}";
+ attributes.name = "${application}";
+ attributes.align = "middle";
+ swfobject.embedSWF(
+ "${swf}.swf", "flashContent",
+ "${width}", "${height}",
+ swfVersionStr, xiSwfUrlStr,
+ flashvars, params, attributes);
+ // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
+ swfobject.createCSS("#flashContent", "display:block;text-align:left;");
+ </script>
+ </head>
+ <body>
+ <!-- SWFObject's dynamic embed method replaces this alternative HTML content with Flash content when enough
+ JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
+ when JavaScript is disabled.
+ -->
+ <div id="flashContent">
+ <p>
+ To view this page ensure that Adobe Flash Player version
+ ${version_major}.${version_minor}.${version_revision} or greater is installed.
+ </p>
+ <script type="text/javascript">
+ var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
+ document.write("<a href='http://www.adobe.com/go/getflashplayer'>Get Adobe Flash player</a>" );
+ </script>
+ </div>
+
+ <noscript>
+ <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="${width}" height="${height}" id="${application}">
+ <param name="movie" value="${swf}.swf" />
+ <param name="quality" value="high" />
+ <param name="bgcolor" value="${bgcolor}" />
+ <param name="allowScriptAccess" value="sameDomain" />
+ <param name="allowFullScreen" value="true" />
+ <!--[if !IE]>-->
+ <object type="application/x-shockwave-flash" data="${swf}.swf" width="${width}" height="${height}">
+ <param name="quality" value="high" />
+ <param name="bgcolor" value="${bgcolor}" />
+ <param name="allowScriptAccess" value="sameDomain" />
+ <param name="allowFullScreen" value="true" />
+ <!--<![endif]-->
+ <!--[if gte IE 6]>-->
+ <p>
+ Either scripts and active content are not permitted to run or Adobe Flash Player version
+ ${version_major}.${version_minor}.${version_revision} or greater is not installed.
+ </p>
+ <!--<![endif]-->
+ <a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash Player</a>
+ <!--[if !IE]>-->
+ </object>
+ <!--<![endif]-->
+ </object>
+ </noscript>
+ </body>
+</html>
View
0 src/playerProductInstall.swf → html-template/playerProductInstall.swf
File renamed without changes.
View
0 src/swfobject.js → html-template/swfobject.js
File renamed without changes.
View
48 src/DataPaging.mxml
@@ -1,54 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:local="*">
+ xmlns:paging="com.jamesward.paging.*">
<fx:Script>
- <![CDATA[
- import mx.collections.errors.ItemPendingError;
+ import mx.collections.errors.ItemPendingError;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
- private var fetchedPages:Dictionary = new Dictionary();
-
private function handleCreatePendingItemFunction(index:int, ipe:ItemPendingError):Object {
- var page:uint = Math.floor(index / pageSize);
- if (fetchedPages[page] == undefined)
- {
- // what if the request tries to get more data than is available?
- var numItemsToFetch:uint = pageSize;
- var startIndex:uint = pageSize * page;
- var endIndex:uint = startIndex + pageSize - 1;
- if (endIndex > items.length)
- {
- numItemsToFetch = items.length - startIndex;
- }
- var asyncToken:AsyncToken = ro.getElements(startIndex, numItemsToFetch);
- asyncToken.addResponder(new AsyncResponder(function result(event:ResultEvent, token:Object = null):void {
- for (var i:uint = 0; i < event.result.length; i++)
- {
- items.setItemAt(event.result[i], token + i);
- }
- }, function fault(event:FaultEvent, token:Object = null):void {
- trace(event.fault.faultString);
- }, startIndex));
- fetchedPages[page] = true;
- }
- return null;
+ return {};
}
- ]]>
</fx:Script>
<fx:Declarations>
- <fx:Number id="pageSize">100</fx:Number>
- <local:PagedList id="items" length="100000"/>
- <s:AsyncListView id="asyncListView" list="{items}" createPendingItemFunction="handleCreatePendingItemFunction"/>
+ <paging:PagedList id="pagedList" length="100000" pageSize="100">
+ <paging:pageNeeded>
+ var asyncToken:AsyncToken = ro.getElements(event.pagePositionStart, (event.pagePositionEnd - event.pagePositionStart + 1));
+ asyncToken.addResponder(new AsyncResponder(function result(event:ResultEvent, token:Object = null):void {
+ pagedList.setPageAt(event.result as Array, token.pagePositionStart);
+ }, function fault(event:FaultEvent, token:Object = null):void {
+ trace(event.fault.faultString);
+ }, event));
+ </paging:pageNeeded>
+ </paging:PagedList>
+ <s:AsyncListView id="asyncListView" list="{pagedList}" createPendingItemFunction="handleCreatePendingItemFunction"/>
<s:RemoteObject id="ro" destination="census" endpoint="http://www.jamesward.com/census2-tests/messagebroker/amf"/>
</fx:Declarations>
- <s:DataGrid dataProvider="{asyncListView}" width="100%" height="100%">
+ <s:DataGrid id="dg" dataProvider="{asyncListView}" width="100%" height="100%">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="id"/>
View
41 src/PagedList.as → src/com/jamesward/paging/PagedList.as
@@ -5,19 +5,22 @@
* Time: 3:49:34 AM
* To change this template use File | Settings | File Templates.
*/
-package
+package com.jamesward.paging
{
import flash.events.EventDispatcher;
-
import flash.utils.Dictionary;
import mx.collections.ArrayList;
import mx.collections.IList;
import mx.collections.ListCollectionView;
import mx.collections.errors.ItemPendingError;
import mx.events.CollectionEvent;
+import mx.events.CollectionEventKind;
+import mx.events.PropertyChangeEvent;
+import mx.events.PropertyChangeEventKind;
[Event(name="collectionChange", type="mx.events.CollectionEvent")]
+[Event(name="pageNeeded", type="com.jamesward.paging.PagedListEvent")]
public class PagedList extends EventDispatcher implements IList
{
@@ -26,10 +29,16 @@ public class PagedList extends EventDispatcher implements IList
private var _list:ArrayList;
private var fetchedItems:Dictionary;
+
+ private var fetchedPages:Dictionary;
+ public var pageSize:uint;
+
public function PagedList()
{
fetchedItems = new Dictionary();
+ fetchedPages = new Dictionary();
+ pageSize = 100;
}
private function handleCollectionChangeEvent(event:CollectionEvent):void {
@@ -54,12 +63,36 @@ public class PagedList extends EventDispatcher implements IList
public function addItemAt(item:Object, index:int):void {
_list.addItemAt(item, index);
}
+
+ public function setPageAt(items:Array, index:int):void {
+ for (var i:uint = 0; i < items.length; i++) {
+ setItemAt(items[i], index + i);
+ }
+ }
public function getItemAt(index:int, prefetch:int = 0):Object {
if (fetchedItems[index] == undefined)
{
- throw new ItemPendingError("itemPending");
+ var page:uint = Math.floor(index / pageSize);
+
+ if (fetchedPages[page] == undefined)
+ {
+ // what if the request tries to get more data than is available?
+ var numItemsToFetch:uint = pageSize;
+ var startIndex:uint = pageSize * page;
+ var endIndex:uint = startIndex + pageSize - 1;
+ if (endIndex > length)
+ {
+ numItemsToFetch = length - startIndex;
+ }
+
+ fetchedPages[page] = true;
+
+ dispatchEvent(new PagedListEvent(PagedListEvent.PAGE_NEEDED, startIndex, endIndex));
+ }
+
+ throw new ItemPendingError("itemPending");
}
return _list.getItemAt(index, prefetch);
@@ -82,7 +115,7 @@ public class PagedList extends EventDispatcher implements IList
}
public function setItemAt(item:Object, index:int):Object {
- fetchedItems[index] = true;
+ fetchedItems[index] = true;
return _list.setItemAt(item, index);
}
View
19 src/com/jamesward/paging/PagedListEvent.as
@@ -0,0 +1,19 @@
+package com.jamesward.paging
+{
+ import flash.events.Event;
+
+ public class PagedListEvent extends Event
+ {
+ public static const PAGE_NEEDED:String = "pageNeeded";
+
+ public var pagePositionStart:uint;
+ public var pagePositionEnd:uint;
+
+ public function PagedListEvent(type:String, pagePositionStart:uint, pagePositionEnd:uint)
+ {
+ super(type, false, false);
+ this.pagePositionStart = pagePositionStart;
+ this.pagePositionEnd = pagePositionEnd;
+ }
+ }
+}

0 comments on commit 53d80d4

Please sign in to comment.
Something went wrong with that request. Please try again.