Author: nbelaevski
Date: 2007-11-26 21:52:11 -0500 (Mon, 26 Nov 2007)
New Revision: 4280
Modified:
branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/Control.js
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java
Log:
latest changes for listShuttle & orderingList
Modified: branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml
===================================================================
--- branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml 2007-11-27
02:52:02 UTC (rev 4279)
+++ branches/3.1.x/ui/orderingList/src/main/config/component/orderinglist.xml 2007-11-27
02:52:11 UTC (rev 4280)
@@ -180,7 +180,7 @@
<defaultvalue>true</defaultvalue>
</property>
- <property>
+ <property elonly="true">
<name>selection</name>
<description>Collection which stores a set of selected
items</description>
</property>
Modified:
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
---
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2007-11-27
02:52:02 UTC (rev 4279)
+++
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2007-11-27
02:52:11 UTC (rev 4280)
@@ -3,10 +3,13 @@
*/
package org.richfaces.component;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -19,6 +22,7 @@
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
@@ -29,6 +33,7 @@
import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.RepeatState;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.EmptyIterator;
@@ -45,6 +50,12 @@
private Object value;
private boolean localValueSet;
+ private Collection selection;
+ private boolean selectionSet;
+
+ private Object activeItem;
+ private boolean activeItemSet;
+
private List validators = null;
private MethodBinding validator;
@@ -68,8 +79,20 @@
private boolean translatedRendering = false;
}
- private static final class ValueHolder {
+ private static final class ValueHolder implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2349104220087787755L;
+
private Object value;
+
+ private Collection selection;
+ private boolean selectionSet;
+
+ private Object activeItem;
+ private boolean activeItemSet;
+
private Object state;
}
@@ -123,8 +146,10 @@
}
}
+ public abstract Object getTranslatedRowKey();
+
public Object saveState(FacesContext faces) {
- Object[] state = new Object[5];
+ Object[] state = new Object[9];
state[0] = super.saveState(faces);
@@ -134,6 +159,41 @@
state[3] = this.value;
state[4] = localValueSet ? Boolean.TRUE : Boolean.FALSE;
+ final HashSet selectionKeySet = new HashSet();
+ final HashSet activeItemSet = new HashSet(1);
+
+ Object rowKey = getRowKey();
+ try {
+ walk(faces, new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+
+ setRowKey(context, rowKey);
+ Object data = getRowData();
+ if (data.equals(activeItem)) {
+ activeItemSet.add(getTranslatedRowKey());
+ }
+
+ if (selection != null && selection.contains(data)) {
+ selectionKeySet.add(getTranslatedRowKey());
+ }
+
+ }
+
+ }, null);
+ } catch (IOException e) {
+ throw new FacesException(e.getLocalizedMessage(), e);
+ }
+
+ setRowKey(rowKey);
+
+ state[5] = selectionKeySet;
+ state[6] = this.selectionSet ? Boolean.TRUE : Boolean.FALSE;
+
+ state[7] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
+ state[8] = this.activeItemSet ? Boolean.TRUE : Boolean.FALSE;
+
return state;
}
@@ -147,6 +207,12 @@
value = state[3];
localValueSet = ((Boolean) state[4]).booleanValue();
+
+ this.selection = (Collection) state[5];
+ this.selectionSet = ((Boolean) state[6]).booleanValue();
+
+ this.activeItem = state[7];
+ this.activeItemSet = ((Boolean) state[8]).booleanValue();
}
protected DataComponentState createComponentState() {
@@ -217,11 +283,17 @@
}
public Object getLocalValue() {
- ValueHolder valueHolder = new ValueHolder();
- valueHolder.value = this.value;
- valueHolder.state = saveIterationState();
+ ValueHolder holder = new ValueHolder();
+ holder.value = this.value;
+ holder.selection = this.selection;
+ holder.selectionSet = this.selectionSet;
- return valueHolder;
+ holder.activeItem = this.activeItem;
+ holder.activeItemSet = this.activeItemSet;
+
+ holder.state = saveIterationState();
+
+ return holder;
}
public void setValue(Object value) {
@@ -230,6 +302,12 @@
setValue(holder.value);
restoreIterationState(holder.state);
+
+ this.selection = holder.selection;
+ this.selectionSet = holder.selectionSet;
+
+ this.activeItem = holder.activeItem;
+ this.activeItemSet = holder.activeItemSet;
} else {
super.setValue(value);
this.value = value;
@@ -310,6 +388,8 @@
return;
}
+ convertState(context);
+
super.processDecodes(context);
if (isImmediate()) {
@@ -408,6 +488,51 @@
public void execute(FacesContext context);
}
+ protected final UpdateModelCommand updateValueCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ if (isLocalValueSet()) {
+ ValueBinding vb = getValueBinding("value");
+ if (vb != null) {
+ vb.setValue(context, getLocalValueFieldValue());
+ setValue(null);
+ setLocalValueSet(false);
+ }
+ }
+ }
+
+ };
+
+ protected final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ if (selectionSet) {
+ ValueBinding vb = getValueBinding("selection");
+ if (vb != null) {
+ vb.setValue(context, selection);
+ selection = null;
+ selectionSet = false;
+ }
+ }
+ }
+
+ };
+
+ protected final UpdateModelCommand updateActiveItemCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ if (activeItemSet) {
+ ValueBinding vb = getValueBinding("activeItem");
+ if (vb != null) {
+ vb.setValue(context, activeItem);
+ activeItem = null;
+ activeItemSet = false;
+ }
+ }
+ }
+
+ };
+
protected void updateModel(FacesContext context, UpdateModelCommand command) {
try {
command.execute(context);
@@ -469,4 +594,108 @@
}
+ protected void addConversionErrorMessage(FacesContext context,
+ ConverterException ce, Object value) {
+ FacesMessage message = ce.getFacesMessage();
+ if (message == null) {
+ message = MessageFactory.getMessage(context,
+ UIInput.CONVERSION_MESSAGE_ID);
+ if (message.getDetail() == null) {
+ message.setDetail(ce.getMessage());
+ }
+ }
+
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ }
+
+ protected boolean isEmpty(Object value) {
+
+ if (value == null) {
+ return (true);
+ } else if ((value instanceof String) &&
+ (((String) value).length() < 1)) {
+ return (true);
+ } else if (value.getClass().isArray()) {
+ if (0 == java.lang.reflect.Array.getLength(value)) {
+ return (true);
+ }
+ }
+ else if (value instanceof List) {
+ if (0 == ((List) value).size()) {
+ return (true);
+ }
+ }
+ return (false);
+ }
+
+ public Collection getSelection() {
+ if (this.selection != null) {
+ return this.selection;
+ } else {
+ ValueBinding vb = getValueBinding("selection");
+ if (vb != null) {
+ return (Collection) vb.getValue(FacesContext.getCurrentInstance());
+ }
+ }
+
+ return null;
+ }
+
+ public void setSelection(Collection collection) {
+ this.selection = collection;
+ this.selectionSet = true;
+ }
+
+ public Object getActiveItem() {
+ if (this.activeItem != null) {
+ return this.activeItem;
+ } else {
+ ValueBinding vb = getValueBinding("activeItem");
+ if (vb != null) {
+ return vb.getValue(FacesContext.getCurrentInstance());
+ }
+ }
+
+ return null;
+ }
+
+ public void setActiveItem(Object activeItem) {
+ this.activeItem = activeItem;
+ this.activeItemSet = true;
+ }
+
+ private void convertState(FacesContext faces) {
+ Object rowKey = getRowKey();
+
+ final HashSet selectionItemsSet = new HashSet();
+ try {
+ walk(faces, new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+
+ setRowKey(context, rowKey);
+
+ if (selection != null && selection.contains(rowKey)) {
+ selectionItemsSet.add(getRowData());
+ }
+
+ if (rowKey.equals(activeItem)) {
+ activeItem = getRowData();
+ }
+ }
+
+ }, null);
+ } catch (IOException e) {
+ throw new FacesException(e.getLocalizedMessage(), e);
+ }
+
+ if (this.selection != null) {
+ this.selection = selectionItemsSet;
+ }
+
+ setRowKey(rowKey);
+ }
+
}
Modified:
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
===================================================================
---
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-27
02:52:02 UTC (rev 4279)
+++
branches/3.1.x/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-27
02:52:11 UTC (rev 4280)
@@ -1,10 +1,8 @@
package org.richfaces.component;
-import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -34,24 +32,11 @@
import javax.faces.validator.ValidatorException;
import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.richfaces.model.TranslatedSequenceDataModel;
public abstract class UIOrderingList extends UIOrderingBaseComponent {
- protected static final class ValueHolder implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 2124352131407581704L;
- private Collection selection;
- private boolean selectionSet;
-
- private Object activeItem;
- private boolean activeItemSet;
- }
-
protected static final class SubmittedValue implements Serializable {
/**
*
@@ -98,7 +83,7 @@
for (int i = 0; i < permutationOrder.length; i++) {
result.append(permutationOrder[i]);
- Integer key = new Integer(i);
+ Integer key = new Integer(permutationOrder[i]);
if (selectedItems.contains(key)) {
result.append('s');
@@ -127,21 +112,15 @@
}
private final class SubmittedItemState implements ItemState {
- private Collection selectedItemsKeys;
- private Object activeItemKey;
- public SubmittedItemState(Collection selectedItemsKeys, Integer activeItemKey) {
- super();
- this.selectedItemsKeys = selectedItemsKeys;
- this.activeItemKey = activeItemKey;
- }
-
public boolean isActive() {
- return activeItemKey != null && activeItemKey.equals(getTranslatedRowKey());
+ return submittedValueHolder.activeItem != null &&
+ submittedValueHolder.activeItem.equals(getTranslatedRowKey());
}
public boolean isSelected() {
- return selectedItemsKeys != null &&
selectedItemsKeys.contains(getTranslatedRowKey());
+ return submittedValueHolder.selectedItems != null &&
+ submittedValueHolder.selectedItems.contains(getTranslatedRowKey());
}
}
@@ -174,102 +153,8 @@
}
}
-
- private Collection localSelection;
- private boolean localSelectionSet;
-
- private Object localActiveItem;
- private boolean localActiveItemSet;
-
private transient SubmittedValue submittedValueHolder = null;
- private void convertState(FacesContext faces) {
- Object rowKey = getRowKey();
-
- final HashSet selectionItemsSet = new HashSet();
- try {
- walk(faces, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- setRowKey(context, rowKey);
-
- if (localSelection != null && localSelection.contains(rowKey)) {
- selectionItemsSet.add(getRowData());
- }
-
- if (rowKey.equals(localActiveItem)) {
- localActiveItem = getRowData();
- }
- }
-
- }, null);
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
-
- if (this.localSelection != null) {
- this.localSelection = selectionItemsSet;
- }
-
- setRowKey(rowKey);
- }
-
- public void restoreState(FacesContext faces, Object object) {
- final Object[] state = (Object[]) object;
- super.restoreState(faces, state[0]);
-
- localSelectionSet = ((Boolean) state[3]).booleanValue();
- localActiveItemSet = ((Boolean) state[4]).booleanValue();
-
- localSelection = (Collection) state[5];
- localActiveItem = state[6];
- }
-
- public Object saveState(FacesContext faces) {
- Object[] state = new Object[7];
- state[0] = super.saveState(faces);
-
- state[3] = localSelectionSet ? Boolean.TRUE : Boolean.FALSE;
- state[4] = localActiveItemSet ? Boolean.TRUE : Boolean.FALSE;
-
- final HashSet selectionKeySet = new HashSet();
- final HashSet activeItemSet = new HashSet(1);
-
- Object rowKey = getRowKey();
- try {
- walk(faces, new DataVisitor() {
-
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
-
- setRowKey(context, rowKey);
- Object data = getRowData();
- if (data.equals(localActiveItem)) {
- activeItemSet.add(getTranslatedRowKey());
- }
-
- if (localSelection != null && localSelection.contains(data)) {
- selectionKeySet.add(getTranslatedRowKey());
- }
-
- }
-
- }, null);
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
-
- setRowKey(rowKey);
-
- state[5] = selectionKeySet;
-
- state[6] = activeItemSet.isEmpty() ? null : activeItemSet.iterator().next();
-
- return state;
- }
-
public void addValueChangeListener(ValueChangeListener listener) {
addFacesListener(listener);
}
@@ -310,25 +195,10 @@
}
protected Object saveIterationState() {
- ValueHolder holder = new ValueHolder();
-
- holder.selection = localSelection;
- holder.selectionSet = localSelectionSet;
-
- holder.activeItem = localActiveItem;
- holder.activeItemSet = localActiveItemSet;
-
- return holder;
+ return null;
}
protected void restoreIterationState(Object object) {
- ValueHolder holder = (ValueHolder) object;
-
- this.localSelection = holder.selection;
- this.localSelectionSet = holder.selectionSet;
-
- this.localActiveItem = holder.activeItem;
- this.localActiveItemSet = holder.activeItemSet;
}
public abstract void setImmediate(boolean immediate);
@@ -355,8 +225,6 @@
*/
public void processDecodes(FacesContext context) {
- convertState(context);
-
if (context == null) {
throw new NullPointerException();
}
@@ -453,51 +321,6 @@
}
- private final UpdateModelCommand updateValueCommand = new UpdateModelCommand() {
-
- public void execute(FacesContext context) {
- if (isLocalValueSet()) {
- ValueBinding vb = getValueBinding("value");
- if (vb != null) {
- vb.setValue(context, getLocalValueFieldValue());
- setValue(null);
- setLocalValueSet(false);
- }
- }
- }
-
- };
-
- private final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
-
- public void execute(FacesContext context) {
- if (localSelectionSet) {
- ValueBinding vb = getValueBinding("selection");
- if (vb != null) {
- vb.setValue(context, localSelection);
- localSelection = null;
- localSelectionSet = false;
- }
- }
- }
-
- };
-
- private final UpdateModelCommand updateActiveItemCommand = new UpdateModelCommand() {
-
- public void execute(FacesContext context) {
- if (localActiveItemSet) {
- ValueBinding vb = getValueBinding("activeItem");
- if (vb != null) {
- vb.setValue(context, localActiveItem);
- localActiveItem = null;
- localActiveItemSet = false;
- }
- }
- }
-
- };
-
/**
* <p>Perform the following algorithm to update the model data
* associated with this {@link UIInput}, if any, as appropriate.</p>
@@ -783,47 +606,10 @@
}
}
-
-
- private boolean isEmpty(Object value) {
-
- if (value == null) {
- return (true);
- } else if ((value instanceof String) &&
- (((String) value).length() < 1)) {
- return (true);
- } else if (value.getClass().isArray()) {
- if (0 == java.lang.reflect.Array.getLength(value)) {
- return (true);
- }
- }
- else if (value instanceof List) {
- if (0 == ((List) value).size()) {
- return (true);
- }
- }
- return (false);
- }
-
public Object getTranslatedRowKey() {
return ((TranslatedSequenceDataModel) getExtendedDataModel()).getTranslatedRowKey();
}
- private void addConversionErrorMessage(FacesContext context,
- ConverterException ce, Object value) {
- FacesMessage message = ce.getFacesMessage();
- if (message == null) {
- message = MessageFactory.getMessage(context,
- UIInput.CONVERSION_MESSAGE_ID);
- if (message.getDetail() == null) {
- message.setDetail(ce.getMessage());
- }
- }
-
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- }
-
public String getElementsOrder() {
Object order = null;
@@ -838,48 +624,12 @@
public ItemState getItemState() {
if (submittedValueHolder != null) {
- return new SubmittedItemState(submittedValueHolder.selectedItems,
submittedValueHolder.activeItem);
+ return new SubmittedItemState();
} else {
return new ModelItemState(getSelection(), getActiveItem());
}
}
- public Collection getSelection() {
- if (this.localSelection != null) {
- return this.localSelection;
- } else {
- ValueBinding vb = getValueBinding("selection");
- if (vb != null) {
- return (Collection) vb.getValue(FacesContext.getCurrentInstance());
- }
- }
-
- return null;
- }
-
- public void setSelection(Collection collection) {
- this.localSelection = collection;
- this.localSelectionSet = true;
- }
-
- public Object getActiveItem() {
- if (this.localActiveItem != null) {
- return this.localActiveItem;
- } else {
- ValueBinding vb = getValueBinding("activeItem");
- if (vb != null) {
- return vb.getValue(FacesContext.getCurrentInstance());
- }
- }
-
- return null;
- }
-
- public void setActiveItem(Object activeItem) {
- this.localActiveItem = activeItem;
- this.localActiveItemSet = true;
- }
-
/*public abstract boolean isOrderControlsVisible();
public abstract void setOrderControlsVisible(boolean visible);
Modified:
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/Control.js
===================================================================
---
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/Control.js 2007-11-27
02:52:02 UTC (rev 4279)
+++
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/Control.js 2007-11-27
02:52:11 UTC (rev 4280)
@@ -1,6 +1,16 @@
-Control = function(eNode, dNode, isShown, isEnabled, action) {
+Control = Class.create();
+
+Control.eventStub = function() {
+ return false;
+}
+
+Control.prototype.initialize = function(eNode, dNode, isShown, isEnabled, action) {
this.disabledNode = dNode;
+ this.disabledNode.onselectstart = Control.eventStub;
+
this.enabledNode = eNode
+ this.enabledNode.onselectstart = Control.eventStub;
+
this.isShown = isShown;
this.isEnabled = isEnabled;
this.action = action;
Modified:
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
===================================================================
---
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-27
02:52:02 UTC (rev 4279)
+++
branches/3.1.x/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-27
02:52:11 UTC (rev 4280)
@@ -158,7 +158,7 @@
Richfaces.OrderingList.ITEM_SEPARATOR = ",";
Richfaces.OrderingList.HANDLERS = {
- first: function (e) { this.moveSelectedItems("first", e);return false; },
+ first: function (e) { this.moveSelectedItems("first", e); return false; },
last: function (e) { this.moveSelectedItems("last", e);return false; },
up: function (e) { this.moveSelectedItems("up", e);return false; },
down: function (e) { this.moveSelectedItems("down", e);return false; }
Modified:
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java
===================================================================
---
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java 2007-11-27
02:52:02 UTC (rev 4279)
+++
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java 2007-11-27
02:52:11 UTC (rev 4280)
@@ -145,7 +145,7 @@
Object valueHolder = ((Object[])submittedValue)[0];
assertNotNull(valueHolder);
assertTrue(valueHolder instanceof UIOrderingList.SubmittedValue);
- assertEquals("1,0sa", valueHolder.toString());
+ assertEquals("1sa,0", valueHolder.toString());
orderingList.setImmediate(true);
orderingList.addValidator(new Validator() {
@@ -225,7 +225,7 @@
Object valueHolder = ((Object[])submittedValue)[0];
assertNotNull(valueHolder);
assertTrue(valueHolder instanceof UIOrderingList.SubmittedValue);
- assertEquals("1,0sa", valueHolder.toString());
+ assertEquals("1sa,0", valueHolder.toString());
}
public void testSaveRestore() throws Exception {