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

First commit of ManageTapSchemas

parents
Loading
Loading
Loading
Loading

src/conf/MANIFEST.MF

0 → 100644
+2 −0
Original line number Diff line number Diff line
Manifest-Version: 1.0
+79 −0
Original line number Diff line number Diff line
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.inaf.oats.ia2.tap.utils;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.model.IModel;

/**
 *
 * @author pietro
 */
public class AjaxCheckBox extends CheckBox {
    
    private String idString;
    
    public AjaxCheckBox(String id, IModel model)
    {
        super(id, model);
        
        OnChangeAjaxBehavior onChangeAjaxBehavior = new OnChangeAjaxBehavior()
        {
            //onUpdate is never called: because is it covered by another behavior?
            @Override
            protected void onUpdate(AjaxRequestTarget target)
            {
                SchemaPage schemaPage = (SchemaPage)getPage();
                String idString = getIdString();
                String[] idSplit = getIdString().split("-");
                if (idSplit.length == 2)
                {
                    if (idSplit[1].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .checked
                                = (boolean)getModelObject();
                    }
                }
                else if (idSplit.length == 3)
                {
                    if (idSplit[2].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .checked
                                = (boolean)getModelObject();
                    }
                }
                else if (idSplit.length == 4)
                {
                    if (idSplit[3].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .checked
                                = (boolean)getModelObject();
                    }
                }
            }
        };
        add(onChangeAjaxBehavior);

    }
    
    public String getIdString()
    {
        return idString;
    }
    
    public void setIdString(String idString)
    {
        this.idString = idString;
    }
    
}
+375 −0
Original line number Diff line number Diff line
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.inaf.oats.ia2.tap.utils;

import it.inaf.oats.ia2.tap.utils.tapschema.Column;
import it.inaf.oats.ia2.tap.utils.tapschema.Schema;
import it.inaf.oats.ia2.tap.utils.tapschema.Table;
import it.inaf.oats.ia2.tap.utils.tapschema.TapSchema;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.DataGridView;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;

/**
 *
 * @author pietro
 */
public class AjaxTextField extends TextField {
    
    private String idString;
    
    public AjaxTextField(String id, IModel model)
    {
        super(id, model);
        
        OnChangeAjaxBehavior onChangeAjaxBehavior = new OnChangeAjaxBehavior()
        {
            @Override
            protected void onUpdate(AjaxRequestTarget target)
            {
                SchemaPage schemaPage = (SchemaPage)getPage();
                String idString = getIdString();
                String[] idSplit = getIdString().split("-");
                if (idSplit.length == 2) //if schema TextField
                {
                    SchemaPanel schemaPanel =
                            (SchemaPanel)schemaPage.schemataTabbedPanel
                            .get("panel");
                    
                    //set selectSchemaCheckBox
                    schemaPanel.selectSchemaCheckBox.setModelObject(true);
                    String idString2 = schemaPanel.selectSchemaCheckBox.getIdString();
                    String[] idSplit2 = schemaPanel.selectSchemaCheckBox.getIdString().split("-");
                    if (idSplit2[1].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit2[0])
                                .checked
                                = (boolean)schemaPanel.selectSchemaCheckBox.getModelObject();
                    }                                                        
                    target.add(schemaPanel.selectSchemaCheckBox);
                    //end set selectSchemaCheckBox
                    
                    for (Schema schema : schemaPage.tapschema.schemasMap.values())
                    {
                        if (schema.schema_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0]).schema_name))
                        {
                            schema.checked = true;
                        }
                    }
                    
