cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] branch master updated: CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen tab
Date Tue, 19 May 2020 11:46:20 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new b1b7113  CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen
tab
b1b7113 is described below

commit b1b7113ed6eb053c49a0f6bd9fc456528c423049
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Tue May 19 14:45:13 2020 +0300

    CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen tab
---
 RELEASE-NOTES.txt                                  |   1 +
 .../org/apache/cayenne/gen/CgenConfiguration.java  |  26 ++--
 .../editor/cgen/CodeGeneratorController.java       | 152 +++++++++------------
 .../modeler/editor/cgen/CustomModeController.java  |  25 +---
 .../editor/cgen/GeneratorTabController.java        |   2 +-
 .../editor/cgen/StandardModeController.java        |   6 -
 6 files changed, 84 insertions(+), 128 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 0f019d0..932d086 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -18,6 +18,7 @@ CAY-2656 Modeler: option to download required jars directly from maven central
 
 Bug Fixes:
 
+CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen tab
 
 ----------------------------------
 Release: 4.2.M1
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
index aa0b44c..1912b95 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
@@ -430,18 +430,18 @@ public class CgenConfiguration implements Serializable, XMLSerializable
{
     public boolean isDefault() {
         // this must be is sync with actual default values
         return isMakePairs()
-                && isUsePkgPath()
-                && !isOverwrite()
-                && !isCreatePKProperties()
-                && !isCreatePropertyNames()
-                && getOutputPattern().equals("*.java")
-                && (getTemplate().equals(ClassGenerationAction.SUBCLASS_TEMPLATE)
-                    || getTemplate().equals(ClientClassGenerationAction.SUBCLASS_TEMPLATE))
-                && (getSuperTemplate().equals(ClassGenerationAction.SUPERCLASS_TEMPLATE)
-                    || getSuperTemplate().equals(ClientClassGenerationAction.SUPERCLASS_TEMPLATE))
-                && (getSuperPkg() == null
-                    || getSuperPkg().isEmpty())
-                && (getExternalToolConfig() == null
-                    || getExternalToolConfig().isEmpty());
+                && usePkgPath
+                && !overwrite
+                && !createPKProperties
+                && !createPropertyNames
+                && "*.java".equals(outputPattern)
+                && (template.equals(ClassGenerationAction.SUBCLASS_TEMPLATE)
+                    || template.equals(ClientClassGenerationAction.SUBCLASS_TEMPLATE))
+                && (superTemplate.equals(ClassGenerationAction.SUPERCLASS_TEMPLATE)
+                    || superTemplate.equals(ClientClassGenerationAction.SUPERCLASS_TEMPLATE))
+                && (superPkg == null
+                    || superPkg.isEmpty())
+                && (externalToolConfig == null
+                    || externalToolConfig.isEmpty());
     }
 }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
index 5af12dc..db214db 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
@@ -68,21 +68,17 @@ import org.slf4j.LoggerFactory;
 public class CodeGeneratorController extends CayenneController implements ObjEntityListener,
