Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAY-2292 #286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,10 +64,12 @@ public class DBGeneratorOptions extends CayenneController {
protected DBGeneratorDefaults generatorDefaults;
protected Collection<DbGenerator> generators;
protected String textForSQL;
protected DataSource dataSource;
protected boolean configured = true;

protected TableSelectorController tables;

public DBGeneratorOptions(ProjectController parent, String title, Collection<DataMap> dataMaps) {
public DBGeneratorOptions(final ProjectController parent, final String title, final Collection<DataMap> dataMaps) {
super(parent);

this.dataMaps = dataMaps;
Expand All @@ -78,9 +81,17 @@ public DBGeneratorOptions(ProjectController parent, String title, Collection<Dat
.node("DbGenerator"));

this.view.setTitle(title);
initController();
connectionInfo.setDbAdapter((String) view.getAdapters().getSelectedItem());

final DataSourceWizard dataSourceWizard = configureDataSource();
if (dataSourceWizard == null) {
configured = false;
return;
}

this.connectionInfo = dataSourceWizard.getConnectionInfo();
this.dataSource = dataSourceWizard.getDataSource();

initController();
tables.updateTables(dataMaps);
prepareGenerator();
generatorDefaults.configureGenerator(generators);
Expand All @@ -102,12 +113,12 @@ public String getTextForSQL() {

protected void initController() {

DefaultComboBoxModel<String> adapterModel = new DefaultComboBoxModel<>(
final DefaultComboBoxModel<String> 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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<ValidationResult> failures = new ArrayList<ValidationResult>();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}