This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new a500e56  CAY-2580 Cgen: Can't use custom templates for client mode
a500e56 is described below

commit a500e564c53349097a93fd9cb4c39d8362c51d46
Author: Arseni Bulatski <ancars...@gmail.com>
AuthorDate: Wed Jun 12 14:09:08 2019 +0300

    CAY-2580 Cgen: Can't use custom templates for client mode
    
    (cherry picked from commit d0df378a18440349555a565432810077a411eb82)
---
 RELEASE-NOTES.txt                                  |  1 +
 .../apache/cayenne/tools/CayenneGeneratorTask.java | 14 +++----
 .../org/apache/cayenne/gen/CgenConfiguration.java  | 35 +++++++++++-----
 .../apache/cayenne/gen/ClassGenerationAction.java  | 21 +++++-----
 .../cayenne/gen/ClientClassGenerationAction.java   | 18 ++++----
 .../apache/cayenne/gen/xml/CgenConfigHandler.java  |  2 +-
 .../cayenne/gen/ClassGenerationActionTest.java     | 27 ++++++------
 .../java/org/apache/cayenne/tools/CgenTask.java    | 11 ++---
 .../apache/cayenne/tools/CayenneGeneratorMojo.java | 14 +++----
 .../cayenne/modeler/CodeTemplateManager.java       | 39 +++++++++++------
 .../editor/cgen/CodeGeneratorController.java       | 36 ++++++++--------
 .../editor/cgen/CodeGeneratorControllerBase.java   | 34 +++++++--------
 .../modeler/editor/cgen/CustomModeController.java  | 49 ++++++++++++++++++----
 .../modeler/editor/cgen/CustomModePanel.java       |  9 ++++
 .../editor/cgen/domain/CgenTabController.java      |  7 ++--
 15 files changed, 194 insertions(+), 123 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 2f397d4..4e8935c 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -16,6 +16,7 @@ Bug Fixes:
 
 CAY-2553 Wrong disjoint prefetch query qualifier
 CAY-2573 DI field injection is triggered when creating sql Driver
+CAY-2580 Cgen: Can't use custom templates for client mode
 CAY-2582 Double insert of manyToMany relationship mapped to Set
 CAY-2584 Crypto: can't use ColumnSelect with encrypted columns
 
