
package org.theospi.portfolio.shared.tool;

/**
 * Created by IntelliJ IDEA.
 * User: John Ellis
 * Date: Jan 19, 2006
 * Time: 1:27:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class BuilderScreen {

   private BuilderTool tool;
   private String navigationKey;
   private int step = 0;

   private BuilderScreen next;
   private BuilderScreen prev;

   public BuilderScreen(String navigationKey) {
      this.navigationKey = navigationKey;
   }

   public String getNavigationKey() {
      return navigationKey;
   }

   public void setNavigationKey(String navigationKey) {
      this.navigationKey = navigationKey;
   }

   public BuilderScreen getNext() {
      return next;
   }

   public void setNext(BuilderScreen next) {
      this.next = next;
   }

   public BuilderScreen getPrev() {
      return prev;
   }

   public void setPrev(BuilderScreen prev) {
      this.prev = prev;
   }

   public BuilderTool getTool() {
      return tool;
   }

   public void setTool(BuilderTool tool) {
      this.tool = tool;
   }

   public int getStep() {
      return step;
   }

   public String getStepString() {
      return "" + (step);
   }

   public void setStep(int step) {
      this.step = step;
   }

   public BuilderScreen processActionSave(boolean forward) {
      getTool().saveScreen(this);

      return forward?getNext():getPrev();
   }

   public String processActionSaveNext() {
      BuilderScreen next = processActionSave(true);
      getTool().setCurrentScreen(next);
      return next.getNavigationKey();
   }

   public String processActionNext() {
      BuilderScreen next = getNext();
      getTool().setCurrentScreen(next);
      return next.getNavigationKey();
   }

   public String processActionSaveBack() {
      BuilderScreen prev = processActionSave(false);
      getTool().setCurrentScreen(prev);
      return prev.getNavigationKey();
   }

   public boolean isLast() {
      return getNext() == null;
   }

   public boolean isFirst() {
      return getPrev() == null;
   }

}