                    if (idSplit[1].equals("utype"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .utype
                                = (String)getModelObject();
                    }
                    else if (idSplit[1].equals("description"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .description
                                = (String)getModelObject();
                    }
                }
                else if (idSplit.length == 3) //if table TextField
                {
                    SchemaPanel schemaPanel =
                            (SchemaPanel)schemaPage.schemataTabbedPanel
                            .get("panel");
                    TablePanel tablePanel =
                            (TablePanel)schemaPanel.tablesTabbedPanel
                            .get("panel");
                    
                    //set selectTableCheckBox
                    tablePanel.selectTableCheckBox.setModelObject(true);
                    String idString2 = tablePanel.selectTableCheckBox.getIdString();
                    String[] idSplit2 = tablePanel.selectTableCheckBox.getIdString().split("-");
                    if (idSplit2[2].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit2[0])
                                .tablesMap.get(idSplit2[1])
                                .checked
                                = (boolean)tablePanel.selectTableCheckBox.getModelObject();
                    }
                    target.add(tablePanel.selectTableCheckBox);
                    //end set selectTableCheckBox

                    //set selectSchemaCheckBox
                    schemaPanel.selectSchemaCheckBox.setModelObject(true);
                    idString2 = schemaPanel.selectSchemaCheckBox.getIdString();
                    idSplit2 = schemaPanel.selectSchemaCheckBox.getIdString().split("-");
                    if (idSplit2[1].equals("checked"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit2[0])
                                .checked
                                = (boolean)schemaPanel.selectSchemaCheckBox.getModelObject();
                    }                                                        
                    target.add(schemaPanel.selectSchemaCheckBox);
                    //end set selectSchemaCheckBox
                    
                    for (Schema schema : schemaPage.tapschema.schemasMap.values())
                    {
                        if (schema.schema_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0]).schema_name))
                        {
                            schema.checked = true;
                        }
                    }
                    
                    for (Table table : schemaPage.tapschema.schemasMap.get(idSplit[0])
                            .tablesMap.values())
                    {
                        if (table.table_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0]).
                                tablesMap.get(idSplit[1]).table_name))
                        {
                            table.checked = true;
                        }
                    }
                    
                    if (idSplit[2].equals("utype"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .utype
                                = (String)getModelObject();
                    }
                    else if (idSplit[2].equals("description"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .description
                                = (String)getModelObject();
                        
                    }
                }
                else if (idSplit.length == 4) //if DataGridView TextField
                {
                    //set row CheckBox
                    List<Column> columnsList = new ArrayList<Column>();
                    for (Column column : schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.values())
                    {
                        columnsList.add(column);
                    }
                    int columnIndex = 0;
                    for (int i = 0; i < columnsList.size(); i++)
                    {
                        if (columnsList.get(i).column_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2]).column_name))
                        {
                            columnIndex = i;
                            break;
                        }
                    }
                    
                    SchemaPanel schemaPanel =
                            (SchemaPanel)schemaPage.schemataTabbedPanel
                            .get("panel");
                    TablePanel tablePanel =
                            (TablePanel)schemaPanel.tablesTabbedPanel
                            .get("panel");
                    DataGridView<Row> rows =
                            (DataGridView<Row>)tablePanel.get("updateTableForm").get("rows");
                    
                    Iterator iterator = rows.getItems();
                    List<Item> itemList = new ArrayList<Item>();
                    while (iterator.hasNext())
                    {
                        itemList.add((Item)iterator.next());
                    }
                    for (Item item : itemList)
                    {
                        if (item.getIndex() == columnIndex)
                        {
                            //AjaxCheckBox cell2 = (AjaxCheckBox)item.get("cell2");
                            //AjaxCheckBox cell2 = (AjaxCheckBox)item.get(0).get("cell2");
                            RepeatingView cells = (RepeatingView)item.get("cells");
                            AjaxCheckBox cell2 = (AjaxCheckBox)cells.get(0).get("cell2");
                            cell2.setModelObject(true);
                            target.add(cell2);
                            
                            //set selectTableCheckBox
                            tablePanel.selectTableCheckBox.setModelObject(true);
                            String idString2 = tablePanel.selectTableCheckBox.getIdString();
                            String[] idSplit2 = tablePanel.selectTableCheckBox.getIdString().split("-");
                            if (idSplit2[2].equals("checked"))
                            {
                                schemaPage.tapschema.schemasMap.get(idSplit2[0])
                                        .tablesMap.get(idSplit2[1])
                                        .checked
                                        = (boolean)tablePanel.selectTableCheckBox.getModelObject();
                            }
                            target.add(tablePanel.selectTableCheckBox);
                            //end set selectTableCheckBox
                            
                            //set selectSchemaCheckBox
                            schemaPanel.selectSchemaCheckBox.setModelObject(true);
                            idString2 = schemaPanel.selectSchemaCheckBox.getIdString();
                            idSplit2 = schemaPanel.selectSchemaCheckBox.getIdString().split("-");
                            if (idSplit2[1].equals("checked"))
                            {
                                schemaPage.tapschema.schemasMap.get(idSplit2[0])
                                        .checked
                                        = (boolean)schemaPanel.selectSchemaCheckBox.getModelObject();
                            }                                                        
                            target.add(schemaPanel.selectSchemaCheckBox);
                            //end set selectSchemaCheckBox
                            
                            break;
                        }
                    }
                    //end set row CheckBox
                    
                    for (Schema schema : schemaPage.tapschema.schemasMap.values())
                    {
                        if (schema.schema_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0]).schema_name))
                        {
                            schema.checked = true;
                        }
                    }
                    
                    for (Table table : schemaPage.tapschema.schemasMap.get(idSplit[0])
                            .tablesMap.values())
                    {
                        if (table.table_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0]).
                                tablesMap.get(idSplit[1]).table_name))
                        {
                            table.checked = true;
                        }
                    }
                    
                    for (Column column : schemaPage.tapschema.schemasMap.get(idSplit[0])
                            .tablesMap.get(idSplit[1])
                            .columnsMap.values())
                    {
                        if (column.column_name.equals(
                                schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .column_name))
                        {
                            column.checked = true;
                        }
                    }
                    
                    if (idSplit[3].equals("table_name"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .table_name
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("column_name"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .column_name
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("utype"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .utype
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("ucd"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .ucd
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("unit"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .unit
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("description"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .description
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("datatype"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .datatype
                                = (String)getModelObject();
                    }
                    else if (idSplit[3].equals("size"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .size
                                = (Integer)getModelObject();
                    }
                    else if (idSplit[3].equals("principal"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .principal
                                = (Integer)getModelObject();
                    }
                    else if (idSplit[3].equals("indexed"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .indexed
                                = (Integer)getModelObject();
                    }
                    else if (idSplit[3].equals("std"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .columnsMap.get(idSplit[2])
                                .std
                                = (Integer)getModelObject();
                    }
                } //if length
            } //end onUpdate
        };
        add(onChangeAjaxBehavior);

    }
    
    public String getIdString()
    {
        return idString;
    }
    
    public void setIdString(String idString)
    {
        this.idString = idString;
    }
    
}
+48 −0
Original line number Diff line number Diff line
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.inaf.oats.ia2.tap.utils;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.response.filter.ServerAndClientTimeFilter;

/**
 *
 * @author pietro
 */
public class Application extends WebApplication {
    
    /**
     * Constructor.
     */
    public Application()
    {
    }

    /**
     * @see org.apache.wicket.protocol.http.WebApplication#init()
     */
    @Override
    protected void init()
    {
        getDebugSettings().setDevelopmentUtilitiesEnabled(true);

        getRequestCycleSettings().addResponseFilter(new ServerAndClientTimeFilter());
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    @Override
    public Class<? extends Page> getHomePage()
    {
        //return Index.class;
        //return HomePage.class;
        return CredentialPage.class;
        //return ProvaPage.class;
    }

    
}
+19 −0
Original line number Diff line number Diff line
<!DOCTYPE html> 
<html xmlns:wicket="http://wicket.apache.org"> 
    <head> 
        <meta charset="UTF-8"> 
        <meta name="description" content="Put your description here!" /> 
    <wicket:head> 
        <wicket:link> 
            <link rel="stylesheet" type="text/css" href="style.css"/> 
        </wicket:link> 
    </wicket:head> 
</head> 
<body>
    <!--<header wicket:id="headerpanel" />-->
    <section class="content_container"> 
        <wicket:child/> 
    </section> 
    <!--<footer wicket:id="footerpanel" />-->
</body> 
</html>