diff --git 
a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java 
b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
index f8b43d5..cd8920b 100644
--- 
a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
+++ 
b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
+import java.io.File;
+
 import foundrylogic.vpp.VPPConfig;
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
@@ -35,8 +37,6 @@ import org.apache.tools.ant.types.Path;
 import org.apache.velocity.VelocityContext;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-
 /**
  * An Ant task to perform class generation based on CayenneDataMap.
  * 
@@ -144,8 +144,9 @@ public class CayenneGeneratorTask extends CayenneTask {
 
     private ClassGenerationAction createGenerator(DataMap dataMap) {
         CgenConfiguration cgenConfiguration = buildConfiguration(dataMap);
-        ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
+        ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new ClientClassGenerationAction() :
+                new ClassGenerationAction();
+        classGenerationAction.setCgenConfiguration(cgenConfiguration);
         injector.injectMembers(classGenerationAction);
 
         return classGenerationAction;
@@ -170,14 +171,14 @@ public class CayenneGeneratorTask extends CayenneTask {
             return cgenConfiguration;
         } else {
             logger.info("Using default cgen config.");
-            cgenConfiguration = new CgenConfiguration();
+            cgenConfiguration = new CgenConfiguration(false);
             cgenConfiguration.setDataMap(dataMap);
             return cgenConfiguration;
         }
     }
 
     private CgenConfiguration cgenConfigFromPom(DataMap dataMap){
-        CgenConfiguration cgenConfiguration = new CgenConfiguration();
+        CgenConfiguration cgenConfiguration = new CgenConfiguration(client != 
null ? client : false);
         cgenConfiguration.setDataMap(dataMap);
         cgenConfiguration.setRelPath(destDir != null ? destDir.toPath() : 
cgenConfiguration.getRelPath());
         cgenConfiguration.setEncoding(encoding != null ? encoding : 
cgenConfiguration.getEncoding());
@@ -198,7 +199,6 @@ public class CayenneGeneratorTask extends CayenneTask {
         cgenConfiguration.setQueryTemplate(querytemplate != null ? 
querytemplate : cgenConfiguration.getQueryTemplate());
         cgenConfiguration.setQuerySuperTemplate(querysupertemplate != null ? 
querysupertemplate : cgenConfiguration.getQuerySuperTemplate());
         cgenConfiguration.setCreatePKProperties(createpkproperties != null ? 
createpkproperties : cgenConfiguration.isCreatePKProperties());
-        cgenConfiguration.setClient(client != null ? client : 
cgenConfiguration.isClient());
         if(!cgenConfiguration.isMakePairs()) {
             if(template == null) {
                 cgenConfiguration.setTemplate(cgenConfiguration.isClient() ? 
ClientClassGenerationAction.SINGLE_CLASS_TEMPLATE : 
ClassGenerationAction.SINGLE_CLASS_TEMPLATE);
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 e03598e..6a6f262 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
@@ -19,6 +19,16 @@
 
 package org.apache.cayenne.gen;
 
+import java.io.Serializable;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
 import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.gen.xml.CgenExtension;
 import org.apache.cayenne.map.DataMap;
@@ -27,12 +37,6 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.util.XMLEncoder;
 import org.apache.cayenne.util.XMLSerializable;
 
-import java.io.Serializable;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.stream.Collectors;
-
 /**
  * Used to keep config of class generation action.
  * Previously was the part of ClassGeneretionAction class.
@@ -77,7 +81,7 @@ public class CgenConfiguration implements Serializable, 
XMLSerializable {
 
     private boolean client;
 
-    public CgenConfiguration() {
+    public CgenConfiguration(boolean client) {
         this.outputPattern = "*.java";
         this.timestamp = 0L;
         this.usePkgPath = true;
@@ -91,12 +95,21 @@ public class CgenConfiguration implements Serializable, 
XMLSerializable {
         this.excludeEmbeddableArtifacts = new ArrayList<>();
         this.artifactsGenerationMode = ArtifactsGenerationMode.ENTITY;
 
-        this.template = ClassGenerationAction.SUBCLASS_TEMPLATE;
-        this.superTemplate = ClassGenerationAction.SUPERCLASS_TEMPLATE;
+        this.client = client;
+
+        if(!client) {
+            this.template = ClassGenerationAction.SUBCLASS_TEMPLATE;
+            this.superTemplate = ClassGenerationAction.SUPERCLASS_TEMPLATE;
+            this.queryTemplate = 
ClassGenerationAction.DATAMAP_SUBCLASS_TEMPLATE;
+            this.querySuperTemplate = 
ClassGenerationAction.DATAMAP_SUPERCLASS_TEMPLATE;
+        } else {
+            this.template = ClientClassGenerationAction.SUBCLASS_TEMPLATE;
+            this.superTemplate = 
ClientClassGenerationAction.SUPERCLASS_TEMPLATE;
+            this.queryTemplate = 
ClientClassGenerationAction.DMAP_SUBCLASS_TEMPLATE;
+            this.querySuperTemplate = 
ClientClassGenerationAction.DMAP_SUPERCLASS_TEMPLATE;
+        }
         this.embeddableTemplate = 
ClassGenerationAction.EMBEDDABLE_SUBCLASS_TEMPLATE;
         this.embeddableSuperTemplate = 
ClassGenerationAction.EMBEDDABLE_SUPERCLASS_TEMPLATE;
-        this.queryTemplate = ClassGenerationAction.DATAMAP_SUBCLASS_TEMPLATE;
-        this.querySuperTemplate = 
ClassGenerationAction.DATAMAP_SUPERCLASS_TEMPLATE;
     }
 
     public void resetCollections(){
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index 52611e9..c0cfd32 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -19,15 +19,6 @@
 
 package org.apache.cayenne.gen;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.map.Embeddable;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.QueryDescriptor;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.slf4j.Logger;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -42,6 +33,15 @@ import java.util.Objects;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.slf4j.Logger;
+
 public class ClassGenerationAction {
 
        private static final String TEMPLATES_DIR_NAME = "templates/v4_1/";
@@ -71,10 +71,9 @@ public class ClassGenerationAction {
     protected VelocityContext context;
     protected Map<String, Template> templateCache;
 
-       public ClassGenerationAction(CgenConfiguration cgenConfiguration) {
+       public ClassGenerationAction() {
                this.context = new VelocityContext();
                this.templateCache = new HashMap<>(5);
-               this.cgenConfiguration = cgenConfiguration;
        }
 
        public String defaultTemplateName(TemplateType type) {
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
index b823c85..0559f69 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
@@ -19,12 +19,12 @@
 
 package org.apache.cayenne.gen;
 
+import java.util.Collection;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.QueryDescriptor;
 
-import java.util.Collection;
-
 /**
  * @since 3.0
  */
