Skip to content

CAY-2649 Class generation only after saving #412

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

Open
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.cayenne.access.types.ExtendedTypeMap;
import org.apache.cayenne.dba.DbAdapter;
import org.apache.cayenne.dba.TypesMapping;
import org.apache.cayenne.dba.frontbase.FrontBaseAdapter;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DefaultScalarResultSegment;
Expand Down Expand Up @@ -188,6 +189,9 @@ protected void execute(Connection connection, OperationObserver callback, SQLSta
boolean iteratedResult = callback.isIteratedResult();
int generatedKeys = query.isReturnGeneratedKeys() ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS;
PreparedStatement statement = connection.prepareStatement(compiled.getSql(), generatedKeys);
if (statement == null && this.dbAdapter instanceof FrontBaseAdapter) {
statement = connection.prepareStatement(compiled.getSql());
}
try {
bind(statement, compiled.getBindings());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

import org.apache.cayenne.modeler.Application;
import org.apache.cayenne.modeler.ProjectController;
import org.apache.cayenne.modeler.action.SaveAction;
import org.apache.cayenne.modeler.editor.cgen.CodeGeneratorController;
import org.apache.cayenne.modeler.editor.cgen.CodeGeneratorPane;
import org.apache.cayenne.modeler.editor.cgen.domain.CgenTab;
import org.apache.cayenne.modeler.editor.dbimport.DbImportView;
import org.apache.cayenne.modeler.editor.dbimport.domain.DbImportTab;

import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import javax.swing.*;
import java.awt.*;

/**
* Data map editing tabs container
Expand All @@ -50,6 +53,11 @@ public DataMapTabbedView(ProjectController mediator) {
initView();
}

protected CodeGeneratorPane view;

public CodeGeneratorPane getView() {
return view;
}
/**
* create tabs
*/
Expand All @@ -71,7 +79,7 @@ private void initView() {

addChangeListener(tab -> {
if(isCgenTabActive()) {
codeGeneratorController.initFromModel();
checkProjectSave(mediator);
} else if(isDbImportTabActive()) {
dbImportView.initFromModel();
}
Expand All @@ -87,6 +95,31 @@ private void initView() {
});
}

private void checkProjectSave(ProjectController mediator) {
if (mediator.getProject().getConfigurationResource() == null) {
int input = JOptionPane.showConfirmDialog(getView(), "You should save", null, JOptionPane.OK_CANCEL_OPTION);
if (input == 0) {
Application.getInstance().getActionManager().getAction(SaveAction.class).performAction();
}
if (mediator.isDirty()) {
enableComponents(cgenView, false);
return;
}
}
enableComponents(cgenView, true);
codeGeneratorController.initFromModel();
}

public void enableComponents(Container container, boolean enable) {
Component[] components = container.getComponents();
for (Component component : components) {
component.setEnabled(enable);
if (component instanceof Container) {
enableComponents((Container)component, enable);
}
}
}

private boolean isCgenTabActive() {
return getSelectedComponent() == cgenView;
}
Expand Down