package org.flymine.web.results;

/*
 * Copyright (C) 2002-2003 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.actions.TilesAction;
import org.apache.struts.tiles.ComponentContext;

import org.flymine.objectstore.query.Results;

/**
 * Implementation of <strong>TilesAction</strong>. Assembles data for
 * a results view.
 *
 * @author Andrew Varley
 */
public class ResultsViewController extends TilesAction
{
    protected static final String DISPLAYABLERESULTS_NAME = "resultsTable";

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param context The Tiles ComponentContext
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @return an ActionForward object defining where control goes next
     *
     * @exception ServletException if a servlet error occurs
     */
 public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws ServletException {
    HttpSession session = request.getSession();

    Results results = (Results) session.getAttribute("results");

    // Do we have a configuration object? If not, create one.
    DisplayableResults dr = (DisplayableResults) session.getAttribute(DISPLAYABLERESULTS_NAME);
    if (dr == null) {
        dr = new DisplayableResults(results);
    }

    // Put required things on the request or session or tile context

    // The DisplayableResults object
    session.setAttribute(DISPLAYABLERESULTS_NAME, dr);

    return null;
  }
}

@@ -2170,16 +2170,24 @@
 / Do we 
+already 
 have a c
@@ -2214,24 +2214,78 @@
  If 
-not, create
+we do, update the%0A    // new one to inherit properties off the old
  one
-.
 %0A   
@@ -2306,16 +2306,20 @@
 sults dr
+Orig
  = (Disp
@@ -2389,36 +2389,32 @@
     
-if (dr == null) %7B%0A        dr
+DisplayableResults drNew
  = n
@@ -2445,16 +2445,72 @@
 sults);%0A
+    if (drOrig != null) %7B%0A        drNew.update(drOrig);%0A
     %7D%0A%0A 
@@ -2615,16 +2615,16 @@
  object%0A
-
     sess
@@ -2667,16 +2667,19 @@
 NAME, dr
+New
 );%0A%0A    

Update new DisplayableResults from any existing on the session