@@ -41,12 +41,8 @@ public class ClientClassGenerationAction extends 
ClassGenerationAction {
 
     public static final String CLIENT_SUPERCLASS_PREFIX = "_Client";
 
-    public ClientClassGenerationAction(CgenConfiguration cgenConfiguration) {
-        super(cgenConfiguration);
-        cgenConfiguration.setTemplate(SUBCLASS_TEMPLATE);
-        cgenConfiguration.setSuperTemplate(SUPERCLASS_TEMPLATE);
-        cgenConfiguration.setQueryTemplate(DMAP_SUBCLASS_TEMPLATE);
-        cgenConfiguration.setQuerySuperTemplate(DMAP_SUPERCLASS_TEMPLATE);
+    public ClientClassGenerationAction() {
+        super();
     }
 
     @Override
@@ -103,4 +99,10 @@ public class ClientClassGenerationAction extends 
ClassGenerationAction {
             }
         }
     }
+
+    public void setCgenConfiguration(CgenConfiguration cgenConfiguration) {
+        super.setCgenConfiguration(cgenConfiguration);
+        cgenConfiguration.setQueryTemplate(DMAP_SUBCLASS_TEMPLATE);
+        cgenConfiguration.setQuerySuperTemplate(DMAP_SUPERCLASS_TEMPLATE);
+    }
 }
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
index 612ffb4..4d2f8e4 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
@@ -61,7 +61,7 @@ public class CgenConfigHandler extends 
NamespaceAwareNestedTagHandler{
         super(parentHandler);
         this.metaData = metaData;
         this.targetNamespace = CgenExtension.NAMESPACE;
-        this.configuration = new CgenConfiguration();
+        this.configuration = new CgenConfiguration(false);
     }
 
     @Override
diff --git 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
index 89dfaaa..f46e2d3 100644
--- 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
+++ 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
@@ -19,6 +19,13 @@
 
 package org.apache.cayenne.gen;
 
