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

Select all on table columns;

Automatic population of tapschema;
Tooltips on utype, ucd, unit, description
parent ed6be648
Loading
Loading
Loading
Loading
+149 −3
Original line number Diff line number Diff line
@@ -10,13 +10,17 @@ import it.inaf.oats.ia2.tap.utils.tapschema.Table;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.behavior.AttributeAppender;
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;
import org.apache.wicket.model.Model;

/**
 *
@@ -278,7 +282,17 @@ public class AjaxTextField extends TextField {
                        }
                    }
                    //end setting variable "checked"
                    
                    /*
                    //get cells of index item, needed to set tooltips
                    RepeatingView cells = null;
                    for (Item item : itemList)
                    {
                        if (item.getIndex() == columnIndex)
                        {
                            cells = (RepeatingView)item.get("cells");
                        }
                    }
                    */
                    //set variables in the correct column of tapschema structure
                    if (idSplit[3].equals("table_name"))
                    {
@@ -303,6 +317,26 @@ public class AjaxTextField extends TextField {
                                .columnsMap.get(idSplit[2])
                                .utype
                                = (String)getModelObject();
                        /*
                        //update tooltip
                        AjaxTextField cell = (AjaxTextField)cells.get(5).get("cell");
                        String modelObject = (String)getModelObject();
                        cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                        target.add(cell);
                        */
                        /*
                        target.appendJavaScript("{ var el=wicketGet('" + cell.getMarkupId() + "');" + 
                                " el.select(); " + 
                                        " }"); 
                        target.focusComponent(cell);
                        */
                        /*
                        target.appendJavaScript("{ " +
                                cell + ".focus();" +
                                cell + ".value += '';" +
                                " }");
                        //target.focusComponent(cell);
                        */
                    }
                    else if (idSplit[3].equals("ucd"))
                    {
@@ -311,6 +345,13 @@ public class AjaxTextField extends TextField {
                                .columnsMap.get(idSplit[2])
                                .ucd
                                = (String)getModelObject();
                        /*
                        //update tooltip
                        AjaxTextField cell = (AjaxTextField)cells.get(6).get("cell");
                        String modelObject = (String)getModelObject();
                        cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                        target.add(cell);
                        */
                    }
                    else if (idSplit[3].equals("unit"))
                    {
@@ -319,6 +360,13 @@ public class AjaxTextField extends TextField {
                                .columnsMap.get(idSplit[2])
                                .unit
                                = (String)getModelObject();
                        /*
                        //update tooltip
                        AjaxTextField cell = (AjaxTextField)cells.get(7).get("cell");
                        String modelObject = (String)getModelObject();
                        cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                        target.add(cell);
                        */
                    }
                    else if (idSplit[3].equals("description"))
                    {
@@ -327,6 +375,13 @@ public class AjaxTextField extends TextField {
                                .columnsMap.get(idSplit[2])
                                .description
                                = (String)getModelObject();
                        /*
                        //update tooltip
                        AjaxTextField cell = (AjaxTextField)cells.get(8).get("cell");
                        String modelObject = (String)getModelObject();
                        cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                        target.add(cell);
                        */
                    }
                    else if (idSplit[3].equals("datatype"))
                    {
@@ -374,6 +429,97 @@ public class AjaxTextField extends TextField {
        };
        add(onChangeAjaxBehavior);
        
        AjaxEventBehavior ajaxEventBehavior = new AjaxEventBehavior("onfocusout")
        {
            @Override
            protected void onEvent(AjaxRequestTarget target)
            {
                SchemaPage schemaPage = (SchemaPage)getPage();
                String[] idSplit = getIdString().split("-");
                    
                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;
                        }
                    }
                    
                    //get current SchemaPanel, TablePanel, DataGridView
                    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)
                        {
                            //get cells of index item, needed to set tooltips
                            RepeatingView cells = (RepeatingView)item.get("cells");
                   
                            if (idSplit[3].equals("utype"))
                            {
                                AjaxTextField cell = (AjaxTextField)cells.get(5).get("cell");
                                String modelObject = (String)getModelObject();
                                cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                                target.add(cell);
                            }
                            else if (idSplit[3].equals("ucd"))
                            {
                                AjaxTextField cell = (AjaxTextField)cells.get(6).get("cell");
                                String modelObject = (String)getModelObject();
                                cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                                target.add(cell);
                            }
                            else if (idSplit[3].equals("unit"))
                            {
                                AjaxTextField cell = (AjaxTextField)cells.get(7).get("cell");
                                String modelObject = (String)getModelObject();
                                cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                                target.add(cell);
                            }
                            else if (idSplit[3].equals("description"))
                            {
                                AjaxTextField cell = (AjaxTextField)cells.get(8).get("cell");
                                String modelObject = (String)getModelObject();
                                cell.add(AttributeModifier.replace("title", new Model(modelObject)));                       
                                target.add(cell);
                            }
                        }
                    }
                    
                    
                }
            }
        };
        add(ajaxEventBehavior);
        
    }
        
    public String getIdString()
