Author: nbelaevski
Date: 2007-11-28 12:59:37 -0500 (Wed, 28 Nov 2007)
New Revision: 4321
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java
branches/3.1.x/sandbox/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/css/listShuttle.xcss
Log:
latest changes for listShuttle & orderingList
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java 2007-11-28
17:08:11 UTC (rev 4320)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java 2007-11-28
17:59:37 UTC (rev 4321)
@@ -6,11 +6,7 @@
import java.io.IOException;
import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
@@ -39,6 +35,25 @@
public static final String COMPONENT_FAMILY = "org.richfaces.ListShuttle";
+ private final class ModelItemState implements ItemState {
+ private Collection selectedItems;
+ private Object activeItem;
+
+ public ModelItemState(Collection selectedItems, Object activeItem) {
+ super();
+ this.selectedItems = selectedItems;
+ this.activeItem = activeItem;
+ }
+
+ public boolean isSelected() {
+ return selectedItems != null && selectedItems.contains(getRowData());
+ }
+
+ public boolean isActive() {
+ return activeItem != null && ((Set) activeItem).contains(getRowData());
+ }
+ }
+
protected static final class SubmittedValue extends OrderingBaseAbstractSubmittedValue
{
private static final Pattern KEY_STRING_PATTERN =
Pattern.compile("(s?\\d+)(s?a?)");
/**
@@ -48,22 +63,22 @@
//ListShuttleRowKey -> ListShuttleRowKey
private Map sourceTranslationTable = null;
private Map targetTranslationTable = null;
-
+
private transient boolean source;
-
+
public SubmittedValue(String[] submittedStrings) {
super();
-
+
source = true;
sourceTranslationTable = asMap(submittedStrings[0]);
source = false;
targetTranslationTable = asMap(submittedStrings[1]);
}
-
+
public String toTargetString() {
return asString(targetTranslationTable);
}
-
+
public String toSourceString() {
return asString(sourceTranslationTable);
}
@@ -84,7 +99,7 @@
char c = keyString.charAt(0);
boolean sourceKey = false;
Integer integer;
-
+
try {
if (c == 's') {
sourceKey = true;
@@ -95,7 +110,7 @@
} catch (NumberFormatException e) {
throw new FacesException(new IllegalArgumentException());
}
-
+
return new ListShuttleRowKey(integer, sourceKey, source);
}
@@ -111,7 +126,7 @@
public String getTargetSubmittedString() {
return submittedValueHolder != null ? submittedValueHolder.toTargetString() :
"";
}
-
+
private transient Map sourceTranslationTable;
private transient Map targetTranslationTable;
@@ -122,7 +137,7 @@
*
*/
private static final long serialVersionUID = 2124352131407581704L;
-
+
private Object sourceValue;
private boolean sourceValueSet;
@@ -141,10 +156,10 @@
public Object saveState(FacesContext context) {
Object[] state = new Object[2];
-
+
state[0] = super.saveState(context);
state[1] = saveIterationState();
-
+
return state;
}
@@ -155,10 +170,6 @@
restoreIterationState(state[1]);
}
- public Object getLocalSourceValue() {
- return sourceValue;
- }
-
public Object getSourceValue() {
if (sourceValue != null) {
return sourceValue;
@@ -178,10 +189,6 @@
this.sourceValueSet = true;
}
- public Object getLocalTargetValue() {
- return targetValue;
- }
-
public Object getTargetValue() {
if (targetValue != null) {
return targetValue;
@@ -201,10 +208,6 @@
this.targetValueSet = true;
}
- public String[] getSubmittedStrings() {
- return null;
- }
-
public void setSubmittedStrings(String[] submittedStrings) {
//TODO check for parameters correlation
this.submittedValueHolder = new SubmittedValue(submittedStrings);
@@ -223,22 +226,22 @@
holder.sourceValue = sourceValue;
holder.sourceValueSet = sourceValueSet;
-
+
holder.targetValue = targetValue;
holder.targetValueSet = targetValueSet;
-
+
holder.sourceTranslationTable = sourceTranslationTable;
holder.targetTranslationTable = targetTranslationTable;
-
+
return holder;
}
-
+
protected void restoreIterationState(Object object) {
ValueHolder holder = (ValueHolder) object;
-
+
sourceValue = holder.sourceValue ;
sourceValueSet = holder.sourceValueSet;
-
+
targetValue = holder.targetValue;
targetValueSet = holder.targetValueSet;
@@ -249,11 +252,11 @@
public org.ajax4jsf.model.ExtendedDataModel createDataModel() {
DataModel sourceDataModel = createDataModel(getSourceValue());
DataModel targetDataModel = createDataModel(getTargetValue());
-
+
if (isTranslatedRenderingState() || isTranslatedState()) {
Map sourceTranslationTable = null;
Map targetTranslationTable = null;
-
+
if (submittedValueHolder != null) {
sourceTranslationTable = submittedValueHolder.sourceTranslationTable;
targetTranslationTable = submittedValueHolder.targetTranslationTable;
@@ -261,7 +264,7 @@
sourceTranslationTable = this.sourceTranslationTable;
targetTranslationTable = this.targetTranslationTable;
}
-
+
return new ListShuttleDataModel(sourceDataModel, targetDataModel,
isTranslatedState(),
sourceTranslationTable,
@@ -294,7 +297,7 @@
ListShuttleDataModel dataModel = (ListShuttleDataModel) getExtendedDataModel();
return dataModel.isTarget();
}
-
+
private final UpdateModelCommand updateSourceCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
@@ -307,9 +310,9 @@
}
}
}
-
+
};
-
+
private final UpdateModelCommand updateTargetCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
@@ -322,7 +325,7 @@
}
}
}
-
+
};
/**
@@ -423,131 +426,18 @@
return;
}
- Object[] newValue = null;
+ Object oldSourceValue = getSourceValue();
+ Object newSourceValue = oldSourceValue;
- try {
- newValue = getConvertedValue(context);
- }
- catch (ConverterException ce) {
- Object submittedValue = submittedValueHolder;
- //addConversionErrorMessage(context, ce, submittedValue);
- setValid(false);
- }
+ Object oldTargetValue = getTargetValue();
+ Object newTargetValue = oldTargetValue;
- //validateValue(context, newValue);
-
- // 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();
- Set selectedItems = submittedValueHolder.getSelection();
- for (Iterator iterator = selectedItems.iterator(); iterator
- .hasNext();) {
- setRowKey(context, iterator.next());
- Object selectionItem = getRowData();
-
- selectionSet.add(selectionItem);
- }
-
- setSelection(selectionSet);
-
-// if (submittedValueHolder.activeItem != null) {
-// setRowKey(context, submittedValueHolder.activeItem);
-// Object activeItem = getRowData();
-//
-// setActiveItem(activeItem);
-// } else {
-// setActiveItem(null);
-// }
-
- Object previousSource = getSourceValue();
- Object previousTarget = getTargetValue();
-
- setSourceValue(newValue[0]);
- setTargetValue(newValue[1]);
-
- setTranslatedState();
-
- if (compareValues(previousSource, newValue[0]) || compareValues(previousTarget,
newValue[1])) {
- queueEvent(new ValueChangeEvent(this, new Object[]{previousSource,previousTarget},
newValue));
- }
-
- this.sourceTranslationTable = this.submittedValueHolder.sourceTranslationTable;
- this.targetTranslationTable = this.submittedValueHolder.targetTranslationTable;
-
- this.submittedValueHolder = null;
-
- }
- }
-
- private interface DataAdder {
- Object getContainer();
- void add(Object object);
- }
-
- private class ListDataAdder implements DataAdder {
- private ArrayList container;
-
- public ListDataAdder(int size) {
- container = new ArrayList(size);
- }
-
- public Object getContainer() {
- container.trimToSize();
- return container;
- }
-
- public void add(Object object) {
- container.add(object);
- }
- }
-
- private class ArrayDataAdder implements DataAdder {
- private int idx = 0;
- private Object[] objects;
-
- public ArrayDataAdder(Class objectClass, int size) {
- this.objects = (Object[]) Array.newInstance(objectClass.getComponentType(),
- size);
- }
-
- public void add(Object object) {
- this.objects[idx++] = object;
- }
-
- public Object getContainer() {
- return objects;
- }
- }
-
- private DataAdder createDataAdder(Object object, int size) {
- if (object instanceof List) {
- return new ListDataAdder(size);
- } else {
- return new ArrayDataAdder(object.getClass(), size);
- }
- }
-
- protected Object[] getConvertedValue(FacesContext context) throws ConverterException {
-// Object convertedValue = getSourceValue();
-// if (convertedValue == null) {
-// convertedValue = new Object[0];
-// }
-
- if (submittedValueHolder != null) {
- Object rowKey = getRowKey();
-
- Object oldSourceValue = getSourceValue();
- Object newSourceValue = oldSourceValue;
-
- Object oldTargetValue = getTargetValue();
- Object newTargetValue = oldTargetValue;
-
+ try {
final ListShuttleDataModel listShuttleDataModel = (ListShuttleDataModel)
getExtendedDataModel();
-
+
listShuttleDataModel.setSourceTranslationTable(submittedValueHolder.getSourceTranslationTable());
listShuttleDataModel.setTargetTranslationTable(submittedValueHolder.getTargetTranslationTable());
-
+
try {
if (listShuttleDataModel.needSourceTranslation()) {
final DataAdder sourceValueAdder = createDataAdder(oldSourceValue,
listShuttleDataModel.getSourceRowCount());
@@ -559,12 +449,12 @@
setRowKey(rowKey);
sourceValueAdder.add(getRowData());
}
-
+
}, null, null);
newSourceValue = sourceValueAdder.getContainer();
}
-
+
if (listShuttleDataModel.needTargetTranslation()) {
final DataAdder targetValueAdder = createDataAdder(oldTargetValue,
listShuttleDataModel.getTargetRowCount());
listShuttleDataModel.walkTarget(context, new DataVisitor() {
@@ -575,21 +465,55 @@
setRowKey(rowKey);
targetValueAdder.add(getRowData());
}
-
+
}, null, null);
newTargetValue = targetValueAdder.getContainer();
}
-
- setRowKey(rowKey);
+
} catch (IOException e) {
throw new ConverterException(e.getLocalizedMessage(), e);
}
-
- return new Object[] {newSourceValue, newTargetValue};
}
+ catch (ConverterException ce) {
+ Object submittedValue = submittedValueHolder;
+ //addConversionErrorMessage(context, ce, submittedValue);
+ setValid(false);
+ }
- return null;
+ //validateValue(context, newValue);
+
+ // If our value is valid, store the new value, erase the
+ // "submitted" value, and emit a ValueChangeEvent if appropriate
+ if (isValid()) {
+ Set[] sets = convertKeySets(context,
+ new Set[] {
+ submittedValueHolder.getSelection(),
+ submittedValueHolder.getActiveItems() });
+
+ setSelection(sets[0]);
+ setActiveItem(sets[1]);
+
+ Object previousSource = getSourceValue();
+ Object previousTarget = getTargetValue();
+
+ setSourceValue(newSourceValue);
+ setTargetValue(newTargetValue);
+
+ setTranslatedState();
+
+ if (compareValues(previousSource, newSourceValue) || compareValues(previousTarget,
newTargetValue)) {
+ queueEvent(new ValueChangeEvent(this,
+ new Object[]{previousSource,previousTarget},
+ new Object[]{newSourceValue, newTargetValue}));
+ }
+
+ this.sourceTranslationTable = this.submittedValueHolder.sourceTranslationTable;
+ this.targetTranslationTable = this.submittedValueHolder.targetTranslationTable;
+
+ this.submittedValueHolder = null;
+
+ }
}
protected void resetDataModel() {
@@ -597,13 +521,22 @@
this.sourceTranslationTable = null;
this.targetTranslationTable = null;
-
+
if (this.submittedValueHolder != null) {
setTranslatedRenderingState();
}
}
-
+
public Object getTranslatedRowKey() {
return ((ListShuttleDataModel) getExtendedDataModel()).getTranslatedRowKey();
}
+
+ public ItemState getItemState() {
+ if (submittedValueHolder != null) {
+ return new SubmittedItemState(submittedValueHolder.getSelection(),
+ submittedValueHolder.getActiveItems());
+ } else {
+ return new ModelItemState(getSelection(), getActiveItem());
+ }
+ }
}
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java 2007-11-28
17:08:11 UTC (rev 4320)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleDataModel.java 2007-11-28
17:59:37 UTC (rev 4321)
@@ -4,6 +4,7 @@
package org.richfaces.model;
import java.io.IOException;
+import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -36,7 +37,12 @@
private Map targetTranslationTable;
- protected static final class TranslatedRowKey {
+ protected static final class TranslatedRowKey implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7299475726153818934L;
+
private Object rowKey;
private String asString;
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-28
17:08:11 UTC (rev 4320)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/renderkit/ListShuttleRendererBase.java 2007-11-28
17:59:37 UTC (rev 4321)
@@ -21,6 +21,7 @@
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIListShuttle;
import org.richfaces.component.UIOrderingBaseComponent;
+import org.richfaces.component.UIOrderingBaseComponent.ItemState;
/**
* @author Nick Belaevski
@@ -65,18 +66,18 @@
encodeHeader(context, shuttle, "rich-table-header", "ol_col
rich-table-header-cell", "sourceHeaderClass");
}
- public void encodeTLRows(FacesContext context, UIListShuttle shuttle) throws IOException
{
+ public void encodeTLRows(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
encodeRows(context, shuttle, new ListShuttleRendererTableHolder(shuttle, false));
}
- public void encodeSLCaption(FacesContext context, UIListShuttle shuttle) throws
IOException {
+ 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 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, UIListShuttle shuttle) throws IOException
{
+ public void encodeSLRows(FacesContext context, UIOrderingBaseComponent shuttle) throws
IOException {
encodeRows(context, shuttle, new ListShuttleRendererTableHolder(shuttle, true));
}
@@ -96,6 +97,16 @@
StringBuffer rowClassName = new StringBuffer("ol_normal
rich-ordering-list-row");
StringBuffer cellClassName = new StringBuffer("ol_cell
rich-ordering-list-cell");
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this, table);
+ ItemState itemState = getItemState(context, table, variables);
+
+ boolean active = itemState.isActive();
+ if (active) {
+
+ }
+
+ boolean selected = itemState.isSelected();
+
writer.writeAttribute("class", rowClassName.toString(), null);
List children = table.getChildren();
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/css/listShuttle.xcss
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/css/listShuttle.xcss 2007-11-28
17:08:11 UTC (rev 4320)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/resources/org/richfaces/renderkit/html/css/listShuttle.xcss 2007-11-28
17:59:37 UTC (rev 4321)
@@ -333,6 +333,15 @@
white-space: nowrap;
}
+.rich-ordering-list-cell-selected, rich-ordering-list-cell-selected * {
+ padding : 2px;
+ white-space: nowrap;
+}
+
+.rich-ordering-list-cell-active, .rich-ordering-list-cell-active * {
+
+}
+
.rich-ordering-list-ds {
-moz-user-select: -moz-none;
}
@@ -441,6 +450,17 @@
<u:style name="font-size" skin="generalSizeFont" />
</u:selector>
+ <u:selector name=".rich-ordering-list-cell-selected,
.rich-ordering-list-cell-selected *">
+ <u:style name="color" skin="generalTextColor"/>
+ <u:style name="font-family" skin="generalFamilyFont" />
+ <u:style name="font-size" skin="generalSizeFont" />
+ </u:selector>
+
+ <u:selector name=".rich-ordering-list-cell-active,
.rich-ordering-list-cell-active *">
+ <u:style name="font-size" skin="generalSizeFont" />
+ <u:style name="font-family" skin="generalFamilyFont" />
+ </u:selector>
+
<u:selector name=".rich-ordering-control-disabled">
<u:style name="border-color" skin="panelBorderColor" />
</u:selector>
@@ -485,6 +505,5 @@
<u:style name="background-color" skin="headerGradientColor"
/>
</u:selector>
}
-
</f:template>
\ No newline at end of file