+import java.io.File;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.cayenne.map.CallbackDescriptor;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjAttribute;
@@ -29,13 +36,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.File;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -51,10 +51,10 @@ public class ClassGenerationActionTest {
        protected CgenConfiguration cgenConfiguration;
 
        @Before
-       public void setUp() throws Exception {
+       public void setUp() {
                writers = new ArrayList<>(3);
-               cgenConfiguration = new CgenConfiguration();
-               action = new ClassGenerationAction(cgenConfiguration) {
+               cgenConfiguration = new CgenConfiguration(false);
+               action = new ClassGenerationAction() {
 
                        @Override
                        protected Writer openWriter(TemplateType templateType) 
throws Exception {
@@ -63,6 +63,7 @@ public class ClassGenerationActionTest {
                                return writer;
                        }
                };
+               action.setCgenConfiguration(cgenConfiguration);
        }
 
        @After
@@ -216,16 +217,16 @@ public class ClassGenerationActionTest {
 
                if (isClient) {
 
-                       action = new 
ClientClassGenerationAction(cgenConfiguration) {
+                       action = new ClientClassGenerationAction() {
                                @Override
-                               protected Writer openWriter(TemplateType 
templateType) throws Exception {
+                               protected Writer openWriter(TemplateType 
templateType) {
                                        StringWriter writer = new 
StringWriter();
                                        writers.add(writer);
                                        return writer;
                                }
 
                        };
-
+                       action.setCgenConfiguration(cgenConfiguration);
                }
 
                cgenConfiguration.setMakePairs(true);
diff --git 
a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java 
b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
index 234030f..41bd141 100644
--- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
+++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
@@ -206,8 +206,10 @@ public class CgenTask extends BaseCayenneTask {
 
     ClassGenerationAction createGenerator(DataMap dataMap) {
         CgenConfiguration cgenConfiguration = buildConfiguration(dataMap);
-        return cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
+        ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new ClientClassGenerationAction() :
+                new ClassGenerationAction();
+        classGenerationAction.setCgenConfiguration(cgenConfiguration);
+        return classGenerationAction;
     }
 
     CgenConfiguration buildConfiguration(DataMap dataMap) {
@@ -222,7 +224,7 @@ public class CgenTask extends BaseCayenneTask {
             return cgenConfiguration;
         } else {
             getLogger().info("Using default cgen config.");
-            cgenConfiguration = new CgenConfiguration();
+            cgenConfiguration = new CgenConfiguration(false);
             cgenConfiguration.setRelPath(getDestDirFile().getPath());
             cgenConfiguration.setDataMap(dataMap);
             return cgenConfiguration;
@@ -230,7 +232,7 @@ public class CgenTask extends BaseCayenneTask {
     }
 
     private CgenConfiguration cgenConfigFromPom(DataMap dataMap){
-        CgenConfiguration cgenConfiguration = new CgenConfiguration();
+        CgenConfiguration cgenConfiguration = new CgenConfiguration(client != 
null ? client : false);
         cgenConfiguration.setDataMap(dataMap);
         cgenConfiguration.setRelPath(getDestDirFile() != null ? 
getDestDirFile().toPath() : cgenConfiguration.getRelPath());
         cgenConfiguration.setEncoding(encoding != null ? encoding : 
cgenConfiguration.getEncoding());
@@ -251,7 +253,6 @@ public class CgenTask extends BaseCayenneTask {
         cgenConfiguration.setQueryTemplate(queryTemplate != null ? 
queryTemplate : cgenConfiguration.getQueryTemplate());
         cgenConfiguration.setQuerySuperTemplate(querySuperTemplate != null ? 
querySuperTemplate : cgenConfiguration.getQuerySuperTemplate());
         cgenConfiguration.setCreatePKProperties(createPKProperties != null ? 
createPKProperties : cgenConfiguration.isCreatePKProperties());
-        cgenConfiguration.setClient(client != null ? client : 
cgenConfiguration.isClient());
         if(!cgenConfiguration.isMakePairs()) {
             if(template == null) {
                 cgenConfiguration.setTemplate(cgenConfiguration.isClient() ? 
ClientClassGenerationAction.SINGLE_CLASS_TEMPLATE : 
ClassGenerationAction.SINGLE_CLASS_TEMPLATE);
diff --git 
a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
 
b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
index 74f92ce..f472c7e 100644
--- 
a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
+++ 
b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.tools;
 
+import java.io.File;
+
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
 import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
@@ -39,8 +41,6 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-
 /**
  * Maven mojo to perform class generation from data cgenConfiguration. This 
class is an Maven
  * adapter to DefaultClassGenerator class.
@@ -305,8 +305,9 @@ public class CayenneGeneratorMojo extends AbstractMojo {
         */
        private ClassGenerationAction createGenerator(DataMap dataMap) {
                CgenConfiguration cgenConfiguration = 
buildConfiguration(dataMap);
-               ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                               new ClassGenerationAction(cgenConfiguration);
+               ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new ClientClassGenerationAction() :
+                               new ClassGenerationAction();
+               classGenerationAction.setCgenConfiguration(cgenConfiguration);
                injector.injectMembers(classGenerationAction);
 
                return classGenerationAction;
@@ -323,7 +324,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
                        return cgenConfiguration;
                } else {
                        logger.info("Using default cgen config.");
-                       cgenConfiguration = new CgenConfiguration();
+                       cgenConfiguration = new CgenConfiguration(false);
                        cgenConfiguration.setDataMap(dataMap);
                        cgenConfiguration.setRelPath(defaultDir.getPath());
                        return cgenConfiguration;
@@ -331,7 +332,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
        }
 
        private CgenConfiguration cgenConfigFromPom(DataMap dataMap){
-               CgenConfiguration cgenConfiguration = new CgenConfiguration();
+               CgenConfiguration cgenConfiguration = new 
CgenConfiguration(client != null ? client : false);
                cgenConfiguration.setDataMap(dataMap);
                cgenConfiguration.setRelPath(destDir != null ? 
destDir.getPath() : defaultDir.getPath());
                cgenConfiguration.setEncoding(encoding != null ? encoding : 
cgenConfiguration.getEncoding());
@@ -352,7 +353,6 @@ public class CayenneGeneratorMojo extends AbstractMojo {
                cgenConfiguration.setQueryTemplate(queryTemplate != null ? 
queryTemplate : cgenConfiguration.getQueryTemplate());
                cgenConfiguration.setQuerySuperTemplate(querySuperTemplate != 
null ? querySuperTemplate : cgenConfiguration.getQuerySuperTemplate());
                cgenConfiguration.setCreatePKProperties(createPKProperties != 
null ? createPKProperties : cgenConfiguration.isCreatePKProperties());
-               cgenConfiguration.setClient(client != null ? client : 
cgenConfiguration.isClient());
                if(!cgenConfiguration.isMakePairs()) {
                        if(template == null) {
                                
cgenConfiguration.setTemplate(cgenConfiguration.isClient() ? 
ClientClassGenerationAction.SINGLE_CLASS_TEMPLATE : 
ClassGenerationAction.SINGLE_CLASS_TEMPLATE);
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
index 76dd2b2..4f8f786 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
@@ -19,13 +19,6 @@
 
 package org.apache.cayenne.modeler;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
-import org.apache.cayenne.gen.ClientClassGenerationAction;
-import org.apache.cayenne.modeler.pref.FSPath;
-import org.apache.cayenne.resource.Resource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -35,6 +28,13 @@ import java.util.Map;
 import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.modeler.pref.FSPath;
+import org.apache.cayenne.resource.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Manages code generation templates.
  */
@@ -58,6 +58,8 @@ public class CodeTemplateManager {
 
        private List<String> standardSubclassTemplates;
        private List<String> standardSuperclassTemplates;
+       private List<String> standardClientSubclassTemplates;
+       private List<String> standardClientSuperclassTemplates;
        private Map<String, String> customTemplates;
        private Map<String, String> reverseCustomTemplate;
        private Map<String, String> standardTemplates;
@@ -77,15 +79,18 @@ public class CodeTemplateManager {
        }
 
        public CodeTemplateManager(Application application) {
-               standardSuperclassTemplates = new ArrayList<>(3);
-
+               standardSuperclassTemplates = new ArrayList<>(2);
                standardSuperclassTemplates.add(STANDARD_SERVER_SUPERCLASS);
-               standardSuperclassTemplates.add(STANDARD_CLIENT_SUPERCLASS);
 
-               standardSubclassTemplates = new ArrayList<>(3);
-               standardSubclassTemplates.add(STANDARD_SERVER_SUBCLASS);
-               standardSubclassTemplates.add(STANDARD_CLIENT_SUBCLASS);
+               standardClientSuperclassTemplates = new ArrayList<>();
+               
standardClientSuperclassTemplates.add(STANDARD_CLIENT_SUPERCLASS);
+
+               standardSubclassTemplates = new ArrayList<>(2);
                standardSubclassTemplates.add(SINGLE_SERVER_CLASS);
+               standardSubclassTemplates.add(STANDARD_SERVER_SUBCLASS);
+
+               standardClientSubclassTemplates = new ArrayList<>();
+               standardClientSubclassTemplates.add(STANDARD_CLIENT_SUBCLASS);
 
                standartEmbeddableTemplates = new ArrayList<>();
                standartEmbeddableTemplates.add(SINGLE_EMBEDDABLE_CLASS);
@@ -190,10 +195,18 @@ public class CodeTemplateManager {
                return standardSubclassTemplates;
        }
 
+       public List<String> getStandardClientSubclassTemplates() {
+               return standardClientSubclassTemplates;
+       }
+
        public List<String> getStandardSuperclassTemplates() {
                return standardSuperclassTemplates;
        }
 
+       public List<String> getStandardClientSuperclassTemplates() {
+               return standardClientSuperclassTemplates;
+       }
+
        public List<String> getStandartEmbeddableTemplates() {
                return standartEmbeddableTemplates;
        }
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 c93fbc4..9a81cb6 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
@@ -19,8 +19,8 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import javax.swing.JOptionPane;
-import java.awt.Component;
+import javax.swing.*;
+import java.awt.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.function.Predicate;
@@ -44,12 +44,6 @@ import org.apache.cayenne.swing.BindingBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.swing.JOptionPane;
-import java.awt.Component;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.function.Predicate;
-
 /**
  * @since 4.1
  * A controller for the class generator dialog.
@@ -80,9 +74,12 @@ public class CodeGeneratorController extends 
CodeGeneratorControllerBase impleme
         super.startup(dataMap);
         classesSelectedAction();
         CgenConfiguration cgenConfiguration = createConfiguration();
-        GeneratorController modeController = 
prevGeneratorController.get(dataMap) != null ? 
prevGeneratorController.get(dataMap) : cgenConfiguration.isClient() ?
-                generatorSelector.getClientGeneratorController() : 
isDefaultConfig(cgenConfiguration) ?
-                generatorSelector.getStandartController() : 
generatorSelector.getCustomModeController();
+        GeneratorController modeController = 
prevGeneratorController.get(dataMap) != null ?
+                prevGeneratorController.get(dataMap) : 
isDefaultConfig(cgenConfiguration) ?
+                cgenConfiguration.isClient() ? 
generatorSelector.getClientGeneratorController() :
+                        generatorSelector.getStandartController() :
+                generatorSelector.getCustomModeController();
+
         prevGeneratorController.put(dataMap, modeController);
         generatorSelector.setSelectedController(modeController);
         classesSelector.startup();
@@ -91,11 +88,13 @@ public class CodeGeneratorController extends 
CodeGeneratorControllerBase impleme
     }
 
     private boolean isDefaultConfig(CgenConfiguration cgenConfiguration) {
-        return cgenConfiguration.isMakePairs() && 
cgenConfiguration.isUsePkgPath() && !cgenConfiguration.isOverwrite() &&
-                !cgenConfiguration.isCreatePKProperties() && 
!cgenConfiguration.isCreatePropertyNames() &&
-                cgenConfiguration.getOutputPattern().equals("*.java") &&
-                
cgenConfiguration.getTemplate().equals(ClassGenerationAction.SUBCLASS_TEMPLATE) 
&&
-                
cgenConfiguration.getSuperTemplate().equals(ClassGenerationAction.SUPERCLASS_TEMPLATE)
 &&
+        return cgenConfiguration.isMakePairs() && 
cgenConfiguration.isUsePkgPath() &&
+                !cgenConfiguration.isOverwrite() && 
!cgenConfiguration.isCreatePKProperties() &&
+                !cgenConfiguration.isCreatePropertyNames() && 
cgenConfiguration.getOutputPattern().equals("*.java") &&
+                
(cgenConfiguration.getTemplate().equals(ClassGenerationAction.SUBCLASS_TEMPLATE)
 ||
+                        
cgenConfiguration.getTemplate().equals(ClientClassGenerationAction.SUBCLASS_TEMPLATE))
 &&
+                
(cgenConfiguration.getSuperTemplate().equals(ClassGenerationAction.SUPERCLASS_TEMPLATE)
 ||
+                        
cgenConfiguration.getSuperTemplate().equals(ClientClassGenerationAction.SUPERCLASS_TEMPLATE))
 &&
                 (cgenConfiguration.getSuperPkg() == null || 
cgenConfiguration.getSuperPkg().isEmpty());
 
     }
@@ -145,8 +144,9 @@ public class CodeGeneratorController extends 
CodeGeneratorControllerBase impleme
     public void generateAction() {
         CgenConfiguration cgenConfiguration = createConfiguration();
         ClassGenerationAction generator = cgenConfiguration.isClient() ?
-                new ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
+                new ClientClassGenerationAction() :
+                new ClassGenerationAction();
+        generator.setCgenConfiguration(cgenConfiguration);
 
         try {
             generator.prepareArtifacts();
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorControllerBase.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorControllerBase.java
index ec99134..f96972a 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorControllerBase.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorControllerBase.java
@@ -19,23 +19,8 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.CgenConfiguration;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.Embeddable;
-import org.apache.cayenne.map.Entity;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
-import org.apache.cayenne.modeler.util.CayenneController;
-import org.apache.cayenne.modeler.util.CellRenderers;
-import org.apache.cayenne.modeler.util.ModelerUtil;
-import org.apache.cayenne.validation.ValidationFailure;
-import org.apache.cayenne.validation.ValidationResult;
-
-import javax.swing.Icon;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import java.awt.Component;
+import javax.swing.*;
+import java.awt.*;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -51,6 +36,19 @@ import java.util.function.Predicate;
 import java.util.prefs.Preferences;
 import java.util.stream.Collectors;
 
+import org.apache.cayenne.gen.CgenConfiguration;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
+import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.modeler.util.CellRenderers;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+import org.apache.cayenne.validation.ValidationFailure;
+import org.apache.cayenne.validation.ValidationResult;
+
 /**
  * @since 4.1
  * A base superclass of a top controller for the code generator. Defines all 
common model
@@ -121,7 +119,7 @@ public abstract class CodeGeneratorControllerBase extends 
CayenneController {
         }
 
         try {
-            cgenConfiguration = new CgenConfiguration();
+            cgenConfiguration = new CgenConfiguration(false);
             cgenConfiguration.setForce(true);
             cgenConfiguration.setDataMap(map);
 
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 f1a8a65..497783b 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
@@ -19,8 +19,8 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import javax.swing.DefaultComboBoxModel;
-import java.awt.Component;
+import javax.swing.*;
+import java.awt.*;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -28,6 +28,7 @@ import java.util.List;
 
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.modeler.CodeTemplateManager;
 import org.apache.cayenne.modeler.dialog.cgen.TemplateDialog;
 import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
@@ -57,20 +58,24 @@ public class CustomModeController extends 
GeneratorController {
         BindingBuilder builder = new 
BindingBuilder(getApplication().getBindingFactory(), this);
         builder.bindToAction(view.getManageTemplatesLink(), 
"popPreferencesAction()");
 
-        updateTemplates();
     }
 
     protected void updateTemplates() {
+        boolean isClient = cgenConfiguration.isClient();
         CodeTemplateManager templateManager = 
getApplication().getCodeTemplateManager();
 
         List<String> customTemplates = new 
ArrayList<>(templateManager.getCustomTemplates().keySet());
         Collections.sort(customTemplates);
 
-        List<String> superTemplates = new 
ArrayList<>(templateManager.getStandardSuperclassTemplates());
+        List<String> superTemplates = isClient ?
+                new 
ArrayList<>(templateManager.getStandardClientSuperclassTemplates()) :
+                new 
ArrayList<>(templateManager.getStandardSuperclassTemplates());
         Collections.sort(superTemplates);
         superTemplates.addAll(customTemplates);
 
-        List<String> subTemplates = new 
ArrayList<>(templateManager.getStandardSubclassTemplates());
+        List<String> subTemplates = isClient ?
+                new 
ArrayList<>(templateManager.getStandardClientSubclassTemplates()) :
+                new 
ArrayList<>(templateManager.getStandardSubclassTemplates());
         Collections.sort(subTemplates);
         subTemplates.addAll(customTemplates);
 
@@ -167,10 +172,40 @@ public class CustomModeController extends 
GeneratorController {
                 getParentController().getProjectController().setDirty(true);
             }
         });
+
+        view.getClientMode().addActionListener(val -> {
+            boolean isSelected = view.getClientMode().isSelected();
+            cgenConfiguration.setClient(isSelected);
+            if(isSelected) {
+                
cgenConfiguration.setTemplate(ClientClassGenerationAction.SUBCLASS_TEMPLATE);
+                
cgenConfiguration.setSuperTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE);
+            } else {
+                
cgenConfiguration.setTemplate(ClassGenerationAction.SUBCLASS_TEMPLATE);
+                
cgenConfiguration.setSuperTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE);
+            }
+            updateTemplates();
+            String templateName = 
getApplication().getCodeTemplateManager().getNameByPath(
+                    isSelected ?
+                            ClientClassGenerationAction.SUBCLASS_TEMPLATE :
+                            ClassGenerationAction.SUBCLASS_TEMPLATE,
+                    cgenConfiguration.getRootPath());
+            String superTemplateName = 
getApplication().getCodeTemplateManager().getNameByPath(
+                    isSelected ?
+                            ClientClassGenerationAction.SUBCLASS_TEMPLATE :
+                            ClassGenerationAction.SUBCLASS_TEMPLATE,
+                    cgenConfiguration.getRootPath());
+            view.getSubclassTemplate().setItem(templateName);
+            view.getSuperclassTemplate().setItem(superTemplateName);
+            if(!getParentController().isInitFromModel()) {
+                getParentController().getProjectController().setDirty(true);
+            }
+        });
     }
 
     public void initForm(CgenConfiguration cgenConfiguration){
         super.initForm(cgenConfiguration);
+        view.getClientMode().setSelected(cgenConfiguration.isClient());
+        updateTemplates();
         view.getOutputPattern().setText(cgenConfiguration.getOutputPattern());
         view.getPairs().setSelected(cgenConfiguration.isMakePairs());
         view.getUsePackagePath().setSelected(cgenConfiguration.isUsePkgPath());
@@ -184,8 +219,6 @@ public class CustomModeController extends 
GeneratorController {
 
     @Override
     public void updateConfiguration(CgenConfiguration cgenConfiguration) {
-        cgenConfiguration.setClient(false);
-        cgenConfiguration.setTemplate(ClassGenerationAction.SUBCLASS_TEMPLATE);
-        
cgenConfiguration.setSuperTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE);
+        // Do nothing
     }
 }
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
index cb2cb25..bdba0fc 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
@@ -50,6 +50,7 @@ public class CustomModePanel extends GeneratorControllerPanel 
{
     private TextAdapter outputPattern;
     private JCheckBox createPropertyNames;
     private JCheckBox pkProperties;
+    private JCheckBox clientMode;
     private TextAdapter superPkg;
 
     private JButton manageTemplatesLink;
@@ -109,6 +110,7 @@ public class CustomModePanel extends 
GeneratorControllerPanel {
 
         this.createPropertyNames = new JCayenneCheckBox();
         this.pkProperties = new JCayenneCheckBox();
+        this.clientMode= new JCayenneCheckBox();
         this.manageTemplatesLink = new JButton("Customize Templates...");
         
this.manageTemplatesLink.setFont(manageTemplatesLink.getFont().deriveFont(10f));
 
@@ -150,6 +152,9 @@ public class CustomModePanel extends 
GeneratorControllerPanel {
         builder.append("Create PK properties:", pkProperties);
         builder.nextLine();
 
+        builder.append("Client mode: ", clientMode);
+        builder.nextLine();
+
         builder.append("Superclass package:", superPkg.getComponent());
 
         setLayout(new BorderLayout());
@@ -198,6 +203,10 @@ public class CustomModePanel extends 
GeneratorControllerPanel {
         return pkProperties;
     }
 
+    public JCheckBox getClientMode() {
+        return clientMode;
+    }
+
     public TextAdapter getSuperPkg() {
         return superPkg;
     }
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
index 8abb583..ff4b53a 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
@@ -62,8 +62,9 @@ public class CgenTabController extends 
GeneratorsTabController {
                 if(cgenConfiguration == null) {
                     cgenConfiguration = createConfiguration(dataMap);
                 }
-                ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                        new ClassGenerationAction(cgenConfiguration);
+                ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new ClientClassGenerationAction() :
+                        new ClassGenerationAction();
+                classGenerationAction.setCgenConfiguration(cgenConfiguration);
                 classGenerationAction.prepareArtifacts();
                 classGenerationAction.execute();
             } catch (Exception e) {
@@ -78,7 +79,7 @@ public class CgenTabController extends 
GeneratorsTabController {
     }
 
     public CgenConfiguration createConfiguration(DataMap dataMap) {
-        CgenConfiguration cgenConfiguration = new CgenConfiguration();
+        CgenConfiguration cgenConfiguration = new CgenConfiguration(false);
         
Application.getInstance().getInjector().injectMembers(cgenConfiguration);
         cgenConfiguration.setDataMap(dataMap);
         Path basePath = Paths.get(ModelerUtil.initOutputFolder());

Reply via email to