+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ div.tabpanel div.tab-row li.selected a:link,
div.tabpanel div.tab-row a:hover {
  background: #fff;
}

span.title {
    font-weight: bold;
    font-size: 25px;
}
            </style>
        
        </wicket:head>
@@ -52,6 +57,8 @@ div.tabpanel div.tab-row a:hover {
    <body>
        <wicket:extend>
            
            <span wicket:id="titleLabel" class="title">Title</span>
            
            <form wicket:id="schemaForm">
                <div wicket:id="schemataTabbedPanel" class="tabpanel"></div>

+9 −2
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
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;
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;
@@ -44,6 +45,10 @@ public class SchemaPage extends BasePage{
    {
        this.tapschema = tapschema;
        
        //utype label
        Label utypeLabel = new Label("titleLabel", new Model(tapschemaName));
        add(utypeLabel);
        
        //schema form
        schemaForm = new Form("schemaForm");
        add(schemaForm);
@@ -75,12 +80,14 @@ public class SchemaPage extends BasePage{
                    
                    if (alert == false)
                    {
                        /*
                        updateTapSchema.createTapSchemaDatabase(
                                hostname,
                                port,
                                username,
                                password,
                                tapschemaName);
                                */
                        updateTapSchema.resetTapSchemaDatabase(
                                hostname,
                                port,
@@ -221,7 +228,7 @@ public class SchemaPage extends BasePage{
                    String primary_key = "";
                    if (column.indexed == 1)
                    {
                        primary_key = "primary_key";
                        primary_key = "pk";
                    }
                                        
                    String foreign_key = "";
@@ -235,7 +242,7 @@ public class SchemaPage extends BasePage{
                                {
                                    if (key_column.from_column.equals(column_name))
                                    {
                                        foreign_key = "foreign_key";
                                        foreign_key = "fk";
                                    }
                                }
                            }
+17 −10
Original line number Diff line number Diff line
@@ -7,19 +7,26 @@ and open the template in the editor.
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
               div.schemapanel {
                    border: 1px solid black;
               }
        </style>
    </head>
    <body>
        <wicket:panel>
            <div class="schemapanel" style="border: 1px solid black;">
                <form wicket:id="updateSchemaForm"> <br /> <br />
                    <span wicket:id="utypeLabel">Schema utype</span>
                    <input type="text" wicket:id="utypeText" /> <br />
                    <span wicket:id="descriptionLabel">Schema description</span>
                    <input type="text" wicket:id="descriptionText" /> <br />
                <span wicket:id="selectSchemaLabel">Drop schema</span>
                    <span wicket:id="selectSchemaLabel">Select schema</span>
                    <input type="checkbox" wicket:id="selectSchemaCheckBox" /> <br />
                </form>
           
                <div wicket:id="tablesTabbedPanel" class="tabpanel"></div> 
            </div>
        </wicket:panel>
    </body>
</html>
+96 −53
Original line number Diff line number Diff line
@@ -169,58 +169,7 @@ public class SelectSchemataPage extends BasePage {
            {
                String newSelection = tapschemaDropDownChoice.getModelObject();
                
                //load schemas from selected tapschema
                String url = "jdbc:mysql://" + hostname + ":" + port + "/";
                Connection connection = null;
                Statement statement = null;
                ResultSet resultSet = null;
                try
                {
                    Class.forName("com.mysql.jdbc.Driver");
                    connection = DriverManager.getConnection(
                            url,
                            username,
                            password
                    );
                    statement = connection.createStatement();
                    String queryString = "SELECT schema_name FROM " + newSelection + ".`schemas`;";
                    resultSet = statement.executeQuery(queryString);
                    
                    //compare schemas in tapschema with schemas in schemataListChoice
                    selectedList.removeAll(selectedList);
                    while (resultSet.next())
                    {
                        for (String schemaName : schemataList)
                        {
                            if (resultSet.getString(1).equals(schemaName))
                            {
                                selectedList.add(resultSet.getString(1));
                            }
                        }
                    }
                    schemataListChoice.setModelObject(selectedList);
                    target.add(schemataListChoice);
                }
                catch (Exception exception)
                {
                    infoTextArea.setModelObject((String)exception.getMessage());
                    target.add(infoTextArea);
                    exception.printStackTrace();
                }
                finally
                {
                    try
                    {
                        resultSet.close();
                        statement.close();
                        connection.close();
                    }
                    catch (Exception exception)
                    {
                        exception.printStackTrace();
                        return;
                    }
                }
                selectDefaultSchema(target, hostname, port, username, password, newSelection);
            }
        });
        
@@ -373,6 +322,20 @@ public class SelectSchemataPage extends BasePage {
                        }
                    }
                    
                    updateTapSchema.createTapSchemaDatabase(
                            hostname,
                            port,
                            username,
                            password,
                            tapschemaName);
                    updateTapSchema.autoUpdateTapSchema(
                            hostname,
                            port,
                            username,
                            password,
                            tapschemaName);
                    selectedDatabases.add(tapschemaName);
                    
                    TapSchema tapschema = updateTapSchema.populateFromDatabases(
                            hostname,
                            port,
@@ -382,6 +345,16 @@ public class SelectSchemataPage extends BasePage {
                            selectedDatabases,
                            true);
                    
                    tapschema = updateTapSchema.populateFromTapSchema(
                            hostname,
                            port,
                            username,
                            password,
                            tapschemaName,
                            selectedDatabases,
                            true,
                            tapschema);

                    loadSchemata(target, form, hostname, port, username, password);
                    
                    SchemaPage schemaPage = new SchemaPage(
@@ -513,6 +486,14 @@ public class SelectSchemataPage extends BasePage {
        selectSchemataForm.add(infoTextArea);
        
        loadSchemata(target, form, hostname, port, username, password);
        
        if (!tapschemaList.isEmpty())
        {
            //String newSelection = tapschemaDropDownChoice.getModelObject();
            String newSelection = tapschemaList.get(0);
            tapschemaDropDownChoice.setModelObject(newSelection);
            selectDefaultSchema(target, hostname, port, username, password, newSelection);
        }
    }
    
    public void loadSchemata(
@@ -644,4 +625,66 @@ public class SelectSchemataPage extends BasePage {
        }
    }
    
    public void selectDefaultSchema(
            AjaxRequestTarget target,
            String hostname,
            String port,
            String username,
            String password,
            String newSelection)
    {                
        //load schemas from selected tapschema
        String url = "jdbc:mysql://" + hostname + ":" + port + "/";
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                    url,
                    username,
                    password
            );
            statement = connection.createStatement();
            String queryString = "SELECT schema_name FROM " + newSelection + ".`schemas`;";
            resultSet = statement.executeQuery(queryString);

            //compare schemas in tapschema with schemas in schemataListChoice
            selectedList.removeAll(selectedList);
            while (resultSet.next())
            {
                for (String schemaName : schemataList)
                {
                    if (resultSet.getString(1).equals(schemaName))
                    {
                        selectedList.add(resultSet.getString(1));
                    }
                }
            }
            schemataListChoice.setModelObject(selectedList);
            target.add(schemataListChoice);
        }
        catch (Exception exception)
        {
            infoTextArea.setModelObject((String)exception.getMessage());
            target.add(infoTextArea);
            exception.printStackTrace();
        }
        finally
        {
            try
            {
                resultSet.close();
                statement.close();
                connection.close();
            }
            catch (Exception exception)
            {
                exception.printStackTrace();
                return;
            }
        }
    }
        
}
Loading