You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2007/12/05 10:33:20 UTC

svn commit: r601271 - in /myfaces/tobago/trunk: example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/ example/sandbox/src/main/webapp/ example/sandbox/src/main/webapp/WEB-INF/ example/sandbox/src/main/webapp/wizard/ sandbox/src/main/...

Author: lofwyr
Date: Wed Dec  5 01:33:18 2007
New Revision: 601271

URL: http://svn.apache.org/viewvc?rev=601271&view=rev
Log:
TOBAGO-518: Adding process course

Added:
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-2.jsp
      - copied, changed from r600427, myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-1.jsp
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/application/WizardNavigationHandler.java
      - copied, changed from r600427, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugNavigationHandler.java
Modified:
    myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Controller.java
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard.jsp
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/fileIntoCondition.jsp
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/filter.jsp
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/finish.jsp
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/forwardCondition.jsp
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/AbstractWizard.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/Wizard.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/WizardTag.java

Modified: myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Controller.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Controller.java?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Controller.java (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Controller.java Wed Dec  5 01:33:18 2007
@@ -99,9 +99,9 @@
   }
 
   public String createFilter() {
-    if (filterType.equals("fileInto")) {
+    if ("fileInto".equals(filterType)) {
       return "fileIntoCondition";
-    } else if (filterType.equals("forward")) {
+    } else if ("forward".equals(filterType)) {
       return "forwardCondition";
     }
     throw new RuntimeException("no filter");

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml Wed Dec  5 01:33:18 2007
@@ -55,6 +55,26 @@
   </navigation-rule>
 
   <navigation-rule>
+    <from-view-id>/wizard/*</from-view-id>
+    <navigation-case>
+      <from-outcome>fileIntoCondition</from-outcome>
+      <to-view-id>/wizard/fileIntoCondition.jsp</to-view-id>
+    </navigation-case>
+    <navigation-case>
+      <from-outcome>forwardCondition</from-outcome>
+      <to-view-id>/wizard/forwardCondition.jsp</to-view-id>
+    </navigation-case>
+    <navigation-case>
+      <from-outcome>finish</from-outcome>
+      <to-view-id>/wizard/finish.jsp</to-view-id>
+    </navigation-case>
+    <navigation-case>
+      <from-outcome>filter</from-outcome>
+      <to-view-id>/wizard/filter.jsp</to-view-id>
+    </navigation-case>
+  </navigation-rule>
+
+  <navigation-rule>
     <from-view-id>/wizard/filter.jsp</from-view-id>
     <navigation-case>
       <from-outcome>fileIntoCondition</from-outcome>
@@ -72,10 +92,12 @@
       <from-outcome>next</from-outcome>
       <to-view-id>/wizard/finish.jsp</to-view-id>
     </navigation-case>
+<!--
     <navigation-case>
       <from-outcome>previous</from-outcome>
       <to-view-id>/wizard/filter.jsp</to-view-id>
     </navigation-case>
+-->
   </navigation-rule>
 
   <navigation-rule>
@@ -84,14 +106,17 @@
       <from-outcome>next</from-outcome>
       <to-view-id>/wizard/finish.jsp</to-view-id>
     </navigation-case>
+<!--
     <navigation-case>
       <from-outcome>previous</from-outcome>
       <to-view-id>/wizard/filter.jsp</to-view-id>
     </navigation-case>
+-->
   </navigation-rule>
 
   <navigation-rule>
     <from-view-id>/wizard/finish.jsp</from-view-id>
+<!--
     <navigation-case>
       <from-outcome>forwardCondition</from-outcome>
       <to-view-id>/wizard/fileIntoCondition.jsp</to-view-id>
@@ -100,6 +125,7 @@
       <from-outcome>forwardCondition</from-outcome>
       <to-view-id>/wizard/forwardCondition.jsp</to-view-id>
     </navigation-case>
+-->
   </navigation-rule>
 
 </faces-config>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp Wed Dec  5 01:33:18 2007
@@ -23,7 +23,7 @@
 
   <tc:page label="Sandbox Menu" id="page" width="200px" height="800px">
     <f:facet name="layout">
-      <tc:gridLayout margin="5px" rows="fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;*"/>
+      <tc:gridLayout margin="5px" rows="fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;*"/>
     </f:facet>
 
     <tc:link link="separator.jsp" label="separator.jsp" target="View"/>
@@ -41,6 +41,8 @@
     <tc:link link="inputSlider.jsp" label="inputSlider.jsp" target="View"/>
 
     <tc:link link="wizard.jsp" label="wizard.jsp" target="View"/>
+
+    <tc:link link="wizard/filter.jsp" label="wizard/filter.jsp" target="View"/>
 
     <tc:link link="wizard.xml" label="wizard.xml" target="View"/>
 

Copied: myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-2.jsp (from r600427, myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-1.jsp)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-2.jsp?p2=myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-2.jsp&p1=myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-1.jsp&r1=600427&r2=601271&rev=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-1.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/snip-2.jsp Wed Dec  5 01:33:18 2007
@@ -19,4 +19,4 @@
 <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
 
-<tc:out value="Second Page" />
+<tc:out value="3rd Page" />

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard.jsp Wed Dec  5 01:33:18 2007
@@ -28,7 +28,7 @@
       <tc:gridLayout margin="10px" rows="600px;*"/>
     </f:facet>
 
-    <tcs:wizard controller="#{controller.wizard}">
+    <tcs:wizard controller="#{controller.wizard}" next="wizard">
 
       <tc:include value="snip-#{controller.wizard.index}.jsp" />
       

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/fileIntoCondition.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/fileIntoCondition.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/fileIntoCondition.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/fileIntoCondition.jsp Wed Dec  5 01:33:18 2007
@@ -22,41 +22,33 @@
 <f:view>
   <tc:loadBundle basename="demo" var="bundle"/>
 
-  <tc:page label="Sandbox - Wizard" id="page"
-           width="500px" height="800px">
+  <tc:page label="Sandbox - Wizard" id="page" width="500px" height="300px">
     <f:facet name="layout">
-      <tc:gridLayout margin="10px" rows="600px;*"/>
+      <tc:gridLayout margin="10px"/>
     </f:facet>
 
-    <tcs:wizard controller="#{controller.wizard}">
+    <tcs:wizard controller="#{controller.wizard}" title="File Into Condition" outcome="fileIntoCondition" next="next">
       <tc:panel>
         <f:facet name="layout">
-          <tc:gridLayout rows="fixed;fixed" />
+          <tc:gridLayout rows="fixed;fixed;fixed;fixed;*"/>
         </f:facet>
 
         <tc:out value="file into condition"/>
 
-        <tc:panel>
-          <f:facet name="layout">
-            <tc:gridLayout columns="1*;1*;1*" />
-          </f:facet>
-
-          <tc:selectOneChoice>
-            <f:selectItems />
-          </tc:selectOneChoice>
-
-          <tc:selectOneChoice>
-            <f:selectItems />
-          </tc:selectOneChoice>
+        <tc:selectOneChoice>
+          <f:selectItems/>
+        </tc:selectOneChoice>
 
-          <tc:in required="true" />
+        <tc:selectOneChoice>
+          <f:selectItems/>
+        </tc:selectOneChoice>
 
-        </tc:panel>
+        <tc:in/>
+
+        <tc:cell/>
 
       </tc:panel>
     </tcs:wizard>
-
-    <tc:cell/>
 
   </tc:page>
 </f:view>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/filter.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/filter.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/filter.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/filter.jsp Wed Dec  5 01:33:18 2007
@@ -23,12 +23,12 @@
   <tc:loadBundle basename="demo" var="bundle"/>
 
   <tc:page label="Sandbox - Wizard" id="page"
-           width="500px" height="800px">
+           width="500px" height="300px">
     <f:facet name="layout">
-      <tc:gridLayout margin="10px" rows="600px;*"/>
+      <tc:gridLayout margin="10px" />
     </f:facet>
 
-    <tcs:wizard controller="#{controller.wizard}" next="#{controller.createFilter}">
+    <tcs:wizard controller="#{controller.wizard}" title="New Filter" outcome="filter" next="#{controller.createFilter}">
 
       <tc:selectOneRadio value="#{controller.filterType}">
         <tc:selectItem itemLabel="File Into" itemValue="fileInto" />
@@ -36,8 +36,6 @@
       </tc:selectOneRadio>
 
     </tcs:wizard>
-
-    <tc:cell/>
 
   </tc:page>
 </f:view>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/finish.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/finish.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/finish.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/finish.jsp Wed Dec  5 01:33:18 2007
@@ -23,18 +23,16 @@
   <tc:loadBundle basename="demo" var="bundle"/>
 
   <tc:page label="Sandbox - Wizard" id="page"
-           width="500px" height="800px">
+           width="500px" height="300px">
     <f:facet name="layout">
-      <tc:gridLayout margin="10px" rows="600px;*"/>
+      <tc:gridLayout margin="10px" />
     </f:facet>
 
-    <tcs:wizard controller="#{controller.wizard}" previous="#{controller.createFilter}">
+    <tcs:wizard controller="#{controller.wizard}" title="Finish" outcome="finish">
 
-      <tc:out value="Click finish to aktivate"/>
+      <tc:out value="Click finish for activation."/>
 
     </tcs:wizard>
-
-    <tc:cell/>
 
   </tc:page>
 </f:view>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/forwardCondition.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/forwardCondition.jsp?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/forwardCondition.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/wizard/forwardCondition.jsp Wed Dec  5 01:33:18 2007
@@ -23,14 +23,16 @@
   <tc:loadBundle basename="demo" var="bundle"/>
 
   <tc:page label="Sandbox - Wizard" id="page"
-           width="500px" height="800px">
+           width="500px" height="300px">
     <f:facet name="layout">
-      <tc:gridLayout margin="10px" rows="600px;*"/>
+      <tc:gridLayout margin="10px" />
     </f:facet>
 
-    <tcs:wizard controller="#{controller.wizard}"/>
+    <tcs:wizard controller="#{controller.wizard}" title="Forward Condition" outcome="forwardCondition" next="next">
 
-    <tc:cell/>
+      <tc:out value="Forward Condition" />
+
+    </tcs:wizard>
 
   </tc:page>
 </f:view>

Copied: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/application/WizardNavigationHandler.java (from r600427, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugNavigationHandler.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/application/WizardNavigationHandler.java?p2=myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/application/WizardNavigationHandler.java&p1=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugNavigationHandler.java&r1=600427&r2=601271&rev=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugNavigationHandler.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/application/WizardNavigationHandler.java Wed Dec  5 01:33:18 2007
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.util;
+package org.apache.myfaces.tobago.application;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,37 +19,40 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.model.Wizard;
+import org.apache.myfaces.tobago.util.DebugNavigationHandler;
 
 import javax.faces.application.NavigationHandler;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 
-/*
- * Created by IntelliJ IDEA.
- * User: bommel
- * Date: Nov 12, 2006
- * Time: 10:32:39 AM
- */
-public class DebugNavigationHandler extends NavigationHandler {
+public class WizardNavigationHandler extends NavigationHandler {
 
   private static final Log LOG = LogFactory.getLog(DebugNavigationHandler.class);
 
-  private NavigationHandler navigationHandler;
+  private NavigationHandler base;
 
-  public DebugNavigationHandler(NavigationHandler navigationHandler) {
-    this.navigationHandler = navigationHandler;
+  public WizardNavigationHandler(NavigationHandler base) {
+    this.base = base;
   }
 
-  public void handleNavigation(FacesContext context, String fromAction, String outcome) {
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("Handle Navigation context: " + context + " fromAction: '"
-          + fromAction + "' outcome: '" + outcome + "'");
-    }
-    navigationHandler.handleNavigation(context, fromAction, outcome);
+  public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
 
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("Handled Navigation context: " + context + " fromAction: '"
-          + fromAction + "' outcome: '" + outcome + "'");
+    // todo: you may find a better indicator
+    Wizard wizard = (Wizard) facesContext.getViewRoot().getAttributes().get(Wizard.class.getName());
+    if (wizard != null) {
+
+      String newViewId = wizard.getViewId();
+      ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+      UIViewRoot viewRoot = viewHandler.createView(facesContext, newViewId);
+      facesContext.setViewRoot(viewRoot);
+      facesContext.renderResponse();
+
+    } else {
+      base.handleNavigation(facesContext, fromAction, outcome);
     }
 
+
   }
-}
+}
\ No newline at end of file

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/AbstractWizard.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/AbstractWizard.java?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/AbstractWizard.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/AbstractWizard.java Wed Dec  5 01:33:18 2007
@@ -25,6 +25,8 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
 import javax.faces.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
 
 public abstract class AbstractWizard implements Wizard {
 
@@ -58,10 +60,12 @@
 
   private WizardBackwardNavigationStrategy backNavStrategy = WizardBackwardNavigationStrategy.NOT_ALLOWED;
 
-/*  protected AbstractWizard() {
-    initialize();
+  private List<Info> course;
+
+  protected AbstractWizard() {
+    reset();
   }
-*/
+
 /*  public boolean isStartable() {
     return true;
   }
@@ -146,6 +150,11 @@
     next();
   }
 
+  public void gotoStep(ActionEvent event) {
+    int step = Integer.parseInt((String) (event.getComponent().getAttributes().get("step")));
+    index = step;
+  }
+
   /*
   * (non-Javadoc)
   * @see org.apache.myfaces.tobago.model.Wizard#isNextAvailable()
@@ -186,7 +195,8 @@
 
 //    makeContentDecision(index);
 
-    return getDefaultOutcome();
+    return course.get(index).getOutcome();
+    //return getDefaultOutcome();
   }
 
   /**
@@ -385,6 +395,7 @@
     if (!sizeSet) {
       size = 0;
     }
+  course = new ArrayList<Info>();
   }
 
   public final String getDefaultOutcome() {
@@ -433,6 +444,67 @@
       this.backNavStrategy = WizardBackwardNavigationStrategy.NOT_ALLOWED;
       LOG.error("WizardBackwardNavigationStrategy is not correctly initialized! Setting strategy to "
           + backNavStrategy.getName(), e);
+    }
+  }
+
+  private String viewId;
+
+  // todo
+  public String getViewId() {
+    viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
+    return viewId;  //To change body of implemented methods use File | Settings | File Templates.
+  }
+
+  public List<Info> getCourse() {
+    return course;
+  }
+
+  public void registerOutcome(String outcome, String title) {
+
+    if (index == course.size()) { // this is a new page
+      course.add(new Info(outcome, title, index));
+    } else if (index < course.size()) {
+      course.set(index, new Info(outcome, title, index));
+    } else {
+      throw new IllegalStateException("Index too large for course: index=" + index + " course.size()=" + course.size());
+    }
+    LOG.info("course: " + course);
+  }
+
+  // XXX
+  public static class Info {
+    private String outcome;
+    private String title;
+    private int index;
+
+    public Info(String outcome, String title, int index) {
+      this.outcome = outcome;
+      this.title = title;
+      this.index = index;
+    }
+
+    public String getOutcome() {
+      return outcome;
+    }
+
+    public void setOutcome(String outcome) {
+      this.outcome = outcome;
+    }
+
+    public String getTitle() {
+      return title;
+    }
+
+    public void setTitle(String title) {
+      this.title = title;
+    }
+
+    public int getIndex() {
+      return index;
+    }
+
+    public void setIndex(int index) {
+      this.index = index;
     }
   }
 

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/Wizard.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/Wizard.java?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/Wizard.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/model/Wizard.java Wed Dec  5 01:33:18 2007
@@ -18,6 +18,7 @@
  */
 
 import javax.faces.event.ActionEvent;
+import java.util.List;
 
 public interface Wizard {
 
@@ -119,4 +120,9 @@
 
   //        void setBackwardNavigationStrategy(String strategy);
 
+  String getViewId();
+
+  List<AbstractWizard.Info> getCourse();
+
+  void registerOutcome(String outcome, String title);
 }

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/WizardTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/WizardTag.java?rev=601271&r1=601270&r2=601271&view=diff
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/WizardTag.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/WizardTag.java Wed Dec  5 01:33:18 2007
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.apache.myfaces.tobago.TobagoConstants.FACET_LAYOUT;
@@ -24,15 +25,21 @@
 import org.apache.myfaces.tobago.apt.annotation.Tag;
 import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
 import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.model.AbstractWizard;
 import org.apache.myfaces.tobago.model.Wizard;
+import org.apache.myfaces.tobago.taglib.component.AttributeTag;
 import org.apache.myfaces.tobago.taglib.component.ButtonTag;
 import org.apache.myfaces.tobago.taglib.component.CellTag;
 import org.apache.myfaces.tobago.taglib.component.GridLayoutTag;
+import org.apache.myfaces.tobago.taglib.component.OutTag;
 import org.apache.myfaces.tobago.taglib.component.PanelTag;
+import org.apache.myfaces.tobago.util.VariableResolverUtil;
 
+import javax.faces.context.FacesContext;
 import javax.faces.webapp.FacetTag;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.BodyTagSupport;
+import java.util.List;
 
 @Tag(name = "wizard")
 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.sandbox.WizardTag")
@@ -43,12 +50,11 @@
   private String controller;
 
   private String next;
-  private String previous;
+  private String outcome;
+  private String title;
 
   private PanelTag panelTag;
 
-  private CellTag cellTag;
-
   @Override
   public int doStartTag() throws JspException {
 
@@ -70,61 +76,109 @@
 
     GridLayoutTag gridLayoutTag = new GridLayoutTag();
     gridLayoutTag.setPageContext(pageContext);
-//    gridLayoutTag.setColumns("*;fixed;fixed;fixed;fixed");
-    gridLayoutTag.setColumns("*;fixed;fixed;fixed");
-    gridLayoutTag.setRows("*;fixed");
+    gridLayoutTag.setRows("fixed;*;fixed");
     gridLayoutTag.setParent(facetTag);
     gridLayoutTag.doStartTag();
     gridLayoutTag.doEndTag();
 
     facetTag.doEndTag();
 
-    cellTag = new CellTag();
-    cellTag.setPageContext(pageContext);
-    cellTag.setParent(panelTag);
-    cellTag.setSpanX("5");
-    cellTag.doStartTag();
+    processTrain();
 
-/*
-    Object bean = VariableResolverUtil.resolveVariable(FacesContext.getCurrentInstance(), "controller");
-    int index = 0;
+    return super.doStartTag();
+  }
+
+  private void processTrain() throws JspException {
+
+    List<AbstractWizard.Info> course = null;
     try {
+      Object bean = VariableResolverUtil.resolveVariable(FacesContext.getCurrentInstance(), "controller");
       Wizard wizard = (Wizard) PropertyUtils.getProperty(bean, "wizard");
-      index = wizard.getIndex();
+      wizard.registerOutcome(outcome, title);
+      course = wizard.getCourse();
     } catch (Exception e) {
       LOG.error("", e);
     }
 
-    if (index < 2) {
-      IncludeTag content = new IncludeTag();
-      content.setPageContext(pageContext);
-      content.setParent(cellTag);
-      content.setValue("snip-" + index + ".jsp");
-      content.doStartTag();
-      content.doEndTag();
-    } else {
-      PanelTag content = new PanelTag();
-      content.setPageContext(pageContext);
-      content.setParent(cellTag);
-      content.setBinding(controller.replace("}", ".currentComponent}"));
-      content.doStartTag();
-      content.doEndTag();
+    PanelTag p = new PanelTag();
+    p.setPageContext(pageContext);
+    p.setParent(panelTag);
+    p.doStartTag();
+
+    FacetTag facetTag = new FacetTag();
+    facetTag.setPageContext(pageContext);
+    facetTag.setName(FACET_LAYOUT);
+    facetTag.setParent(panelTag);
+    facetTag.doStartTag();
+
+    GridLayoutTag gridLayoutTag = new GridLayoutTag();
+    gridLayoutTag.setPageContext(pageContext);
+//    gridLayoutTag.setColumns("*");
+    StringBuilder columns = new StringBuilder();
+    for (AbstractWizard.Info info : course) {
+      columns.append("fixed;");
     }
-*/
-    return super.doStartTag();
-  }
+    gridLayoutTag.setColumns(columns + "*");
+    gridLayoutTag.setParent(facetTag);
+    gridLayoutTag.doStartTag();
+    gridLayoutTag.doEndTag();
 
-  @Override
-  public int doEndTag() throws JspException {
+    facetTag.doEndTag();
 
-    cellTag.doEndTag();
+    for (AbstractWizard.Info info : course) {
+      ButtonTag button = new ButtonTag();
+      button.setPageContext(pageContext);
+      button.setParent(p);
+      button.setAction(info.getOutcome());
+      button.setActionListener(controller.replace("}", ".gotoStep}"));
+      button.setLabel(info.getTitle());
+      button.doStartTag();
+
+      AttributeTag step = new AttributeTag();
+      step.setPageContext(pageContext);
+      step.setParent(button);
+      step.setName("step");
+      step.setValue("" + info.getIndex());
+      step.doStartTag();
+      step.doEndTag();
 
-    CellTag spacer = new CellTag();
+      button.doEndTag();
+    }
+    OutTag spacer = new OutTag();
     spacer.setPageContext(pageContext);
-    spacer.setParent(panelTag);
+    spacer.setParent(p);
+    spacer.setValue(controller.replace("}", ".index}"));
     spacer.doStartTag();
     spacer.doEndTag();
 
+    p.doEndTag();
+  }
+
+  @Override
+  public int doEndTag() throws JspException {
+
+    PanelTag p = new PanelTag();
+    p.setPageContext(pageContext);
+    p.setParent(panelTag);
+    p.doStartTag();
+
+    FacetTag facetTag = new FacetTag();
+    facetTag.setPageContext(pageContext);
+    facetTag.setName(FACET_LAYOUT);
+    facetTag.setParent(panelTag);
+    facetTag.doStartTag();
+
+    GridLayoutTag gridLayoutTag = new GridLayoutTag();
+    gridLayoutTag.setPageContext(pageContext);
+    gridLayoutTag.setColumns("*;fixed;fixed;fixed");
+    gridLayoutTag.setParent(facetTag);
+    gridLayoutTag.doStartTag();
+    gridLayoutTag.doEndTag();
+
+    facetTag.doEndTag();
+
+    cell(panelTag);
+
 /*
     WizardControllerTag controllerTag = new WizardControllerTag();
     controllerTag.setPageContext(pageContext);
@@ -134,29 +188,11 @@
     controllerTag.doEndTag();
 */
 
-    // XXX remove start? using process train instead
-/*
-    ButtonTag start = new ButtonTag();
-    start.setPageContext(pageContext);
-    start.setParent(panelTag);
-    start.setLabel("Start");
-    start.setAction(controller.replace("}", ".start}"));
-    start.setDisabled(controller.replace("}", ".startAvailable}").replace("#{", "#{!"));
-    start.doStartTag();
-    start.doEndTag();
-*/
-
     ButtonTag previousTag = new ButtonTag();
     previousTag.setPageContext(pageContext);
     previousTag.setParent(panelTag);
     previousTag.setLabel("Previous");
-//    previous.setAction(controller.replace("}", ".previous}"));
-    if (previous != null) {
-      previousTag.setAction(previous);
-      previousTag.setActionListener(controller.replace("}", ".previous}"));
-    } else {
-      previousTag.setAction(controller.replace("}", ".previous}"));
-    }
+    previousTag.setAction(controller.replace("}", ".previous}"));
     previousTag.setDisabled(controller.replace("}", ".previousAvailable}").replace("#{", "#{!"));
     previousTag.doStartTag();
     previousTag.doEndTag();
@@ -165,13 +201,8 @@
     nextTag.setPageContext(pageContext);
     nextTag.setParent(panelTag);
     nextTag.setLabel("Next");
-//    nextTag.setAction(controller.replace("}", ".next}"));
-    if (next != null) {
-      nextTag.setAction(next);
-      nextTag.setActionListener(controller.replace("}", ".next}"));
-    } else {
-      nextTag.setAction(controller.replace("}", ".next}"));
-    }
+    nextTag.setAction(next);
+    nextTag.setActionListener(controller.replace("}", ".next}"));
     nextTag.setDisabled(controller.replace("}", ".nextAvailable}").replace("#{", "#{!"));
     nextTag.doStartTag();
     nextTag.doEndTag();
@@ -185,19 +216,29 @@
     finish.doStartTag();
     finish.doEndTag();
 
+    p.doEndTag();
+
     panelTag.doEndTag();
 
     return super.doEndTag();
   }
 
+  private void cell(javax.servlet.jsp.tagext.Tag tag) throws JspException {
+    CellTag spacer = new CellTag();
+    spacer.setPageContext(pageContext);
+    spacer.setParent(tag);
+    spacer.doStartTag();
+    spacer.doEndTag();
+  }
+
   @Override
   public void release() {
     super.release();
     controller = null;
     next = null;
-    previous = null;
+    outcome = null;
+    title = null;
     panelTag = null;
-    cellTag = null;
   }
 
   @TagAttribute(required = true, type = Wizard.class)
@@ -214,7 +255,14 @@
 
   @TagAttribute
   @UIComponentTagAttribute
-  public void setPreviousNext(String previous) {
-    this.previous = previous;
+  public void setOutcome(String outcome) {
+    this.outcome = outcome;
+  }
+
+  @TagAttribute
+  @UIComponentTagAttribute
+  public void setTitle(String title) {
+    this.title = title;
   }
+
 }