Author: maksimkaszynski
Date: 2007-07-27 11:01:42 -0400 (Fri, 27 Jul 2007)
New Revision: 1897
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SortIconRenderer.java
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader.js
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
trunk/sandbox/ui/scrollable-grid/src/main/resources/org/richfaces/renderkit/html/css/grid.xcss
trunk/sandbox/ui/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid-header-itself.jspx
Log:
server rendering of scroll icons
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-07-27
15:01:42 UTC (rev 1897)
@@ -52,10 +52,6 @@
public static final String SORT_SINGLE = "single";
public static final String SORT_MULTI = "multi";
- public static String ASC_ICON = "ascIcon";
- public static String DESC_ICON = "descIcon";
-
-
private boolean MODEL_RANGE = false;
private final static Log log = LogFactory.getLog(UIScrollableGrid.class);
@@ -387,30 +383,4 @@
public abstract String getSortMode();
public abstract void setSortMode(String mode);
-
- public UIComponent getAscIcon() {
- return getFacet(ASC_ICON);
- }
-
- public void setAscIcon(UIComponent component) {
- if (component == null) {
- getFacets().remove(ASC_ICON);
- } else {
- getFacets().put(ASC_ICON, component);
- }
- }
-
- public UIComponent getDescIcon() {
- return getFacet(DESC_ICON);
- }
-
- public void setDescIcon(UIComponent component) {
- if (component == null) {
- getFacets().remove(DESC_ICON);
- } else {
- getFacets().put(DESC_ICON, component);
- }
- }
-
-
}
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java 2007-07-27
15:01:42 UTC (rev 1897)
@@ -17,6 +17,9 @@
*/
public abstract class UIScrollableGridColumn extends UIColumn implements SortSource{
+ public static String ASC_ICON = "ascIcon";
+ public static String DESC_ICON = "descIcon";
+
public Iterator getChildIterator(){
return getChildren().iterator();
}
@@ -50,34 +53,29 @@
}
public UIComponent getAscIcon() {
- UIComponent facet = getFacet(UIScrollableGrid.ASC_ICON);
- if (facet == null) {
- facet = getGrid().getAscIcon();
- }
+ UIComponent facet = getFacet(ASC_ICON);
return facet;
}
public void setAscIcon(UIComponent component) {
if (component == null) {
- getFacets().remove(UIScrollableGrid.ASC_ICON);
+ getFacets().remove(ASC_ICON);
} else {
- getFacets().put(UIScrollableGrid.ASC_ICON, component);
+ getFacets().put(ASC_ICON, component);
}
}
public UIComponent getDescIcon() {
- UIComponent facet = getFacet(UIScrollableGrid.DESC_ICON);
- if (facet == null) {
- facet = getGrid().getDescIcon();
- }
+ UIComponent facet = getFacet(DESC_ICON);
+
return facet;
}
public void setDescIcon(UIComponent component) {
if (component == null) {
- getFacets().remove(UIScrollableGrid.DESC_ICON);
+ getFacets().remove(DESC_ICON);
} else {
- getFacets().put(UIScrollableGrid.DESC_ICON, component);
+ getFacets().put(DESC_ICON, component);
}
}
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-07-27
15:01:42 UTC (rev 1897)
@@ -146,6 +146,7 @@
super();
_grid = grid;
_cachedClientId = grid.getClientId(context);
+ clientId = _cachedClientId;
_previousState = previsiosState;
if(AjaxRendererUtils.isAjaxRequest(context)){
}
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-07-27
15:01:42 UTC (rev 1897)
@@ -44,6 +44,7 @@
public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
public final String PARTIAL_UPDATE= "partialUpdate";
+ public final String UPDATE_HEADER = "updateHeader";
public final String FOOTER_PART = "footer";
@@ -53,9 +54,6 @@
private final String COLUMN_NORMAL_TYPE = "normal";
- private static final String ASC_ICON_CREATED = "ASC_ICON_CREATED";
- private static final String DESC_ICON_CREATED = "DESC_ICON_CREATED";
-
private RendererBase cellTemplate = null;
private RendererBase headerCellTemplate = null;
@@ -563,32 +561,9 @@
public void setUpState(FacesContext context, UIScrollableGrid grid) {
GridRendererState.createState(context, grid);
- Map attrs = grid.getAttributes();
-
- if (grid.getAscIcon() == null) {
- attrs.put(ASC_ICON_CREATED, Boolean.TRUE);
- }
-
- if (grid.getDescIcon() == null) {
- attrs.put(DESC_ICON_CREATED, Boolean.TRUE);
- }
-
}
public void tearDownState(FacesContext context, UIScrollableGrid grid){
-
- Map attrs = grid.getAttributes();
- if (attrs.containsKey(ASC_ICON_CREATED)) {
- grid.setAscIcon(null);
- attrs.remove(ASC_ICON_CREATED);
- }
-
- if (attrs.containsKey(DESC_ICON_CREATED)) {
- grid.setDescIcon(null);
- attrs.remove(DESC_ICON_CREATED);
- }
-
-
GridRendererState.restoreState(context);
}
@@ -637,6 +612,8 @@
super.doDecode(context, component);
component.getAttributes().remove(PARTIAL_UPDATE);
+ component.getAttributes().remove(UPDATE_HEADER);
+
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
@@ -691,6 +668,7 @@
if (ajaxContext.isAjaxRequest()) {
component.getAttributes().put(PARTIAL_UPDATE, Boolean.TRUE);
+ component.getAttributes().put(UPDATE_HEADER, Boolean.TRUE);
}
}
}
@@ -733,6 +711,8 @@
UIScrollableGrid grid = (UIScrollableGrid)component;
+
+
GridRendererState state = GridRendererState.createState(context, grid);
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
@@ -769,6 +749,9 @@
//Then call contributors to write additional HTML content
contributorsEncodeHere(context, grid);
+ if (shouldUpdateHeader(component)) {
+ ColumnWalker.iterateOverColumns(context, component, headerRenderer, writer, new
GridRendererState(context, null, grid));
+ }
}
@@ -788,6 +771,11 @@
Boolean b = (Boolean) grid.getAttributes().get(PARTIAL_UPDATE);
return b != null && b.booleanValue();
}
+
+ private boolean shouldUpdateHeader(UIComponent grid) {
+ Boolean b = (Boolean) grid.getAttributes().get(PARTIAL_UPDATE);
+ return b != null && b.booleanValue();
+ }
public void encodeChildren(FacesContext context, UIComponent component
) throws IOException {
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SortIconRenderer.java
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SortIconRenderer.java 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SortIconRenderer.java 2007-07-27
15:01:42 UTC (rev 1897)
@@ -3,10 +3,45 @@
*/
package org.richfaces.renderkit.html;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.UIScrollableGridColumn;
+
/**
* @author Maksim Kaszynski
*
*/
-public class SortIconRenderer {
+public abstract class SortIconRenderer extends RendererBase {
+
+
+ public void renderAscIcon(FacesContext context, UIComponent component) throws
IOException{
+ renderFacetOrIcon(context, component, UIScrollableGridColumn.ASC_ICON,
"dr-sgrid-sort-asc");
+ }
+ public void renderDescIcon(FacesContext context, UIComponent component) throws
IOException{
+ renderFacetOrIcon(context, component, UIScrollableGridColumn.DESC_ICON,
"dr-sgrid-sort-desc");
+ }
+
+ private void renderFacetOrIcon(FacesContext context, UIComponent component, String
facetName, String clazz) throws IOException{
+ UIComponent facet = component.getFacet(facetName);
+ if (facet != null) {
+ renderChild(context, facet);
+ } else {
+ renderIcon(context.getResponseWriter(), clazz);
+ }
+ }
+
+ private void renderIcon(ResponseWriter writer, String clazz) throws IOException {
+ writer.startElement(HTML.DIV_ELEM, null);
+ if (clazz != null) {
+ writer.writeAttribute(HTML.class_ATTRIBUTE, clazz, null);
+ }
+ writer.endElement(HTML.DIV_ELEM);
+ }
}
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js 2007-07-27
15:01:42 UTC (rev 1897)
@@ -103,12 +103,12 @@
header.updateSize();
this.getBody().updateSize();
if(this.getFooter()) {this.getFooter().updateSize();}
- }
+ }
if(this.layout) {
this.layout.updateLayout();
}
-
+ header.updateLayout();
header.setFakeColumnWidth();
this.getBody().setFakeColumnWidth();
if(this.getFooter()) {this.getFooter().setFakeColumnWidth();}
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader.js
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2007-07-27
15:01:42 UTC (rev 1897)
@@ -169,6 +169,7 @@
sep.setStyle({cursor: 'auto'});
}
// sort icons
+ //columns[j].sortIcon = new ClientUI.common.box.Box(details[1], null, true);
//columns[j].sortDesc = new ClientUI.common.box.Box(details[1], null, true);
//columns[j].sortAsc = new ClientUI.common.box.Box(details[2], null, true);
j++;
@@ -216,6 +217,7 @@
sep.setStyle({cursor: 'auto'});
}
// sort icons
+ //columns[j].sortIcon = new ClientUI.common.box.Box(details[1], null, true);
//columns[j].sortDesc = new ClientUI.common.box.Box(details[1], null, true);
//columns[j].sortAsc = new ClientUI.common.box.Box(details[2], null, true);
}
@@ -241,7 +243,8 @@
_getCellElements: function(column) {
var details = new Array(3);
var clientId = this.grid.getElement().id;
- details[0] = document.getElementById(clientId + ":hsep_" + column);
+ details[0] = $(clientId + ":hsep_" + column);
+ details[1] = $(clientId + ":hs_" + column);
//details[1] = document.getElementById(clientId + ":hsortd_" + column);
//details[2] = document.getElementById(clientId + ":hsorta_" + column);
return details;
@@ -292,6 +295,7 @@
this.setHeight(this.defaultHeight);
this.setWidth(this.defaultWidth);
this.agjustSeparators();
+ this.updateHeaders();
},
updateLayout: function() {
if(!this.controlCreated || !this.grid.controlCreated) {
@@ -311,6 +315,7 @@
this.frozenContentBox.moveTo(0, 0);
this.headerFrozenRow.setHeight(height);
this.frozenSubstrate.setWidth(frozenContentWidth);
+ this.updateHeaders();
},
getColumns: function() {
return this._columns;
@@ -429,6 +434,26 @@
}
}
},
+
+ updateHeaders : function() {
+ var cols = this.getColumns();
+ for(var i = 0; i < cols.length; i++) {
+ var col = cols[i];
+ var th = col.object;
+ var icon = this._getCellElements(i)[1];
+
+ if (icon) {
+ var newPosX = th.getWidth() - icon.getWidth();
+ var newPosY = (th.getHeight() - icon.getHeight())/2;
+
+ newPosX = Math.floor(newPosX);
+ newPosY = Math.floor(newPosY);
+
+ icon.setStyle({left: newPosX + "px",top: newPosY + "px",
visibility : "inherit"});
+ }
+ }
+ },
+
adjustColumnWidth: function(column, width) {
this._columns[column].col.width = width>0 ? width : 1;
if(width<=0) this.getColumns()[column].sep.hide();
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-07-27
15:01:42 UTC (rev 1897)
@@ -108,6 +108,7 @@
this.selectionManager.restoreState();
this.eventOnPostSort.fire(options.column, options.order);
}]);
+ this.updateLayout();
},
onScrollComplete : function(request, event, data){
var options = this.dataModel.getCurrentOptions();
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/resources/org/richfaces/renderkit/html/css/grid.xcss
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/resources/org/richfaces/renderkit/html/css/grid.xcss 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/resources/org/richfaces/renderkit/html/css/grid.xcss 2007-07-27
15:01:42 UTC (rev 1897)
@@ -9,13 +9,13 @@
XPTable
*/
-<u:selector name=".dr-sgrid-hc .sort-asc">
+<u:selector name=".dr-sgrid-sort-asc">
<u:style name="background-image">
<f:resource
f:key="/org/richfaces/renderkit/html/images/sort_asc.gif"/>
</u:style>
</u:selector>
-<u:selector name=".dr-sgrid-hc .sort-desc">
+<u:selector name=".dr-sgrid-sort-desc">
<u:style name="background-image">
<f:resource
f:key="/org/richfaces/renderkit/html/images/sort_desc.gif"/>
</u:style>
@@ -30,7 +30,18 @@
<f:verbatim>
<![CDATA[
+.dr-sgrid-sort-asc, .dr-sgrid-sort-desc {
+ width: 16px;
+ height: 6px;
+ background-position: 50% 50%;
+ background-repeat: no-repeat;
+}
+.dr-sgrid-sort-icon {
+ position:absolute;
+ visibility: hidden;
+}
+
.dr-sgrid {
font: menu;
background-color: white;
Modified:
trunk/sandbox/ui/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid-header-itself.jspx
===================================================================
---
trunk/sandbox/ui/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid-header-itself.jspx 2007-07-27
14:58:15 UTC (rev 1896)
+++
trunk/sandbox/ui/scrollable-grid/src/main/templates/org/richfaces/scrollable-grid-header-itself.jspx 2007-07-27
15:01:42 UTC (rev 1897)
@@ -7,19 +7,24 @@
xmlns:x="
http://ajax4jsf.org/cdk/x"
xmlns:h="
http://ajax4jsf.org/cdk/headers"
xmlns:vcp="http://ajax4jsf.org/cdk/vcp"
-
+ baseclass="org.richfaces.renderkit.html.SortIconRenderer"
class="org.richfaces.renderkit.html.ScrollableGridHeaderItselfRenderer"
component="javax.faces.component.UIComponent"
<div id="#{client_id}:hcb_#{cell_index}"
class="dr-sgrid-hcbody">
<vcp:body/>
- <c:if test="#{sortAscending}">
- <div align="right" id="#{client_id}:hsorta_#{cell_index}"
class="sort-asc" />
- </c:if>
- <c:if test="#{sortDescending}">
- <div align="right" id="#{client_id}:hsortd_#{cell_index}"
class="sort-desc" />
- </c:if>
+
+ <div align="right" id="#{client_id}:hs_#{cell_index}"
class="dr-sgrid-sort-icon">
+ <c:if test="#{sortAscending}">
+ <f:call name="renderAscIcon"/>
+ </c:if>
+ <c:if test="#{sortDescending}">
+ <f:call name="renderDescIcon"/>
+ </c:if>
+ </div>
+
</div>
+<ajax:update>#{client_id}:hcb_#{cell_index}</ajax:update>
</f:root>
\ No newline at end of file