cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: rev 47332 - in cocoon/trunk/src: blocks/forms/java/org/apache/cocoon/forms/formmodel documentation/xdocs/userdocs/forms
Date Mon, 27 Sep 2004 21:00:05 GMT
Author: sylvain
Date: Mon Sep 27 14:00:04 2004
New Revision: 47332

Modified:
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/DeleteRowsActionDefinition.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinition.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
   cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_repeater_action.xml
   cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_row_action.xml
Log:
Rename 'on-activate' to 'on-action' and call handlers before deleting rows

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/DeleteRowsActionDefinition.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/DeleteRowsActionDefinition.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/DeleteRowsActionDefinition.java
Mon Sep 27 14:00:04 2004
@@ -16,13 +16,15 @@
 package org.apache.cocoon.forms.formmodel;
 
 import org.apache.cocoon.forms.event.ActionEvent;
-import org.apache.cocoon.forms.event.ActionListener;
 
 /**
  * The definition for a repeater action that deletes the selected rows of a sibling repeater.
+ * <p>
+ * The action listeners attached to this action, if any, are called <em>before</em>
the rows
+ * are actually removed
  * 
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
- * @version CVS $Id: DeleteRowsActionDefinition.java,v 1.2 2004/05/07 16:43:42 mpo Exp $
+ * @version CVS $Id$
  */
 public class DeleteRowsActionDefinition extends RepeaterActionDefinition {
     
@@ -31,17 +33,24 @@
     public DeleteRowsActionDefinition(String repeaterName, String selectName) {
         super(repeaterName);
         this.selectName = selectName;
+    }
+    
+    public boolean hasActionListeners() {
+        // we always want to be notified
+        return true;
+    }
+        
+    public void fireActionEvent(ActionEvent event) {
+        // Call action listeners, if any
+        super.fireActionEvent(event);
         
-        this.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent event) {
-                Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
-                for (int i = repeater.getSize() - 1; i >= 0; i--) {
-                    Repeater.RepeaterRow row = repeater.getRow(i);
-                    if (Boolean.TRUE.equals(row.getChild(DeleteRowsActionDefinition.this.selectName).getValue()))
{
-                        repeater.removeRow(i);
-                    }
-                }
+        // and actually delete the rows
+        Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
+        for (int i = repeater.getSize() - 1; i >= 0; i--) {
+            Repeater.RepeaterRow row = repeater.getRow(i);
+            if (Boolean.TRUE.equals(row.getChild(DeleteRowsActionDefinition.this.selectName).getValue()))
{
+                repeater.removeRow(i);
             }
-        });
+        }
     }
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
Mon Sep 27 14:00:04 2004
@@ -17,6 +17,7 @@
 
 import java.util.Iterator;
 
+import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
@@ -49,7 +50,14 @@
 
         definition.setActionCommand(actionCommand);
 
-        Iterator iter = buildEventListeners(widgetElement, "on-activate", ActionListener.class).iterator();
+        // Warn of the mis-named 'on-action' that existed initially
+        Element buggyOnActivate = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
"on-activate", false);
+        if (buggyOnActivate != null) {
+            throw new Exception("Use 'on-action' instead of 'on-activate' on row-action at
" +
+                DomHelper.getLocation(buggyOnActivate));
+        }
+
+        Iterator iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
         while (iter.hasNext()) {
             definition.addActionListener((ActionListener)iter.next());
         }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinition.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinition.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinition.java
Mon Sep 27 14:00:04 2004
@@ -21,7 +21,7 @@
 /**
  * 
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
- * @version CVS $Id: RowActionDefinition.java,v 1.1 2004/03/09 10:33:50 reinhard Exp $
+ * @version CVS $Id$
  */
 public class RowActionDefinition extends ActionDefinition {
     
@@ -29,19 +29,32 @@
         return new RowAction(this);
     }
     
