Commit af22b82f authored by Pietro Apollo's avatar Pietro Apollo
Browse files

Wicket 1.6 installed. Improved submitting mechanisms. Solved DropDownChoice...

Wicket 1.6 installed. Improved submitting mechanisms. Solved DropDownChoice problem. Inserted closing session buttons.
parent c31a1ec4
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -6,22 +6,47 @@ and open the template in the editor.
<html>
    <head>        
        <title></title>
        
            <wicket:head>
                <style type="text/css">
                    input[type="text"] {
                        position: absolute;
                        left: 80px;
                        width: 200px;
                    }
                    
                    input[type="password"] {
                        position: absolute;
                        left: 80px;
                        width: 200px;
                    }
                    
                    span.title {
                        font-weight: bold;
                        font-size: 25px;
                    }
                </style>
            </wicket:head>
                            
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <wicket:extend>
            
            <span wicket:id="titleLabel" class="title">Title</span>
        
            <form wicket:id="credentialForm">
                <span wicket:id="hostnameLabel">Hostname</span>
                <input type="text" wicket:id="hostnameTextField" /> <br />
                <span wicket:id="portLabel">Port</span>
                <span wicket:id="portLabel" style="position:absolute; left:50px;">Port</span>
                <input type="text" wicket:id="portTextField" /> <br />
                <span wicket:id="usernameLabel">Username</span>
                <input type="text" wicket:id="usernameTextField" /> <br />
                <span wicket:id="passwordLabel">Password</span>
                <input type="password" wicket:id="passwordTextField"  /> <br />
                <input type="submit" wicket:id="credentialSubmit" value="Submit credentials" /> <br />
                <textarea wicket:id="infoTextArea" rows="2" cols="50"></textarea>
                <input type="submit" wicket:id="credentialSubmit" value="Submit credentials" />
                <input type="submit" wicket:id="exit" value="Close session" /> <br />
                <textarea wicket:id="infoTextArea" rows="10" cols="50"></textarea>
            </form>
            
        </wicket:extend>
+211 −8
Original line number Diff line number Diff line
@@ -6,14 +6,18 @@ package it.inaf.oats.ia2.tap.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxCallListener;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.attributes.IAjaxCallListener;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;

