|
From: <vla...@us...> - 2008-12-23 14:50:31
|
Revision: 920
http://equanda.svn.sourceforge.net/equanda/?rev=920&view=rev
Author: vladimirt
Date: 2008-12-23 14:50:20 +0000 (Tue, 23 Dec 2008)
Log Message:
-----------
EQ-270 - JSPagedLoop component is too slow
Modified Paths:
--------------
trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.java.vm
trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.tml.vm
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPagedLoop.java
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPager.java
trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/JSPagedLoop.tml
Added Paths:
-----------
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/base/PagerConfig.java
Modified: trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.java.vm
===================================================================
--- trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.java.vm 2008-12-23 12:01:07 UTC (rev 919)
+++ trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.java.vm 2008-12-23 14:50:20 UTC (rev 920)
@@ -95,7 +95,7 @@
private boolean caseConversionLower;
@Parameter
- private Translator translator;
+ private Translator<?> translator;
@Inject
private Request request;
Modified: trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.tml.vm
===================================================================
--- trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.tml.vm 2008-12-23 12:01:07 UTC (rev 919)
+++ trunk/equanda-generate/src/main/velocity/t5gui/components/InlinePrimitiveList.tml.vm 2008-12-23 14:50:20 UTC (rev 920)
@@ -7,13 +7,14 @@
<input t:type="TextField" t:id="hiddenDeletedRows" class="nodisplay" />
<!-- @todo should be pagedloop but this is too slow, EQ-270
+ <div class="eqInlPR" t:id="pagedLoop" t:type="loop" source="value" value="current" volatile="true" index="index" rowsPerPage="5" additionalRowCount="prop:additionalRowCount" addRowLinkTitle="${dollar}{equanda-message:Add}" objectCreatorDelegate="prop:this">
+ <t:equanda.formactionlink t:id="Add">${dollar}{equanda-message:Add}</t:equanda.formactionlink>
+-->
<div class="eqInlPR" t:id="pagedLoop" t:type="equanda/JSPagedLoop" source="value" value="current" volatile="true" index="index" rowsPerPage="5" additionalRowCount="prop:additionalRowCount" addRowLinkTitle="${dollar}{equanda-message:Add}" objectCreatorDelegate="prop:this">
<t:parameter name="empty"></t:parameter>
<t:parameter name="bottomBlock">
<t:equanda.formactionlink t:id="Add">${dollar}{equanda-message:Add}</t:equanda.formactionlink>
</t:parameter>
--->
- <div class="eqInlPR" t:id="pagedLoop" t:type="loop" source="value" value="current" volatile="true" index="index" rowsPerPage="5" additionalRowCount="prop:additionalRowCount" addRowLinkTitle="${dollar}{equanda-message:Add}" objectCreatorDelegate="prop:this">
<div class="eqInlPRL">
<a href="javascript:;" id="ed-${dollar}{clientId}-${dollar}{index}" onclick="eqMarkDel( this, '${dollar}{deletedHiddenId}', ${dollar}{index}, 'er-${dollar}{clientId}-${dollar}{index}', 'ea-${dollar}{clientId}-${dollar}{index}' )" title="Delete"><img src="${dollar}{asset:classpath:org/equanda/t5gui/delete.png}" alt="${dollar}{equanda-message:Delete}" /></a>
<a href="javascript:;" id="ea-${dollar}{clientId}-${dollar}{index}" onclick="eqRevDel( this, '${dollar}{deletedHiddenId}', ${dollar}{index}, 'er-${dollar}{clientId}-${dollar}{index}', 'ed-${dollar}{clientId}-${dollar}{index}' )" style="display: none;" title="Undo Delete"><img src="${dollar}{asset:classpath:org/equanda/t5gui/undo_delete.gif}" alt="${dollar}{equanda-message:UndoDelete}" /></a>
@@ -39,6 +40,5 @@
</t:if>
</div>
</div>
- <t:equanda.formactionlink t:id="Add">${dollar}{equanda-message:Add}</t:equanda.formactionlink>
</div>
\ No newline at end of file
Added: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/base/PagerConfig.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/base/PagerConfig.java (rev 0)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/base/PagerConfig.java 2008-12-23 14:50:20 UTC (rev 920)
@@ -0,0 +1,247 @@
+/**
+ * This file is part of the equanda project.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
+ * ANY KIND, either express or implied. See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ */
+
+package org.equanda.tapestry5.base;
+
+import org.apache.tapestry5.json.JSONObject;
+
+/**
+ * Configuration bean for {@link org.equanda.tapestry5.components.JSPager}
+ * @author <a href="mailto:vla...@gm...">Vladimir Tkachenko</a>
+ */
+public class PagerConfig
+{
+ private int range;
+ private int maxPages;
+ private int rowsPerPage;
+ private int lastIndex;
+ private int currentPage;
+ private int rowCount;
+ private int addedRowCount;
+ private int additionalRowCount;
+ private String currentPageFieldName;
+ private String addedRowFieldName;
+ private String containerClass;
+ private String rowClass;
+ private String addLinkClass;
+ private String addBlockClass;
+ private String name;
+
+ public PagerConfig()
+ {
+
+ }
+
+ public PagerConfig( int range, int maxPages, int rowsPerPage, int lastIndex, int currentPage, int rowCount,
+ int addedRowCount, int additionalRowCount, String currentPageFieldName, String addedRowFieldName,
+ String containerClass, String rowClass, String addLinkClass, String addBlockClass, String name )
+ {
+ super();
+ this.range = range;
+ this.maxPages = maxPages;
+ this.rowsPerPage = rowsPerPage;
+ this.lastIndex = lastIndex;
+ this.currentPage = currentPage;
+ this.rowCount = rowCount;
+ this.addedRowCount = addedRowCount;
+ this.additionalRowCount = additionalRowCount;
+ this.currentPageFieldName = currentPageFieldName;
+ this.addedRowFieldName = addedRowFieldName;
+ this.containerClass = containerClass;
+ this.rowClass = rowClass;
+ this.addLinkClass = addLinkClass;
+ this.addBlockClass = addBlockClass;
+ this.name = name;
+ }
+
+ public int getRange()
+ {
+ return range;
+ }
+
+ public void setRange( int range )
+ {
+ this.range = range;
+ }
+
+ public int getMaxPages()
+ {
+ return maxPages;
+ }
+
+ public void setMaxPages( int maxPages )
+ {
+ this.maxPages = maxPages;
+ }
+
+ public int getRowsPerPage()
+ {
+ return rowsPerPage;
+ }
+
+ public void setRowsPerPage( int rowsPerPage )
+ {
+ this.rowsPerPage = rowsPerPage;
+ }
+
+ public int getLastIndex()
+ {
+ return lastIndex;
+ }
+
+ public void setLastIndex( int lastIndex )
+ {
+ this.lastIndex = lastIndex;
+ }
+
+ public int getCurrentPage()
+ {
+ return currentPage;
+ }
+
+ public void setCurrentPage( int currentPage )
+ {
+ this.currentPage = currentPage;
+ }
+
+ public int getRowCount()
+ {
+ return rowCount;
+ }
+
+ public void setRowCount( int rowCount )
+ {
+ this.rowCount = rowCount;
+ }
+
+ public int getAddedRowCount()
+ {
+ return addedRowCount;
+ }
+
+ public void setAddedRowCount( int addedRowCount )
+ {
+ this.addedRowCount = addedRowCount;
+ }
+
+ public int getAdditionalRowCount()
+ {
+ return additionalRowCount;
+ }
+
+ public void setAdditionalRowCount( int additionalRowCount )
+ {
+ this.additionalRowCount = additionalRowCount;
+ }
+
+ public String getCurrentPageFieldName()
+ {
+ return currentPageFieldName;
+ }
+
+ public void setCurrentPageFieldName( String currentPageFieldName )
+ {
+ this.currentPageFieldName = currentPageFieldName;
+ }
+
+ public String getAddedRowFieldName()
+ {
+ return addedRowFieldName;
+ }
+
+ public void setAddedRowFieldName( String addedRowFieldName )
+ {
+ this.addedRowFieldName = addedRowFieldName;
+ }
+
+ public String getContainerClass()
+ {
+ return containerClass;
+ }
+
+ public void setContainerClass( String containerClass )
+ {
+ this.containerClass = containerClass;
+ }
+
+ public String getRowClass()
+ {
+ return rowClass;
+ }
+
+ public void setRowClass( String rowClass )
+ {
+ this.rowClass = rowClass;
+ }
+
+ public String getAddLinkClass()
+ {
+ return addLinkClass;
+ }
+
+ public void setAddLinkClass( String addLinkClass )
+ {
+ this.addLinkClass = addLinkClass;
+ }
+
+ public String getAddBlockClass()
+ {
+ return addBlockClass;
+ }
+
+ public void setAddBlockClass( String addBlockClass )
+ {
+ this.addBlockClass = addBlockClass;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public JSONObject getJSONObject()
+ {
+ JSONObject object = new JSONObject();
+ object.put( "range", range );
+ object.put( "rowsPerPage", rowsPerPage );
+ object.put( "lastIndex", lastIndex );
+ object.put( "currentPage", currentPage );
+ object.put( "rowCount", rowCount );
+ object.put( "addedRowCount", addedRowCount );
+ object.put( "additionalRowCount", additionalRowCount );
+ object.put( "currentPageFieldName", currentPageFieldName );
+ object.put( "addedRowFieldName", addedRowFieldName );
+ object.put( "containerClass", containerClass );
+ object.put( "rowClass", rowClass );
+ object.put( "addLinkClass", addLinkClass );
+ object.put( "addBlockClass", addBlockClass );
+ object.put( "name", name );
+ return object;
+ }
+}
Modified: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPagedLoop.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPagedLoop.java 2008-12-23 12:01:07 UTC (rev 919)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPagedLoop.java 2008-12-23 14:50:20 UTC (rev 920)
@@ -35,6 +35,7 @@
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.Request;
import org.equanda.tapestry5.base.ObjectCreatorDelegate;
+import org.equanda.tapestry5.base.PagerConfig;
import org.slf4j.Logger;
import java.util.ArrayList;
@@ -312,7 +313,49 @@
{
return addedRowHidden.getClientId();
}
+
+ private PagerConfig config;
+ public PagerConfig getConfig()
+ {
+ return config;
+ }
+
+ public void setConfig( PagerConfig config )
+ {
+ this.config = config;
+ }
+
+ public String getDisplayStyle()
+ {
+ if ( getConfig() == null )
+ {
+ setConfig( internalPager.getConfig() );
+ }
+ PagerConfig config = getConfig();
+ int availableRows = config.getRowCount() - config.getAdditionalRowCount() + config.getAddedRowCount();
+
+ config.setMaxPages( ( ( availableRows - 1 ) / config.getRowsPerPage() ) + 1 );
+
+ if ( config.getMaxPages() > 0 && config.getCurrentPage() > config.getMaxPages() )
+ {
+ config.setCurrentPage( config.getMaxPages() );
+ }
+
+ int startIndex = config.getRowsPerPage() * ( config.getCurrentPage() - 1 );
+ int endIndex = startIndex + config.getRowsPerPage() - 1;
+
+ if ( index >= startIndex && index <= endIndex
+ && index < config.getRowCount() - config.getAdditionalRowCount() + config.getAddedRowCount() )
+ {
+ return "";
+ }
+ else
+ {
+ return "display:none;";
+ }
+ }
+
@SetupRender
Object setupRender()
{
Modified: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPager.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPager.java 2008-12-23 12:01:07 UTC (rev 919)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/JSPager.java 2008-12-23 14:50:20 UTC (rev 920)
@@ -28,14 +28,14 @@
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.Environment;
+import org.equanda.tapestry5.base.PagerConfig;
import java.util.List;
/**
* Equanda modification of {@link org.apache.tapestry5.corelib.components.GridPager}
- *
+ *
* @author <a href="mailto:vla...@gm...">Vladimir Tkachenko</a>
*/
@IncludeStylesheet( value = { "classpath:/org/equanda/tapestry5/resources/jspager.css" } )
@@ -65,6 +65,22 @@
@Inject
private Environment environment;
+ public PagerConfig getConfig()
+ {
+ JSPagedLoop pagedLoop = environment.peek( JSPagedLoop.class );
+
+ int availableRows = source.size() - pagedLoop.getAddedRowCount();
+
+ String clientId = pagedLoop.getClientId().toLowerCase();
+
+ int maxPages = ( ( availableRows - 1 ) / rowsPerPage ) + 1;
+
+ return new PagerConfig( range, maxPages, rowsPerPage, 0, pagedLoop.getCurrentPage(), source.size(), pagedLoop
+ .getAddedRowCount(), pagedLoop.getAdditionalRowCount(), pagedLoop.getCurrentPageFieldName(), pagedLoop
+ .getAddedRowFieldName(), "eqpl_" + clientId, "eqplr_" + clientId, "eqplal_" + clientId, "eqplab_"
+ + clientId, clientId );
+ }
+
@BeginRender
void render( MarkupWriter writer )
{
@@ -80,12 +96,17 @@
{
return;
}*/
+
String clientId = pagedLoop.getClientId().toLowerCase();
writer.element( "div", "class", "eqplp eqpl_" + clientId );
+
+ PagerConfig config = getConfig();
+
+ showPage( pagedLoop.getCurrentPage(), config, writer );
writer.end();
- JSONObject object = new JSONObject();
+ /*JSONObject object = new JSONObject();
object.put( "range", range );
// object.put( "maxPages", maxPages );
object.put( "rowsPerPage", rowsPerPage );
@@ -101,10 +122,138 @@
object.put( "addLinkClass", "eqplal_" + clientId );
object.put( "addBlockClass", "eqplab_" + clientId );
object.put( "name", clientId );
- renderSupport.addScript( "eqJsplC.%s = %s;", clientId, object );
- renderSupport.addScript( "eqShwPg( %s, eqJsplC.%s );", pagedLoop.getCurrentPage(), clientId );
+ renderSupport.addScript( "eqJsplC.%s = %s;", clientId, object );*/
+ renderSupport.addScript( "eqJsplC.%s = %s;", clientId, config.getJSONObject() );
+ // renderSupport.addScript( "eqShwPg( %s, eqJsplC.%s );", pagedLoop.getCurrentPage(), clientId );
renderSupport.addScript( "eqChAL( eqJsplC.%s );", clientId );
// logger.info( String.format( "Config Object. %s = %s ", clientId, object ) );
}
}
+
+ private void showPage( int pageIdx, PagerConfig config, MarkupWriter writer )
+ {
+ if ( pageIdx > 0 )
+ {
+ config.setCurrentPage( pageIdx );
+ }
+
+ if ( config.getCurrentPage() == 0 )
+ {
+ config.setCurrentPage( 1 );
+ }
+
+ int availableRows = config.getRowCount() - config.getAdditionalRowCount() + config.getAddedRowCount();
+
+ config.setMaxPages( ( ( availableRows - 1 ) / config.getRowsPerPage() ) + 1 );
+
+ if ( config.getMaxPages() > 0 && config.getCurrentPage() > config.getMaxPages() )
+ {
+ config.setCurrentPage( config.getMaxPages() );
+ }
+
+ if ( config.getMaxPages() < 2 )
+ {
+ return;
+ }
+
+ config.setLastIndex( 0 );
+
+ for ( int i = 1; i <= 2; i++ )
+ {
+ equandaWritePageLink( i, config, writer );
+ }
+
+ int low = config.getCurrentPage() - config.getRange();
+ int high = config.getCurrentPage() + config.getRange();
+
+ if ( low < 1 )
+ {
+ low = 1;
+ high = 2 * config.getRange() + 1;
+ }
+ else
+ {
+ if ( high > config.getMaxPages() )
+ {
+ high = config.getMaxPages();
+ low = high - 2 * config.getRange();
+ }
+ }
+
+ for ( int i = low; i <= high; i++ )
+ {
+ equandaWritePageLink( i, config, writer );
+ }
+
+ for ( int i = config.getMaxPages() - 1; i <= config.getMaxPages(); i++ )
+ {
+ equandaWritePageLink( i, config, writer );
+ }
+ }
+
+ private void equandaWritePageLink( int pageIndex, PagerConfig config, MarkupWriter writer )
+ {
+ if ( pageIndex < 1 || pageIndex > config.getMaxPages() )
+ return;
+
+ if ( pageIndex <= config.getLastIndex() )
+ return;
+
+ if ( pageIndex != config.getLastIndex() + 1 )
+ {
+ // element.appendChild( document.createTextNode( "..." ) );
+ writer.element( "div" );
+ writer.write( "..." );
+ writer.end();
+ }
+
+ config.setLastIndex( pageIndex );
+
+ if ( pageIndex == config.getCurrentPage() )
+ {
+ // Object span = document.createElement( "span" );
+ // span.className = "eqplc";
+ // span.innerHTML = "" + pageIndex;
+ // element.appendChild( span );
+ writer.element( "span", "class", "eqplc" );
+ writer.write( "" + pageIndex );
+ writer.end();
+ return;
+ }
+
+ // Object anchor = document.createElement( "a" );
+ // anchor.href = "javascript:;";
+ // anchor.onclick = function()
+ // {
+ // eqShwPg( pageIndex, config );
+ // };
+ // anchor.title = "Goto Page " + pageIndex;
+ // anchor.innerHTML = "" + pageIndex;
+ // element.appendChild( anchor );
+ writer.element( "a", "href", "javascript:;", "onclick", String.format( "eqShwPg( %s, %s )", pageIndex,
+ "eqJsplC." + config.getName() ), "title", "Goto Page " + pageIndex );
+ writer.write( "" + pageIndex );
+ writer.end();
+ }
+
+ private boolean eqChAL( PagerConfig config )
+ {
+ /*var addLinks = $$( "." + config.addLinkClass );
+ var addBlocks = $$( "." + config.addBlockClass );
+ if( addLinks.length == 0 || addBlocks.length == 0 )
+ {
+ return;
+ }*/
+ return config.getAdditionalRowCount() != 0 && config.getAddedRowCount() != config.getAdditionalRowCount();
+ /*{
+ // addLinks[0].hide();
+ // addBlocks[0].show();
+ }
+ else
+ {
+ // addLinks[0].show();
+ // addBlocks[0].hide();
+ }*/
+ }
+
}
Modified: trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/JSPagedLoop.tml
===================================================================
--- trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/JSPagedLoop.tml 2008-12-23 12:01:07 UTC (rev 919)
+++ trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/JSPagedLoop.tml 2008-12-23 14:50:20 UTC (rev 920)
@@ -1,7 +1,7 @@
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <t:loop t:id="loop" source="pagedSource">
- <div id="${currentRowId}" class="eqplr_${fixedClientId} eqJSPL" style="display:none;">
+ <t:loop t:id="loop" source="pagedSource" index="index">
+ <div id="${currentRowId}" class="eqplr_${fixedClientId} eqJSPL" style="${displayStyle}">
<t:body />
</div>
</t:loop>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|