You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/02/27 22:26:53 UTC

svn commit: r381454 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/event/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/examp...

Author: weber
Date: Mon Feb 27 13:26:52 2006
New Revision: 381454

URL: http://svn.apache.org/viewcvs?rev=381454&view=rev
Log:
introducing SortActionEvent

Added:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/event/SortActionEvent.java
Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
    incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=381454&r1=381453&r2=381454&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Mon Feb 27 13:26:52 2006
@@ -901,8 +901,8 @@
     final Application application = facesContext.getApplication();
     if (actionListener != null) {
       if (UIComponentTag.isValueReference(actionListener)) {
-        MethodBinding binding
-            = application.createMethodBinding(actionListener, ACTION_LISTENER_ARGS);
+        MethodBinding binding = application.createMethodBinding(
+            actionListener, ACTION_LISTENER_ARGS);
         data.setSortActionListener(binding);
       } else {
         throw new IllegalArgumentException(

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=381454&r1=381453&r2=381454&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Mon Feb 27 13:26:52 2006
@@ -20,6 +20,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.TobagoConstants;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
+import org.apache.myfaces.tobago.event.SortActionEvent;
 import org.apache.myfaces.tobago.model.SheetState;
 import org.apache.myfaces.tobago.util.BeanComparator;
 import org.apache.myfaces.tobago.util.ValueBindingComparator;
@@ -32,7 +33,6 @@
 import javax.faces.el.MethodBinding;
 import javax.faces.el.MethodNotFoundException;
 import javax.faces.el.ValueBinding;
-import javax.faces.event.ActionEvent;
 import javax.faces.model.DataModel;
 import java.util.*;
 
@@ -48,14 +48,13 @@
 
   public Object invoke(FacesContext facesContext, Object[] aobj)
       throws EvaluationException {
-    if (aobj[0] instanceof ActionEvent) {
-      javax.faces.component.UICommand command =
-          (javax.faces.component.UICommand) ((ActionEvent) aobj[0]).getSource();
+    if (aobj[0] instanceof SortActionEvent) {
+      SortActionEvent sortEvent = (SortActionEvent) aobj[0];
       if (LOG.isDebugEnabled()) {
-        LOG.debug("sorterId = " + command.getId());
+        LOG.debug("sorterId = " + sortEvent.getComponent().getId());
       }
-      UIColumn column = (UIColumn) command.getParent();
-      UIData data = (UIData) column.getParent();
+      UIColumn column = sortEvent.getColumn();
+      UIData data = sortEvent.getSheet();
 
       Object value = data.getValue();
       if (value instanceof DataModel) {

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=381454&r1=381453&r2=381454&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Mon Feb 27 13:26:52 2006
@@ -25,6 +25,7 @@
 import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
 import org.apache.myfaces.tobago.event.SheetStateChangeListener;
 import org.apache.myfaces.tobago.event.SheetStateChangeSource;
+import org.apache.myfaces.tobago.event.SortActionEvent;
 import org.apache.myfaces.tobago.model.SheetState;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.SheetRendererWorkaround;
@@ -333,6 +334,8 @@
     }
   }
 
+
+
   public Object saveState(FacesContext context) {
     Object[] saveState = new Object[5];
     saveState[0] = super.saveState(context);
@@ -391,6 +394,7 @@
   }
 
   public void queueEvent(FacesEvent facesEvent) {
+
     if (facesEvent instanceof SheetStateChangeEvent) {
       UIComponent parent = getParent();
       if (parent == null) {
@@ -398,9 +402,19 @@
       }
       parent.queueEvent(facesEvent);
     } else {
-      super.queueEvent(facesEvent);
+      UIComponent source = facesEvent.getComponent();
+      UIComponent parent = source.getParent();
+//      if (parent == this
+//          && source.getId() != null ) {
+//        super.queueEvent(new PageActionEvent(this));
+//      } else
+      if (parent.getParent() == this
+          && source.getId() != null && source.getId().endsWith(SORTER_ID)) {
+        super.queueEvent(new SortActionEvent(source));
+      } else {
+        super.queueEvent(facesEvent);
+      }
     }
-
   }
 
   public void broadcast(FacesEvent facesEvent) throws AbortProcessingException {

Added: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/event/SortActionEvent.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/event/SortActionEvent.java?rev=381454&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/event/SortActionEvent.java (added)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/event/SortActionEvent.java Mon Feb 27 13:26:52 2006
@@ -0,0 +1,43 @@
+package org.apache.myfaces.tobago.event;
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.myfaces.tobago.component.UIData;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.event.ActionEvent;
+
+public class SortActionEvent extends ActionEvent {
+
+  public SortActionEvent(UIComponent uiComponent) {
+    super(uiComponent);
+  }
+
+  /**
+   * Convenience method to get the UIColumn to sort.
+   */
+  public UIColumn getColumn() {
+    return (UIColumn) getComponent().getParent();
+  }
+
+  /**
+   * Convenience method to get the UIData Component. 
+   */
+  public UIData getSheet() {
+    return (UIData) getColumn().getParent();
+  }
+}

Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=381454&r1=381453&r2=381454&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java Mon Feb 27 13:26:52 2006
@@ -24,11 +24,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.component.Sorter;
-import org.apache.myfaces.tobago.component.UIData;
 import org.apache.myfaces.tobago.context.ResourceManager;
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
+import org.apache.myfaces.tobago.event.SortActionEvent;
 
-import javax.faces.component.UICommand;
 import javax.faces.context.FacesContext;
 import javax.faces.event.ActionEvent;
 import javax.faces.model.SelectItem;
@@ -116,15 +115,14 @@
 
   
   public void sheetSorter(ActionEvent event) {
-    Object eventSource = event.getSource();
-    UIData data = (UIData) ((UICommand) eventSource).getParent().getParent();
-    List list = (List) data.getValue();
-    Object sun = list.remove(0);
-    Object[] objects = new Object[1];
-    objects[0] = event;
-    Sorter sorter = new Sorter();
-    sorter.invoke(FacesContext.getCurrentInstance(), objects);
-    list.add(0, sun);
+    if (event instanceof SortActionEvent) {
+      SortActionEvent sortEvent = (SortActionEvent) event;
+      List list = (List) sortEvent.getSheet().getValue();
+      Object sun = list.remove(0);
+      Object[] objects = new Object[] {sortEvent};
+      new Sorter().invoke(FacesContext.getCurrentInstance(), objects);
+      list.add(0, sun);
+    }
   }
 
   public boolean getShowPopup() {