You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2006/05/17 16:44:25 UTC
svn commit: r407270 -
/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java
Author: bruno
Date: Wed May 17 07:44:24 2006
New Revision: 407270
URL: http://svn.apache.org/viewcvs?rev=407270&view=rev
Log:
Add a 'normal-behaving' moveRow2 method.
Modified:
cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=407270&r1=407269&r2=407270&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/Repeater.java Wed May 17 07:44:24 2006
@@ -225,6 +225,33 @@
broadcastEvent(new RepeaterEvent(this, RepeaterEventAction.ROWS_REARRANGED));
}
+ /**
+ * Move a row from one place to another. In contrast to {@link #moveRow}, this
+ * method treats the to-index as the exact row-index where you want to have the
+ * row moved to.
+ *
+ * @param from the existing row position
+ * @param to the target position. The "from" item will be moved before that position.
+ */
+ public void moveRow2(int from, int to) {
+ int size = this.rows.size();
+
+ if (from < 0 || from >= size || to < 0 || to >= size) {
+ throw new IllegalArgumentException("Cannot move from " + from + " to " + to +
+ " on repeater with " + size + " rows");
+ }
+
+ if (from == to) {
+ return;
+ }
+
+ Object fromRow = this.rows.remove(from);
+ this.rows.add(to, fromRow);
+
+ getForm().addWidgetUpdate(this);
+ broadcastEvent(new RepeaterEvent(this, RepeaterEventAction.ROWS_REARRANGED));
+ }
+
public void moveRowLeft(int index) {
if (index == 0 || index >= this.rows.size()) {
// do nothing