Author: nbelaevski
Date: 2007-11-11 17:43:50 -0500 (Sun, 11 Nov 2007)
New Revision: 3893
Modified:
trunk/sandbox/ui/orderingList/src/main/config/component/orderinglist.xml
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
trunk/sandbox/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx
Log:
more features for orderingList implemented
Modified: trunk/sandbox/ui/orderingList/src/main/config/component/orderinglist.xml
===================================================================
--- trunk/sandbox/ui/orderingList/src/main/config/component/orderinglist.xml 2007-11-11
22:43:38 UTC (rev 3892)
+++ trunk/sandbox/ui/orderingList/src/main/config/component/orderinglist.xml 2007-11-11
22:43:50 UTC (rev 3893)
@@ -162,9 +162,17 @@
<defaultvalue>true</defaultvalue>
</property>
+ <property>
+ <name>selection</name>
+ <description>Collection which stores a set of selected
items</description>
+ </property>
+
<property hidden="true" el="false">
<name>submittedValue</name>
</property>
+ <property hidden="true" el="false"
exist="true">
+ <name>submittedString</name>
+ </property>
<property hidden="true" el="false">
<name>localValueSet</name>
</property>
Modified:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-11
22:43:38 UTC (rev 3892)
+++
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java 2007-11-11
22:43:50 UTC (rev 3893)
@@ -2,6 +2,7 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@@ -11,7 +12,6 @@
import java.util.regex.Pattern;
import javax.faces.FacesException;
-import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIColumn;
@@ -52,6 +52,16 @@
private boolean translatedRendering = false;
}
+ public static final class ValueHolder {
+ private Object value;
+
+ private Collection selection;
+ private boolean selectionSet;
+
+ private Object activeItem;
+ private boolean activeItemSet;
+ }
+
public static final class SubmittedValue {
private int[] permutationOrder;
private Set selectedItems = new HashSet();
@@ -75,9 +85,9 @@
for (int j = 0; j < group.length(); j++) {
char c = group.charAt(j);
if ('s' == c) {
- selectedItems.add(new Integer(i));
+ selectedItems.add(new Integer(permutationOrder[i]));
} else if ('a' == c) {
- activeItem = i;
+ activeItem = permutationOrder[i];
} else {
break ;
}
@@ -115,13 +125,11 @@
}
- public static final Predicate isColumn = new ColumnPredicate();
-
- private static final class ColumnPredicate implements Predicate {
+ public static final Predicate isColumn = new Predicate() {
public boolean evaluate(Object input) {
return (input instanceof UIColumn || input instanceof Column);
}
- }
+ };
protected DataComponentState createComponentState() {
return new RepeatState();
@@ -174,6 +182,12 @@
private Object value;
private boolean localValueSet;
+ private Collection selection;
+ private boolean localSelectionSet;
+
+ private Object activeItem;
+ private boolean localActiveItemSet;
+
private transient SubmittedValue submittedValueHolder = null;
private transient EditableState editableState = new EditableState();
@@ -182,18 +196,32 @@
super.restoreState(faces, state[0]);
validators = (List) restoreAttachedState(faces, state[1]);
validator = (MethodBinding) restoreAttachedState(faces, state[2]);
+
value = state[3];
localValueSet = ((Boolean) state[4]).booleanValue();
+
+ selection = (Collection) state[5];
+ localSelectionSet = ((Boolean) state[6]).booleanValue();
+
+ activeItem = state[7];
+ localActiveItemSet = ((Boolean) state[8]).booleanValue();
}
public Object saveState(FacesContext faces) {
- Object[] state = new Object[5];
+ Object[] state = new Object[9];
state[0] = super.saveState(faces);
state[1] = saveAttachedState(faces, validators);
state[2] = saveAttachedState(faces, validator);
+
state[3] = value;
state[4] = localValueSet ? Boolean.TRUE : Boolean.FALSE;
+ state[5] = selection;
+ state[6] = localSelectionSet ? Boolean.TRUE : Boolean.FALSE;
+
+ state[7] = activeItem;
+ state[8] = localActiveItemSet ? Boolean.TRUE : Boolean.FALSE;
+
return state;
}
@@ -256,18 +284,18 @@
}
- public Object getSubmittedValueAsString() {
- return submittedValueHolder;
+ public String getSubmittedString() {
+ return submittedValueHolder != null ? submittedValueHolder.toString() : "";
}
+ public void setSubmittedString(String submittedString) {
+ this.submittedValueHolder = new SubmittedValue(submittedString);
+ }
+
public Object getSubmittedValue() {
return new Object[] { submittedValueHolder, editableState };
}
- public void setSubmittedString(String submittedString) {
- this.submittedValueHolder = new SubmittedValue(submittedString);
- }
-
public void setSubmittedValue(Object submittedValue) {
if (submittedValue != null) {
Object[] values = (Object[]) submittedValue;
@@ -297,13 +325,33 @@
public Object getLocalValue() {
- return value;
+ ValueHolder holder = new ValueHolder();
+ holder.value = value;
+
+ holder.selection = selection;
+ holder.selectionSet = localSelectionSet;
+
+ holder.activeItem = activeItem;
+ holder.activeItemSet = localActiveItemSet;
+ return holder;
}
public void setValue(Object value) {
- super.setValue(value);
- this.value = value;
- setLocalValueSet(true);
+ if (value instanceof ValueHolder) {
+ ValueHolder holder = (ValueHolder) value;
+
+ setValue(holder.value);
+
+ this.selection = holder.selection;
+ this.localSelectionSet = holder.selectionSet;
+
+ this.activeItem = holder.activeItem;
+ this.localActiveItemSet = holder.activeItemSet;
+ } else {
+ super.setValue(value);
+ this.value = value;
+ setLocalValueSet(true);
+ }
}
public Object getValue() {
@@ -457,8 +505,97 @@
}
}
+
+ private interface UpdateModelCommand {
+ public void execute(FacesContext context);
+ }
+ private final UpdateModelCommand updateValueCommand = new UpdateModelCommand() {
+ public void execute(FacesContext context) {
+ if (isLocalValueSet()) {
+ ValueBinding vb = getValueBinding("value");
+ if (vb != null) {
+ ValueHolder localValue = (ValueHolder) getLocalValue();
+ vb.setValue(context, localValue.value);
+ setValue(null);
+ setLocalValueSet(false);
+ }
+ }
+ }
+
+ };
+
+ private final UpdateModelCommand updateSelectionCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ ValueHolder localValue = (ValueHolder) getLocalValue();
+ if (localValue.selectionSet) {
+ ValueBinding vb = getValueBinding("selection");
+ if (vb != null) {
+ vb.setValue(context, localValue.selection);
+ localValue.selection = null;
+ localValue.selectionSet = false;
+ }
+ }
+ }
+
+ };
+
+ private final UpdateModelCommand updateActiveItemCommand = new UpdateModelCommand() {
+
+ public void execute(FacesContext context) {
+ ValueHolder localValue = (ValueHolder) getLocalValue();
+ if (localValue.activeItemSet) {
+ ValueBinding vb = getValueBinding("activeItem");
+ if (vb != null) {
+ vb.setValue(context, localValue.activeItem);
+ localValue.activeItem = null;
+ localValue.activeItemSet = false;
+ }
+ }
+ }
+
+ };
+
+ private void updateModel(FacesContext context, UpdateModelCommand command) {
+ try {
+ command.execute(context);
+ } catch (EvaluationException e) {
+ String messageStr = e.getMessage();
+ FacesMessage message = null;
+ if (null == messageStr) {
+ message =
+ MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
+ }
+ else {
+ message = new FacesMessage(messageStr);
+ }
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ setValid(false);
+ }
+ catch (FacesException e) {
+ FacesMessage message =
+ MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ setValid(false);
+ } catch (IllegalArgumentException e) {
+ FacesMessage message =
+ MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ setValid(false);
+ } catch (Exception e) {
+ FacesMessage message =
+ MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ setValid(false);
+ }
+ }
+
/**
* <p>Perform the following algorithm to update the model data
* associated with this {@link UIInput}, if any, as appropriate.</p>
@@ -497,51 +634,13 @@
throw new NullPointerException();
}
- if (!isValid() || !isLocalValueSet()) {
+ if (!isValid()) {
return;
}
- ValueBinding vb = getValueBinding("value");
- if (vb != null) {
- try {
- vb.setValue(context, getLocalValue());
- setValue(null);
- setLocalValueSet(false);
- return;
- } catch (EvaluationException e) {
- String messageStr = e.getMessage();
- FacesMessage message = null;
- if (null == messageStr) {
- message =
- MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
- }
- else {
- message = new FacesMessage(messageStr);
- }
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- setValid(false);
- }
- catch (FacesException e) {
- FacesMessage message =
- MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- setValid(false);
- } catch (IllegalArgumentException e) {
- FacesMessage message =
- MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- setValid(false);
- } catch (Exception e) {
- FacesMessage message =
- MessageFactory.getMessage(context, UIInput.CONVERSION_MESSAGE_ID);
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- setValid(false);
- }
- }
+ updateModel(context, updateValueCommand);
+ updateModel(context, updateSelectionCommand);
+ updateModel(context, updateActiveItemCommand);
}
@@ -590,8 +689,7 @@
// Submitted value == null means "the component was not submitted
// at all"; validation should not continue
- Object submittedValue = getSubmittedValue();
- if (submittedValue == null) {
+ if (submittedValueHolder == null) {
return;
}
@@ -601,6 +699,7 @@
newValue = getConvertedValue();
}
catch (ConverterException ce) {
+ Object submittedValue = submittedValueHolder;
addConversionErrorMessage(context, ce, submittedValue);
setValid(false);
}
@@ -610,16 +709,36 @@
// If our value is valid, store the new value, erase the
// "submitted" value, and emit a ValueChangeEvent if appropriate
if (isValid()) {
+ Set selectionSet = new HashSet();
+ ExtendedDataModel dataModel = getExtendedDataModel();
+ Set selectedItems = submittedValueHolder.selectedItems;
+ for (Iterator iterator = selectedItems.iterator(); iterator
+ .hasNext();) {
+ dataModel.setRowKey(iterator.next());
+ Object selectionItem = dataModel.getRowData();
+
+ selectionSet.add(selectionItem);
+ }
+
+ this.selection = selectionSet;
+ this.localSelectionSet = true;
+
+ dataModel.setRowIndex(new Integer(submittedValueHolder.activeItem));
+ Object activeItem = dataModel.getRowData();
+
+ this.activeItem = activeItem;
+ this.localActiveItemSet = true;
+
Object previous = getValue();
setValue(newValue);
- this.submittedValueHolder = null;
this.editableState.isTranslated = true;
//setSubmittedValue(null);
if (compareValues(previous, newValue)) {
queueEvent(new ValueChangeEvent(this, previous, newValue));
}
+
+ this.submittedValueHolder = null;
}
-
}
protected Object getConvertedValue() throws ConverterException {
@@ -812,36 +931,6 @@
}
- private Converter getConverterWithType(FacesContext context) {
- Converter converter = getConverter();
- if (converter != null) {
- return converter;
- }
-
- ValueBinding valueBinding = getValueBinding("value");
- if (valueBinding == null) {
- return null;
- }
-
- Class converterType = valueBinding.getType(context);
- // if converterType is null, String, or Object, assume
- // no conversion is needed
- if (converterType == null ||
- converterType == String.class ||
- converterType == Object.class) {
- return null;
- }
-
- // if getType returns a type for which we support a default
- // conversion, acquire an appropriate converter instance.
- try {
- Application application = context.getApplication();
- return application.createConverter(converterType);
- } catch (Exception e) {
- return (null);
- }
- }
-
private void addConversionErrorMessage(FacesContext context,
ConverterException ce, Object value) {
FacesMessage message = ce.getFacesMessage();
@@ -869,6 +958,17 @@
return ScriptUtils.toScript(order);
}
+ public boolean isActiveItem() {
+ return activeItem != null && activeItem.equals(getRowData());
+ }
+
+ public boolean isSelected() {
+ return selection != null && selection.contains(getRowData());
+ }
+
+ public abstract Collection getSelection();
+ public abstract void setSelection(Collection collection);
+
public abstract boolean isOrderControlsVisible();
public abstract void setOrderControlsVisible(boolean visible);
Modified:
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-11-11
22:43:38 UTC (rev 3892)
+++
trunk/sandbox/ui/orderingList/src/main/java/org/richfaces/renderkit/OrderingListRendererBase.java 2007-11-11
22:43:50 UTC (rev 3893)
@@ -12,7 +12,6 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
@@ -142,7 +141,7 @@
}
},
- new ControlsHelper("down", "↡",
OrderingListIconDown.class.getName(), FACET_DOWN,
+ new ControlsHelper("down", "↓",
OrderingListIconDown.class.getName(), FACET_DOWN,
"rich-ordering-control-down", CONTROL_ID_DOWN, ATTRIBUTE_CE_ONDOWNCLICK) {
public boolean isRendered(FacesContext context, UIOrderingList list) {
@@ -150,7 +149,7 @@
}
},
- new ControlsHelper("botton", "↓",
OrderingListIconBottom.class.getName(), FACET_BOTTOM,
+ new ControlsHelper("botton", "↡",
OrderingListIconBottom.class.getName(), FACET_BOTTOM,
"rich-ordering-control-bottom", CONTROL_ID_BOTTOM,
ATTRIBUTE_CE_ONBOTTOMCLICK) {
public boolean isRendered(FacesContext context, UIOrderingList list) {
@@ -333,10 +332,22 @@
public void encodeOneRow(FacesContext context, TableHolder holder)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
- UIDataAdaptor table = holder.getTable();
+ UIOrderingList table = (UIOrderingList) holder.getTable();
String clientId = holder.getTable().getClientId(context);
writer.startElement(HTML.TR_ELEMENT, table);
writer.writeAttribute("id", clientId, null);
+
+ String className = null;
+ if (table.isActiveItem()) {
+ className = "ol_active rich-ordering-list-row-active";
+ } else if (table.isSelected()) {
+ className = "ol_select rich-ordering-list-row-selected";
+ } else {
+ className = "ol_normal rich-ordering-list-row";
+ }
+
+ writer.writeAttribute("class", className, null);
+
List<UIComponent> children = table.getChildren();
for (UIComponent component : children) {
if (component instanceof UIColumn && component.isRendered()) {
Modified:
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-11
22:43:38 UTC (rev 3892)
+++
trunk/sandbox/ui/orderingList/src/main/resources/org/richfaces/renderkit/html/scripts/OrderingList.js 2007-11-11
22:43:50 UTC (rev 3893)
@@ -68,6 +68,13 @@
Shuttle.SELECTION_MARKER = "s";
Shuttle.ITEM_SEPARATOR = ",";
+Shuttle.HANDLERS = {
+ 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; }
+};
+
Shuttle.prototype.init = function(containerId, contentTableId, headerTableId, ids,
onclickControlId, focusKeeperId) {
var obj = this;
Shuttle.setFocus(focusKeeperId);
@@ -76,7 +83,7 @@
var node = document.getElementById(containerId + id[0]);
var disNode = document.getElementById(containerId + id[1]);
if (node && disNode) {
- Shuttle.addClickListener(node, function(e) {obj.moveSelectedItems(id[0], e);return
false;});
+ Shuttle.addClickListener(node, Shuttle.HANDLERS[id[0]].bindAsEventListener(this));
this.controlList[i] = new Control(node, disNode, false, false, id[0]);
}
}
Modified:
trunk/sandbox/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx
===================================================================
---
trunk/sandbox/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx 2007-11-11
22:43:38 UTC (rev 3892)
+++
trunk/sandbox/ui/orderingList/src/main/templates/org/richfaces/htmlOrderingList.jspx 2007-11-11
22:43:50 UTC (rev 3893)
@@ -12,6 +12,7 @@
<h:styles>css/orderingList.xcss</h:styles>
<h:scripts>
+ new org.ajax4jsf.javascript.PrototypeScript(),
scripts/SelectItem.js,
scripts/LayoutManager.js
scripts/Control.js,
@@ -22,7 +23,7 @@
<div id="#{clientId}" x:passThruWithExclusions="id">
<input id="#{clientId}focusKeeper" type="button"
value="" style="width: 1px; position: absolute; left: -32767px;"
name="focusKeeper"/>
- <input id="#{clientId}valueKeeper" type="hidden"
name="#{clientId}" value="#{component.submittedValueAsString}"/>
+ <input id="#{clientId}valueKeeper" type="hidden"
name="#{clientId}" value="#{component.submittedString}"/>
<table id="#{clientId}table" cellpadding="0"
cellspacing="0" class="ol_body">
<tbody>