EmbeddableListener, DataMapListener {
     private static final Logger LOGGER = LoggerFactory.getLogger(ErrorDebugDialog.class);
 
-    public static final String SELECTED_PROPERTY = "selected";
-
-    protected ProjectController projectController;
-
-    protected List<Object> classes;
-    protected SelectionModel selectionModel;
-    protected Object currentClass;
-
-    protected boolean initFromModel;
-
-    protected CodeGeneratorPane view;
-
-    protected ClassesTabController classesSelector;
-    protected GeneratorTabController generatorSelector;
-    private ConcurrentMap<DataMap, GeneratorController> prevGeneratorController;
+    protected final ProjectController projectController;
+    protected final List<Object> classes;
+    protected final SelectionModel selectionModel;
+    protected final CodeGeneratorPane view;
+    protected final ClassesTabController classesSelector;
+    protected final GeneratorTabController generatorSelector;
+    protected final ConcurrentMap<DataMap, GeneratorController> prevGeneratorController;
+
+    private Object currentClass;
+    private CgenConfiguration cgenConfiguration;
+    private boolean initFromModel;
 
     public CodeGeneratorController(ProjectController projectController) {
         super(projectController);
@@ -99,17 +95,21 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
 
     public void initFromModel() {
         initFromModel = true;
-        prepareClasses(projectController.getCurrentDataMap());
         DataMap dataMap = projectController.getCurrentDataMap();
-        classesSelectedAction();
-        CgenConfiguration cgenConfiguration = createConfiguration();
-        GeneratorController modeController = prevGeneratorController.get(dataMap) != null
-                        ? prevGeneratorController.get(dataMap)
-                        : isDefaultConfig(cgenConfiguration)
-                            ? cgenConfiguration != null && cgenConfiguration.isClient()
-                                ? generatorSelector.getClientGeneratorController()
-                                : generatorSelector.getStandartController()
-                            : generatorSelector.getCustomModeController();
+
+        prepareClasses(dataMap);
+        createConfiguration(dataMap);
+
+        GeneratorController modeController = prevGeneratorController.get(dataMap);
+        if(modeController == null) {
+            if(cgenConfiguration.isDefault()) {
+                modeController = cgenConfiguration.isClient()
+                        ? generatorSelector.getClientGeneratorController()
+                        : generatorSelector.getStandartController();
+            } else {
+                modeController = generatorSelector.getCustomModeController();
+            }
+        }
 
         prevGeneratorController.put(dataMap, modeController);
         generatorSelector.setSelectedController(modeController);
@@ -118,10 +118,6 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         classesSelector.validate(classes);
     }
 
-    private boolean isDefaultConfig(CgenConfiguration cgenConfiguration) {
-        return cgenConfiguration == null || cgenConfiguration.isDefault();
-    }
-
     private void initListeners(){
         projectController.addObjEntityListener(this);
         projectController.addEmbeddableListener(this);
@@ -137,7 +133,6 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(),
this);
 
         builder.bindToAction(view.getGenerateButton(), "generateAction()");
-        builder.bindToAction(this, "classesSelectedAction()", SELECTED_PROPERTY);
         builder.bindToAction(generatorSelector, "generatorSelectedAction()",
                 GeneratorTabController.GENERATOR_PROPERTY);
 
@@ -167,14 +162,8 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         classesSelector.classSelectedAction();
     }
 
-    public void classesSelectedAction() {
-        if(!isInitFromModel()) {
-            getProjectController().setDirty(true);
-        }
-    }
-
+    @SuppressWarnings("unused")
     public void generateAction() {
-        CgenConfiguration cgenConfiguration = createConfiguration();
         List<Module> modules = new ModuleLoader()
                 .load(CayenneToolsModuleProvider.class);
         modules.add(binder -> binder.bind(DataChannelMetaData.class)
@@ -217,16 +206,15 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
     /**
      * Creates a class generator for provided selections.
      */
-    public CgenConfiguration createConfiguration() {
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
+    public void createConfiguration(DataMap map) {
+        cgenConfiguration = projectController.getApplication().getMetaData().get(map, CgenConfiguration.class);
         if(cgenConfiguration != null){
             addToSelectedEntities(cgenConfiguration.getEntities());
             addToSelectedEmbeddables(cgenConfiguration.getEmbeddables());
             cgenConfiguration.setForce(true);
-            return cgenConfiguration;
+            return;
         }
 
-        DataMap map = projectController.getCurrentDataMap();
         cgenConfiguration = new CgenConfiguration(false);
         cgenConfiguration.setForce(true);
         cgenConfiguration.setDataMap(map);
@@ -240,13 +228,13 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
                 Files.createDirectories(basePath);
             } catch (IOException e) {
                 JOptionPane.showMessageDialog(getView(), "Can't create directory. Select
a different one.");
-                return null;
+                return;
             }
         }
         // not a directory
         if (!Files.isDirectory(basePath)) {
             JOptionPane.showMessageDialog(this.getView(), basePath + " is not a valid directory.");
-            return null;
+            return;
         }
 
         cgenConfiguration.setRootPath(basePath);
@@ -263,11 +251,6 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
                 .stream()
                 .map(Embeddable::getClassName)
                 .collect(Collectors.toList()));
-
-        getApplication().getMetaData().add(map, cgenConfiguration);
-        projectController.setDirty(true);
-
-        return cgenConfiguration;
     }
 
     public List<Object> getClasses() {
@@ -284,20 +267,16 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
             }
         }
 
-        if (modified) {
-            firePropertyChange(SELECTED_PROPERTY, null, null);
-        }
-
         return modified;
     }
 
     private void updateArtifactGenerationMode(boolean selected) {
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
         if(selected) {
             cgenConfiguration.setArtifactsGenerationMode("all");
         } else {
             cgenConfiguration.setArtifactsGenerationMode("entity");
         }
+        checkCgenConfigDirty();
     }
 
     public boolean isSelected() {
@@ -308,13 +287,7 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         if (currentClass instanceof DataMap) {
             updateArtifactGenerationMode(selectedFlag);
         }
-        if (selectionModel.setSelected(currentClass, selectedFlag)) {
-            firePropertyChange(SELECTED_PROPERTY, null, null);
-        }
-    }
-
-    public Object getCurrentClass() {
-        return currentClass;
+        selectionModel.setSelected(currentClass, selectedFlag);
     }
 
     public void setCurrentClass(Object currentClass) {
@@ -326,29 +299,38 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         updateEmbeddables();
     }
 
