Author: abelevich
Date: 2009-11-17 12:16:22 -0500 (Tue, 17 Nov 2009)
New Revision: 15893
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIToggleControl.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js
root/ui-sandbox/trunk/components/tables/ui/src/main/templates/org/richfaces/renderkit/html/toggle-control.template.xml
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/tables.taglib.xml
Log:
add client subTables expand/collapse functionality, add dataTable toggle control
Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml 2009-11-17
17:16:22 UTC (rev 15893)
@@ -22,7 +22,27 @@
</superclass>
</tag>
</component>
+
<component>
+ <name>org.richfaces.ToggleControl</name>
+ <family>org.richfaces.ToggleControl</family>
+ <classname>org.richfaces.component.html.HtmlToggleControl</classname>
+ <superclass>org.richfaces.component.UIToggleControl</superclass>
+
+ <renderer generate="true" override="true">
+ <name>org.richfaces.renderkit.html.ToggleControlRenderer</name>
+ <template>org/richfaces/renderkit/html/toggle-control.template.xml</template>
+ </renderer>
+
+ <tag>
+ <name>toggleControl</name>
+ <superclass>
+ org.ajax4jsf.webapp.taglib.UIComponentTagBase
+ </superclass>
+ </tag>
+ </component>
+
+ <component>
<name>org.richfaces.Colgroup</name>
<family>org.richfaces.Colgroup</family>
<classname>org.richfaces.component.html.HtmlColumnGroup</classname>
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataIterator.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -44,7 +44,7 @@
UIComponent child = childrenIterator.next();
//TODO nick - why non-rendered children are filtered?
//TODO nick - should be (child instanceof UIColumn || child instanceof Column)?
- if ((child instanceof UIColumn) && child.isRendered()) {
+ if ((child instanceof UIColumn) || (child instanceof Column) || child instanceof
UISubTable) {
nextColumn = child;
} else if(checkAjaxComponent(child)) {
nextColumn = child;
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -39,7 +39,17 @@
public static final String COMPONENT_FAMILY = "org.richfaces.SubTable";
+ public static final String SWITCH_TYPE_SERVER = "server";
+ public static final String SWITCH_TYPE_CLIENT = "client";
+
+ public static final String SWITCH_TYPE_AJAX = "ajax";
+
+
+ enum PropertyKeys {
+ switchType, expanded
+ }
+
@Override
public Iterator<UIComponent> fixedChildren() {
return new SubtableFixedChildrenIterator(this);
@@ -69,6 +79,22 @@
super.walk(context, visitor, argument);
}
+ public String getSwichType(){
+ return (String)getStateHelper().eval(PropertyKeys.switchType, SWITCH_TYPE_SERVER);
+ }
+
+ public void setSwitchType(String switchType){
+ getStateHelper().put(PropertyKeys.switchType, switchType);
+ }
+
+ public void setExpanded(boolean expanded) {
+ getStateHelper().put(PropertyKeys.expanded, expanded);
+ }
+
+ public boolean getExpanded() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.expanded, Boolean.TRUE);
+ }
+
@Override
public boolean getRendersChildren() {
//TODO nick - why "false"?
@@ -92,11 +118,11 @@
}
public String getHeaderRowSkinClass() {
- return "rich-subtable-header-continue";
+ return "rich-subtable-header-row";
}
public String getHeaderFirstRowSkinClass() {
- return "rich-subtable-header";
+ return "rich-subtable-header-first-row";
}
public String getColumnHeaderCellSkinClass() {
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIToggleControl.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIToggleControl.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIToggleControl.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -0,0 +1,54 @@
+package org.richfaces.component;
+
+import javax.faces.component.UICommand;
+
+public abstract class UIToggleControl extends UICommand{
+
+ public static final String COMPONENT_TYPE = "org.richfaces.ToggleControl";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.ToggleControl";
+
+
+ enum PropertyKeys {
+ expandControl, collapseControl, forId, event
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public String getExpandControl(){
+ return (String) getStateHelper().eval(PropertyKeys.expandControl, null);
+ }
+
+ public void setExpandControl(String expandControl) {
+ getStateHelper().put(PropertyKeys.expandControl, expandControl);
+ }
+
+ public String getCollapseControl() {
+ return (String) getStateHelper().eval(PropertyKeys.collapseControl, null);
+ }
+
+ public void setCollapseControl(String collapseControl) {
+ getStateHelper().put(PropertyKeys.collapseControl, collapseControl);
+ }
+
+ public String getForId(){
+ return (String)getStateHelper().eval(PropertyKeys.forId, null);
+ }
+
+ public void setForId(String forId) {
+ getStateHelper().put(PropertyKeys.forId, forId);
+ }
+
+ public String getEvent() {
+ return (String)getStateHelper().eval(PropertyKeys.event, "onclick");
+
+ }
+
+ public void setEvent(String event) {
+ getStateHelper().put(PropertyKeys.event, event);
+ }
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -12,7 +12,7 @@
import org.richfaces.component.UIDataTableBase;
-@ResourceDependencies({
+@ResourceDependencies(value = {
@ResourceDependency(library = "javax.faces", name = "jsf.js"),
@ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "richfaces.js")
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -16,8 +16,11 @@
import org.richfaces.component.UIDataTable;
import org.richfaces.component.UISubTable;
-@ResourceDependencies({
- @ResourceDependency(name = "datatable.js"),
+@ResourceDependencies( {
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "datatable.js"),
@ResourceDependency(name = "table.css")
})
public class DataTableRenderer extends AbstractTableRenderer implements
ElementEncodeListener{
@@ -66,13 +69,17 @@
holder.setRowClass(dataTable.getRowSkinClass());
holder.setFirstRowClass(dataTable.getFirstRowSkinClass());
holder.setHeaderRow(false);
+ holder.setCellElement(HTML.TD_ELEM);
encodeRows(context, dataTable, holder);
}
-
+ //TODO: refactor
public void encodeRow(FacesContext context, RowHolder rowHolder) throws IOException {
boolean rowStart = true;
+ boolean bodyStart = false;
+
+
int processCell = 0;
Row row = rowHolder.getRow();
@@ -80,6 +87,11 @@
ResponseWriter writer = context.getResponseWriter();
+ if(rowHolder.isDataTable()) {
+ encodeTableBodyStart(writer, context, (UIDataTable)row);
+ bodyStart = true;
+ }
+
Iterator<UIComponent> iterator = row.columns();
while(iterator.hasNext()) {
@@ -95,21 +107,39 @@
childRowHolder.setRowClass(rowHolder.getRowClass());
childRowHolder.setFirstRowClass(rowHolder.getFirstRowClass());
childRowHolder.setCellClass(rowHolder.getCellClass());
+ childRowHolder.setCellElement(HTML.TH_ELEM);
} else {
childRowHolder.setRowClass(childRow.getRowSkinClass());
childRowHolder.setFirstRowClass(childRow.getFirstRowSkinClass());
childRowHolder.setCellClass(childRow.getCellSkinClass());
+ childRowHolder.setCellElement(HTML.TD_ELEM);
}
childRowHolder.setHeaderRow(rowHolder.isHeaderRow());
if(child instanceof UISubTable) {
//ecode subTable header facet
- encodeHeader(writer, context, (UISubTable)child);
+ UISubTable subTable = (UISubTable)child;
+ if(bodyStart) {
+ encodeTableBodyEnd(writer, context, (UIDataTableBase)row);
+ bodyStart = false;
+ }
+// subTable.setRowKey(childRowHolder.getCurrentRow());
+ encodeTableBodyStart(writer, context, subTable);
+ encodeHeader(writer, context, subTable);
}
encodeRows(context, childRow, childRowHolder);
if(child instanceof UISubTable) {
- encodeFooter(writer, context, (UISubTable)child);
+ UISubTable subTable = (UISubTable)child;
+ encodeFooter(writer, context, subTable);
+
+ encodeTableBodyEnd(writer, context, subTable);
+
+ bodyStart = false;
+ if(iterator.hasNext()) {
+ encodeTableBodyStart(writer, context, (UIDataTableBase)row);
+ bodyStart=true;
+ }
}
} else if(child instanceof UIColumn) {
@@ -124,7 +154,6 @@
}
if(rowStart) {
-
if(processRow == 0) {
encodeFirstRowStart(writer, context, child, rowHolder);
} else {
@@ -135,7 +164,7 @@
}
encodeCellStart(writer, context, child, rowHolder);
- encodeCellEnd(writer, context, child);
+ encodeCellEnd(writer, context, child, rowHolder);
if(!iterator.hasNext()) {
if(processRow == 0) {
@@ -146,7 +175,12 @@
}
processCell++;
}
+ }
+
+ if(bodyStart && rowHolder.isDataTable()) {
+ encodeTableBodyEnd(writer, context, (UIDataTableBase) row);
}
+
}
@Override
@@ -167,9 +201,9 @@
}
UIDataTableBase dataTable = (UIDataTableBase)component;
- encodeTableBodyStart(writer, context, dataTable);
+// encodeTableBodyStart(writer, context, dataTable);
encodeRows(context, dataTable);
- encodeTableBodyEnd(writer, context, dataTable);
+// encodeTableBodyEnd(writer, context, dataTable);
}
@@ -193,12 +227,13 @@
return UIDataTable.class;
}
- public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- writer.endElement(HTML.TD_ELEM);
+ public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
+ writer.endElement(holder.getCellElement());
}
public void encodeCellStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
- writer.startElement(HTML.TD_ELEM, component);
+ //anton - TODO: scope attribute
+ writer.startElement(holder.getCellElement(), component);
String cellClass = holder.getCellClass();
encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, cellClass);
@@ -224,7 +259,8 @@
public void encodeFirstRowStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
writer.startElement(HTML.TR_ELEMENT, component);
- String styleClass = holder.getFirstRowClass() + " " + holder.getRowClass();
+ getUtils().encodeId(context, component);
+ String styleClass = holder.getRowClass() + " " +
holder.getFirstRowClass();
encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
}
@@ -234,20 +270,22 @@
public void encodeRowStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
writer.startElement(HTML.TR_ELEMENT, component);
+ getUtils().encodeId(context, component);
String styleClass = holder.getRowClass();
encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
}
public void encodeTableBodyEnd(ResponseWriter writer, FacesContext context,
UIDataTableBase component) throws IOException {
- writer.endElement(HTML.TABLE_ELEMENT);
+ writer.endElement(HTML.TBOBY_ELEMENT);
}
public void encodeTableBodyStart(ResponseWriter writer, FacesContext context,
UIDataTableBase component) throws IOException {
- writer.startElement(HTML.BODY_ELEMENT, component);
+ writer.startElement(HTML.TBOBY_ELEMENT, component);
+ getUtils().encodeId(context, component);
}
public void encodeTableEnd(ResponseWriter writer, FacesContext context, UIDataTableBase
component) throws IOException {
- writer.endElement(HTML.BODY_ELEMENT);
+ writer.endElement(HTML.TABLE_ELEMENT);
}
public void encodeTableStart(ResponseWriter writer, FacesContext context,
UIDataTableBase component) throws IOException {
@@ -382,12 +420,6 @@
}
- public void encodeSubTableHeader(ResponseWriter writer, FacesContext context,
UIDataTable table){
- }
-
- public void encodeSubTableFooter(ResponseWriter writer, FacesContext context,
UIDataTable table) {
- }
-
protected void encodeTableHeaderFacet(FacesContext context, int columns,
ResponseWriter writer, UIComponent footer,
String skinFirstRowClass, String skinRowClass, String skinCellClass, String
footerClass, String element)
throws IOException {
@@ -400,7 +432,7 @@
holder.setFirstRowClass(skinFirstRowClass);
holder.setRowClass(skinRowClass);
holder.setCellClass(skinCellClass);
- holder.resetCurrentRow();
+ //holder.resetCurrentRow();
holder.setHeaderRow(true);
encodeRows(context, row, holder);
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -16,7 +16,7 @@
public void encodeCellStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException;
- public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException;
+ public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException;
// public void encodeHeaderCellStart(ResponseWriter writer, FacesContext context,
UIComponent component, String styleClass) throws IOException;
//
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -1,6 +1,9 @@
package org.richfaces.renderkit;
import org.richfaces.component.Row;
+import org.richfaces.component.UIColumnGroup;
+import org.richfaces.component.UIDataTable;
+import org.richfaces.component.UISubTable;
public class RowHolder {
@@ -16,6 +19,7 @@
private boolean headerRow;
+
public boolean isHeaderRow() {
return headerRow;
}
@@ -85,6 +89,19 @@
public void setRow(Row row) {
this.row = row;
}
+
+ public boolean isColGroup(){
+ return row instanceof UIColumnGroup;
+ }
+
+ public boolean isSubTable(){
+ return row instanceof UISubTable;
+ }
+
+ public boolean isDataTable(){
+ return row instanceof UIDataTable;
+ }
+
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java 2009-11-17
17:16:22 UTC (rev 15893)
@@ -0,0 +1,130 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+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.UISubTable;
+import org.richfaces.component.UIToggleControl;
+
+@ResourceDependencies({
+ @ResourceDependency(name = "toggler.js")
+})
+public abstract class ToggleControlRendererBase extends RendererBase {
+
+ private static final String MANAGER_SCRIPT = "<script
type=\"text/javascript\">ToggleManager.add(new Toggle(\"{0}\",
\"{1}\", \"{2}\"));</script>";
+
+ private static final String CLIENT_TOGGLE_SCRIPT =
"ToggleManager.clientToggle(''{0}'',
''{1}'');";
+
+ private static final String SERVER_TOGGLE_SCRIPT =
"ToggleManager.serverToggle(''{0}'',
''{1}'');";
+
+ private static final String AJAX_TOGGLE_SCRIPT =
"ToggleManager.ajaxToggle(''{0}'', ''{1}'');";
+
+ private static final String DISPLAY_NONE = "display: none;";
+
+ private static final String EXPAND_STATE = "expand";
+
+ private static final String COLLAPSE_STATE = "collapse";
+
+
+ public void encodeControl(FacesContext context, UIToggleControl toggleControl) throws
IOException{
+
+ UISubTable subTable = findComponent(context, toggleControl);
+ if(subTable != null) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ String toggleId = toggleControl.getClientId();
+ String subTableId = subTable.getClientId();
+ boolean expanded = subTable.getExpanded();
+ String initialState = expanded ? EXPAND_STATE : COLLAPSE_STATE;
+
+ String registerScript = MessageFormat.format(MANAGER_SCRIPT, toggleId, subTableId,
initialState);
+ writer.write(registerScript);
+
+ String switchType = subTable.getSwichType();
+ encodeControl(context, writer, toggleControl, switchType, expanded, false);
+ encodeControl(context, writer, toggleControl, switchType, !expanded, true);
+ }
+ }
+
+ protected void encodeControl(FacesContext context, ResponseWriter writer,
UIToggleControl control, String switchType, boolean expanded, boolean visible) throws
IOException {
+
+ String state = expanded ? EXPAND_STATE: COLLAPSE_STATE;
+ String image = expanded ? control.getExpandControl() : control.getCollapseControl();
+
+ String script = getScript(control, switchType, state);
+
+ String style = getStyle(context, control);
+ String styleClass = getStyleClass(context, control);
+
+ writer.startElement(HTML.SPAN_ELEM, control);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, null);
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, style, null);
+
+ writer.startElement(HTML.IMG_ELEMENT,control);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, control.getClientId() + ":" + state,
null);
+
+ if(!visible) {
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, DISPLAY_NONE, null);
+ }
+
+ if(script != null && script.length() > 0) {
+ String eventName = control.getEvent();
+ writer.writeAttribute(eventName,script, null);
+ }
+
+ if(image != null && image.trim().length() > 0) {
+ writer.writeAttribute(HTML.SRC_ATTRIBUTE, image, null);
+ }
+
+ writer.endElement(HTML.IMG_ELEMENT);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+
+ public String getStyleClass(FacesContext context, UIToggleControl control) {
+ return null;
+ }
+
+ public String getStyle(FacesContext context, UIToggleControl control) {
+ return null;
+ }
+
+ protected UISubTable findComponent(FacesContext context, UIToggleControl toggleControl)
{
+ String forId = toggleControl.getForId();
+
+ if(forId != null && forId.length() > 0) {
+ UIComponent subTable = getUtils().findComponentFor(context, toggleControl, forId);
+ if(subTable instanceof UISubTable) {
+ return (UISubTable)subTable;
+ }
+ }
+ return null;
+ }
+
+ public String getScript(UIToggleControl toggleControl, String switchType ,String state)
{
+
+ StringBuffer pattern = new StringBuffer();
+
+ if(switchType.equals(UISubTable.SWITCH_TYPE_CLIENT)) {
+ pattern.append(CLIENT_TOGGLE_SCRIPT);
+ } else if (switchType.equals(UISubTable.SWITCH_TYPE_AJAX)){
+ pattern.append(AJAX_TOGGLE_SCRIPT);
+ } else {
+ pattern.append(SERVER_TOGGLE_SCRIPT);
+ }
+
+ String toggleId = toggleControl.getClientId();
+
+ String script = ( pattern.length() > 0) ? MessageFormat.format(pattern.toString(),
toggleId, state) : null;
+
+ return script;
+ }
+
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml 2009-11-17
17:16:22 UTC (rev 15893)
@@ -47,6 +47,10 @@
<component-type>org.richfaces.SubTable</component-type>
<component-class>org.richfaces.component.html.HtmlSubTable</component-class>
</component>
+ <component>
+ <component-type>org.richfaces.ToggleControl</component-type>
+ <component-class>org.richfaces.component.html.HtmlToggleControl</component-class>
+ </component>
<render-kit>
<render-kit-id>HTML_BASIC</render-kit-id>
@@ -60,5 +64,10 @@
<renderer-type>org.richfaces.ExtendedDataTableRenderer</renderer-type>
<renderer-class>org.richfaces.renderkit.ExtendedDataTableRenderer</renderer-class>
</renderer>
+ <renderer>
+ <component-family>org.richfaces.ToggleControl</component-family>
+ <renderer-type>org.richfaces.ToggleControlRenderer</renderer-type>
+ <renderer-class>org.richfaces.renderkit.html.ToggleControlRenderer</renderer-class>
+ </renderer>
</render-kit>
</faces-config>
\ No newline at end of file
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js 2009-11-17
17:16:22 UTC (rev 15893)
@@ -1 +1 @@
-var i = 1;
\ No newline at end of file
+var c = 1;
\ No newline at end of file
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css 2009-11-17
17:16:22 UTC (rev 15893)
@@ -25,7 +25,7 @@
.rich-subtable-row{
}
-.rich-subtable-firstrow{
+.rich-subtable-first-row{
}
.rich-subtable-cell{
@@ -112,7 +112,7 @@
text-align:left;
}
-.rich-subtable-header {
+.rich-subtable-header-row {
background-color: grey;
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js 2009-11-17
17:16:22 UTC (rev 15893)
@@ -0,0 +1,85 @@
+function Toggle(id, forId, initialState){
+ this.id = id;
+ this.forId = forId;
+ this.state = initialState;
+}
+
+Toggle.prototype.convertId = function(id) {
+ return id.replace(/:/g, "\\:");
+}
+
+Toggle.prototype.clientToggle= function(toState){
+ var elements = this.getElement(this.forId);
+
+ if(this.state != toState) {
+
+ var hideId = this.id + ":" + toState;
+ var showId = this.id + ":" + this.state;
+
+ var hideControl = this.getElement(hideId);
+ var showControl = this.getElement(showId);
+
+ this.command("show", showControl);
+ this.command("hide", hideControl);
+
+ if(toState == 'collapse') {
+ this.command("hide", elements);
+ } else {
+ this.command("show", elements);
+ }
+ this.state = toState;
+ }
+}
+
+Toggle.prototype.serverToggle = function(toState) {
+}
+
+Toggle.prototype.ajaxToggle = function(toState) {
+}
+
+Toggle.prototype.command = function(name, elements){
+ if(name) {
+ for(var i in elements) {
+ var element = elements[i];
+ if(element && typeof element[name] == 'function') {
+ element[name]();
+ }
+ }
+ }
+}
+
+Toggle.prototype.getElement = function() {
+ var elements = new Array();
+ for(var i = 0; i < arguments.length; i++) {
+ elements[i] = $("#" + this.convertId(arguments[i]));
+ }
+ return elements;
+}
+
+ToggleManager = new Object();
+
+ToggleManager.process = {};
+
+ToggleManager.add = function (toggler){
+ if(toggler) {
+ this.process[toggler.id] = toggler;
+ }
+}
+
+ToggleManager.clientToggle = function(id, state) {
+ if(id) {
+ this.process[id].clientToggle(state);
+ }
+}
+
+ToggleManager.serverToggle = function(id, state) {
+ if(id) {
+ this.process[id].serverToggle(state);
+ }
+}
+
+ToggleManager.ajaxToggle = function(id, state) {
+ if(id) {
+ this.process[id].ajaxToggle(state);
+ }
+}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/tables.taglib.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/tables.taglib.xml 2009-11-17
15:28:13 UTC (rev 15892)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/tables.taglib.xml 2009-11-17
17:16:22 UTC (rev 15893)
@@ -37,4 +37,11 @@
<!--
renderer-type>org.richfaces.renderkit.SubTableRenderer</renderer-type-->
</component>
</tag>
+ <tag>
+ <tag-name>toggleControl</tag-name>
+ <component>
+ <component-type>org.richfaces.ToggleControl</component-type>
+ <renderer-type>org.richfaces.ToggleControlRenderer</renderer-type>
+ </component>
+ </tag>
</facelet-taglib>
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/templates/org/richfaces/renderkit/html/toggle-control.template.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/templates/org/richfaces/renderkit/html/toggle-control.template.xml
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/templates/org/richfaces/renderkit/html/toggle-control.template.xml 2009-11-17
17:16:22 UTC (rev 15893)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ class="org.richfaces.renderkit.html.ToggleControlRenderer"
+ superclass="org.richfaces.renderkit.ToggleControlRendererBase"
+ componentclass="org.richfaces.component.UIToggleControl">
+
+ <span id="#{clientId}"
class="#{component.attributes['styleClass']}">
+ <cdk:call expression="encodeControl(context, component);" />
+ </span>
+
+</cdk:root>
\ No newline at end of file