<%@ page language="java" import="java.util.*,java.sql.*,java.beans.*,iDSS.*,iDSS.utils.*,iDSS.webBeans.*,iDSS.beans.*,iDSS.beans2.*,iDSS.grids.*,iDSS.tidalData.*" errorPage="../error/error.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
	<TITLE><%=IDSSAppConstants.programTitle%></TITLE>

<META HTTP-EQUIV="KEYWORDS" CONTENT="internet-based, DSS, decision support system, Java, Enterprise edition, J2EE">
<META HTTP-EQUIV="DESCRIPTION" CONTENT="">		
</HEAD>

<jsp:useBean id="modelSetupControllerJBean" scope="session" class="iDSS.beans2.ModelSetupControllerJBean"/>
<jsp:useBean id="statusJBean" scope="session" class="iDSS.beans2.StatusJBean"/>
<jsp:useBean id="scenarioListJBean" scope="session" class="iDSS.beans2.ScenarioListJBean"/>
<jsp:useBean id="scenarioDetailJBean" scope="session" class="iDSS.beans2.ScenarioDetailJBean"/>


<body>
<h2><%=IDSSAppConstants.modelSetupSlrScenario%></h2>



<%

    statusJBean = modelSetupControllerJBean.getStatusBean();
    Vector scenarios = scenarioListJBean.getScenarios();
    String actionButtonName = request.getParameter(IDSSAppConstants.selectButtonText);

    Vector slrData = new Vector();

    Vector columnNames = new Vector();
    columnNames = new Vector();
    columnNames.add("Scenario");
    columnNames.add("Year");
    columnNames.add("1.5C Sensitivity");
    columnNames.add("4.5C Sensitivity");
    columnNames.add("2.5C Sensitivity");
    columnNames.add("2.5C w/o Sulphate Forcing");


    if(actionButtonName != null) {

%>
        <p>The button you clicked is <%=actionButtonName%>. </p>
<%


        if (actionButtonName.equals(IDSSAppConstants.selectButtonText)) {

            String[] scenarioNames = request.getParameterValues(IDSSAppConstants.selectButtonCommand);

            if(scenarioNames != null) {

                if(scenarioNames.length > 0) {

                    String scenarioName = scenarioNames[0];

                    %>
                        <p>scenarioName : <%=scenarioName%></p>
                    <%

                    scenarioDetailJBean.setScenarioName(scenarioName);
                    slrData = scenarioDetailJBean.getScenarioDetail();

                } //if(scenarioNames.length > 0)

                else {

                    slrData = new Vector();

                } //else

            } //if(scenarioNames != null)

        } //if (actionButtonName.equals(IDSSAppConstants.selectButtonText))



        if (actionButtonName.equals(IDSSAppConstants.acceptButtonText)) {

            String[] selectedColumns = request.getParameterValues(IDSSAppConstants.acceptButtonCommand);
            String scenarioName = request.getParameter("scenName");

            if(selectedColumns != null) {

                if(selectedColumns.length > 0) {

                    int selectedColumn = Integer.parseInt(selectedColumns[0]);
                    int yearColumn = 1;
                    String columnName = columnNames.elementAt(selectedColumn).toString();

                    %>
                        <p>scenarioName : <%=scenarioName%></p>
                        <p>columnName : <%=columnName%></p>
                    <%

                    ClientDataSet slrDataSet = scenarioDetailJBean.makeSLRDataSet(selectedColumn,yearColumn);

                    String stationName = scenarioName+":"+columnName;
                    slrDataSet.setStationName(stationName);
                    statusJBean.setSlrScen(stationName);
                    modelSetupControllerJBean.setSLRScenario(slrDataSet);

                } //if(selectedColumns.length > 0)

            } //if(selectedColumns != null)

        } //if (actionButtonName.equals(IDSSAppConstants.acceptButtonText))

    } //if(actionButtonName != null)
%>







<form method=get>


    <table width="45%" border="0" VSPACE="5" HSPACE="5" CELLPADDING="5">
        <tr BGCOLOR="#C0C0C0">
            <th width="5%">Sel</th>
            <th width="20%">Scenario name</th>
            <th width="20%">Storyline</th>
        </tr>

    <%


        for(int i=0;i<scenarios.size();i++) {

            Vector oneRow = (Vector)scenarios.elementAt(i);
            String scenarioName = (String)oneRow.elementAt(0);
            String storyline = (String)oneRow.elementAt(1);
            String scenarioTable = (String)oneRow.elementAt(2);

    %>

            <tr BGCOLOR="#90FFFF">
                <td  align="center"><input type=checkbox name="<%=IDSSAppConstants.selectButtonCommand%>" value="<%=scenarioName%>"></td>
                <td><%=scenarioName%> </td>
                <td><a href="<%=storyline%>">read storyline</a> </td>
            </tr>

    <%
        } //for(int i=0;i<scenarios.size();i++)
    %>

    </table>

    <input type=submit name="<%=IDSSAppConstants.selectButtonText%>" value="<%=IDSSAppConstants.selectButtonText%>">

</form>




<%
    if(slrData.size()>0) {
%>
        <form method=get>


            <%
                Vector topRow = (Vector)slrData.elementAt(0);
                String scenName = (String)topRow.elementAt(0);
            %>

            <h3><%=scenName%></h3>


            <input type=hidden name="scenName" value="<%=scenName%>">

            <table width="100%" border="0" VSPACE="5" HSPACE="5" CELLPADDING="5">
                <tr BGCOLOR="#C0C0C0">

                    <%
                        for(int i=1;i<columnNames.size();i++) {
                    %>

                            <th><%=(String)columnNames.elementAt(i)%></th>

                    <%
                        } //for(int i=1;i<columnNames.size();i++)
                    %>

                </tr>


                <tr>
                    <%
                        for(int j=1;j<columnNames.size();j++) {
                    %>
                            <td align="center">
                                <%
                                    if(j>1) {
                                %>
                                        <input type=checkbox name="<%=IDSSAppConstants.acceptButtonCommand%>" value="<%=j%>">
                                <%
                                    } //if(j>1)

                                    else {
                                %>
                                        &nbsp
                                <%
                                    } //else
                                %>

                            </td>

                    <%
                        } // for(int j=1;j<columnNames.size();j++)
                    %>

                </tr>





            <%


                for(int i=0;i<slrData.size();i++) {

                    Vector oneRow = (Vector)slrData.elementAt(i);

            %>
                    <tr BGCOLOR="#90FFFF">

                        <%
                            for(int j=1;j<oneRow.size();j++) {
                        %>

                                <td align="center"><%=oneRow.elementAt(j).toString()%></td>

                        <%
                            } //for(int j=1;j<oneRow.size();j++)
                        %>


                    </tr>

            <%
                } //for(int i=0;i<slrData.size();i++)
            %>


            </table>

            <input type=submit name="<%=IDSSAppConstants.selectButtonText%>" value="<%=IDSSAppConstants.acceptButtonText%>">

        </form>


<%
    } //if(slrData.size()>0)
%>






</body>

</HTML>