/**
 * CredentialPage class extends the default BasePage class and is the home page.
@@ -39,6 +43,7 @@ public class CredentialPage extends BasePage {
    Label passwordLabel;
    final PasswordTextField passwordTextField;
    AjaxSubmitLink credentialSubmit;
    AjaxSubmitLink exit;
    TextArea infoTextArea;
        
    /**
@@ -46,6 +51,10 @@ public class CredentialPage extends BasePage {
     */
    public CredentialPage()
    {
        //title label
        Label titleLabel = new Label("titleLabel", new Model("TapSchema Manager - Credentials insertion page"));
        add(titleLabel);
        
        //credential form
        credentialForm = new Form("credentialForm");
        add(credentialForm);
@@ -98,11 +107,28 @@ public class CredentialPage extends BasePage {
            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form)
            {
                
                try
                {
                    //target.appendJavaScript("alert('Error in submitting credentials: session closed')");
                    Thread.sleep(3000);
                    setResponsePage(CredentialPage.class);
                    this.getSession().invalidate();
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                                "\nError in submitting credentials: session closed");
                    target.add(infoTextArea);
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in closing session: " + 
                            (String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
            }
            
            /**
             * onSubmit method of credentialSubmit AjaxSubmitLink get the credentials
             * onSubmit method of credentialSubmit AjaxSubmitLink gets the credentials
             * from the TextFields and passes the credentials to SelectSchemataPage
             * 
             * @param target
@@ -139,11 +165,17 @@ public class CredentialPage extends BasePage {
                            password
                    );
                    setResponsePage(selectSchemataPage);
                    
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nCredentials submitted");
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)exception.getMessage());
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in submitting credentials: " +
                            (String)exception.getMessage());
                    exception.printStackTrace();
                    target.add(infoTextArea);
                }
                finally
                {
@@ -159,8 +191,179 @@ public class CredentialPage extends BasePage {
                target.add(infoTextArea);
            }
        };
        credentialSubmit.add(new AjaxEventBehavior("onmousedown")
        {
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                        "\nSubmitting credentials...");
                target.add(infoTextArea);
            }
        });
        credentialSubmit.add(new AjaxEventBehavior("onkeydown")
        {
            @Override
            protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                super.updateAjaxAttributes(attributes);

                IAjaxCallListener listener = new AjaxCallListener(){
                    @Override
                    public CharSequence getPrecondition(Component component) {
                        //this javascript code evaluates wether an ajaxcall is necessary.
                        //Here only by keycode for Enter
                        return  "var keycode = Wicket.Event.keyCode(attrs.event);" +
                                "if (keycode == 13)" +
                                "    return true;" +
                                "else" +
                                "    return false;";
                    }
                };
                attributes.getAjaxCallListeners().add(listener);

                //Append the pressed keycode to the ajaxrequest 
                attributes.getDynamicExtraParameters()
                    .add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
                        "return {keycode: eventKeycode};");

                //whithout setting, no keyboard events will reach any inputfield
                attributes.setAllowDefault(true);
            }
            
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                //Extract the keycode parameter from RequestCycle
                final Request request = RequestCycle.get().getRequest();
                final String jsKeycode = request.getRequestParameters()
                                .getParameterValue("keycode").toString("");

                if (jsKeycode.equals("13")) //if Enter key
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nSubmitting credentials...");
                }
                target.add(infoTextArea);
            }
        });
        credentialForm.add(credentialSubmit);
        
        //close session
        exit = new AjaxSubmitLink(
                "exit",
                credentialForm)
        {
            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form)
            {
                //infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                //            "\nError in closing the session");
                //target.add(infoTextArea); 
                try
                {
                    //target.appendJavaScript("alert('Session closed')");
                    Thread.sleep(3000);
                    setResponsePage(CredentialPage.class);
                    this.getSession().invalidate();
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                                "\nSession closed");
                    target.add(infoTextArea);
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in closing session: " + 
                            (String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
            }
            
            /**
             * onSubmit method of exit AjaxSubmitLink exits from the web application
             * 
             * @param target
             * @param form
             */
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                try
                {
                    Thread.sleep(3000);
                    setResponsePage(CredentialPage.class);
                    this.getSession().invalidate();
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                                "\nSession closed");
                    target.add(infoTextArea);
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in closing session: " + 
                            (String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
            }
        };
        exit.add(new AjaxEventBehavior("onmousedown")
        {
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                        "\nClosing session...");
                target.add(infoTextArea);
            }
        });
        exit.add(new AjaxEventBehavior("onkeydown")
        {
            @Override
            protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                super.updateAjaxAttributes(attributes);

                IAjaxCallListener listener = new AjaxCallListener(){
                    @Override
                    public CharSequence getPrecondition(Component component) {
                        //this javascript code evaluates wether an ajaxcall is necessary.
                        //Here only by keycode for Enter
                        return  "var keycode = Wicket.Event.keyCode(attrs.event);" +
                                "if (keycode == 13)" +
                                "    return true;" +
                                "else" +
                                "    return false;";
                    }
                };
                attributes.getAjaxCallListeners().add(listener);

                //Append the pressed keycode to the ajaxrequest 
                attributes.getDynamicExtraParameters()
                    .add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
                        "return {keycode: eventKeycode};");

                //whithout setting, no keyboard events will reach any inputfield
                attributes.setAllowDefault(true);
            }
            
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                //Extract the keycode parameter from RequestCycle
                final Request request = RequestCycle.get().getRequest();
                final String jsKeycode = request.getRequestParameters()
                                .getParameterValue("keycode").toString("");

                if (jsKeycode.equals("13")) //if Enter key
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nClosing session...");
                }
                target.add(infoTextArea);
            }
        });
        credentialForm.add(exit);
        
        //info textarea
        infoTextArea = new TextArea("infoTextArea", Model.of(""));
        infoTextArea.setOutputMarkupPlaceholderTag(true);
