Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated PagedList to contain more of the paging functionality

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

0 comments on commit 53d80d4

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