Author: nbelaevski
Date: 2007-11-27 22:24:08 -0500 (Tue, 27 Nov 2007)
New Revision: 4307
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/ListShuttleRowKey.java
Log:
abstract submitted value class created
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
03:24:01 UTC (rev 4306)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java 2007-11-28
03:24:08 UTC (rev 4307)
@@ -10,13 +10,12 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.faces.FacesException;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
@@ -40,8 +39,8 @@
public static final String COMPONENT_FAMILY = "org.richfaces.ListShuttle";
- protected static final class SubmittedValue implements Serializable {
- private static final Pattern ITEM_PATTERN =
Pattern.compile("(s|t)(\\d+)(s?a?)");
+ protected static final class SubmittedValue extends OrderingBaseAbstractSubmittedValue
{
+ private static final Pattern KEY_STRING_PATTERN =
Pattern.compile("(s?\\d+)(s?a?)");
/**
*
*/
@@ -50,95 +49,23 @@
private Map sourceTranslationTable = null;
private Map targetTranslationTable = null;
- private Set selectedItems = new HashSet();
- private List activeItems = new ArrayList();
-
+ private transient boolean source;
+
public SubmittedValue(String[] submittedStrings) {
super();
- sourceListFromString(submittedStrings[0]);
- targetListFromString(submittedStrings[1]);
+ source = true;
+ sourceTranslationTable = asMap(submittedStrings[0]);
+ source = false;
+ targetTranslationTable = asMap(submittedStrings[1]);
}
- private Map convertAndStoreKey(String string, boolean keySource) {
- String[] valueOrder = string.split(",");
- Map map = new LinkedHashMap();
-
- for (int i = 0; i < valueOrder.length; i++) {
- Matcher matcher = ITEM_PATTERN.matcher(valueOrder[i]);
- matcher.matches();
-
- try {
- char c = matcher.group(1).charAt(0);
- boolean source;
-
- if (c == 's') {
- source = true;
- } else if (c == 't') {
- source = false;
- } else {
- throw new IllegalArgumentException();
- }
-
- Integer key = Integer.valueOf(matcher.group(2));
- ListShuttleRowKey oldKey = new ListShuttleRowKey(key, source, keySource);
-
- ListShuttleRowKey newKey = new ListShuttleRowKey(Integer.valueOf(i), keySource);
-
- map.put(oldKey, newKey);
-
- String group = matcher.group(3);
- for (int j = 0; j < group.length(); j++) {
- c = group.charAt(j);
- if ('s' == c) {
- selectedItems.add(oldKey);
- } else if ('a' == c) {
- activeItems.add(newKey);
- } else {
- break ;
- }
-
- }
- } catch (NumberFormatException e) {
- // TODO: handle exception
- }
- }
-
- return map;
+ public String toTargetString() {
+ return asString(targetTranslationTable);
}
-
- private void targetListFromString(String string) {
- if (string != null && string.length() != 0) {
- targetTranslationTable = convertAndStoreKey(string, false);
- }
- }
-
- private void sourceListFromString(String string) {
- if (string != null && string.length() != 0) {
- sourceTranslationTable = convertAndStoreKey(string, true);
- }
- }
- public String toString() {
- StringBuffer result = new StringBuffer();
-// for (int i = 0; i < permutationOrder.length; i++) {
-// result.append(permutationOrder[i]);
-//
-// Integer key = new Integer(i);
-//
-// if (selectedItems.contains(key)) {
-// result.append('s');
-// }
-//
-// if (key.equals(activeItem)) {
-// result.append('a');
-// }
-//
-// if (i < permutationOrder.length - 1) {
-// result.append(',');
-// }
-// }
- return result.toString();
+ public String toSourceString() {
+ return asString(sourceTranslationTable);
}
public Map getSourceTranslationTable() {
@@ -148,8 +75,43 @@
public Map getTargetTranslationTable() {
return targetTranslationTable;
}
+
+ protected Object createNewKey(int i) {
+ return new ListShuttleRowKey(new Integer(i), source);
+ }
+
+ protected Object createOldKey(String keyString) {
+ char c = keyString.charAt(0);
+ boolean sourceKey = false;
+ Integer integer;
+
+ try {
+ if (c == 's') {
+ sourceKey = true;
+ integer = new Integer(keyString.substring(1));
+ } else {
+ integer = new Integer(keyString);
+ }
+ } catch (NumberFormatException e) {
+ throw new FacesException(new IllegalArgumentException());
+ }
+
+ return new ListShuttleRowKey(integer, sourceKey, source);
+ }
+
+ protected Pattern getKeyStringPattern() {
+ return KEY_STRING_PATTERN;
+ }
}
+ public String getSourceSubmittedString() {
+ return submittedValueHolder != null ? submittedValueHolder.toSourceString() :
"";
+ }
+
+ public String getTargetSubmittedString() {
+ return submittedValueHolder != null ? submittedValueHolder.toTargetString() :
"";
+ }
+
private transient Map sourceTranslationTable;
private transient Map targetTranslationTable;
@@ -333,16 +295,6 @@
return dataModel.isTarget();
}
- public String getSourceSubmittedString() {
- //TODO implement
- return "";
- }
-
- public String getTargetSubmittedString() {
- //TODO implement
- return "";
- }
-
private final UpdateModelCommand updateSourceCommand = new UpdateModelCommand() {
public void execute(FacesContext context) {
@@ -488,7 +440,7 @@
// "submitted" value, and emit a ValueChangeEvent if appropriate
if (isValid()) {
Set selectionSet = new HashSet();
- Set selectedItems = submittedValueHolder.selectedItems;
+ Set selectedItems = submittedValueHolder.getSelection();
for (Iterator iterator = selectedItems.iterator(); iterator
.hasNext();) {
setRowKey(context, iterator.next());
Modified:
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java
===================================================================
---
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java 2007-11-28
03:24:01 UTC (rev 4306)
+++
branches/3.1.x/sandbox/ui/listShuttle/src/main/java/org/richfaces/model/ListShuttleRowKey.java 2007-11-28
03:24:08 UTC (rev 4307)
@@ -61,7 +61,7 @@
}
public String toString() {
- return (source ? "s" : "t") + rowKey.toString();
+ return (source ? "s" : "") + rowKey.toString();
}
public ListShuttleRowKey(Object rowKey, boolean source) {
Show replies by date