+6 −5
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@ import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AbstractBehavior;
//import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
@@ -120,7 +121,7 @@ public class HomePage extends BasePage {
                new Model(selectedDrop),
                tapschemaList);
        tapschemaDropDownChoice.setOutputMarkupPlaceholderTag(true);
        tapschemaDropDownChoice.add(new AbstractBehavior()
        tapschemaDropDownChoice.add(new Behavior()
        {
            @Override
            public void onConfigure(Component component)
@@ -141,7 +142,7 @@ public class HomePage extends BasePage {
                "tapschemaText",
                Model.of(""));
        tapschemaText.setOutputMarkupPlaceholderTag(true);
        tapschemaText.add(new AbstractBehavior()
        tapschemaText.add(new Behavior()
        {
            @Override
            public void onConfigure(Component component)
@@ -192,7 +193,7 @@ public class HomePage extends BasePage {
            }
        };
        editTapschemaSubmit.setOutputMarkupPlaceholderTag(true);
        editTapschemaSubmit.add(new AbstractBehavior()
        editTapschemaSubmit.add(new Behavior()
        {
            @Override
            public void onConfigure(Component component)
@@ -246,7 +247,7 @@ public class HomePage extends BasePage {
            }
        };
        createTapschemaSubmit.setOutputMarkupPlaceholderTag(true);
        createTapschemaSubmit.add(new AbstractBehavior()
        createTapschemaSubmit.add(new Behavior()
        {
            @Override
            public void onConfigure(Component component)
+3 −2
Original line number Diff line number Diff line
@@ -65,8 +65,9 @@ span.title {

                <br />
                <input type="submit" wicket:id="updateSubmit" value="Update all" />
                <input type="submit" wicket:id="backSubmit" value="Back to select schemata" /> <br />
                <textarea wicket:id="infoTextArea" rows="2" cols="50"></textarea>
                <input type="submit" wicket:id="backSubmit" value="Back to select schemata" />
                <input type="submit" wicket:id="exit" value="Close session" /> <br />
                <textarea wicket:id="infoTextArea" rows="10" cols="50"></textarea>
            </form>
            
        </wicket:extend>
+116 −5
Original line number Diff line number Diff line
@@ -7,7 +7,12 @@ package it.inaf.oats.ia2.tap.utils;
import it.inaf.oats.ia2.tap.utils.tapschema.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxCallListener;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.attributes.IAjaxCallListener;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
@@ -15,6 +20,8 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;

/**
 * SchemaPage class extends the default BasePage class.
@@ -33,6 +40,7 @@ public class SchemaPage extends BasePage{
    
    AjaxSubmitLink updateSubmit;
    AjaxSubmitLink backSubmit;
    AjaxSubmitLink exit;
    TextArea infoTextArea;
    
    public TapSchema tapschema;
@@ -61,9 +69,9 @@ public class SchemaPage extends BasePage{
    {
        this.tapschema = tapschema;
        
        //utype label
        Label utypeLabel = new Label("titleLabel", new Model(tapschemaName));
        add(utypeLabel);
        //title label
        Label titleLabel = new Label("titleLabel", new Model("TapSchema Manager - " + tapschemaName));
        add(titleLabel);
        
        //schema form
        schemaForm = new Form("schemaForm");
@@ -127,19 +135,79 @@ public class SchemaPage extends BasePage{
                                password,
                                tapschemaName,
                                tapschema);
                        infoTextArea.setModelObject(tapschemaName + " database updated");
                        infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                                "\n" + tapschemaName + " database updated");
                        target.add(infoTextArea);
                        
                        target.appendJavaScript("alert('" + tapschemaName + " database updated')");
                    }
                    
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)exception.getMessage());
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in updating " + tapschemaName + " database: " +
                            (String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
            }
        };
        updateSubmit.add(new AjaxEventBehavior("onmousedown")
        {
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                        "\nUpdating " + tapschemaName + " database...");
                target.add(infoTextArea);
            }
        });
        updateSubmit.add(new AjaxEventBehavior("onkeydown")
        {
            @Override
            protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                super.updateAjaxAttributes(attributes);

                IAjaxCallListener listener = new AjaxCallListener(){
                    @Override
                    public CharSequence getPrecondition(Component component) {
                        //this javascript code evaluates wether an ajaxcall is necessary.
                        //Here only by keycode for Enter
                        return  "var keycode = Wicket.Event.keyCode(attrs.event);" +
                                "if (keycode == 13)" +
                                "    return true;" +
                                "else" +
                                "    return false;";
                    }
                };
                attributes.getAjaxCallListeners().add(listener);

                //Append the pressed keycode to the ajaxrequest 
                attributes.getDynamicExtraParameters()
                    .add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
                        "return {keycode: eventKeycode};");

                //whithout setting, no keyboard events will reach any inputfield
                attributes.setAllowDefault(true);
            }
            
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                //Extract the keycode parameter from RequestCycle
                final Request request = RequestCycle.get().getRequest();
                final String jsKeycode = request.getRequestParameters()
                                .getParameterValue("keycode").toString("");

                if (jsKeycode.equals("13")) //if Enter key
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nUpdating " + tapschemaName + " database...");
                }
                target.add(infoTextArea);
            }
        });
        schemaForm.add(updateSubmit);
        
        //back AjaxSubmitLink
@@ -183,6 +251,49 @@ public class SchemaPage extends BasePage{
        };
        schemaForm.add(backSubmit);
        
        //close session
        exit = new AjaxSubmitLink(
                "exit",
                schemaForm)
        {
            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form)
            {
                infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nError in closing the session");
                target.add(infoTextArea);
            }
            
            /**
             * onSubmit method of exit AjaxSubmitLink exits from the web application
             * 
             * @param target
             * @param form
             */
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                try
                {
                    setResponsePage(CredentialPage.class);
                    //System.exit(0);
                    this.getSession().invalidate();
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                                "\nSession closed");
                    target.add(infoTextArea);
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)infoTextArea.getModelObject() +
                            "\nException occurred in closing session: " + 
                            (String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
            }
        };
        schemaForm.add(exit);
        
        //info textarea
        infoTextArea = new TextArea("infoTextArea", Model.of(""));
        infoTextArea.setOutputMarkupPlaceholderTag(true);
Loading