Commit e2505e9e authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Refactoring

parent 0214d711
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -96,14 +96,12 @@ public class AjaxTextField extends TextField {
                    if (idSplit[1].equals("utype"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .utype
                                = (String)getModelObject();
                                .setUtype((String)getModelObject());
                    }
                    else if (idSplit[1].equals("description"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .description
                                = (String)getModelObject();
                                .setDescription((String)getModelObject());
                    }
                    //end setting variables "utype" and "description"
                }
@@ -171,15 +169,13 @@ public class AjaxTextField extends TextField {
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .utype
                                = (String)getModelObject();
                                .setUtype((String)getModelObject());
                    }
                    else if (idSplit[2].equals("description"))
                    {
                        schemaPage.tapschema.schemasMap.get(idSplit[0])
                                .tablesMap.get(idSplit[1])
                                .description
                                = (String)getModelObject();
                                .setDescription((String)getModelObject());
                        
                    }
                    //end setting variables "utype" and "description"
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
                <span wicket:id="message"></span>
            </div>
        </div>
        <br/><br/>
        <wicket:child/> 
    </section> 
    <!--<footer wicket:id="footerpanel" />-->
+5 −4
Original line number Diff line number Diff line
@@ -8,13 +8,14 @@
        <div id="container">

            <form wicket:id="schemaForm">
                <br />
                <div class="col-xs-12 text-center vpadding">
                    <input type="submit" wicket:id="updateSubmit" value="Update all" class="btn btn-lg btn-success" />
                </div>

                <div wicket:id="schemataTabbedPanel" class="tabpanel"></div>
                <br /><br />
                <input type="submit" wicket:id="updateSubmit" value="Update all" />
                <input type="submit" wicket:id="backSubmit" value="Back to select schemata" />
                <input type="submit" wicket:id="exit" value="Close session" />
                <br /><br />
                <div wicket:id="schemataTabbedPanel" class="tabpanel"></div>
            </form>
        </div>
    </wicket:extend>
+88 −34
Original line number Diff line number Diff line
<wicket:panel>
    <div class="col-xs-3 schema-tab-block">
        <h3>Table name</h3>
        <ul class="nav nav-pills row">
            <li role="presentation" wicket:id="tablesList">
                <a wicket:id="tableLink"><span wicket:id="tableName"></span></a>
            </li>
        </ul>
    <div class="schema-info">
        <div class="form-horizontal">
            <div class="form-group">
                <label for="schema-utype" class="col-sm-2 control-label">Schema utype</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="schema-utype" wicket:id="schemaUtype" />
                </div>
    <div class="col-xs-3 schema-tab-block">
        <h3>Column name</h3>
        <ul class="nav nav-pills row">
            </div>
            <div class="form-group">
                <label for="schema-description" class="col-sm-2 control-label">Schema description</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="schema-description" wicket:id="schemaDescription" />
                </div>
            </div>
        </div>
    </div>
    <div class="table-info">
        <div class="form-horizontal">
            <div class="form-group">
                <label for="table-selector" class="col-sm-2 control-label">Table</label>
                <div class="col-sm-10">
                    <select id="table-selector" wicket:id="tableDropDownChoice" class="form-control"></select>
                </div>
            </div>
            <div wicket:id="tableInfo">
                <div class="form-group">
                    <label for="table-utype" class="col-sm-2 control-label">Table utype</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="table-utype" wicket:id="tableUtype" />
                    </div>
                </div>
                <div class="form-group">
                    <label for="table-description" class="col-sm-2 control-label">Table description</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="table-description" wicket:id="tableDescription" />
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div wicket:id="columnsContainer">
        <div class="columns-header">
            <div class="columns-header-name">Column name</div>
            <div class="columns-header-properties">Column properties</div>
        </div>
        <div class="columns-wrapper">
            <div class="columns-selector">
                <ul class="nav nav-pills">
                    <li role="presentation" wicket:id="columnsList">
                        <a wicket:id="columnLink"><span wicket:id="columnName"></span></a>
                    </li>
                </ul>
            </div>
    <div class="col-xs-6 schema-tab-block">
        <h3>Column properties</h3>
            <div class="column-info">
                <div wicket:id="selectedColumn">
                    <div class="form-group">
                        <label for="utype" class="control-label">UType:</label>
@@ -44,4 +81,21 @@
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--<div class="col-xs-3 schema-tab-block">
        <h3>Table name</h3>
        <ul class="nav nav-pills row">
            <li role="presentation" wicket:id="tablesList">
                <a wicket:id="tableLink"><span wicket:id="tableName"></span></a>
            </li>
        </ul>
    </div>
    <div class="col-xs-3 schema-tab-block">

    </div>
    <div class="col-xs-6 schema-tab-block">

    </div>-->
</wicket:panel>
 No newline at end of file
+123 −45
Original line number Diff line number Diff line
@@ -13,10 +13,15 @@ import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

@@ -28,23 +33,6 @@ public final class SchemaPanel extends Panel {

    static final Logger log = Logger.getLogger(SelectSchemataPage.class.getName());

    class TableSelector extends AjaxFallbackLink {

        private final ListItem<String> item;

        public TableSelector(String id, ListItem<String> item) {
            super(id);
            this.item = item;
            add(new Label("tableName", item.getModel()));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            SchemaPanel.this.selectTable(item.getIndex());
            target.add(SchemaPanel.this);
        }
    }

    class ColumnSelector extends AjaxFallbackLink {

        private final ListItem<String> item;
@@ -64,8 +52,10 @@ public final class SchemaPanel extends Panel {

    private final Schema schema;

    int selectedTableIndex = 0;
    Table selectedTable = null;
    final ArrayList<String> tablesNames;
    final Model<String> selectedTableModel;
    final DropDownChoice tableDropDownChoice;

    int selectedColumnIndex = 0;
    final ArrayList<String> columnsNames;
@@ -78,23 +68,130 @@ public final class SchemaPanel extends Panel {
        this.schema = schema;
        setOutputMarkupPlaceholderTag(true);

        TextField<String> schemaUtypeTextField
                = new TextField<String>("schemaUtype", new Model<String>() {

                    @Override
                    public String getObject() {
                        return SchemaPanel.this.schema.getUtype();
                    }

                    @Override
                    public void setObject(String object) {
                        SchemaPanel.this.schema.setUtype(object);
                    }
                });
        add(schemaUtypeTextField);

        TextField<String> schemaDescriptionTextField
                = new TextField<String>("schemaDescription", new Model<String>() {

                    @Override
                    public String getObject() {
                        return SchemaPanel.this.schema.getDescription();
                    }

                    @Override
                    public void setObject(String object) {
                        SchemaPanel.this.schema.setDescription(object);
                    }
                });
        add(schemaDescriptionTextField);

        tablesNames = new ArrayList<String>();
        for (String tableName : schema.tablesMap.keySet()) {
            tablesNames.add(tableName);
        }
        add(new ListView<String>("tablesList", tablesNames) {

        selectedTableModel = new Model<String>() {

            private String selectedTableName = null;

            @Override
            public String getObject() {
                return selectedTableName;
            }

            @Override
            protected void populateItem(ListItem<String> item) {
                item.add(new TableSelector("tableLink", item));
            public void setObject(String object) {
                selectedTableName = object;
                if (selectedTableName != null) {
                    selectedTable = SchemaPanel.this.schema.getTable(selectedTableName);
                    columnsNames.clear();
                    for (String columnName : selectedTable.getColumnsMap().keySet()) {
                        columnsNames.add(columnName);
                    }

                if (selectedTableIndex == item.getIndex()) {
                    item.add(new AttributeModifier("class", "active"));
                    selectColumn(0);
                }
            }
        };

        tableDropDownChoice = new DropDownChoice<String>(
                "tableDropDownChoice", selectedTableModel, tablesNames);
        tableDropDownChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                target.add(SchemaPanel.this);
            }
        });
        add(tableDropDownChoice);

        WebMarkupContainer tableInfo = new WebMarkupContainer("tableInfo");
        tableInfo.add(new Behavior() {
            @Override
            public void onConfigure(Component component) {
                component.setVisible(selectedTableModel.getObject() != null);
            }
        });
        add(tableInfo);

        tableInfo.add(new TextField<String>("tableUtype", new Model<String>() {

            @Override
            public String getObject() {
                if (selectedTable != null) {
                    return selectedTable.getUtype();
                }
                return null;
            }

            @Override
            public void setObject(String object) {
                if (selectedTable != null) {
                    selectedTable.setUtype(object);
                }
            }
        }));
        tableInfo.add(new TextField<String>("tableDescription", new Model<String>() {

            @Override
            public String getObject() {
                if (selectedTable != null) {
                    return selectedTable.getDescription();
                }
                return null;
            }

            @Override
            public void setObject(String object) {
                if (selectedTable != null) {
                    selectedTable.setDescription(object);
                }
            }
        }));

        WebMarkupContainer columnsContainer = new WebMarkupContainer("columnsContainer");
        columnsContainer.add(new Behavior() {
            @Override
            public void onConfigure(Component component) {
                component.setVisible(selectedColumn != null);
            }
        });
        add(columnsContainer);

        columnsNames = new ArrayList<String>();
        add(new ListView<String>("columnsList", columnsNames) {
        columnsContainer.add(new ListView<String>("columnsList", columnsNames) {
            @Override
            protected void populateItem(ListItem<String> item) {
                item.add(new ColumnSelector("columnLink", item));
@@ -117,32 +214,13 @@ public final class SchemaPanel extends Panel {
            }
        };

        add(selectedColumnView);

        selectTable(0);
    }

    private Table getSelectedTable() {
        return schema.getTable(tablesNames.get(selectedTableIndex));
    }

    private void selectTable(int index) {
        if (tablesNames.size() > 0) {
            selectedTableIndex = index;

            columnsNames.clear();
            for (String columnName : getSelectedTable().getColumnsMap().keySet()) {
                columnsNames.add(columnName);
            }

            selectColumn(0);
        }
        columnsContainer.add(selectedColumnView);
    }

    private void selectColumn(int index) {
        if (columnsNames.size() > 0) {
            selectedColumnIndex = index;
            selectedColumn = getSelectedTable().getColumn(columnsNames.get(index));
            selectedColumn = selectedTable.getColumn(columnsNames.get(index));
            selectedColumnView.setContent(selectedColumn);
        } else {
            selectedColumnView.clear();
Loading