cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [03/10] cayenne git commit: CAY-2172 Split DB actions to different packages Clean up ReverseEngineeringAction Clean up DataSource select dialogs
Date Mon, 19 Dec 2016 11:46:19 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbMigrateOptionsDialog.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbMigrateOptionsDialog.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbMigrateOptionsDialog.java
deleted file mode 100644
index f53bf9c..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbMigrateOptionsDialog.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.dialog.db;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.Collection;
-
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.util.CayenneDialog;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
-public class DbMigrateOptionsDialog extends CayenneDialog {
-	private static final long serialVersionUID = 1L;
-	public static final int CANCEL = 0;
-    public static final int SELECT = 1;
-
-	protected JLabel schemaLabel;
-	protected JLabel catalogLabel;
-    protected JComboBox<String> catalogSelector;
-    protected JComboBox<String> schemaSelector;
-    protected JButton selectButton;
-    protected JButton cancelButton;
-    protected int choice;
-    
-    public DbMigrateOptionsDialog(Collection<String> catalogs, Collection<String> schemas, String dbUserName) {
-        super(Application.getFrame(), "Migrate DB Schema: Select Catalog and Schema");
-        init();
-        initController();
-        initFromModel(catalogs, schemas, dbUserName);
-
-        pack();
-        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-        setModal(true);
-        centerWindow();    	
-    }
-    
-    protected void init() {
-        selectButton = new JButton("Continue");
-        cancelButton = new JButton("Cancel");
-        catalogSelector = new JComboBox<>();
-        schemaSelector = new JComboBox<>();
-        FormLayout layout = new FormLayout(
-                "right:pref, 3dlu, fill:max(170dlu;pref):grow",
-                "");
-        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
-        builder.setDefaultDialogBorder();
-
-        catalogLabel = builder.append("Select Catalog:", catalogSelector, true);
-        schemaLabel = builder.append("Select Schema:", schemaSelector);
-
-        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        buttons.add(selectButton);
-        buttons.add(cancelButton);
-        
-        getContentPane().setLayout(new BorderLayout());
-        getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
-        getContentPane().add(buttons, BorderLayout.SOUTH);        
-    }
-    
-    protected void initController() {
-        selectButton.addActionListener(new ActionListener() {
-
-            public void actionPerformed(ActionEvent e) {
-                processSelect();
-            }
-        });
-
-        cancelButton.addActionListener(new ActionListener() {
-
-            public void actionPerformed(ActionEvent e) {
-                processCancel();
-            }
-        });
-    }
-    
-    private void processSelect() {
-        choice = SELECT;
-        setVisible(false);
-    }
-
-    private void processCancel() {
-    	schemaSelector.setSelectedItem(null);
-        choice = CANCEL;
-        setVisible(false);
-    }
-    
-    protected void initFromModel(Collection<String> catalogs, Collection<String> schemas, String dbUserName) {
-
-        this.choice = CANCEL;
-
-        if(!schemas.isEmpty()) {
-            schemaLabel.setVisible(true);
-            schemaSelector.setModel(new DefaultComboBoxModel<>(schemas.toArray(new String[0])));
-            schemaSelector.setVisible(true);
-        } else {
-            schemaLabel.setVisible(false);
-            schemaSelector.setVisible(false);
-        }
-
-        if(!catalogs.isEmpty()) {
-            catalogLabel.setVisible(true);
-            catalogSelector.setModel(new DefaultComboBoxModel<>(catalogs.toArray(new String[0])));
-            catalogSelector.setVisible(true);
-        } else {
-            catalogLabel.setVisible(false);
-            catalogSelector.setVisible(false);
-        }
-
-        if (dbUserName == null) {
-            return;
-        }
-
-        // select schema belonging to the user
-        for (String schema : schemas) {
-            if (dbUserName.equalsIgnoreCase(schema)) {
-                schemaSelector.setSelectedItem(schema);
-                break;
-            }
-        }
-
-        for(String catalog : catalogs) {
-            if(dbUserName.equalsIgnoreCase(catalog)) {
-                catalogSelector.setSelectedItem(catalog);
-                break;
-            }
-        }
-    }
-    
-    /**
-     * Returns selected schema.
-     */
-    public String getSelectedSchema() {
-    	return (String) schemaSelector.getSelectedItem();
-    }
-
-    public String getSelectedCatalog() {
-        return (String) catalogSelector.getSelectedItem();
-    }
-    
-    public int getChoice() {
-    	return choice;
-    }
-    
-    public void showDialog() {
-    	setVisible(true);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
deleted file mode 100644
index 52a3666..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- *    or more contributor license agreements.  See the NOTICE file
- *    distributed with this work for additional information
- *    regarding copyright ownership.  The ASF licenses this file
- *    to you under the Apache License, Version 2.0 (the
- *    "License"); you may not use this file except in compliance
- *    with the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing,
- *    software distributed under the License is distributed on an
- *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *    KIND, either express or implied.  See the License for the
- *    specific language governing permissions and limitations
- *    under the License.
- */
-
-package org.apache.cayenne.modeler.dialog.db;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.configuration.event.DataMapEvent;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.AbstractToDbToken;
-import org.apache.cayenne.dbsync.merge.DbMerger;
-import org.apache.cayenne.dbsync.merge.DefaultModelMergeDelegate;
-import org.apache.cayenne.dbsync.merge.MergeDirection;
-import org.apache.cayenne.dbsync.merge.MergerContext;
-import org.apache.cayenne.dbsync.merge.MergerToken;
-import org.apache.cayenne.dbsync.merge.ModelMergeDelegate;
-import org.apache.cayenne.dbsync.merge.ProxyModelMergeDelegate;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
-import org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator;
-import org.apache.cayenne.dbsync.naming.NoStemStemmer;
-import org.apache.cayenne.dbsync.reverse.db.DbLoader;
-import org.apache.cayenne.dbsync.reverse.db.DbLoaderConfiguration;
-import org.apache.cayenne.dbsync.reverse.db.LoggingDbLoaderDelegate;
-import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
-import org.apache.cayenne.dbsync.reverse.filters.PatternFilter;
-import org.apache.cayenne.dbsync.reverse.filters.TableFilter;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.dialog.ValidationResultBrowser;
-import org.apache.cayenne.modeler.pref.DBConnectionInfo;
-import org.apache.cayenne.modeler.util.CayenneController;
-import org.apache.cayenne.project.Project;
-import org.apache.cayenne.resource.Resource;
-import org.apache.cayenne.swing.BindingBuilder;
-import org.apache.cayenne.swing.ObjectBinding;
-import org.apache.cayenne.tools.dbimport.DefaultDbImportAction;
-import org.apache.cayenne.validation.ValidationResult;
-import org.apache.commons.logging.LogFactory;
-
-import javax.sql.DataSource;
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
-import javax.swing.WindowConstants;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import java.awt.Component;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-public class MergerOptions extends CayenneController {
-
-    protected MergerOptionsView view;
-    protected ObjectBinding sqlBinding;
-
-    protected DBConnectionInfo connectionInfo;
-    protected DataMap dataMap;
-    protected DbAdapter adapter;
-    protected String textForSQL;
-
-    protected MergerTokenSelectorController tokens;
-    protected String defaultCatalog;
-    protected String defaultSchema;
-    private MergerTokenFactoryProvider mergerTokenFactoryProvider;
-
-    public MergerOptions(ProjectController parent,
-                         String title,
-                         DBConnectionInfo connectionInfo,
-                         DataMap dataMap,
-                         String defaultCatalog,
-                         String defaultSchema,
-                         MergerTokenFactoryProvider mergerTokenFactoryProvider) {
-        super(parent);
-
-        this.mergerTokenFactoryProvider = mergerTokenFactoryProvider;
-        this.dataMap = dataMap;
-        this.tokens = new MergerTokenSelectorController(parent);
-        this.view = new MergerOptionsView(tokens.getView());
-        this.connectionInfo = connectionInfo;
-        this.defaultCatalog = defaultCatalog;
-        this.defaultSchema = defaultSchema;
-        this.view.setTitle(title);
-        initController();
-
-        prepareMigrator();
-        createSQL();
-        refreshView();
-    }
-
-    public Component getView() {
-        return view;
-    }
-
-    public String getTextForSQL() {
-        return textForSQL;
-    }
-
-    protected void initController() {
-
-        BindingBuilder builder = new BindingBuilder(
-                getApplication().getBindingFactory(),
-                this);
-
-        sqlBinding = builder.bindToTextArea(view.getSql(), "textForSQL");
-
-        builder.bindToAction(view.getGenerateButton(), "generateSchemaAction()");
-        builder.bindToAction(view.getSaveSqlButton(), "storeSQLAction()");
-        builder.bindToAction(view.getCancelButton(), "closeAction()");
-
-        // refresh SQL if different tables were selected
-        view.getTabs().addChangeListener(new ChangeListener() {
-
-            public void stateChanged(ChangeEvent e) {
-                if (view.getTabs().getSelectedIndex() == 1) {
-                    // this assumes that some tables where checked/unchecked... not very
-                    // efficient
-                    refreshGeneratorAction();
-                }
-            }
-        });
-    }
-
-    /**
-     * check database and create the {@link List} of {@link MergerToken}s
-     */
-    protected void prepareMigrator() {
-        try {
-            adapter = connectionInfo.makeAdapter(getApplication().getClassLoadingService());
-
-            MergerTokenFactory mergerTokenFactory = mergerTokenFactoryProvider.get(adapter);
-            tokens.setMergerTokenFactory(mergerTokenFactory);
-
-
-            FiltersConfig filters = FiltersConfig.create(defaultCatalog, defaultSchema, TableFilter.everything(),
-                    PatternFilter.INCLUDE_NOTHING);
-
-            DbMerger merger = DbMerger.builder(mergerTokenFactory)
-                    .filters(filters)
-                    .build();
-
-            DbLoaderConfiguration config = new DbLoaderConfiguration();
-            config.setFiltersConfig(filters);
-
-            DataSource dataSource = connectionInfo.makeDataSource(getApplication().getClassLoadingService());
-
-            DataMap dbImport = new DataMap();
-            try (Connection conn = dataSource.getConnection();) {
-                new DbLoader(conn,
-                        adapter,
-                        new LoggingDbLoaderDelegate(LogFactory.getLog(DbLoader.class)),
-                        new DefaultObjectNameGenerator(NoStemStemmer.getInstance()))
-                        .load(dbImport, config);
-
-            } catch (SQLException e) {
-                throw new CayenneRuntimeException("Can't doLoad dataMap from db.", e);
-            }
-
-            tokens.setTokens(merger.createMergeTokens(dataMap, dbImport));
-        } catch (Exception ex) {
-            reportError("Error loading adapter", ex);
-        }
-    }
-
-    /**
-     * Returns SQL statements generated for selected schema generation options.
-     */
-    protected void createSQL() {
-        // convert them to string representation for display
-        StringBuilder buf = new StringBuilder();
-
-        Iterator<MergerToken> it = tokens.getSelectedTokens().iterator();
-        String batchTerminator = adapter.getBatchTerminator();
-
-        String lineEnd = batchTerminator != null ? "\n" + batchTerminator + "\n\n" : "\n\n";
-        while (it.hasNext()) {
-            MergerToken token = it.next();
-
-            if (token instanceof AbstractToDbToken) {
-                AbstractToDbToken tdb = (AbstractToDbToken) token;
-                for (String sql : tdb.createSql(adapter)) {
-                    buf.append(sql);
-                    buf.append(lineEnd);
-                }
-            }
-        }
-
-        textForSQL = buf.toString();
-    }
-
-    protected void refreshView() {
-        sqlBinding.updateView();
-    }
-
-    // ===============
-    // Actions
-    // ===============
-
-    /**
-     * Starts options dialog.
-     */
-    public void startupAction() {
-        view.pack();
-        view.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
-        view.setModal(true);
-        makeCloseableOnEscape();
-        centerView();
-        view.setVisible(true);
-    }
-
-    public void refreshGeneratorAction() {
-        refreshSQLAction();
-    }
-
-    /**
-     * Updates a text area showing generated SQL.
-     */
-    public void refreshSQLAction() {
-        createSQL();
-        sqlBinding.updateView();
-    }
-
-    /**
-     * Performs configured schema operations via DbGenerator.
-     */
-    public void generateSchemaAction() {
-        refreshGeneratorAction();
-
-        // sanity check...
-        List<MergerToken> tokensToMigrate = tokens.getSelectedTokens();
-        if (tokensToMigrate.isEmpty()) {
-            JOptionPane.showMessageDialog(getView(), "Nothing to migrate.");
-            return;
-        }
-
-        DataSource dataSource;
-        try {
-            dataSource = connectionInfo.makeDataSource(getApplication()
-                    .getClassLoadingService());
-        } catch (SQLException ex) {
-            reportError("Migration Error", ex);
-            return;
-        }
-
-        final Collection<ObjEntity> loadedObjEntities = new LinkedList<>();
-
-        MergerContext mergerContext = MergerContext.builder(dataMap)
-                .syntheticDataNode(dataSource, adapter)
-                .delegate(createDelegate(loadedObjEntities))
-                .build();
-
-        boolean modelChanged = applyTokens(tokensToMigrate, mergerContext);
-
-        DefaultDbImportAction.flattenManyToManyRelationships(
-                dataMap,
-                loadedObjEntities,
-                mergerContext.getNameGenerator());
-
-        notifyProjectModified(modelChanged);
-
-        reportFailures(mergerContext);
-    }
-
-    private ModelMergeDelegate createDelegate(final Collection<ObjEntity> loadedObjEntities) {
-        return new ProxyModelMergeDelegate(new DefaultModelMergeDelegate()) {
-            @Override
-            public void objEntityAdded(ObjEntity ent) {
-                loadedObjEntities.add(ent);
-                super.objEntityAdded(ent);
-            }
-        };
-    }
-
-    private boolean applyTokens(List<MergerToken> tokensToMigrate, MergerContext mergerContext) {
-        boolean modelChanged = false;
-
-        try {
-            for (MergerToken tok : tokensToMigrate) {
-                int numOfFailuresBefore = getFailuresCount(mergerContext);
-
-                tok.execute(mergerContext);
-
-                if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
-                    modelChanged = true;
-                }
-                if (numOfFailuresBefore == getFailuresCount(mergerContext)) {
-                    // looks like the token executed without failures
-                    tokens.removeToken(tok);
-                }
-            }
-        } catch (Throwable th) {
-            reportError("Migration Error", th);
-        }
-
-        return modelChanged;
-    }
-
-    private int getFailuresCount(MergerContext mergerContext) {
-        return mergerContext.getValidationResult().getFailures().size();
-    }
-
-    private void reportFailures(MergerContext mergerContext) {
-        ValidationResult failures = mergerContext.getValidationResult();
-        if (failures == null || !failures.hasFailures()) {
-            JOptionPane.showMessageDialog(getView(), "Migration Complete.");
-        } else {
-            new ValidationResultBrowser(this).startupAction(
-                    "Migration Complete",
-                    "Migration finished. The following problem(s) were ignored.",
-                    failures);
-        }
-    }
-
-    private void notifyProjectModified(boolean modelChanged) {
-        if(!modelChanged) {
-            return;
-        }
-
-        // mark the model as unsaved
-        Project project = getApplication().getProject();
-        project.setModified(true);
-
-        ProjectController projectController = getProjectController();
-        projectController.setDirty(true);
-
-        projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(),
-                dataMap, MapEvent.REMOVE));
-        projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(),
-                dataMap, MapEvent.ADD));
-    }
-
-    /**
-     * Allows user to save generated SQL in a file.
-     */
-    public void storeSQLAction() {
-        JFileChooser fc = new JFileChooser();
-        fc.setDialogType(JFileChooser.SAVE_DIALOG);
-        fc.setDialogTitle("Save SQL Script");
-
-        Resource projectDir = getApplication().getProject().getConfigurationResource();
-
-        if (projectDir != null) {
-            fc.setCurrentDirectory(new File(projectDir.getURL().getPath()));
-        }
-
-        if (fc.showSaveDialog(getView()) == JFileChooser.APPROVE_OPTION) {
-            refreshGeneratorAction();
-
-            try {
-                File file = fc.getSelectedFile();
-                FileWriter fw = new FileWriter(file);
-                PrintWriter pw = new PrintWriter(fw);
-                pw.print(textForSQL);
-                pw.flush();
-                pw.close();
-            } catch (IOException ex) {
-                reportError("Error Saving SQL", ex);
-            }
-        }
-    }
-
-    private ProjectController getProjectController() {
-        return getApplication().getFrameController().getProjectController();
-    }
-
-    public void closeAction() {
-        view.dispose();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptionsView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptionsView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptionsView.java
deleted file mode 100644
index 24069da..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptionsView.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.db;
-
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-
-import javax.swing.Box;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTabbedPane;
-import javax.swing.JTextArea;
-import javax.swing.ScrollPaneConstants;
-import javax.swing.SwingConstants;
-
-import org.apache.cayenne.modeler.Application;
-
-import com.jgoodies.forms.builder.PanelBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-import com.jgoodies.forms.layout.FormLayout;
-
-/**
- * Wizard for altering the database to match the data map.
- */
-public class MergerOptionsView extends JDialog {
-
-    protected JTextArea sql;
-    protected JButton generateButton;
-    protected JButton cancelButton;
-    protected JButton saveSqlButton;
-
-    protected Component tables;
-    protected JTabbedPane tabs;
-
-    public MergerOptionsView(Component tables) {
-        super(Application.getFrame());
-        
-        // create widgets
-        this.generateButton = new JButton("Migrate");
-        this.cancelButton = new JButton("Close");
-        this.saveSqlButton = new JButton("Save SQL");
-
-        this.tables = tables;
-        this.tabs = new JTabbedPane(SwingConstants.TOP);
-        this.sql = new JTextArea();
-        sql.setEditable(false);
-        sql.setLineWrap(true);
-        sql.setWrapStyleWord(true);
-
-        JPanel sqlTextPanel = new JPanel(new BorderLayout());
-        sqlTextPanel.add(new JScrollPane(
-                sql,
-                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
-                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
-
-        CellConstraints cc = new CellConstraints();
-        PanelBuilder builder = new PanelBuilder(new FormLayout(
-                "fill:min(50dlu;pref):grow",
-                "p, 9dlu, p, 3dlu, fill:40dlu:grow"));
-        builder.setDefaultDialogBorder();
-        builder.addSeparator("Generated SQL", cc.xywh(1, 3, 1, 1));
-        builder.add(sqlTextPanel, cc.xy(1, 5));
-
-        tabs.addTab("Operations", new JScrollPane(
-                tables,
-                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
-                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
-        tabs.addTab("Generated SQL", builder.getPanel());
-
-        // we need the right preferred size so that dialog "pack()" produces decent
-        // default size...
-        tabs.setPreferredSize(new Dimension(600, 350));
-
-        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        buttons.add(saveSqlButton);
-        buttons.add(Box.createHorizontalStrut(20));
-        buttons.add(cancelButton);
-        buttons.add(generateButton);
-
-        Container contentPane = this.getContentPane();
-        contentPane.setLayout(new BorderLayout());
-        contentPane.add(tabs, BorderLayout.CENTER);
-        contentPane.add(buttons, BorderLayout.SOUTH);
-    }
-
-    public JButton getCancelButton() {
-        return cancelButton;
-    }
-
-    public JTabbedPane getTabs() {
-        return tabs;
-    }
-
-    /*
-     * public JCheckBox getCreateFK() { return createFK; } public JCheckBox getCreatePK() {
-     * return createPK; } public JCheckBox getCreateTables() { return createTables; }
-     * public JCheckBox getDropPK() { return dropPK; } public JCheckBox getDropTables() {
-     * return dropTables; }
-     */
-
-    public JButton getGenerateButton() {
-        return generateButton;
-    }
-
-    public JButton getSaveSqlButton() {
-        return saveSqlButton;
-    }
-
-    public JTextArea getSql() {
-        return sql;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
deleted file mode 100644
index 666b113..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.dialog.db;
-
-import org.apache.cayenne.dbsync.merge.MergeDirection;
-import org.apache.cayenne.dbsync.merge.MergerToken;
-import org.apache.cayenne.dbsync.merge.TokenComparator;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.util.CayenneController;
-import org.apache.cayenne.swing.BindingBuilder;
-import org.apache.cayenne.swing.ObjectBinding;
-
-import javax.swing.*;
-import javax.swing.table.AbstractTableModel;
-import javax.swing.table.TableColumn;
-import javax.swing.table.TableColumnModel;
-import javax.swing.table.TableModel;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class MergerTokenSelectorController extends CayenneController {
-
-    protected MergerTokenSelectorView view;
-    protected ObjectBinding tableBinding;
-
-    protected MergerToken token;
-    protected int permanentlyExcludedCount;
-    protected Set<MergerToken> excludedTokens;
-    protected List<MergerToken> selectableTokensList;
-    protected MergerTokenFactory mergerTokenFactory;
-
-    public MergerTokenSelectorController(CayenneController parent) {
-        super(parent);
-        this.view = new MergerTokenSelectorView();
-        this.excludedTokens = new HashSet<MergerToken>();
-        this.selectableTokensList = new ArrayList<MergerToken>();
-        initController();
-    }
-
-    public void setMergerTokenFactory(MergerTokenFactory mergerTokenFactory) {
-        this.mergerTokenFactory = mergerTokenFactory;
-    }
-
-    public void setTokens(List<MergerToken> tokens) {
-        selectableTokensList.clear();
-        selectableTokensList.addAll(tokens);
-        excludedTokens.addAll(tokens);
-    }
-
-    public List<MergerToken> getSelectedTokens() {
-        List<MergerToken> t = new ArrayList<MergerToken>(selectableTokensList);
-        t.removeAll(excludedTokens);
-        return Collections.unmodifiableList(t);
-    }
-
-    public List<MergerToken> getSelectableTokens() {
-        return Collections.unmodifiableList(selectableTokensList);
-    }
-    
-    public void removeToken(MergerToken token) {
-        selectableTokensList.remove(token);
-        excludedTokens.remove(token);
-
-        AbstractTableModel model = (AbstractTableModel) view.getTokens().getModel();
-        model.fireTableDataChanged();
-    }
-
-    // ----- properties -----
-
-    public Component getView() {
-        return view;
-    }
-
-    /**
-     * Called by table binding script to set current token.
-     */
-    public void setToken(MergerToken token) {
-        this.token = token;
-    }
-
-    /**
-     * Returns {@link MergerToken}s that are excluded from DB generation.
-     */
-    /*
-     * public Collection getExcludedTokens() { return excludedTokens; }
-     */
-
-    public boolean isIncluded() {
-        if (token == null) {
-            return false;
-        }
-
-        return !excludedTokens.contains(token);
-    }
-
-    public void setIncluded(boolean b) {
-        if (token == null) {
-            return;
-        }
-
-        if (b) {
-            excludedTokens.remove(token);
-        }
-        else {
-            excludedTokens.add(token);
-        }
-
-        tableSelectedAction();
-    }
-
-    /**
-     * A callback action that updates the state of Select All checkbox.
-     */
-    public void tableSelectedAction() {
-        int unselectedCount = excludedTokens.size() - permanentlyExcludedCount;
-
-        if (unselectedCount == selectableTokensList.size()) {
-            view.getCheckAll().setSelected(false);
-        }
-        else if (unselectedCount == 0) {
-            view.getCheckAll().setSelected(true);
-        }
-    }
-
-    // ------ other stuff ------
-
-    protected void initController() {
-        BindingBuilder builder = new BindingBuilder(
-                getApplication().getBindingFactory(),
-                this);
-
-        builder.bindToAction(view.getCheckAll(), "checkAllAction()");
-        builder.bindToAction(view.getReverseAll(), "reverseAllAction()");
-
-        TableModel model = new MergerTokenTableModel(this);
-
-        MergeDirection[] dirs = new MergeDirection[] {
-                MergeDirection.TO_DB, MergeDirection.TO_MODEL
-        };
-
-        view.getTokens().setModel(model);
-
-        TableColumnModel columnModel = view.getTokens().getColumnModel();
-        
-        // dropdown for direction column
-        JComboBox directionCombo = Application.getWidgetFactory().createComboBox(dirs, false);
-        directionCombo.setEditable(false);
-        TableColumn directionColumn = columnModel.getColumn(
-                MergerTokenTableModel.COL_DIRECTION);
-        directionColumn.setCellEditor(new DefaultCellEditor(directionCombo));
-
-        columnModel.getColumn(MergerTokenTableModel.COL_SELECT).setPreferredWidth(50);
-        columnModel.getColumn(MergerTokenTableModel.COL_DIRECTION).setPreferredWidth(100);
-        columnModel.getColumn(MergerTokenTableModel.COL_SELECT).setMaxWidth(50);
-        columnModel.getColumn(MergerTokenTableModel.COL_DIRECTION).setMaxWidth(100);
-    }
-
-    public boolean isSelected(MergerToken token) {
-        return (selectableTokensList.contains(token) && !excludedTokens.contains(token));
-    }
-
-    public void select(MergerToken token, boolean select) {
-        if (select) {
-            excludedTokens.remove(token);
-        }
-        else {
-            excludedTokens.add(token);
-        }
-    }
-
-    public void setDirection(MergerToken token, MergeDirection direction) {
-        if (token.getDirection().equals(direction)) {
-            return;
-        }
-        int i = selectableTokensList.indexOf(token);
-        MergerToken reverse = token.createReverse(mergerTokenFactory);
-        selectableTokensList.set(i, reverse);
-        if (excludedTokens.remove(token)) {
-            excludedTokens.add(reverse);
-        }
-        
-        /**
-         * Repaint, so that "Operation" column updates properly
-         */
-        view.getTokens().repaint();
-    }
-
-    public void checkAllAction() {
-
-        boolean isCheckAllSelected = view.getCheckAll().isSelected();
-
-        if (isCheckAllSelected) {
-            excludedTokens.clear();
-        }
-        else {
-            excludedTokens.addAll(selectableTokensList);
-        }
-
-        AbstractTableModel model = (AbstractTableModel) view.getTokens().getModel();
-        model.fireTableDataChanged();
-    }
-
-    public void reverseAllAction() {
-        
-        for (int i = 0; i < selectableTokensList.size(); i++) {
-            MergerToken token = selectableTokensList.get(i);
-            MergerToken reverse = token.createReverse(mergerTokenFactory);
-            selectableTokensList.set(i, reverse);
-            if (excludedTokens.remove(token)) {
-                excludedTokens.add(reverse);
-            }
-        }
-
-        Collections.sort(selectableTokensList, new TokenComparator());
-        AbstractTableModel model = (AbstractTableModel) view.getTokens().getModel();
-        model.fireTableDataChanged();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorView.java
deleted file mode 100644
index a644a48..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorView.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.db;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-
-import com.jgoodies.forms.builder.PanelBuilder;
-import com.jgoodies.forms.factories.ButtonBarFactory;
-import com.jgoodies.forms.layout.CellConstraints;
-import com.jgoodies.forms.layout.FormLayout;
-
-/**
- */
-public class MergerTokenSelectorView extends JPanel {
-
-    protected JTable tokens;
-    protected JCheckBox checkAll;
-    protected JLabel checkAllLabel;
-    protected JButton reverseAll;
-
-    public MergerTokenSelectorView() {
-
-        this.checkAll = new JCheckBox();
-        this.checkAllLabel = new JLabel("Check All Operations");
-        this.reverseAll = new JButton("Reverse All Operations");
-
-        checkAll.addItemListener(new ItemListener() {
-
-            public void itemStateChanged(ItemEvent event) {
-                if (checkAll.isSelected()) {
-                    checkAllLabel.setText("Uncheck All Operations");
-                }
-                else {
-                    checkAllLabel.setText("Check All Operations");
-                }
-            }
-        });
-
-        // assemble
-        JPanel checkAllPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
-        checkAllPanel.add(checkAll);
-        checkAllPanel.add(checkAllLabel);
-        JPanel topPanel = new JPanel();
-        topPanel.setLayout(new BorderLayout());
-        topPanel.add(checkAllPanel, BorderLayout.WEST);
-        topPanel.add(ButtonBarFactory.buildRightAlignedBar(reverseAll), BorderLayout.EAST);
-
-        tokens = new JTable();
-        tokens.setRowHeight(25);
-        tokens.setRowMargin(3);
-
-        CellConstraints cc = new CellConstraints();
-        PanelBuilder builder = new PanelBuilder(new FormLayout(
-                "fill:min(50dlu;pref):grow",
-                "p, 3dlu, fill:40dlu:grow"));
-        builder.setDefaultDialogBorder();
-        builder.addSeparator("Select Operations", cc.xy(1, 1));
-        builder.add(new JScrollPane(
-                tokens,
-                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cc.xy(1, 3));
-
-        setLayout(new BorderLayout());
-        add(topPanel, BorderLayout.NORTH);
-        add(builder.getPanel(), BorderLayout.CENTER);
-    }
-
-    public JTable getTokens() {
-        return tokens;
-    }
-
-    public JCheckBox getCheckAll() {
-        return checkAll;
-    }
-    
-    public JButton getReverseAll() {
-        return reverseAll;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
deleted file mode 100644
index 488b1e8..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.dialog.db;
-
-import org.apache.cayenne.dbsync.merge.MergeDirection;
-import org.apache.cayenne.dbsync.merge.MergerToken;
-
-import javax.swing.table.AbstractTableModel;
-import java.util.List;
-
-
-public class MergerTokenTableModel extends AbstractTableModel {
-
-    public static final int COL_SELECT = 0;
-    public static final int COL_DIRECTION = 1;
-    public static final int COL_NAME = 2;
-    public static final int COL_VALUE = 3;
-
-    private MergerTokenSelectorController controller;
-
-    private List<MergerToken> tokens;
-
-    public MergerTokenTableModel(MergerTokenSelectorController controller) {
-        this.controller = controller;
-        this.tokens = controller.getSelectableTokens();
-    }
-
-    private MergerTokenSelectorController getController() {
-        return controller;
-    }
-
-    public Class getColumnClass(int columnIndex) {
-        switch (columnIndex) {
-            case COL_SELECT:
-                return Boolean.class;
-            case COL_DIRECTION:
-                // TODO: correct?
-                return String.class;
-            case COL_NAME:
-            case COL_VALUE:
-                return String.class;
-        }
-
-        return null;
-    }
-
-    public int getColumnCount() {
-        return 4;
-    }
-
-    public String getColumnName(int columnIndex) {
-        switch (columnIndex) {
-            case COL_SELECT:
-                return "";
-            case COL_NAME:
-                return "Operation";
-            case COL_DIRECTION:
-                return "Direction";
-            case COL_VALUE:
-                return "";
-        }
-
-        return null;
-    }
-
-    public int getRowCount() {
-        return tokens.size();
-    }
-
-    public MergerToken getToken(int rowIndex) {
-        return tokens.get(rowIndex);
-    }
-
-    public Object getValueAt(int rowIndex, int columnIndex) {
-        MergerToken token = getToken(rowIndex);
-        switch (columnIndex) {
-            case COL_SELECT:
-                return Boolean.valueOf(getController().isSelected(token));
-            case COL_NAME:
-                return token.getTokenName();
-            case COL_DIRECTION:
-                return token.getDirection();
-            case COL_VALUE:
-                return token.getTokenValue();
-        }
-        return null;
-    }
-
-    public boolean isCellEditable(int rowIndex, int columnIndex) {
-        switch (columnIndex) {
-            case COL_SELECT:
-            case COL_DIRECTION:
-                return true;
-        }
-        return false;
-    }
-
-    public void setValueAt(Object value, int rowIndex, int columnIndex) {
-        MergerToken token = getToken(rowIndex);
-        switch (columnIndex) {
-            case COL_SELECT:
-                Boolean val = (Boolean) value;
-                getController().select(token, val.booleanValue());
-                break;
-            case COL_DIRECTION:
-                MergeDirection direction = (MergeDirection) value;
-                getController().setDirection(token, direction);
-                break;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ModelerDbImportAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ModelerDbImportAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ModelerDbImportAction.java
deleted file mode 100644
index 1b271bb..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ModelerDbImportAction.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- *    or more contributor license agreements.  See the NOTICE file
- *    distributed with this work for additional information
- *    regarding copyright ownership.  The ASF licenses this file
- *    to you under the Apache License, Version 2.0 (the
- *    "License"); you may not use this file except in compliance
- *    with the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing,
- *    software distributed under the License is distributed on an
- *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *    KIND, either express or implied.  See the License for the
- *    specific language governing permissions and limitations
- *    under the License.
- */
-package org.apache.cayenne.modeler.dialog.db;
-
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
-import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
-import org.apache.cayenne.dbsync.reverse.db.DbLoader;
-import org.apache.cayenne.dbsync.reverse.db.DbLoaderDelegate;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.project.ProjectSaver;
-import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
-import org.apache.cayenne.tools.dbimport.DefaultDbImportAction;
-import org.apache.commons.logging.Log;
-
-import java.io.IOException;
-import java.sql.Connection;
-
-public class ModelerDbImportAction extends DefaultDbImportAction {
-
-    private DataMap targetMap;
-    private DbLoader dbLoader;
-
-    public ModelerDbImportAction(Log logger,
-                                 ProjectSaver projectSaver,
-                                 DataSourceFactory dataSourceFactory,
-                                 DbAdapterFactory adapterFactory,
-                                 MapLoader mapLoader,
-                                 MergerTokenFactoryProvider mergerTokenFactoryProvider,
-                                 DataMap targetMap,
-                                 DbLoader dbLoader
-                                 ) {
-
-        super(logger, projectSaver, dataSourceFactory, adapterFactory, mapLoader, mergerTokenFactoryProvider);
-
-        this.targetMap = targetMap;
-        this.dbLoader = dbLoader;
-    }
-
-    @Override
-    protected DbLoader createDbLoader(DbAdapter adapter,
-                                      Connection connection,
-                                      DbLoaderDelegate dbLoaderDelegate,
-                                      ObjectNameGenerator objectNameGenerator) {
-        return dbLoader;
-    }
-
-    @Override
-    protected DataMap existingTargetMap(DbImportConfiguration configuration) throws IOException {
-        return targetMap;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorController.java
deleted file mode 100644
index f9690c2..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorController.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.db;
-
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.util.CayenneController;
-import org.apache.cayenne.project.Project;
-import org.apache.cayenne.project.validation.ProjectValidator;
-import org.apache.cayenne.swing.BindingBuilder;
-import org.apache.cayenne.swing.ObjectBinding;
-import org.apache.cayenne.swing.TableBindingBuilder;
-import org.apache.cayenne.validation.ValidationFailure;
-import org.apache.cayenne.validation.ValidationResult;
-
-import java.awt.Component;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- */
-public class TableSelectorController extends CayenneController {
-
-    protected TableSelectorView view;
-    protected ObjectBinding tableBinding;
-
-    protected DbEntity table;
-    protected List<DbEntity> tables;
-    protected int permanentlyExcludedCount;
-    protected Map<String, DbEntity> excludedTables;
-    protected List<DbEntity> selectableTablesList;
-
-    protected Map<String, String> validationMessages;
-
-    public TableSelectorController(ProjectController parent) {
-        super(parent);
-        this.view = new TableSelectorView();
-        this.excludedTables = new HashMap<>();
-        this.selectableTablesList = new ArrayList<>();
-        this.validationMessages = new HashMap<>();
-        initController();
-    }
-
-    public Component getView() {
-        return view;
-    }
-
-    /**
-     * Called by table binding script to set current table.
-     */
-    public void setTable(DbEntity table) {
-        this.table = table;
-    }
-
-    /**
-     * Returns DbEntities that are excluded from DB generation.
-     */
-    public Collection<DbEntity> getExcludedTables() {
-        return excludedTables.values();
-    }
-
-    public List<DbEntity> getTables() {
-        return tables;
-    }
-
-    public boolean isIncluded() {
-        if (table == null) {
-            return false;
-        }
-
-        return !excludedTables.containsKey(table.getName());
-    }
-
-    public void setIncluded(boolean b) {
-        if (table == null) {
-            return;
-        }
-
-        if (b) {
-            excludedTables.remove(table.getName());
-        }
-        else {
-            excludedTables.put(table.getName(), table);
-        }
-
-        tableSelectedAction();
-    }
-
-    /**
-     * A callback action that updates the state of Select All checkbox.
-     */
-    public void tableSelectedAction() {
-        int unselectedCount = excludedTables.size() - permanentlyExcludedCount;
-
-        if (unselectedCount == selectableTablesList.size()) {
-            view.getCheckAll().setSelected(false);
-        }
-        else if (unselectedCount == 0) {
-            view.getCheckAll().setSelected(true);
-        }
-    }
-
-    public Object getProblem() {
-        return (table != null) ? validationMessages.get(table.getName()) : null;
-    }
-
-    // ------ other stuff ------
-
-    protected void initController() {
-
-        BindingBuilder builder = new BindingBuilder(
-                getApplication().getBindingFactory(),
-                this);
-
-        builder.bindToAction(view.getCheckAll(), "checkAllAction()");
-
-        TableBindingBuilder tableBuilder = new TableBindingBuilder(builder);
-
-        tableBuilder.addColumn(
-                "",
-                "setTable(#item), included",
-                Boolean.class,
-                true,
-                Boolean.TRUE);
-        tableBuilder.addColumn(
-                "Table",
-                "#item.name",
-                String.class,
-                false,
-                "XXXXXXXXXXXXXXXX");
-        tableBuilder.addColumn(
-                "Problems",
-                "setTable(#item), problem",
-                String.class,
-                false,
-                "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
-
-        this.tableBinding = tableBuilder.bindToTable(view.getTables(), "tables");
-    }
-
-    /**
-     * Performs validation of DbEntities in the current DataMap. Returns a collection of
-     * ValidationInfo objects describing the problems.
-     */
-    public void updateTables(Collection<DataMap> dataMaps) {
-        this.tables = new ArrayList<DbEntity>();
-
-        for (DataMap dataMap : dataMaps) {
-            this.tables.addAll(dataMap.getDbEntities());
-        }
-
-        excludedTables.clear();
-        validationMessages.clear();
-
-        // if there were errors, filter out those related to
-        // non-derived DbEntities...
-
-        // TODO: this is inefficient.. we need targeted validation
-        // instead of doing it on the whole project
-
-        Project project = getApplication().getProject();
-
-        ProjectValidator projectValidator = getApplication().getInjector().getInstance(
-                ProjectValidator.class);
-        ValidationResult validationResult = projectValidator.validate(project
-                .getRootNode());
-
-        if (validationResult.getFailures().size() > 0) {
-
-            for (ValidationFailure nextProblem : validationResult.getFailures()) {
-                DbEntity failedEntity = null;
-
-                if (nextProblem.getSource() instanceof DbAttribute) {
-                    DbAttribute failedAttribute = (DbAttribute) nextProblem.getSource();
-                    failedEntity = (DbEntity) failedAttribute.getEntity();
-                }
-                else if (nextProblem.getSource() instanceof DbRelationship) {
-                    DbRelationship failedRelationship = (DbRelationship) nextProblem
-                            .getSource();
-                    failedEntity = (DbEntity) failedRelationship.getSourceEntity();
-                }
-                else if (nextProblem.getSource() instanceof DbEntity) {
-                    failedEntity = (DbEntity) nextProblem.getSource();
-                }
-
-                if (failedEntity == null) {
-                    continue;
-                }
-
-                excludedTables.put(failedEntity.getName(), failedEntity);
-                validationMessages.put(failedEntity.getName(), nextProblem
-                        .getDescription());
-            }
-        }
-
-        // Find selectable tables
-        permanentlyExcludedCount = excludedTables.size();
-        selectableTablesList.clear();
-        for (DbEntity table : tables) {
-            if (false == excludedTables.containsKey(table.getName())) {
-                selectableTablesList.add(table);
-            }
-        }
-
-        tableBinding.updateView();
-        tableSelectedAction();
-    }
-
-    public void checkAllAction() {
-
-        boolean isCheckAllSelected = view.getCheckAll().isSelected();
-
-        if (isCheckAllSelected) {
-            selectableTablesList.clear();
-            selectableTablesList.addAll(tables);
-            excludedTables.clear();
-        }
-        else {
-            excludedTables.clear();
-            for (DbEntity table : tables) {
-                excludedTables.put(table.getName(), table);
-            }
-            selectableTablesList.clear();
-        }
-
-        tableBinding.updateView();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorView.java
deleted file mode 100644
index 80bab48..0000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/TableSelectorView.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.db;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import javax.swing.JCheckBox;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-
-import com.jgoodies.forms.builder.PanelBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-import com.jgoodies.forms.layout.FormLayout;
-
-/**
- */
-public class TableSelectorView extends JPanel {
-
-    protected JTable tables;
-    protected JCheckBox checkAll;
-    protected JLabel checkAllLabel;
-
-    public TableSelectorView() {
-
-        this.checkAll = new JCheckBox();
-        this.checkAllLabel = new JLabel("Check All Tables");
-
-        checkAll.addItemListener(new ItemListener() {
-
-            public void itemStateChanged(ItemEvent event) {
-                if (checkAll.isSelected()) {
-                    checkAllLabel.setText("Uncheck All Tables");
-                }
-                else {
-                    checkAllLabel.setText("Check All Tables");
-                }
-            }
-        });
-
-        // assemble
-        JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
-        topPanel.add(checkAll);
-        topPanel.add(checkAllLabel);
-
-        tables = new JTable();
-        tables.setRowHeight(25);
-        tables.setRowMargin(3);
-
-        CellConstraints cc = new CellConstraints();
-        PanelBuilder builder = new PanelBuilder(new FormLayout(
-                "fill:min(50dlu;pref):grow",
-                "p, 3dlu, fill:40dlu:grow"));
-        builder.setDefaultDialogBorder();
-        builder.addSeparator("Select Tables", cc.xy(1, 1));
-        builder.add(new JScrollPane(
-                tables,
-                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cc.xy(1, 3));
-
-        setLayout(new BorderLayout());
-        add(topPanel, BorderLayout.NORTH);
-        add(builder.getPanel(), BorderLayout.CENTER);
-    }
-
-    public JTable getTables() {
-        return tables;
-    }
-
-    public JCheckBox getCheckAll() {
-        return checkAll;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptions.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptions.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptions.java
new file mode 100644
index 0000000..441aba7
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptions.java
@@ -0,0 +1,332 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.modeler.dialog.db.gen;
+
+import org.apache.cayenne.access.DbGenerator;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.dialog.ValidationResultBrowser;
+import org.apache.cayenne.modeler.dialog.db.DataSourceWizard;
+import org.apache.cayenne.modeler.pref.DBConnectionInfo;
+import org.apache.cayenne.modeler.pref.DBGeneratorDefaults;
+import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.modeler.util.DbAdapterInfo;
+import org.apache.cayenne.swing.BindingBuilder;
+import org.apache.cayenne.swing.ObjectBinding;
+import org.apache.cayenne.validation.ValidationResult;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.WindowConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.Component;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ */
+public class DBGeneratorOptions extends CayenneController {
+
+    protected DBGeneratorOptionsView view;
+    protected ObjectBinding[] optionBindings;
+    protected ObjectBinding sqlBinding;
+    protected ObjectBinding adapterBinding;
+
+    protected DBConnectionInfo connectionInfo;
+    protected Collection<DataMap> dataMaps;
+    protected DBGeneratorDefaults generatorDefaults;
+    protected Collection<DbGenerator> generators;
+    protected String textForSQL;
+
+    protected TableSelectorController tables;
+
+    public DBGeneratorOptions(ProjectController parent, String title, Collection<DataMap> dataMaps) {
+        super(parent);
+
+        this.dataMaps = dataMaps;
+        this.tables = new TableSelectorController(parent);
+        this.view = new DBGeneratorOptionsView(tables.getView());
+        this.connectionInfo = new DBConnectionInfo();
+        this.generatorDefaults = new DBGeneratorDefaults(parent
+                .getPreferenceForProject()
+                .node("DbGenerator"));
+
+        this.view.setTitle(title);
+        initController();
+        connectionInfo.setDbAdapter((String) view.getAdapters().getSelectedItem());
+
+        tables.updateTables(dataMaps);
+        prepareGenerator();
+        generatorDefaults.configureGenerator(generators);
+        createSQL();
+        refreshView();
+    }
+
+    public Component getView() {
+        return view;
+    }
+
+    public DBGeneratorDefaults getGeneratorDefaults() {
+        return generatorDefaults;
+    }
+
+    public String getTextForSQL() {
+        return textForSQL;
+    }
+
+    protected void initController() {
+
+        DefaultComboBoxModel<String> adapterModel = new DefaultComboBoxModel<>(
+                DbAdapterInfo.getStandardAdapters());
+        view.getAdapters().setModel(adapterModel);
+        view.getAdapters().setSelectedIndex(0);
+
+        BindingBuilder builder = new BindingBuilder(
+                getApplication().getBindingFactory(),
+                this);
+
+        sqlBinding = builder.bindToTextArea(view.getSql(), "textForSQL");
+        adapterBinding = builder.bindToComboSelection(
+                view.getAdapters(),
+                "connectionInfo.dbAdapter",
+                "refreshSQLAction()",
+                "org.apache.cayenne.dba.JdbcAdapter");
+
+        optionBindings = new ObjectBinding[5];
+        optionBindings[0] = builder.bindToStateChangeAndAction(
+                view.getCreateFK(),
+                "generatorDefaults.createFK",
+                "refreshSQLAction()");
+        optionBindings[1] = builder.bindToStateChangeAndAction(
+                view.getCreatePK(),
+                "generatorDefaults.createPK",
+                "refreshSQLAction()");
+        optionBindings[2] = builder.bindToStateChangeAndAction(
+                view.getCreateTables(),
+                "generatorDefaults.createTables",
+                "refreshSQLAction()");
+        optionBindings[3] = builder.bindToStateChangeAndAction(
+                view.getDropPK(),
+                "generatorDefaults.dropPK",
+                "refreshSQLAction()");
+        optionBindings[4] = builder.bindToStateChangeAndAction(
+                view.getDropTables(),
+                "generatorDefaults.dropTables",
+                "refreshSQLAction()");
+
+        builder.bindToAction(view.getGenerateButton(), "generateSchemaAction()");
+        builder.bindToAction(view.getSaveSqlButton(), "storeSQLAction()");
+        builder.bindToAction(view.getCancelButton(), "closeAction()");
+
+        // refresh SQL if different tables were selected
+        view.getTabs().addChangeListener(new ChangeListener() {
+
+            public void stateChanged(ChangeEvent e) {
+                if (view.getTabs().getSelectedIndex() == 0) {
+                    // this assumes that some tables where checked/unchecked... not very
+                    // efficient
+                    refreshGeneratorAction();
+                }
+            }
+        });
+    }
+
+    /**
+     * Creates new internal DbGenerator instance.
+     */
+    protected void prepareGenerator() {
+        try {
+            DbAdapter adapter = connectionInfo.makeAdapter(getApplication()
+                    .getClassLoadingService());
+            generators = new ArrayList<>();
+            for (DataMap dataMap : dataMaps) {
+                this.generators.add(new DbGenerator(
+                        adapter,
+                        dataMap,
+                        tables.getExcludedTables(),
+                        null,
+                        NoopJdbcEventLogger.getInstance()));
+            }
+        } catch (Exception ex) {
+            reportError("Error loading adapter", ex);
+        }
+    }
+
+    /**
+     * Returns SQL statements generated for selected schema generation options.
+     */
+    protected void createSQL() {
+        // convert them to string representation for display
+        StringBuilder buf = new StringBuilder();
+        for (DbGenerator generator : generators) {
+            Iterator<String> it = generator.configuredStatements().iterator();
+            String batchTerminator = generator.getAdapter().getBatchTerminator();
+
+            String lineEnd = (batchTerminator != null)
+                    ? "\n" + batchTerminator + "\n\n"
+                    : "\n\n";
+
+            while (it.hasNext()) {
+                buf.append(it.next()).append(lineEnd);
+            }
+        }
+
+        textForSQL = buf.toString();
+    }
+
+    protected void refreshView() {
+        getView().setEnabled(connectionInfo != null);
+
+        for (ObjectBinding optionBinding : optionBindings) {
+            optionBinding.updateView();
+        }
+
+        sqlBinding.updateView();
+    }
+
+    // ===============
+    // Actions
+    // ===============
+
+    /**
+     * Starts options dialog.
+     */
+    public void startupAction() {
+        view.pack();
+        view.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+        view.setModal(true);
+        makeCloseableOnEscape();
+        centerView();
+        view.setVisible(true);
+    }
+
+    public void refreshGeneratorAction() {
+        prepareGenerator();
+        refreshSQLAction();
+    }
+
+    /**
+     * Updates a text area showing generated SQL.
+     */
+    public void refreshSQLAction() {
+        // sync generator with defaults, make SQL, then sync the view...
+        adapterBinding.updateView();
+        connectionInfo.setDbAdapter((String) view.getAdapters().getSelectedItem());
+        prepareGenerator();
+        generatorDefaults.configureGenerator(generators);
+        createSQL();
+        sqlBinding.updateView();
+    }
+
+    /**
+     * Performs configured schema operations via DbGenerator.
+     */
+    public void generateSchemaAction() {
+
+        DataSourceWizard connectWizard = new DataSourceWizard(
+                this.getParent(),
+                "Generate DB Schema: Connect to Database");
+        if (!connectWizard.startupAction()) {
+            return;
+        }
+
+        this.connectionInfo = connectWizard.getConnectionInfo();
+
+        refreshGeneratorAction();
+
+        Collection<ValidationResult> failures = new ArrayList<ValidationResult>();
+
+        // sanity check...
+        for (DbGenerator generator : generators) {
+            if (generator.isEmpty(true)) {
+                JOptionPane.showMessageDialog(getView(), "Nothing to generate.");
+                return;
+            }
+
+            try {
+                generator.runGenerator(connectWizard.getDataSource());
+                failures.add(generator.getFailures());
+            } catch (Throwable th) {
+                reportError("Schema Generation Error", th);
+            }
+        }
+
+        if (failures.size() == 0) {
+            JOptionPane.showMessageDialog(getView(), "Schema Generation Complete.");
+        } else {
+            new ValidationResultBrowser(this)
+                    .startupAction(
+                            "Schema Generation Complete",
+                            "Schema generation finished. The following problem(s) were ignored.",
+                            failures);
+        }
+    }
+
+    /**
+     * Allows user to save generated SQL in a file.
+     */
+    public void storeSQLAction() {
+        JFileChooser fc = new JFileChooser();
+        fc.setDialogType(JFileChooser.SAVE_DIALOG);
+        fc.setDialogTitle("Save SQL Script");
+
+        File projectDir = new File(getApplication()
+                .getProject()
+                .getConfigurationResource()
+                .getURL()
+                .getPath());
+        fc.setCurrentDirectory(projectDir);
+        if (fc.showSaveDialog(getView()) == JFileChooser.APPROVE_OPTION) {
+            refreshGeneratorAction();
+            try {
+                File file = fc.getSelectedFile();
+                FileWriter fw = new FileWriter(file);
+                PrintWriter pw = new PrintWriter(fw);
+                pw.print(textForSQL);
+                pw.flush();
+                pw.close();
+            } catch (IOException ex) {
+                reportError("Error Saving SQL", ex);
+            }
+        }
+    }
+
+    public void closeAction() {
+        view.dispose();
+    }
+
+    public DBConnectionInfo getConnectionInfo() {
+        return this.connectionInfo;
+    }
+
+    public void setConnectionInfo(DBConnectionInfo connectionInfo) {
+        this.connectionInfo = connectionInfo;
+        refreshView();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7da0e897/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptionsView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptionsView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptionsView.java
new file mode 100644
index 0000000..724d3f1
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/gen/DBGeneratorOptionsView.java
@@ -0,0 +1,178 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.modeler.dialog.db.gen;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.GridLayout;
+
+import javax.swing.Box;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTextArea;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.SwingConstants;
+
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+/**
+ * Wizard for generating the database from the data map.
+ */
+public class DBGeneratorOptionsView extends JDialog {
+
+    protected JTextArea sql;
+    protected JButton generateButton;
+    protected JButton cancelButton;
+    protected JButton saveSqlButton;
+    protected JCheckBox dropTables;
+    protected JCheckBox createTables;
+    protected JCheckBox createFK;
+    protected JCheckBox createPK;
+    protected JCheckBox dropPK;
+    protected Component tables;
+    protected JTabbedPane tabs;
+    protected JComboBox<String> adapters;
+
+    public DBGeneratorOptionsView(Component tables) {
+        // create widgets
+        this.generateButton = new JButton("Generate");
+        this.cancelButton = new JButton("Close");
+        this.saveSqlButton = new JButton("Save SQL");
+        this.dropTables = new JCheckBox("Drop Tables");
+        this.createTables = new JCheckBox("Create Tables");
+        this.createFK = new JCheckBox("Create FK Support");
+        this.createPK = new JCheckBox("Create Primary Key Support");
+        this.dropPK = new JCheckBox("Drop Primary Key Support");
+        this.tables = tables;
+        this.tabs = new JTabbedPane(SwingConstants.TOP);
+        this.adapters = new JComboBox<>();
+        adapters.setEditable(true);
+        this.sql = new JTextArea();
+        sql.setEditable(false);
+        sql.setLineWrap(true);
+        sql.setWrapStyleWord(true);
+
+        // assemble...
+        JPanel optionsPane = new JPanel(new GridLayout(3, 2));
+        optionsPane.add(dropTables);
+        optionsPane.add(createTables);
+        optionsPane.add(new JLabel());
+        optionsPane.add(createFK);
+        optionsPane.add(dropPK);
+        optionsPane.add(createPK);
+
+        JPanel sqlTextPanel = new JPanel(new BorderLayout());
+        sqlTextPanel.add(new JScrollPane(
+                sql,
+                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
+        
+        JPanel adapterPanel = new JPanel(new BorderLayout());
+        adapterPanel.add(adapters);
+
+        CellConstraints cc = new CellConstraints();
+        PanelBuilder builder = new PanelBuilder(new FormLayout(
+                "fill:min(50dlu;pref):grow",
+                "p, 3dlu, p, 9dlu, p, 3dlu, p, 3dlu, p, 3dlu, fill:40dlu:grow"));
+        builder.setDefaultDialogBorder();
+        builder.addSeparator("Options", cc.xywh(1, 1, 1, 1));
+        builder.add(optionsPane, cc.xy(1, 3, "left,fill"));
+        builder.addSeparator("Adapter", cc.xywh(1, 5, 1, 1));
+        builder.add(adapterPanel, cc.xy(1, 7));
+        builder.addSeparator("Generated SQL", cc.xywh(1, 9, 1, 1));
+        builder.add(sqlTextPanel, cc.xy(1, 11));
+
+        tabs.addTab("SQL Options", builder.getPanel());
+        tabs.addTab("Tables", new JScrollPane(
+                tables,
+                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
+
+        // we need the right preferred size so that dialog "pack()" produces decent
+        // default size...
+        tabs.setPreferredSize(new Dimension(450, 500));
+
+        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+        buttons.add(saveSqlButton);
+        buttons.add(Box.createHorizontalStrut(20));
+        buttons.add(cancelButton);
+        buttons.add(generateButton);
+
+        Container contentPane = this.getContentPane();
+        contentPane.setLayout(new BorderLayout());
+        contentPane.add(tabs, BorderLayout.CENTER);
+        contentPane.add(buttons, BorderLayout.SOUTH);
+    }
+
+    public JButton getCancelButton() {
+        return cancelButton;
+    }
+
+    public JTabbedPane getTabs() {
+        return tabs;
+    }
+
+    public JCheckBox getCreateFK() {
+        return createFK;
+    }
+
+    public JCheckBox getCreatePK() {
+        return createPK;
+    }
+
+    public JCheckBox getCreateTables() {
+        return createTables;
+    }
+
+    public JCheckBox getDropPK() {
+        return dropPK;
+    }
+
+    public JCheckBox getDropTables() {
+        return dropTables;
+    }
+
+    public JButton getGenerateButton() {
+        return generateButton;
+    }
+
+    public JButton getSaveSqlButton() {
+        return saveSqlButton;
+    }
+
+    public JTextArea getSql() {
+        return sql;
+    }
+    
+    public JComboBox<String> getAdapters() {
+        return adapters;
+    }
+}


Mime
View raw message