Author: abelevich
Date: 2010-03-26 10:27:21 -0400 (Fri, 26 Mar 2010)
New Revision: 16671
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.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/component/html/HtmlSubTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/DataTableState.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/SubTableState.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
Log:
paging support, refactoring
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -7,8 +7,6 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
-import org.ajax4jsf.model.DataComponentState;
-import org.richfaces.component.state.DataTableState;
import org.richfaces.event.SortingEvent;
/**
@@ -32,15 +30,6 @@
return (MethodExpression) getStateHelper().eval(PropertyKeys.sortingExpression);
}
- public DataTableState getCurrentComponentState() {
- return (DataTableState) getComponentState();
- }
-
- @Override
- protected DataComponentState createComponentState() {
- return new DataTableState(getFirst(), getRows());
- }
-
public UIComponent getCaption() {
return getFacet("caption");
}
@@ -50,22 +39,16 @@
super.broadcast(event);
if(event instanceof SortingEvent) {
SortingEvent sortingEvent = (SortingEvent)event;
-
- DataTableState state = getCurrentComponentState();
- if(event.isAppropriateListener(state)) {
- sortingEvent.processListener(state);
- }
-
- MethodExpression expression = getSortingListener();
+
FacesContext context = getFacesContext();
+ MethodExpression expression = getSortingListener();
if (expression != null) {
expression.invoke(context.getELContext(), new Object[] { sortingEvent
});
}
-
+
}
}
-
@Override
public void queueEvent(FacesEvent event) {
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -29,22 +29,23 @@
import java.util.List;
import java.util.Map;
+import javax.faces.component.StateHelper;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.ajax4jsf.model.ExtendedDataModel;
-import org.richfaces.model.FilterField;
import org.richfaces.model.Arrangeable;
import org.richfaces.model.ArrangeableModel;
import org.richfaces.model.ArrangeableState;
import org.richfaces.model.ArrangeableStateDefaultImpl;
+import org.richfaces.model.FilterField;
import org.richfaces.model.SortField;
import org.richfaces.model.SortMode;
public class UIDataTableBase extends UISequence implements Row {
protected enum PropertyKeys {
- filterVar, sortPriority, sortMode
+ filterVar, sortPriority, sortMode, first, rows
}
public Iterator<UIComponent> columns() {
@@ -164,4 +165,22 @@
public void setSortMode(SortMode sortMode) {
getStateHelper().put(PropertyKeys.sortMode, sortMode);
}
+
+ @Override
+ public Object getIterationState() {
+ Object stateObject = super.getIterationState();
+ StateHelper stateHelper = getStateHelper();
+ return new Object []{stateObject, stateHelper.get(PropertyKeys.first),
stateHelper.get(PropertyKeys.rows)};
+ }
+
+ @Override
+ public void setIterationState(Object stateObject) {
+ StateHelper stateHelper = getStateHelper();
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+ super.setIterationState(state[0]);
+ stateHelper.put(PropertyKeys.first, state[1]);
+ stateHelper.put(PropertyKeys.rows, state[2]);
+ }
+ }
}
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 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -23,15 +23,11 @@
import javax.el.MethodExpression;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.RepeatState;
import org.richfaces.component.state.DataTableState;
-import org.richfaces.component.state.SubTableState;
-import org.richfaces.event.ToggleEvent;
import org.richfaces.event.ToggleListener;
/**
@@ -40,17 +36,22 @@
*/
-public abstract class UISubTable extends UIDataTableBase implements Row, Column,
Expandable {
+public class UISubTable extends UIDataTableBase implements Column {
- public static final String SWITCH_TYPE_SERVER = "server";
-
- public static final String SWITCH_TYPE_AJAX = "ajax";
-
-
enum PropertyKeys {
switchType, expanded, toggleExpression
}
+
+
+ public boolean isExpanded() {
+ return (Boolean)getStateHelper().eval(PropertyKeys.expanded, false);
+ }
+
+ public void setExpanded(boolean expanded) {
+ getStateHelper().put(PropertyKeys.expanded, expanded);
+ }
+
public boolean isBreakBefore() {
return true;
}
@@ -67,67 +68,6 @@
public void setSortExpression(String sortExpression) {
throw new IllegalArgumentException("subtable is not sortable
element");
}
-
- public String getSwichType() {
- return (String) getStateHelper().eval(PropertyKeys.switchType,
SWITCH_TYPE_SERVER);
- }
-
- public void setSwitchType(String switchType) {
- getStateHelper().put(PropertyKeys.switchType, switchType);
- }
-
- public SubTableState getCurrentComponentState() {
- DataComponentState dataComponentState = (SubTableState)getComponentState();
-
- DataTableState parentState = getParentState();
- parentState.addSubTableState((SubTableState) dataComponentState);
-
- return (SubTableState) dataComponentState;
- }
-
- public DataTableState getParentState() {
- DataTableState dataTableState = null;
-
- UIComponent parent = getParent();
- while(parent != null && !(parent instanceof UIDataTable)) {
- parent = parent.getParent();
- }
-
- if(parent == null) {
- throw new AbortProcessingException("UISubTable should have a UIDataTable
parent");
- }
-
- UIDataTable dataTable = (UIDataTable) parent;
- DataComponentState state = dataTable.getComponentState();
-
- if (state instanceof DataTableState) {
- dataTableState = (DataTableState) state;
- }
-
- return dataTableState;
- }
-
- @Override
- protected DataComponentState createComponentState() {
- DataComponentState state = null;
- DataTableState parentState = getParentState();
-
- if (parentState != null) {
- //TODO nick - use getClientId(FacesContext)
- //what's wrong with getClientId()???
- state = parentState.getChildState(getClientId());
- }
-
- if (state == null) {
- state = new SubTableState(getClientId(), getFirst(), getRows());
- }
-
- return state;
- }
-
- public abstract void setExpanded(boolean expanded);
-
- public abstract boolean isExpanded();
public void setToggleListener(MethodExpression toggleExpression) {
//TODO nick - use addToggleListener() & MethodExpression wrapper in tag
@@ -138,42 +78,6 @@
return (MethodExpression) getStateHelper().eval(PropertyKeys.toggleExpression);
}
- @Override
- public void queueEvent(FacesEvent event) {
- //TODO nick - what if event comes from the nested subTable?
- if (event instanceof ToggleEvent) {
- //TODO nick - "immediate" support?
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
- }
- super.queueEvent(event);
- }
-
- @Override
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- super.broadcast(event);
-
- if (event instanceof ToggleEvent) {
- ToggleEvent toggleEvent = (ToggleEvent) event;
-
- // not sure that this is right ... need to discuss
- SubTableState state = getCurrentComponentState();
- if (event.isAppropriateListener(state)) {
- toggleEvent.processListener(state);
- }
-
- MethodExpression expression = getToggleListener();
- FacesContext context = getFacesContext();
-
- if (expression != null) {
- expression.invoke(context.getELContext(), new Object[] { toggleEvent });
- }
-
- UIToggleControl toggle = (UIToggleControl)toggleEvent.getSource();
-// toggle.addExecuteId((String)getAttributes().get("clientId"));
- toggle.addRenderId(getClientId(context));
- }
- }
-
public void addToggleListener(ToggleListener listener) {
addFacesListener(listener);
}
@@ -185,6 +89,7 @@
public ToggleListener[] getToggleListeners() {
return (ToggleListener[]) getFacesListeners(ToggleListener.class);
}
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlSubTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlSubTable.java 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlSubTable.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -6,19 +6,5 @@
public static final String COMPONENT_TYPE = "org.richfaces.SubTable";
-
-
- protected enum PropertyKeys {
- expand
- }
-
- @Override
- public boolean isExpanded() {
- return (Boolean)getStateHelper().eval(PropertyKeys.expand, false);
- }
-
- @Override
- public void setExpanded(boolean expanded) {
- getStateHelper().put(PropertyKeys.expand, expanded);
- }
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/DataTableState.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/DataTableState.java 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/DataTableState.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -1,28 +1,17 @@
package org.richfaces.component.state;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.component.StateHolder;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.RepeatState;
-import org.richfaces.event.SortingEvent;
-import org.richfaces.event.SortingListener;
/**
* @author Anton Belevich
*
*/
-public class DataTableState extends RepeatState implements StateHolder, SortingListener
{
+public class DataTableState extends RepeatState {
- private Map<String, SubTableState> subTableStates = new HashMap<String,
SubTableState>();
+ private Integer first;
- private int first;
+ private Integer rows;
- private int rows;
-
public DataTableState(int first, int rows) {
this.first = first;
this.rows = rows;
@@ -37,48 +26,5 @@
public int getRows() {
return this.rows;
}
-
- //TODO nick - save/restore first/rows/visualModel
- public void restoreState(FacesContext context, Object state) {
- Object[] newState = (Object[]) state;
- if (newState != null) {
- //TODO nick - do we need to support SubTableState that are StateHolder?
- subTableStates = (Map<String, SubTableState>) newState[0];
- }
- }
-
- public Object saveState(FacesContext context) {
- return new Object[] { subTableStates };
- }
-
- public boolean isTransient() {
- return false;
- }
-
- public void setTransient(boolean newTransientValue) {
- }
-
- public void addSubTableState(SubTableState state) {
- if (state != null) {
- this.subTableStates.put(state.getId(), state);
- }
- }
-
- public SubTableState getSubTableState(String id) {
- return this.subTableStates.get(id);
- }
-
- public void addChildState(DataComponentState childState) {
- if (childState instanceof SubTableState) {
- addSubTableState((SubTableState) childState);
- }
- }
-
- public DataComponentState getChildState(String id) {
- DataComponentState state = getSubTableState(id);
- return state;
- }
-
- public void processSorting(SortingEvent sortingEvent) {
- }
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/SubTableState.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/SubTableState.java 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/state/SubTableState.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -1,65 +1,12 @@
package org.richfaces.component.state;
-import javax.faces.component.StateHolder;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.model.RepeatState;
-import org.richfaces.event.ToggleEvent;
-import org.richfaces.event.ToggleListener;
-
/**
+ *
* @author Anton Belevich
- *
*/
-public class SubTableState extends RepeatState implements StateHolder, ToggleListener {
+public class SubTableState extends DataTableState {
- private String id;
-
- private int first;
-
- private int rows;
-
- public SubTableState(String id, int first, int rows) {
- this.id = id;
- this.first = first;
- this.rows = rows;
+ public SubTableState(int first, int rows) {
+ super(first, rows);
}
-
- public String getId() {
- return this.id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public int getFirst() {
- return this.first;
- }
-
- @Override
- public int getRows() {
- return this.rows;
- }
-
- public boolean isTransient() {
- return false;
- }
-
- public void setTransient(boolean newTransientValue) {
- }
-
- public void processToggle(ToggleEvent event) {
- }
-
- @Override
- public void restoreState(FacesContext arg0, Object arg1) {
- }
-
- @Override
- public Object saveState(FacesContext arg0) {
- return null;
- }
-
}
Modified:
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 2010-03-26
10:43:08 UTC (rev 16670)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java 2010-03-26
14:27:21 UTC (rev 16671)
@@ -89,11 +89,11 @@
String toggleId = toggleControl.getClientId(context);
String options = encodeOptions(context, toggleControl, subTable);
- String switchType = subTable.getSwichType();
- boolean expanded = subTable.isExpanded();
+ String switchType = null;//subTable.getSwichType();
+// boolean expanded = subTable.isExpanded();
- encodeControl(context, writer, toggleControl, switchType, expanded,
false);
- encodeControl(context, writer, toggleControl, switchType, !expanded,
true);
+// encodeControl(context, writer, toggleControl, switchType, expanded,
false);
+// encodeControl(context, writer, toggleControl, switchType, !expanded,
true);
encodeHiddenInput(context, writer, toggleControl);
@@ -153,11 +153,11 @@
HashMap<String, Object> options = new HashMap<String, Object>();
options.put("formId", formId);
options.put("forId", forId);
- options.put("initialState", (Boolean) subTable.isExpanded());
+// options.put("initialState", (Boolean) subTable.isExpanded());
options.put("eventName", toggleControl.getEvent());
- if(subTable.getSwichType().equals(UISubTable.SWITCH_TYPE_AJAX)) {
- options.put("ajax", AjaxRendererUtils.buildEventOptions(context,
subTable));
- }
+// if(subTable.getSwichType().equals(UISubTable.SWITCH_TYPE_AJAX)) {
+// options.put("ajax", AjaxRendererUtils.buildEventOptions(context,
subTable));
+// }
return ScriptUtils.toScript(options);
}