+    /**
+     * Deletes the row containing this action. Action listeners, if any, are called <em>before</em>
+     * the row is deleted.
+     */
     public static class DeleteRowDefinition extends RowActionDefinition {
-        public DeleteRowDefinition() {
-            super.addActionListener(new ActionListener() {
-
-                public void actionPerformed(ActionEvent event) {
-                    Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
-                    Repeater repeater = (Repeater)row.getParent();
-                    repeater.removeRow(repeater.indexOf(row));
-                }
-            });
+        
+        public boolean hasActionListeners() {
+            // We always want to be notified
+            return true;
+        }
+        
+        public void fireActionEvent(ActionEvent event) {
+            // Call event listeners, if any (the row still exists)
+            super.fireActionEvent(event);
+
+            // and delete the row
+            Repeater.RepeaterRow row = Repeater.getParentRow(event.getSourceWidget());
+            Repeater repeater = (Repeater)row.getParent();
+            repeater.removeRow(repeater.indexOf(row));
         }
     }
     
+    /**
+     * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
+     * the row has been moved.
+     */
     public static class MoveUpDefinition extends RowActionDefinition {
         public MoveUpDefinition() {
             super.addActionListener(new ActionListener() {
@@ -56,6 +69,10 @@
         }
     }
     
+    /**
+     * Moves up the row containing this action. Action listeners, if any, are called <em>after</em>
+     * the row has been moved.
+     */
     public static class MoveDownDefinition extends RowActionDefinition {
         public MoveDownDefinition() {
             super.addActionListener(new ActionListener() {
@@ -70,6 +87,10 @@
         }
     }
     
+    /**
+     * Adds a row after the one containing this action. Action listeners, if any, are called
<em>after</em>
+     * the new row has been created.
+     */
     public static class AddAfterDefinition extends RowActionDefinition {
         public AddAfterDefinition() {
             super.addActionListener(new ActionListener() {
@@ -82,6 +103,4 @@
             });
         }
     }
-
-
 }

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
Mon Sep 27 14:00:04 2004
@@ -17,6 +17,7 @@
 
 import java.util.Iterator;
 
+import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
@@ -37,7 +38,14 @@
 
         definition.setActionCommand(actionCommand);
 
-        Iterator iter = buildEventListeners(widgetElement, "on-activate", ActionListener.class).iterator();
+        // Warn of the mis-named 'on-action' that existed initially
+        Element buggyOnActivate = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
"on-activate", false);
+        if (buggyOnActivate != null) {
+            throw new Exception("Use 'on-action' instead of 'on-activate' on row-action at
" +
+                DomHelper.getLocation(buggyOnActivate));
+        }
+
+        Iterator iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
         while (iter.hasNext()) {
             definition.addActionListener((ActionListener)iter.next());
         }

Modified: cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_repeater_action.xml
==============================================================================
--- cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_repeater_action.xml	(original)
+++ cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_repeater_action.xml	Mon Sep
27 14:00:04 2004
@@ -36,9 +36,9 @@
   <fd:label>...</fd:label>
   <fd:help>...</fd:help>
   <fd:hint>...</fd:hint>
-  <fd:on-activate>
+  <fd:on-action>
     ...
-  </fd:on-activate>
+  </fd:on-action>
 </fd:repeater-action>]]></source>
 
       <p>The <strong>action-command</strong> attribute should have either
@@ -56,10 +56,13 @@
       returns a boolean) that is part of the repeater and used to mark
       the rows to be deleted.</p>
 
-      <p><strong>fd:on-activate</strong> allows additional event handlers
+      <p><strong>fd:on-action</strong> allows additional event handlers
       to be defined, see also <link href="eventhandling.html">Event Handling</link>.
The interface to be
       implemented for Java event listeners is <code>org.apache.cocoon.forms.event.ActionListener</code>.
-      The WidgetEvent subclass is <code>org.apache.cocoon.forms.event.ActionEvent</code>.</p>
+      The WidgetEvent subclass is <code>org.apache.cocoon.forms.event.ActionEvent</code>.
+	  The event handlers are called <em>after</em> the action is performed except
for the
+	  <code>delete-rows</code> action where event handlers are called <em>before</em>
the
+	  selected rows are deleted.</p>
     </s1>
   </body>
 </document>

Modified: cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_row_action.xml
==============================================================================
--- cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_row_action.xml	(original)
+++ cocoon/trunk/src/documentation/xdocs/userdocs/forms/widget_row_action.xml	Mon Sep 27 14:00:04
2004
@@ -37,19 +37,22 @@
   <fd:label>...</fd:label>
   <fd:help>...</fd:help>
   <fd:hint>...</fd:hint>
-  <fd:on-activate>
+  <fd:on-action>
     ...
-  </fd:on-activate>
+  </fd:on-action>
 </fd:row-action>]]></source>
 
       <p>The <strong>action-command</strong> attribute should have either
the
       value <code>add-after</code>, <code>delete</code>, <code>move-up</code>
       or <code>move-down</code>.</p>
 
-      <p><strong>fd:on-activate</strong> allows additional event handlers
to
+      <p><strong>fd:on-action</strong> allows additional event handlers
to
       be defined, see also <link href="eventhandling.html">Event Handling</link>.
The interface to be implemented
       for Java event listeners is <code>org.apache.cocoon.forms.event.ActionListener</code>.
-      The WidgetEvent subclass is <code>org.apache.cocoon.forms.event.ActionEvent</code>.</p>
+      The WidgetEvent subclass is <code>org.apache.cocoon.forms.event.ActionEvent</code>.
+	  The event handlers are called <em>after</em> the action is performed except
for the
+	  <code>delete</code> row action where event handlers are called <em>before</em>
the
+	  row is deleted.</p>
 
       <p>Where all you want to do is submit a specific row on a repeater,
       simply add a fd:submit element to the widgets for the repeater.</p>

Mime
View raw message