Author: nbelaevski
Date: 2007-11-28 22:52:22 -0500 (Wed, 28 Nov 2007)
New Revision: 4340
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java
branches/3.1.x/sandbox/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
Log:
latest changes for listShuttle
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java 2007-11-29
03:45:55 UTC (rev 4339)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java 2007-11-29
03:52:22 UTC (rev 4340)
@@ -4,6 +4,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -29,6 +30,8 @@
*/
public abstract class ListShuttleRendererBase extends OrderingComponentRendererBase {
+ protected static final String SELECTION_STATE_VAR_NAME = "selectionState";
+
public final static String FACET_SOURCE_CAPTION = "sourceCaption";
public final static String FACET_TARGET_CAPTION = "targetCaption";
@@ -58,29 +61,33 @@
super(MESSAGE_BUNDLE_NAME);
}
+ public void encodeSLCaption(FacesContext context, UIOrderingBaseComponent shuttle)
throws IOException {
+ encodeCaption(context, shuttle, FACET_SOURCE_CAPTION, "ol_label ol_out_label
rich-ordering-list-caption");
+ }
+
public void encodeTLCaption(FacesContext context, UIComponent shuttle) throws
IOException {
encodeCaption(context, shuttle, FACET_TARGET_CAPTION, "ol_label ol_out_label
rich-ordering-list-caption");
}
- public void encodeTLHeader(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
+ public void encodeSLHeader(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
encodeHeader(context, shuttle, "rich-table-header", "ol_col
rich-table-header-cell", "sourceHeaderClass");
}
- public void encodeTLRows(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
- encodeRows(context, shuttle, new ListShuttleRendererTableHolder(shuttle, false));
+ public void encodeTLHeader(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
+ encodeHeader(context, shuttle, "rich-table-header", "ol_col
rich-table-header-cell", "sourceHeaderClass");
}
- public void encodeSLCaption(FacesContext context, UIOrderingBaseComponent shuttle)
throws IOException {
- encodeCaption(context, shuttle, FACET_SOURCE_CAPTION, "ol_label ol_out_label
rich-ordering-list-caption");
+ protected String encodeRows(FacesContext context, UIOrderingBaseComponent shuttle,
boolean source) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ StringWriter stringWriter = new StringWriter();
+ context.setResponseWriter(writer.cloneWithWriter(stringWriter));
+ encodeRows(context, shuttle, new ListShuttleRendererTableHolder(shuttle, source));
+ context.getResponseWriter().flush();
+ context.setResponseWriter(writer);
+
+ return stringWriter.getBuffer().toString();
}
- public void encodeSLHeader(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
- encodeHeader(context, shuttle, "rich-table-header", "ol_col
rich-table-header-cell", "sourceHeaderClass");
- }
- public void encodeSLRows(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
- encodeRows(context, shuttle, new ListShuttleRendererTableHolder(shuttle, true));
- }
-
public void encodeOneRow(FacesContext context, TableHolder holder)
throws IOException {
UIListShuttle table = (UIListShuttle) holder.getTable();
@@ -98,14 +105,21 @@
StringBuffer cellClassName = new StringBuffer("ol_cell
rich-ordering-list-cell");
ComponentVariables variables = ComponentsVariableResolver.getVariables(this, table);
+ SelectionState selectionState = (SelectionState)
variables.getVariable(SELECTION_STATE_VAR_NAME);
ItemState itemState = getItemState(context, table, variables);
boolean active = itemState.isActive();
if (active) {
-
+ rowClassName.append(" rich-ordering-list-row-active");
+ cellClassName.append(" rich-ordering-list-cell-active");
}
boolean selected = itemState.isSelected();
+ selectionState.addState(selected);
+ if (selected) {
+ rowClassName.append(" rich-ordering-list-row-selected");
+ cellClassName.append(" rich-ordering-list-cell-selected");
+ }
writer.writeAttribute("class", rowClassName.toString(), null);
@@ -138,39 +152,56 @@
}
}
- public void encodeShuttleControlsFacets(FacesContext context, UIOrderingBaseComponent
component)
+ public void encodeShuttleControlsFacets(FacesContext context, UIOrderingBaseComponent
component,
+ SelectionState sourceSelectionState, SelectionState targetSelectionState)
throws IOException {
String clientId = component.getClientId(context);
- encodeControlsFacets(context, component, SHUTTLE_HELPERS, clientId);
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ int divider = SHUTTLE_HELPERS.length / 2;
+
+ int metric;
+ for (int i = 0; i < SHUTTLE_HELPERS.length; i++) {
+ metric = Math.abs(i - divider) / 2;
+ SelectionState state = (i < divider ? sourceSelectionState :
targetSelectionState);
+
+ boolean enabled;
+ if (metric <= 1) {
+ enabled = state.isSelected();
+ } else {
+ enabled = state.isItemExist();
+ }
+
+ if (i % 2 == 1) {
+ enabled = !enabled;
+ }
+
+ if (SHUTTLE_HELPERS[i].isRendered(context, component)) {
+ //proper assumption about helpers ordering
+ encodeControlFacet(context, component, SHUTTLE_HELPERS[i], clientId, writer,
enabled);
+ }
+ }
}
- public void encodeTLControlsFacets(FacesContext context, UIOrderingBaseComponent
component)
+ public void encodeTLControlsFacets(FacesContext context, UIOrderingBaseComponent
component, SelectionState selectionState)
throws IOException {
String clientId = component.getClientId(context);
- encodeControlsFacets(context, component, TL_HELPERS, clientId);
- }
-
- protected void encodeControlsFacets(FacesContext context, UIOrderingBaseComponent
component, OrderingComponentRendererBase.ControlsHelper[] helpers ,String clientId)
- throws IOException {
+
ResponseWriter writer = context.getResponseWriter();
- //proper assumption about helpers ordering
- int divider = helpers.length / 2;
+ int divider = TL_HELPERS.length / 2;
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
- //OrderingListSelectionState selectionState = (OrderingListSelectionState)
variables.getVariable(SELECTION_STATE_VAR_NAME);
-
- for (int i = 0; i < helpers.length; i++) {
- //boolean boundarySelection = i < divider ? selectionState.isFirstSelected() :
selectionState.isLastSelected();
- //boolean enabled = selectionState.isSelected() && !boundarySelection;
- boolean enabled = true;
+ for (int i = 0; i < TL_HELPERS.length; i++) {
+ boolean boundarySelection = i < divider ? selectionState.isFirstSelected() :
selectionState.isLastSelected();
+ boolean enabled = selectionState.isSelected() && !boundarySelection;
if (i % 2 == 1) {
enabled = !enabled;
}
- if (helpers[i].isRendered(context, component)) {
+ if (TL_HELPERS[i].isRendered(context, component)) {
//proper assumption about helpers ordering
- encodeControlFacet(context, component, helpers[i], clientId, writer, enabled);
+ encodeControlFacet(context, component, TL_HELPERS[i], clientId, writer, enabled);
}
}
}
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-11-29
03:45:55 UTC (rev 4339)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/templates/org/richfaces/htmlListShuttle.jspx 2007-11-29
03:52:22 UTC (rev 4340)
@@ -4,11 +4,15 @@
xmlns:c="
http://java.sun.com/jsf/core"
xmlns:ui="
http://ajax4jsf.org/cdk/ui"
xmlns:u="
http://ajax4jsf.org/cdk/u"
+ xmlns:jsp="
http://ajax4jsf.org/cdk/jsp"
xmlns:x="
http://ajax4jsf.org/cdk/x"
baseclass="org.richfaces.renderkit.ListShuttleRendererBase"
class="org.richfaces.renderkit.html.ListShuttleRenderer"
component="org.richfaces.component.UIListShuttle"
+
+ <jsp:directive.page
import="org.richfaces.renderkit.OrderingComponentRendererBase" />
+
<h:styles>css/listShuttle.xcss</h:styles>
<h:scripts>
@@ -26,6 +30,17 @@
<f:clientId var="clientId"/>
<vcp:body>
<f:clientId var="clientId"/>
+ <jsp:scriptlet>
+ <![CDATA[
+ SelectionState sourceSelectionState = new SelectionState();
+ variables.setVariable(SELECTION_STATE_VAR_NAME, sourceSelectionState);
+ String encodedSourceRows = encodeRows(context, component, true);
+
+ SelectionState targetSelectionState = new SelectionState();
+ variables.setVariable(SELECTION_STATE_VAR_NAME, targetSelectionState);
+ String encodedTargetRows = encodeRows(context, component, false);
+ ]]>
+ </jsp:scriptlet>
<table id="#{clientId}">
<tr>
<td>
@@ -52,7 +67,10 @@
<div id="#{clientId}contentBox" class="ol_list_content"
style="width: #{component.attributes['listWidth']}px;
height:#{component.attributes['listHeight']}px;">
<table id="#{clientId}internal_tab"
class="ol_internal_tab" cellpadding="0" cellspacing="0">
<tbody id="#{clientId}tbody">
- <f:call name="encodeSLRows" />
+ <jsp:scriptlet><![CDATA[
+ writer.write(encodedSourceRows);
+ encodedSourceRows = null;
+ ]]></jsp:scriptlet>
</tbody>
</table>
</div>
@@ -65,17 +83,11 @@
</td>
<td>
<div class="shuttle_button_layout">
- <f:call name="encodeShuttleControlsFacets" />
+ <jsp:scriptlet><![CDATA[
+ encodeShuttleControlsFacets(context, component, sourceSelectionState,
targetSelectionState);
+ ]]></jsp:scriptlet>
</div>
- <!-- a id="#{clientId}copy"
href="#">copy</a><br/>
- <a id="#{clientId}disCopy"
href="#">dcopy</a><br/>
- <a id="#{clientId}copyAll"
href="#">copyAll</a><br/>
- <a id="#{clientId}disCopyAll"
href="#">dcopyAll</a><br/>
- <a id="#{clientId}remove"
href="#">remove</a><br/>
- <a id="#{clientId}disRemove"
href="#">dremove</a><br/>
- <a id="#{clientId}removeAll"
href="#">removeAll</a><br/>
- <a id="#{clientId}disRemoveAll"
href="#">dremoveAll</a-->
</td>
<td>
<div>
@@ -99,7 +111,10 @@
<div id="#{clientId}tlContentBox"
class="ol_list_content" style="width:
#{component.attributes['listWidth']}px;
height:#{component.attributes['listHeight']}px;">
<table id="#{clientId}tlInternal_tab"
class="ol_internal_tab" cellpadding="0" cellspacing="0">
<tbody id="#{clientId}tlTbody">
- <f:call name="encodeTLRows" />
+ <jsp:scriptlet><![CDATA[
+ writer.write(encodedTargetRows);
+ encodedTargetRows = null;
+ ]]></jsp:scriptlet>
</tbody>
</table>
</div>
@@ -107,7 +122,9 @@
</td>
<td class="ol_center_button_col_valign">
<div class="shuttle_button_layout rich-ordering-controls">
- <f:call name="encodeTLControlsFacets" />
+ <jsp:scriptlet><![CDATA[
+ encodeTLControlsFacets(context, component, targetSelectionState);
+ ]]></jsp:scriptlet>
</div>
</td>
</tr>