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

abulatski 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 d0df378  CAY-2580 Cgen: Can't use custom templates for client mode
d0df378 is described below

commit d0df378a18440349555a565432810077a411eb82
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
---
 RELEASE-NOTES.txt                                  |  1 +
 .../apache/cayenne/tools/CayenneGeneratorTask.java |  5 +--
 .../org/apache/cayenne/gen/CgenConfiguration.java  | 35 +++++++++++-----
 .../cayenne/gen/ClientClassGenerationAction.java   |  2 -
 .../apache/cayenne/gen/xml/CgenConfigHandler.java  |  2 +-
 .../cayenne/gen/ClassGenerationActionTest.java     |  2 +-
 .../java/org/apache/cayenne/tools/CgenTask.java    |  5 +--
 .../apache/cayenne/tools/CayenneGeneratorMojo.java |  5 +--
 .../cayenne/modeler/CodeTemplateManager.java       | 39 +++++++++++------
 .../editor/cgen/CodeGeneratorController.java       | 22 ++++++----
 .../editor/cgen/CodeGeneratorControllerBase.java   | 34 +++++++--------
 .../modeler/editor/cgen/CustomModeController.java  | 49 ++++++++++++++++++----
 .../modeler/editor/cgen/CustomModePanel.java       |  9 ++++
 .../editor/cgen/domain/CgenTabController.java      |  2 +-
 14 files changed, 140 insertions(+), 72 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 38e5dd1..432f6cb 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -57,6 +57,7 @@ CAY-2575 Select translator: Wrong translation of IN Expression
 CAY-2576 Ant cgen task is broken
 CAY-2577 Between property with extended type failure
 CAY-2578 Wrong bindings in select of related entity by compound FK
+CAY-2580 Cgen: Can't use custom templates for client mode
 CAY-2582 Double insert of manyToMany relationship mapped to Set
 
 ----------------------------------
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 03c2605..d6411b0 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
@@ -172,14 +172,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());
@@ -200,7 +200,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 eea1b93..71055f0 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/ClientClassGenerationAction.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
index 10a1a21..9e3927b 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
@@ -102,8 +102,6 @@ public class ClientClassGenerationAction extends 
ClassGenerationAction {
 
     public void setCgenConfiguration(CgenConfiguration cgenConfiguration) {
         super.setCgenConfiguration(cgenConfiguration);
-        cgenConfiguration.setTemplate(SUBCLASS_TEMPLATE);
-        cgenConfiguration.setSuperTemplate(SUPERCLASS_TEMPLATE);
         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 fd6848d..d84dfb2 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 c7d285c..58a1489 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
@@ -53,7 +53,7 @@ public class ClassGenerationActionTest extends CgenCase {
        @Before
        public void setUp() throws Exception {
                writers = new ArrayList<>(3);
-               cgenConfiguration = new CgenConfiguration();
+               cgenConfiguration = new CgenConfiguration(false);
                action = new 
TestClassGenerationAction(getUnitTestInjector().getInstance(ClassGenerationActionFactory.class)
                                .createAction(cgenConfiguration), writers);
        }
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 4ee87b8..20bc8a6 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
@@ -224,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;
@@ -232,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());
@@ -253,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 b06ef46..84ddbdd 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
@@ -320,7 +320,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;
@@ -328,7 +328,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());
@@ -349,7 +349,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 b9a6a13..9b4b4f1 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 2156c0e..fe03397 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
@@ -32,6 +32,7 @@ import org.apache.cayenne.di.spi.ModuleLoader;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.gen.ClassGenerationActionFactory;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.event.EmbeddableEvent;
@@ -77,9 +78,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();
@@ -88,11 +92,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());
 
     }
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 832568a..59f973e 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 6e716c5..46f8f33 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 e7f811d..7bb7912 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 773080f..4fe28e0 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
@@ -84,7 +84,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