From b80007cd557c44907a35b05d838373b62acb75e0 Mon Sep 17 00:00:00 2001 From: kkomyak Date: Mon, 9 Apr 2018 17:30:50 +0300 Subject: [PATCH 1/2] CAY-2292 Change configuration process order - made connection configuration start before DB generator window open. --- .../dialog/db/gen/DBGeneratorOptions.java | 59 +++++++++++++------ 1 file changed, 42 insertions(+), 17 deletions(-) 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 index 441aba71cd..58cf5f1a91 100644 --- 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 @@ -34,13 +34,14 @@ import org.apache.cayenne.swing.ObjectBinding; import org.apache.cayenne.validation.ValidationResult; +import javax.sql.DataSource; 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.awt.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -63,10 +64,12 @@ public class DBGeneratorOptions extends CayenneController { protected DBGeneratorDefaults generatorDefaults; protected Collection generators; protected String textForSQL; + protected DataSource dataSource; + protected boolean configured = true; protected TableSelectorController tables; - public DBGeneratorOptions(ProjectController parent, String title, Collection dataMaps) { + public DBGeneratorOptions(final ProjectController parent, final String title, final Collection dataMaps) { super(parent); this.dataMaps = dataMaps; @@ -78,9 +81,17 @@ public DBGeneratorOptions(ProjectController parent, String title, Collection adapterModel = new DefaultComboBoxModel<>( + final DefaultComboBoxModel adapterModel = new DefaultComboBoxModel<>( DbAdapterInfo.getStandardAdapters()); view.getAdapters().setModel(adapterModel); - view.getAdapters().setSelectedIndex(0); + adapterModel.setSelectedItem(connectionInfo.getDbAdapter()); - BindingBuilder builder = new BindingBuilder( + final BindingBuilder builder = new BindingBuilder( getApplication().getBindingFactory(), this); @@ -218,6 +229,9 @@ protected void refreshView() { * Starts options dialog. */ public void startupAction() { + if (!configured) { + return; + } view.pack(); view.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); view.setModal(true); @@ -249,15 +263,6 @@ public void refreshSQLAction() { */ 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 failures = new ArrayList(); @@ -270,7 +275,7 @@ public void generateSchemaAction() { } try { - generator.runGenerator(connectWizard.getDataSource()); + generator.runGenerator(dataSource); failures.add(generator.getFailures()); } catch (Throwable th) { reportError("Schema Generation Error", th); @@ -329,4 +334,24 @@ public void setConnectionInfo(DBConnectionInfo connectionInfo) { this.connectionInfo = connectionInfo; refreshView(); } + + public boolean isConfigured() { + return configured; + } + + private DataSourceWizard configureDataSource() { + final DataSourceWizard connectWizard = new DataSourceWizard( + this.getParent(), + "Generate DB Schema: Connect to Database"); + if (!(this.getParent() instanceof ProjectController)) { + return null; + } + + connectWizard.setProjectController((ProjectController) this.getParent()); + if (!connectWizard.startupAction()) { + return null; + + } + return connectWizard; + } } From fda2b66921c10ea19c7d8a4609fe58409146965e Mon Sep 17 00:00:00 2001 From: kkomyak Date: Tue, 10 Apr 2018 10:42:38 +0300 Subject: [PATCH 2/2] CAY-2292 Disable Generate Database action if datamap not exist. --- .../org/apache/cayenne/modeler/action/DefaultActionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DefaultActionManager.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DefaultActionManager.java index c476fff29d..2880802a3e 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DefaultActionManager.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DefaultActionManager.java @@ -193,7 +193,6 @@ private void initActions() { ReverseEngineeringAction.class.getName(), ImportEOModelAction.class.getName(), GenerateCodeAction.class.getName(), - GenerateDBAction.class.getName(), PasteAction.class.getName(), ReverseEngineeringToolMenuAction.class.getName())); @@ -210,6 +209,7 @@ private void initActions() { CreateQueryAction.class.getName(), CreateProcedureAction.class.getName(), MigrateAction.class.getName(), + GenerateDBAction.class.getName(), RemoveAction.class.getName(), InferRelationshipsAction.class.getName(), CutAction.class.getName(),