-    CgenConfiguration getCurrentConfiguration() {
-        DataMap map = getProjectController().getCurrentDataMap();
-        return projectController.getApplication().getMetaData().get(map, CgenConfiguration.class);
+    public void checkCgenConfigDirty() {
+        if(initFromModel || cgenConfiguration == null) {
+            return;
+        }
+
+        DataMap map = projectController.getCurrentDataMap();
+        CgenConfiguration existingConfig = projectController.getApplication().getMetaData().get(map,
CgenConfiguration.class);
+        if(existingConfig == null) {
+            getApplication().getMetaData().add(map, cgenConfiguration);
+        }
+
+        projectController.setDirty(true);
     }
 
     private void updateEntities() {
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
         if(cgenConfiguration != null) {
             cgenConfiguration.getEntities().clear();
             for(ObjEntity entity: selectionModel.getSelectedEntities(classes)) {
                 cgenConfiguration.loadEntity(entity);
             }
         }
+        checkCgenConfigDirty();
     }
 
     private void updateEmbeddables() {
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
         if(cgenConfiguration != null) {
             cgenConfiguration.getEmbeddables().clear();
             for(Embeddable embeddable : selectionModel.getSelectedEmbeddables(classes)) {
                 cgenConfiguration.loadEmbeddable(embeddable.getClassName());
             }
         }
+        checkCgenConfigDirty();
     }
 
     private void addToSelectedEntities(Collection<String> entities) {
@@ -359,10 +341,8 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
     void addEntity(DataMap dataMap, ObjEntity objEntity) {
         prepareClasses(dataMap);
         selectionModel.addSelectedEntity(objEntity.getName());
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
-        if(cgenConfiguration != null) {
-            cgenConfiguration.loadEntity(objEntity);
-        }
+        cgenConfiguration.loadEntity(objEntity);
+        checkCgenConfigDirty();
     }
 
     private void addToSelectedEmbeddables(Collection<String> embeddables) {
@@ -370,7 +350,6 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         updateEmbeddables();
     }
 
-
     public int getSelectedEntitiesSize() {
         return selectionModel.getSelectedEntitiesCount();
     }
@@ -406,11 +385,8 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
     @Override
     public void objEntityRemoved(EntityEvent e) {
         selectionModel.removeFromSelectedEntities((ObjEntity) e.getEntity());
-        DataMap map = e.getEntity().getDataMap();
-        CgenConfiguration cgenConfiguration = projectController.getApplication().getMetaData().get(map,
CgenConfiguration.class);
-        if(cgenConfiguration != null) {
-            cgenConfiguration.getEntities().remove(e.getEntity().getName());
-        }
+        cgenConfiguration.getEntities().remove(e.getEntity().getName());
+        checkCgenConfigDirty();
     }
 
     @Override
@@ -421,32 +397,26 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
         prepareClasses(map);
         String embeddableClassName = e.getEmbeddable().getClassName();
         selectionModel.addSelectedEmbeddable(embeddableClassName);
-        CgenConfiguration cgenConfiguration = getCurrentConfiguration();
-        if(cgenConfiguration != null) {
-            cgenConfiguration.loadEmbeddable(embeddableClassName);
-        }
+        cgenConfiguration.loadEmbeddable(embeddableClassName);
+        checkCgenConfigDirty();
     }
 
     @Override
     public void embeddableRemoved(EmbeddableEvent e, DataMap map) {
         selectionModel.removeFromSelectedEmbeddables(e.getEmbeddable());
-        CgenConfiguration cgenConfiguration = projectController.getApplication().getMetaData().get(map,
CgenConfiguration.class);
-        if(cgenConfiguration != null) {
-            cgenConfiguration.getEmbeddables().remove(e.getEmbeddable().getClassName());
-        }
+        cgenConfiguration.getEmbeddables().remove(e.getEmbeddable().getClassName());
+        checkCgenConfigDirty();
     }
 
     @Override
     public void dataMapChanged(DataMapEvent e) {
         if(e.getSource() instanceof DbImportController) {
-            CgenConfiguration cgenConfiguration = getCurrentConfiguration();
-            if(cgenConfiguration != null) {
-                for(ObjEntity objEntity : e.getDataMap().getObjEntities()) {
-                    if(!cgenConfiguration.getExcludeEntityArtifacts().contains(objEntity.getName()))
{
-                        addEntity(cgenConfiguration.getDataMap(), objEntity);
-                    }
+            for(ObjEntity objEntity : e.getDataMap().getObjEntities()) {
+                if(!cgenConfiguration.getExcludeEntityArtifacts().contains(objEntity.getName()))
{
+                    addEntity(cgenConfiguration.getDataMap(), objEntity);
                 }
             }
+            checkCgenConfigDirty();
         }
     }
 
@@ -455,4 +425,8 @@ public class CodeGeneratorController extends CayenneController implements
ObjEnt
 
     @Override
     public void dataMapRemoved(DataMapEvent e) {}
+
+    public CgenConfiguration getCgenConfiguration() {
+        return cgenConfiguration;
+    }
 }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
index 6d5be73..d051015 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
@@ -139,37 +139,27 @@ public class CustomModeController extends GeneratorController {
                 cgenConfiguration.setQueryTemplate(ClassGenerationAction.DATAMAP_SUBCLASS_TEMPLATE);
             }
             initForm(cgenConfiguration);
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
 
         view.getOverwrite().addActionListener(val -> {
             cgenConfiguration.setOverwrite(view.getOverwrite().isSelected());
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
 
         view.getCreatePropertyNames().addActionListener(val -> {
             cgenConfiguration.setCreatePropertyNames(view.getCreatePropertyNames().isSelected());
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
 
         view.getUsePackagePath().addActionListener(val -> {
             cgenConfiguration.setUsePkgPath(view.getUsePackagePath().isSelected());
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
 
         view.getPkProperties().addActionListener(val -> {
             cgenConfiguration.setCreatePKProperties(view.getPkProperties().isSelected());
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
 
         view.getClientMode().addActionListener(val -> {
@@ -195,9 +185,7 @@ public class CustomModeController extends GeneratorController {
                     cgenConfiguration.getRootPath());
             view.getSubclassTemplate().setItem(templateName);
             view.getSuperclassTemplate().setItem(superTemplateName);
-            if(!getParentController().isInitFromModel()) {
-                getParentController().getProjectController().setDirty(true);
-            }
+            getParentController().checkCgenConfigDirty();
         });
     }
 
@@ -213,7 +201,6 @@ public class CustomModeController extends GeneratorController {
         view.getPkProperties().setSelected(cgenConfiguration.isCreatePKProperties());
         view.getSuperPkg().setText(cgenConfiguration.getSuperPkg());
         updateComboBoxes();
-        getParentController().setInitFromModel(false);
     }
 
     @Override
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabController.java
index d7a6121..259cb2c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabController.java
@@ -78,7 +78,7 @@ public class GeneratorTabController extends CayenneController {
         view.getGenerationMode().addActionListener(action -> {
             String name = (String)view.getGenerationMode().getSelectedItem();
             GeneratorController modeController = getGeneratorController();
-            CgenConfiguration cgenConfiguration = getParentController().createConfiguration();
+            CgenConfiguration cgenConfiguration = getParentController().getCgenConfiguration();
             modeController.updateConfiguration(cgenConfiguration);
             controllers.get(name).initForm(cgenConfiguration);
             getParentController().getPrevGeneratorController().put(cgenConfiguration.getDataMap(),
modeController);
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
index 90368ab..b3156ed 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
@@ -44,12 +44,6 @@ public class StandardModeController extends GeneratorController {
     }
 
     @Override
-    protected void initForm(CgenConfiguration cgenConfiguration) {
-        super.initForm(cgenConfiguration);
-        getParentController().setInitFromModel(false);
-    }
-
-    @Override
     public void updateConfiguration(CgenConfiguration cgenConfiguration) {
         cgenConfiguration.setClient(false);
         cgenConfiguration.setTemplate(ClassGenerationAction.SUBCLASS_TEMPLATE);


Mime
View raw message