cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [14/32] cayenne git commit: Cgen tab, cgen configuration, cgen in maven, ant, gradle.
Date Wed, 14 Nov 2018 14:27:45 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModePanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModePanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModePanel.java
index cbb3f35..81bd599 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModePanel.java
@@ -1,42 +1,42 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.codegen;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
-import java.awt.BorderLayout;
-
-public class StandardModePanel extends GeneratorControllerPanel {
-
-    private DefaultFormBuilder builder;
-
-    public StandardModePanel() {
-        FormLayout layout = new FormLayout(
-                "right:77dlu, 1dlu, fill:100:grow, 1dlu, left:80dlu, 1dlu", "");
-
-        builder = new DefaultFormBuilder(layout);
-        builder.append("Output Directory:", outputFolder, selectOutputFolder);
-        builder.nextLine();
-
-        setLayout(new BorderLayout());
-        add(builder.getPanel(), BorderLayout.CENTER);
-    }
-}
\ No newline at end of file
+///*****************************************************************
+// *   Licensed to the Apache Software Foundation (ASF) under one
+// *  or more contributor license agreements.  See the NOTICE file
+// *  distributed with this work for additional information
+// *  regarding copyright ownership.  The ASF licenses this file
+// *  to you under the Apache License, Version 2.0 (the
+// *  "License"); you may not use this file except in compliance
+// *  with the License.  You may obtain a copy of the License at
+// *
+// *    http://www.apache.org/licenses/LICENSE-2.0
+// *
+// *  Unless required by applicable law or agreed to in writing,
+// *  software distributed under the License is distributed on an
+// *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// *  KIND, either express or implied.  See the License for the
+// *  specific language governing permissions and limitations
+// *  under the License.
+// ****************************************************************/
+//
+//package org.apache.cayenne.modeler.dialog.codegen;
+//
+//import com.jgoodies.forms.builder.DefaultFormBuilder;
+//import com.jgoodies.forms.layout.FormLayout;
+//
+//import java.awt.BorderLayout;
+//
+//public class StandardModePanel extends GeneratorControllerPanel {
+//
+//    private DefaultFormBuilder builder;
+//
+//    public StandardModePanel() {
+//        FormLayout layout = new FormLayout(
+//                "right:77dlu, 1dlu, fill:100:grow, 1dlu, left:80dlu, 1dlu", "");
+//
+//        builder = new DefaultFormBuilder(layout);
+//        builder.append("Output Directory:", outputFolder, selectOutputFolder);
+//        builder.nextLine();
+//
+//        setLayout(new BorderLayout());
+//        add(builder.getPanel(), BorderLayout.CENTER);
+//    }
+//}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardPanelComponent.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardPanelComponent.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardPanelComponent.java
index 425a0f2..c900728 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardPanelComponent.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardPanelComponent.java
@@ -1,81 +1,81 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.dialog.codegen;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.modeler.pref.DataMapDefaults;
-
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JTextField;
-import java.awt.BorderLayout;
-
-public class StandardPanelComponent extends JComponent {
-
-    private DataMap dataMap;
-    private DataMapDefaults preferences;
-    private JLabel dataMapName;
-    private JTextField superclassPackage;
-    private DefaultFormBuilder builder;
-
-    public StandardPanelComponent() {
-        super();
-        dataMapName = new JLabel();
-        dataMapName.setFont(dataMapName.getFont().deriveFont(1));
-        superclassPackage = new JTextField();
-
-        FormLayout layout = new FormLayout(
-                "right:77dlu, 3dlu, fill:200:grow, 3dlu", "");
-        builder = new DefaultFormBuilder(layout);
-        builder.append(dataMapName);
-        builder.nextLine();
-        builder.append("Superclass Package:", superclassPackage);
-
-        setLayout(new BorderLayout());
-        add(builder.getPanel(), BorderLayout.CENTER);
-    }
-
-    public DataMap getDataMap() {
-        return dataMap;
-    }
-
-    public void setDataMap(DataMap dataMap) {
-        this.dataMap = dataMap;
-    }
-
-    public DataMapDefaults getPreferences() {
-        return preferences;
-    }
-
-    public void setPreferences(DataMapDefaults preferences) {
-        this.preferences = preferences;
-    }
-
-    public JLabel getDataMapName() {
-        return dataMapName;
-    }
-
-    public JTextField getSuperclassPackage() {
-        return superclassPackage;
-    }
-
-}
\ No newline at end of file
+///*****************************************************************
+// *   Licensed to the Apache Software Foundation (ASF) under one
+// *  or more contributor license agreements.  See the NOTICE file
+// *  distributed with this work for additional information
+// *  regarding copyright ownership.  The ASF licenses this file
+// *  to you under the Apache License, Version 2.0 (the
+// *  "License"); you may not use this file except in compliance
+// *  with the License.  You may obtain a copy of the License at
+// *
+// *    http://www.apache.org/licenses/LICENSE-2.0
+// *
+// *  Unless required by applicable law or agreed to in writing,
+// *  software distributed under the License is distributed on an
+// *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// *  KIND, either express or implied.  See the License for the
+// *  specific language governing permissions and limitations
+// *  under the License.
+// ****************************************************************/
+//
+//package org.apache.cayenne.modeler.dialog.codegen;
+//
+//import com.jgoodies.forms.builder.DefaultFormBuilder;
+//import com.jgoodies.forms.layout.FormLayout;
+//import org.apache.cayenne.map.DataMap;
+//import org.apache.cayenne.modeler.pref.DataMapDefaults;
+//
+//import javax.swing.JComponent;
+//import javax.swing.JLabel;
+//import javax.swing.JTextField;
+//import java.awt.BorderLayout;
+//
+//public class StandardPanelComponent extends JComponent {
+//
+//    private DataMap dataMap;
+//    private DataMapDefaults preferences;
+//    private JLabel dataMapName;
+//    private JTextField superclassPackage;
+//    private DefaultFormBuilder builder;
+//
+//    public StandardPanelComponent() {
+//        super();
+//        dataMapName = new JLabel();
+//        dataMapName.setFont(dataMapName.getFont().deriveFont(1));
+//        superclassPackage = new JTextField();
+//
+//        FormLayout layout = new FormLayout(
+//                "right:77dlu, 3dlu, fill:200:grow, 3dlu", "");
+//        builder = new DefaultFormBuilder(layout);
+//        builder.append(dataMapName);
+//        builder.nextLine();
+//        builder.append("Superclass Package:", superclassPackage);
+//
+//        setLayout(new BorderLayout());
+//        add(builder.getPanel(), BorderLayout.CENTER);
+//    }
+//
+//    public DataMap getDataMap() {
+//        return dataMap;
+//    }
+//
+//    public void setDataMap(DataMap dataMap) {
+//        this.dataMap = dataMap;
+//    }
+//
+//    public DataMapDefaults getPreferences() {
+//        return preferences;
+//    }
+//
+//    public void setPreferences(DataMapDefaults preferences) {
+//        this.preferences = preferences;
+//    }
+//
+//    public JLabel getDataMapName() {
+//        return dataMapName;
+//    }
+//
+//    public JTextField getSuperclassPackage() {
+//        return superclassPackage;
+//    }
+//
+//}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
index be3a0e8..96a195e 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
@@ -1,84 +1,99 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.editor;
-
-import javax.swing.JScrollPane;
-import javax.swing.JTabbedPane;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.event.DomainDisplayEvent;
-import org.apache.cayenne.modeler.event.DomainDisplayListener;
-import org.apache.cayenne.modeler.event.EntityDisplayEvent;
-import org.apache.cayenne.modeler.graph.DataDomainGraphTab;
-
-/**
- * DataDomain editing tabs container 
- */
-public class DataDomainTabbedView extends JTabbedPane 
-    implements ChangeListener, DomainDisplayListener {
-    
-    ProjectController mediator;
-    
-    DataDomainGraphTab graphTab;
-
-    /**
-     * constructor
-     * @param mediator mediator instance
-     */
-    public DataDomainTabbedView(ProjectController mediator) {
-        this.mediator = mediator;
-
-        initView();
-    }
-
-    /**
-     * create tabs
-     */
-    private void initView() {
-      
-        setTabPlacement(JTabbedPane.TOP);
-
-        // add panels to tabs
-        // note that those panels that have no internal scrollable tables
-        // must be wrapped in a scroll pane
-        JScrollPane domainView = new JScrollPane(new DataDomainView(mediator));
-        addTab("Main", domainView);
-
-        graphTab = new DataDomainGraphTab(mediator);
-        addTab("Graph", graphTab);
-        
-        addChangeListener(this);
-        mediator.addDomainDisplayListener(this);
-    }
-
-    public void stateChanged(ChangeEvent e) {
-        if (getSelectedComponent() == graphTab) {
-            graphTab.refresh();
-        }
-    }
-
-    public void currentDomainChanged(DomainDisplayEvent e) {
-        if (e instanceof EntityDisplayEvent) {
-            //need select an entity
-            setSelectedComponent(graphTab);
-        }
-    }
-}
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.editor;
+
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.action.GenerateCodeAction;
+import org.apache.cayenne.modeler.editor.cgen.domain.CgenTabController;
+import org.apache.cayenne.modeler.event.DomainDisplayEvent;
+import org.apache.cayenne.modeler.event.DomainDisplayListener;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.graph.DataDomainGraphTab;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+/**
+ * DataDomain editing tabs container 
+ */
+public class DataDomainTabbedView extends JTabbedPane 
+    implements ChangeListener, DomainDisplayListener {
+    
+    ProjectController mediator;
+    
+    DataDomainGraphTab graphTab;
+    JScrollPane cgenView;
+    CgenTabController cgenTabController;
+
+    /**
+     * constructor
+     * @param mediator mediator instance
+     */
+    public DataDomainTabbedView(ProjectController mediator) {
+        this.mediator = mediator;
+
+        initView();
+    }
+
+    /**
+     * create tabs
+     */
+    private void initView() {
+      
+        setTabPlacement(JTabbedPane.TOP);
+
+        // add panels to tabs
+        // note that those panels that have no internal scrollable tables
+        // must be wrapped in a scroll pane
+        JScrollPane domainView = new JScrollPane(new DataDomainView(mediator));
+        addTab("Main", domainView);
+
+        graphTab = new DataDomainGraphTab(mediator);
+        addTab("Graph", graphTab);
+
+        addChangeListener(this);
+        mediator.addDomainDisplayListener(this);
+
+        cgenTabController = new CgenTabController(mediator);
+        cgenView = new JScrollPane(cgenTabController.getView());
+        addTab("Class Generation", cgenView);
+    }
+
+    public void stateChanged(ChangeEvent e) {
+        if (getSelectedComponent() == graphTab) {
+            graphTab.refresh();
+        } else if(getSelectedComponent() == cgenView) {
+            cgenTabController.getView().initView();
+        }
+    }
+
+    public void currentDomainChanged(DomainDisplayEvent e) {
+        if (e instanceof EntityDisplayEvent) {
+            //need select an entity
+            setSelectedComponent(graphTab);
+        }
+        if(getSelectedComponent() == cgenView) {
+            fireStateChanged();
+        }
+        if(e.getSource() instanceof GenerateCodeAction) {
+            setSelectedComponent(cgenView);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapTabbedView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapTabbedView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapTabbedView.java
index 388e087..76cf573 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapTabbedView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapTabbedView.java
@@ -21,6 +21,7 @@ package org.apache.cayenne.modeler.editor;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.editor.cgen.CodeGeneratorController;
+import org.apache.cayenne.modeler.editor.cgen.domain.CgenTab;
 import org.apache.cayenne.modeler.editor.dbimport.DbImportView;
 
 import javax.swing.*;
@@ -30,9 +31,11 @@ import javax.swing.*;
  * Data map editing tabs container
  *
  */
-public class DataMapTabbedView extends JTabbedPane {
+public class DataMapTabbedView extends JTabbedPane{
     ProjectController mediator;
     private CodeGeneratorController codeGeneratorController;
+    JScrollPane cgenView;
+
 
     /**
      * constructor
@@ -57,7 +60,7 @@ public class DataMapTabbedView extends JTabbedPane {
         JScrollPane dataMapView = new JScrollPane(new DataMapView(mediator));
         JScrollPane dbImportView = new JScrollPane(new DbImportView(mediator));
         this.codeGeneratorController = new CodeGeneratorController(Application.getInstance().getFrameController(), mediator);
-        JScrollPane cgenView = new JScrollPane(codeGeneratorController.getView());
+        cgenView = new JScrollPane(codeGeneratorController.getView());
         addTab("DataMap", dataMapView);
         addTab("DbImport", dbImportView);
         addTab("Class Generation", cgenView);
@@ -70,13 +73,14 @@ public class DataMapTabbedView extends JTabbedPane {
         mediator.addDataMapDisplayListener(e -> {
             if(isCgenTabActive()) {
                 fireStateChanged();
+            } else if(e.getSource() instanceof CgenTab){
+                setSelectedComponent(cgenView);
             }
         });
     }
 
     private boolean isCgenTabActive() {
-        return getSelectedIndex() == 2;
+        return getSelectedComponent() == cgenView;
     }
-
 }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/ClientModeController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/ClientModeController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/ClientModeController.java
index 9f217f0..87881f4 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/ClientModeController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/ClientModeController.java
@@ -19,8 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
-import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 
 public class ClientModeController extends StandardModeController {
 
@@ -34,7 +33,12 @@ public class ClientModeController extends StandardModeController {
     }
 
     @Override
-    protected ClassGenerationAction newGenerator() {
-        return new ClientClassGenerationAction();
+    public CgenConfiguration createConfiguration() {
+        return super.createConfiguration();
+    }
+
+    @Override
+    public void updateConfiguration(CgenConfiguration cgenConfiguration) {
+        cgenConfiguration.setClient(true);
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
----------------------------------------------------------------------
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 db6edb4..f4ab6bc 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,7 +19,9 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
@@ -31,6 +33,8 @@ import org.slf4j.LoggerFactory;
 import javax.swing.*;
 import java.awt.*;
 import java.util.Collections;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.function.Predicate;
 
 /**
@@ -46,12 +50,14 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase {
 
     protected ClassesTabController classesSelector;
     protected GeneratorTabController generatorSelector;
+    private ConcurrentMap<DataMap, GeneratorController> prevGeneratorController;
 
     public CodeGeneratorController(CayenneController parent, ProjectController projectController) {
         super(parent, projectController);
         this.classesSelector = new ClassesTabController(this);
         this.generatorSelector = new GeneratorTabController(this);
         view = new CodeGeneratorPane(generatorSelector.getView(), classesSelector.getView());
+        this.prevGeneratorController = new ConcurrentHashMap<>();
         initBindings();
         initListeners();
     }
@@ -59,10 +65,14 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase {
     public void startup(DataMap dataMap) {
         super.startup(dataMap);
         classesSelectedAction();
-        GeneratorController modeController = generatorSelector.getGeneratorController();
-        ClassGenerationAction classGenerationAction = modeController.createGenerator();
-        modeController.initForm(classGenerationAction);
+        GeneratorController modeController = prevGeneratorController.get(dataMap) != null ? prevGeneratorController.get(dataMap) : generatorSelector.getStandartController();
+        CgenConfiguration cgenConfiguration = modeController.createConfiguration();
+        if(cgenConfiguration.isClient()) {
+            modeController = generatorSelector.getClientGeneratorController();
+        }
         classesSelector.startup();
+        prevGeneratorController.put(dataMap, modeController);
+        generatorSelector.setSelectedController(modeController);
     }
 
     private void initListeners(){
@@ -141,21 +151,26 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase {
     }
 
     public void generateAction() {
-        ClassGenerationAction generator = generatorSelector.getGenerator();
-
-        if (generator != null) {
-            try {
-                generator.prepareArtifacts();
-                generator.execute();
-                JOptionPane.showMessageDialog(
-                        this.getView(),
-                        "Class generation finished");
-            } catch (Exception e) {
-                logObj.error("Error generating classes", e);
-                JOptionPane.showMessageDialog(
-                        this.getView(),
-                        "Error generating classes - " + e.getMessage());
-            }
+        CgenConfiguration cgenConfiguration = generatorSelector.getConfiguration();
+        ClassGenerationAction generator = cgenConfiguration.isClient() ?
+                new ClientClassGenerationAction(cgenConfiguration) :
+                new ClassGenerationAction(cgenConfiguration);
+
+        try {
+            generator.prepareArtifacts();
+            generator.execute();
+            JOptionPane.showMessageDialog(
+                    this.getView(),
+                    "Class generation finished");
+        } catch (Exception e) {
+            logObj.error("Error generating classes", e);
+            JOptionPane.showMessageDialog(
+                    this.getView(),
+                    "Error generating classes - " + e.getMessage());
         }
     }
+
+    public ConcurrentMap<DataMap, GeneratorController> getPrevGeneratorController() {
+        return prevGeneratorController;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorControllerBase.java
----------------------------------------------------------------------
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 e9c2965..35ba15e 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,7 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.map.ObjEntity;
@@ -67,11 +67,14 @@ public abstract class CodeGeneratorControllerBase extends CayenneController {
 
     public void startup(DataMap dataMap){
         this.dataMap = dataMap;
+        prepareClasses(dataMap);
+    }
+
+    private void prepareClasses(DataMap dataMap) {
         classes.clear();
         this.classes.add(dataMap);
         this.classes.addAll(dataMap.getObjEntities());
         this.classes.addAll(dataMap.getEmbeddables());
-
         initCollectionsForSelection(dataMap);
     }
 
@@ -277,11 +280,11 @@ public abstract class CodeGeneratorControllerBase extends CayenneController {
 
     private void updateArtifactGenerationMode(Object classObj, boolean selected) {
         DataMap dataMap = (DataMap) classObj;
-        ClassGenerationAction generator = projectController.getApplication().getMetaData().get(dataMap, ClassGenerationAction.class);
+        CgenConfiguration cgenConfiguration = projectController.getApplication().getMetaData().get(dataMap, CgenConfiguration.class);
         if(selected) {
-            generator.setArtifactsGenerationMode("all");
+            cgenConfiguration.setArtifactsGenerationMode("all");
         } else {
-            generator.setArtifactsGenerationMode("entity");
+            cgenConfiguration.setArtifactsGenerationMode("entity");
         }
     }
 
@@ -307,32 +310,30 @@ public abstract class CodeGeneratorControllerBase extends CayenneController {
 
     public void updateEntities(){
         DataMap map = getProjectController().getCurrentDataMap();
-        ClassGenerationAction generator = projectController.getApplication().getMetaData().get(map, ClassGenerationAction.class);
-        if(generator != null) {
-            generator.resetCollections();
+        CgenConfiguration cgenConfiguration = projectController.getApplication().getMetaData().get(map, CgenConfiguration.class);
+        if(cgenConfiguration != null) {
+            cgenConfiguration.resetCollections();
             for(ObjEntity entity: getSelectedEntities()) {
                 if(!entity.isGeneric()) {
-                    generator.loadEntity(entity.getName());
+                    cgenConfiguration.loadEntity(entity.getName());
                 }
             }
             for(Embeddable embeddable : getSelectedEmbeddables()) {
-                generator.loadEmbeddable(embeddable.getClassName());
+                cgenConfiguration.loadEmbeddable(embeddable.getClassName());
             }
         }
     }
 
-    public void addToSelectedEntities(DataMap dataMap, Collection<String> entities) {
-        if(selectedEntities == null) {
-            initCollectionsForSelection(dataMap);
-        }
+    void addToSelectedEntities(DataMap dataMap, Collection<String> entities) {
+        prepareClasses(dataMap);
         selectedEntities.addAll(entities);
+        updateEntities();
     }
 
-    public void addToSelectedEmbeddables(DataMap dataMap, Collection<String> embeddables) {
-        if(selectedEmbeddables == null) {
-            initCollectionsForSelection(dataMap);
-        }
+    void addToSelectedEmbeddables(DataMap dataMap, Collection<String> embeddables) {
+        prepareClasses(dataMap);
         selectedEmbeddables.addAll(embeddables);
+        updateEntities();
     }
 
     public int getSelectedEntitiesSize() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
----------------------------------------------------------------------
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 6a081a5..5626a38 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,6 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.CodeTemplateManager;
 import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
@@ -85,57 +86,70 @@ public class CustomModeController extends GeneratorController {
     }
 
     private void updateComboBoxes() {
-        view.getSubclassTemplate().setItem(getApplication().getCodeTemplateManager().getNameByPath(classGenerationAction.getTemplate()));
-        view.getSuperclassTemplate().setItem(getApplication().getCodeTemplateManager().getNameByPath(classGenerationAction.getSuperclassTemplate()));
+        view.getSubclassTemplate().setItem(getApplication().getCodeTemplateManager().getNameByPath(cgenConfiguration.getTemplate()));
+        view.getSuperclassTemplate().setItem(getApplication().getCodeTemplateManager().getNameByPath(cgenConfiguration.getSuperTemplate()));
         view.setDisableSuperComboBoxes(view.getPairs().isSelected());
     }
 
     @Override
-    protected ClassGenerationAction newGenerator() {
-        ClassGenerationAction action = new ClassGenerationAction();
-        getApplication().getInjector().injectMembers(action);
-        return action;
+    public CgenConfiguration createConfiguration() {
+        return super.createConfiguration();
     }
 
     private void initListeners(){
         view.getPairs().addActionListener(val -> {
-            classGenerationAction.setMakePairs(view.getPairs().isSelected());
+            cgenConfiguration.setMakePairs(view.getPairs().isSelected());
+            if(!view.getPairs().isSelected()) {
+                cgenConfiguration.setTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE);
+                cgenConfiguration.setEmbeddableTemplate(ClassGenerationAction.EMBEDDABLE_SINGLE_CLASS_TEMPLATE);
+                cgenConfiguration.setQueryTemplate(ClassGenerationAction.DATAMAP_SINGLE_CLASS_TEMPLATE);
+            } else {
+                cgenConfiguration.setTemplate(ClassGenerationAction.SUBCLASS_TEMPLATE);
+                cgenConfiguration.setEmbeddableTemplate(ClassGenerationAction.EMBEDDABLE_SUBCLASS_TEMPLATE);
+                cgenConfiguration.setQueryTemplate(ClassGenerationAction.DATAMAP_SUBCLASS_TEMPLATE);
+            }
+            initForm(cgenConfiguration);
             getParentController().getProjectController().setDirty(true);
         });
 
         view.getOverwrite().addActionListener(val -> {
-            classGenerationAction.setOverwrite(view.getOverwrite().isSelected());
+            cgenConfiguration.setOverwrite(view.getOverwrite().isSelected());
             getParentController().getProjectController().setDirty(true);
         });
 
         view.getCreatePropertyNames().addActionListener(val -> {
-            classGenerationAction.setCreatePropertyNames(view.getCreatePropertyNames().isSelected());
+            cgenConfiguration.setCreatePropertyNames(view.getCreatePropertyNames().isSelected());
             getParentController().getProjectController().setDirty(true);
         });
 
         view.getUsePackagePath().addActionListener(val -> {
-            classGenerationAction.setUsePkgPath(view.getUsePackagePath().isSelected());
+            cgenConfiguration.setUsePkgPath(view.getUsePackagePath().isSelected());
             getParentController().getProjectController().setDirty(true);
         });
 
         view.getPkProperties().addActionListener(val -> {
-            classGenerationAction.setCreatePKProperties(view.getPkProperties().isSelected());
+            cgenConfiguration.setCreatePKProperties(view.getPkProperties().isSelected());
             getParentController().getProjectController().setDirty(true);
         });
     }
 
-    public void initForm(ClassGenerationAction classGenerationAction){
-        super.initForm(classGenerationAction);
-        view.getOutputPattern().setText(classGenerationAction.getOutputPattern());
-        view.getPairs().setSelected(classGenerationAction.isMakePairs());
-        view.getUsePackagePath().setSelected(classGenerationAction.isUsePkgPath());
-        view.getOverwrite().setSelected(classGenerationAction.isOverwrite());
-        view.getCreatePropertyNames().setSelected(classGenerationAction.isCreatePropertyNames());
-        view.getPkProperties().setSelected(classGenerationAction.isCreatePKProperties());
-        if(classGenerationAction.getArtifactsGenerationMode().equalsIgnoreCase("all")) {
-            ((CodeGeneratorControllerBase)parent).setCurrentClass(classGenerationAction.getDataMap());
-            ((CodeGeneratorControllerBase)parent).setSelected(true);
+    public void initForm(CgenConfiguration cgenConfiguration){
+        super.initForm(cgenConfiguration);
+        view.getOutputPattern().setText(cgenConfiguration.getOutputPattern());
+        view.getPairs().setSelected(cgenConfiguration.isMakePairs());
+        view.getUsePackagePath().setSelected(cgenConfiguration.isUsePkgPath());
+        view.getOverwrite().setSelected(cgenConfiguration.isOverwrite());
+        view.getCreatePropertyNames().setSelected(cgenConfiguration.isCreatePropertyNames());
+        view.getPkProperties().setSelected(cgenConfiguration.isCreatePKProperties());
+        if(cgenConfiguration.getArtifactsGenerationMode().equalsIgnoreCase("all")) {
+            ((CodeGeneratorControllerBase) parent).setCurrentClass(cgenConfiguration.getDataMap());
+            ((CodeGeneratorControllerBase) parent).setSelected(true);
         }
         updateComboBoxes();
     }
+
+    @Override
+    public void updateConfiguration(CgenConfiguration cgenConfiguration) {
+        cgenConfiguration.setClient(false);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java
index 6b8db21..31aec74 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java
@@ -20,13 +20,14 @@
 package org.apache.cayenne.modeler.editor.cgen;
 
 import org.apache.cayenne.gen.ArtifactsGenerationMode;
-import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.map.*;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
 import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.modeler.util.CodeValidationUtil;
+import org.apache.cayenne.modeler.util.ModelerUtil;
 import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.util.Util;
@@ -52,7 +53,7 @@ import java.util.stream.Collectors;
 public abstract class GeneratorController extends CayenneController {
 
     protected String mode = ArtifactsGenerationMode.ENTITY.getLabel();
-    protected ClassGenerationAction classGenerationAction;
+    protected CgenConfiguration cgenConfiguration;
 
     public GeneratorController(CodeGeneratorControllerBase parent) {
         super(parent);
@@ -72,36 +73,31 @@ public abstract class GeneratorController extends CayenneController {
 
     protected abstract GeneratorControllerPanel createView();
 
-    /**
-     * Creates an appropriate subclass of {@link ClassGenerationAction},
-     * returning it in an unconfigured state. Configuration is performed by
-     * {@link #createGenerator()} method.
-     */
-    protected abstract ClassGenerationAction newGenerator();
-
-    protected void initForm(ClassGenerationAction classGenerationAction) {
-        this.classGenerationAction = classGenerationAction;
-        classGenerationAction.setRootPath(Paths.get(initOutputFolder()));
-        ((GeneratorControllerPanel)getView()).getOutputFolder().setText(classGenerationAction.getDir());
+    protected void initForm(CgenConfiguration cgenConfiguration) {
+        this.cgenConfiguration = cgenConfiguration;
+        ((GeneratorControllerPanel)getView()).getOutputFolder().setText(cgenConfiguration.getDir());
     }
 
+    public abstract void updateConfiguration(CgenConfiguration cgenConfiguration);
+
     /**
      * Creates a class generator for provided selections.
      */
-    public ClassGenerationAction createGenerator() {
+    public CgenConfiguration createConfiguration() {
         DataMap map = getParentController().getProjectController().getCurrentDataMap();
-        ClassGenerationAction generator = getParentController().projectController.getApplication().getMetaData().get(map, ClassGenerationAction.class);
-        if(generator != null){
-            getParentController().addToSelectedEntities(generator.getDataMap(), generator.getEntities());
-            getParentController().addToSelectedEmbeddables(generator.getDataMap(), generator.getEmbeddables());
-            return generator;
+        CgenConfiguration cgenConfiguration = getParentController().projectController.getApplication().getMetaData().get(map, CgenConfiguration.class);
+        if(cgenConfiguration != null){
+            getParentController().addToSelectedEntities(cgenConfiguration.getDataMap(), cgenConfiguration.getEntities());
+            getParentController().addToSelectedEmbeddables(cgenConfiguration.getDataMap(), cgenConfiguration.getEmbeddables());
+            cgenConfiguration.setRootPath(Paths.get(ModelerUtil.initOutputFolder()));
+            return cgenConfiguration;
         }
 
         try {
-            generator = newGenerator();
-            generator.setDataMap(map);
+            cgenConfiguration = new CgenConfiguration();
+            cgenConfiguration.setDataMap(map);
 
-            Path basePath = Paths.get(initOutputFolder());
+            Path basePath = Paths.get(ModelerUtil.initOutputFolder());
 
             // no destination folder
             if (basePath == null) {
@@ -120,10 +116,10 @@ public abstract class GeneratorController extends CayenneController {
                 return null;
             }
 
-            generator.setRootPath(basePath);
+            cgenConfiguration.setRootPath(basePath);
             Preferences preferences = application.getPreferencesNode(GeneralPreferences.class, "");
             if (preferences != null) {
-                generator.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));
+                cgenConfiguration.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));
             }
             getParentController().addToSelectedEntities(map, map.getObjEntities()
                     .stream()
@@ -133,14 +129,14 @@ public abstract class GeneratorController extends CayenneController {
                     .stream()
                     .map(Embeddable::getClassName)
                     .collect(Collectors.toList()));
-            getParentController().projectController.getApplication().getMetaData().add(map, generator);
+            getParentController().projectController.getApplication().getMetaData().add(map, cgenConfiguration);
         } catch (IOException exception) {
             JOptionPane.showMessageDialog(this.getView(), "Can't create directory. " +
                     ". Select a different one.");
             return null;
         }
 
-        return generator;
+        return cgenConfiguration;
     }
 
     public void validateEmbeddable(ValidationResult validationBuffer, Embeddable embeddable) {
@@ -449,44 +445,4 @@ public abstract class GeneratorController extends CayenneController {
             ((GeneratorControllerPanel) getView()).getOutputFolder().updateModel();
         }
     }
-
-    private String initOutputFolder() {
-        String path;
-        if (System.getProperty("cayenne.cgen.destdir") != null) {
-            return System.getProperty("cayenne.cgen.destdir");
-        } else {
-            // init default directory..
-            FSPath lastPath = Application.getInstance().getFrameController().getLastDirectory();
-
-            path = checkDefaultMavenResourceDir(lastPath, "test");
-
-            if (path != null || (path = checkDefaultMavenResourceDir(lastPath, "main")) != null) {
-                return path;
-            } else {
-                File lastDir = lastPath.getExistingDirectory(false);
-                return lastDir != null ? lastDir.getAbsolutePath() : ".";
-            }
-        }
-    }
-
-    private String checkDefaultMavenResourceDir(FSPath lastPath, String dirType) {
-        String path = lastPath.getPath();
-        String resourcePath = buildFilePath("src", dirType, "resources");
-        int idx = path.indexOf(resourcePath);
-        if (idx < 0) {
-            return null;
-        }
-        return path.substring(0, idx) + buildFilePath("src", dirType, "java");
-    }
-
-    private static String buildFilePath(String... pathElements) {
-        if (pathElements.length == 0) {
-            return "";
-        }
-        StringBuilder path = new StringBuilder(pathElements[0]);
-        for (int i = 1; i < pathElements.length; i++) {
-            path.append(File.separator).append(pathElements[i]);
-        }
-        return path.toString();
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java
index 98e7841..21bd223 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java
@@ -19,7 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.util.TextAdapter;
@@ -61,8 +61,8 @@ public class GeneratorControllerPanel extends JPanel {
         return selectOutputFolder;
     }
 
-    public ClassGenerationAction getCgenByDataMap() {
+    public CgenConfiguration getCgenByDataMap() {
         DataMap dataMap = projectController.getCurrentDataMap();
-        return projectController.getApplication().getMetaData().get(dataMap, ClassGenerationAction.class);
+        return projectController.getApplication().getMetaData().get(dataMap, CgenConfiguration.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabController.java
----------------------------------------------------------------------
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 ef290a6..16aebae 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
@@ -19,12 +19,9 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.modeler.util.CayenneController;
-import org.apache.cayenne.pref.CayenneProjectPreferences;
 import org.apache.cayenne.pref.PreferenceDetail;
-import org.apache.cayenne.swing.BindingBuilder;
-import org.apache.cayenne.util.Util;
 
 import java.awt.*;
 import java.util.HashMap;
@@ -77,39 +74,39 @@ public class GeneratorTabController extends CayenneController {
     }
 
     protected void initBindings() {
-
-        // bind actions
-        BindingBuilder builder = new BindingBuilder(
-                getApplication().getBindingFactory(),
-                this);
-
-        CayenneProjectPreferences cayPrPref = application.getCayenneProjectPreferences();
-
-        this.preferences = (PreferenceDetail) cayPrPref.getProjectDetailObject(
-                PreferenceDetail.class,
-                getViewPreferences().node("controller"));
-
-        if (Util.isEmptyString(preferences.getProperty("mode"))) {
-            preferences.setProperty("mode", STANDARD_OBJECTS_MODE);
-        }
-
-        builder.bindToComboSelection(
-                view.getGenerationMode(),
-                "preferences.property['mode']").updateView();
-
         view.getGenerationMode().addActionListener(action -> {
             String name = (String)view.getGenerationMode().getSelectedItem();
-            controllers.get(name).initForm(getGenerator());
+            GeneratorController modeController = getGeneratorController();
+            CgenConfiguration cgenConfiguration = modeController.createConfiguration();
+            modeController.updateConfiguration(cgenConfiguration);
+            controllers.get(name).initForm(cgenConfiguration);
+            ((CodeGeneratorController)getParentController()).getPrevGeneratorController().put(cgenConfiguration.getDataMap(), modeController);
         });
     }
 
+    public void setSelectedController(GeneratorController generatorController) {
+        for(String key : controllers.keySet()) {
+            if(generatorController.equals(controllers.get(key))) {
+                ((GeneratorTabPanel)getView()).getGenerationMode().setSelectedItem(key);
+            }
+        }
+    }
+
     GeneratorController getGeneratorController() {
         String name = (String)view.getGenerationMode().getSelectedItem();
         return controllers.get(name);
     }
 
-    public ClassGenerationAction getGenerator() {
+    GeneratorController getStandartController() {
+        return controllers.get(STANDARD_OBJECTS_MODE);
+    }
+
+    GeneratorController getClientGeneratorController() {
+        return controllers.get(CLIENT_OBJECTS_MODE);
+    }
+
+    public CgenConfiguration getConfiguration() {
         GeneratorController modeController = getGeneratorController();
-        return (modeController != null) ? modeController.createGenerator() : null;
+        return (modeController != null) ? modeController.createConfiguration() : null;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
----------------------------------------------------------------------
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 6985896..69cb19f 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
@@ -19,7 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.modeler.pref.DataMapDefaults;
 
 import java.awt.*;
@@ -43,19 +43,18 @@ public class StandardModeController extends GeneratorController {
     }
 
     @Override
-    protected ClassGenerationAction newGenerator() {
-        ClassGenerationAction action = new ClassGenerationAction();
-        getApplication().getInjector().injectMembers(action);
-        return action;
+    public CgenConfiguration createConfiguration() {
+        return super.createConfiguration();
     }
 
     @Override
-    protected void initForm(ClassGenerationAction classGenerationAction) {
-        super.initForm(classGenerationAction);
+    protected void initForm(CgenConfiguration cgenConfiguration) {
+        super.initForm(cgenConfiguration);
     }
 
     @Override
-    public ClassGenerationAction createGenerator() {
-        return super.createGenerator();
+    public void updateConfiguration(CgenConfiguration cgenConfiguration) {
+        cgenConfiguration.setClient(false);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenPanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenPanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenPanel.java
new file mode 100644
index 0000000..cf9b27a8
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenPanel.java
@@ -0,0 +1,59 @@
+package org.apache.cayenne.modeler.editor.cgen.domain;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import org.apache.cayenne.configuration.xml.DataChannelMetaData;
+import org.apache.cayenne.gen.CgenConfiguration;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class CgenPanel extends JPanel {
+
+    private JCheckBox checkConfig;
+    private JLabel dataMapLabel;
+    private JButton toConfigButton;
+    private DataMap dataMap;
+
+    public CgenPanel(DataMap dataMap) {
+        setLayout(new BorderLayout());
+        FormLayout layout = new FormLayout(
+                "left:pref, 4dlu, fill:50dlu, 3dlu, fill:120", "");
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder.setDefaultDialogBorder();
+
+        this.dataMap = dataMap;
+        this.checkConfig = new JCheckBox();
+        this.dataMapLabel = new JLabel(dataMap.getName());
+        DataChannelMetaData metaData = Application.getInstance().getMetaData();
+        this.toConfigButton = new JButton();
+        if(metaData.get(dataMap, CgenConfiguration.class) != null) {
+            this.toConfigButton.setText("Edit Config");
+        } else {
+            this.toConfigButton.setText("Create Config");
+        }
+        this.toConfigButton.setIcon(ModelerUtil.buildIcon("icon-datamap.png"));
+
+        builder.append(checkConfig, dataMapLabel, toConfigButton);
+        this.add(builder.getPanel(), BorderLayout.CENTER);
+    }
+
+    public JCheckBox getCheckConfig() {
+        return checkConfig;
+    }
+
+    public JButton getToConfigButton() {
+        return toConfigButton;
+    }
+
+    public JLabel getDataMapLabel() {
+        return dataMapLabel;
+    }
+
+    public DataMap getDataMap() {
+        return dataMap;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTab.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTab.java
new file mode 100644
index 0000000..87a7cc4
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTab.java
@@ -0,0 +1,89 @@
+package org.apache.cayenne.modeler.editor.cgen.domain;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentMap;
+
+public class CgenTab extends JPanel {
+
+    protected ProjectController projectController;
+    private CgenTabController cgenTabController;
+
+    private JCheckBox selectAll;
+    private JButton generateAll;
+
+    public CgenTab(ProjectController projectController, CgenTabController cgenTabController) {
+        this.projectController = projectController;
+        this.cgenTabController = cgenTabController;
+        this.selectAll = new JCheckBox();
+        generateAll = new JButton("Generate");
+        generateAll.setEnabled(false);
+        generateAll.setIcon(ModelerUtil.buildIcon("icon-gen_java.png"));
+        generateAll.setPreferredSize(new Dimension(120, 30));
+        generateAll.addActionListener(action -> cgenTabController.runGenerators(cgenTabController.getSelectedDataMaps()));
+        setLayout(new BorderLayout());
+    }
+
+    public void initView() {
+        removeAll();
+        cgenTabController.createPanels();
+        FormLayout layout = new FormLayout(
+                "left:pref, 4dlu, 50dlu", "");
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder.setDefaultDialogBorder();
+        ConcurrentMap<DataMap, CgenPanel> panels = cgenTabController.getGeneratorsPanels();
+
+        if(panels.isEmpty()) {
+            this.add(new JLabel("There are no cgen configs."), BorderLayout.NORTH);
+            return;
+        }
+
+        JPanel selectAllPanel = new JPanel(new FlowLayout());
+        selectAllPanel.add(new JLabel("Select All"), FlowLayout.LEFT);
+        selectAllPanel.add(selectAll, FlowLayout.CENTER);
+        builder.append(selectAllPanel);
+        builder.nextLine();
+
+        SortedSet<DataMap> keys = new TreeSet<>(panels.keySet());
+        for(DataMap dataMap : keys) {
+            builder.append(panels.get(dataMap));
+            builder.nextLine();
+        }
+        builder.append(generateAll);
+        this.add(builder.getPanel(), BorderLayout.CENTER);
+    }
+
+    void showSuccessMessage() {
+        JOptionPane.showMessageDialog(
+                this,
+                "Class generation finished");
+    }
+
+    void showErrorMessage(String msg) {
+        JOptionPane.showMessageDialog(
+                this,
+                "Error generating classes - " + msg);
+    }
+
+    void showEmptyMessage() {
+        JOptionPane.showMessageDialog(
+                this,
+                "Nothing to generate - ");
+    }
+
+    public JCheckBox getSelectAll() {
+        return selectAll;
+    }
+
+    public JButton getGenerateAll() {
+        return generateAll;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..daeb677
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
@@ -0,0 +1,197 @@
+package org.apache.cayenne.modeler.editor.cgen.domain;
+
+import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.configuration.xml.DataChannelMetaData;
+import org.apache.cayenne.gen.CgenConfiguration;
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
+import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
+import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+import org.apache.cayenne.project.Project;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.prefs.Preferences;
+
+public class CgenTabController {
+
+    private static Logger logObj = LoggerFactory.getLogger(ErrorDebugDialog.class);
+
+    private ProjectController projectController;
+    private CgenTab view;
+
+    private ConcurrentMap<DataMap, CgenPanel> generatorsPanels;
+    private Set<DataMap> selectedDataMaps;
+
+    public CgenTabController(ProjectController projectController) {
+        this.projectController = projectController;
+        this.view = new CgenTab(projectController, this);
+        this.generatorsPanels = new ConcurrentHashMap<>();
+        this.selectedDataMaps = new HashSet<>();
+    }
+
+    void createPanels() {
+        Collection<DataMap> dataMaps = getDataMaps();
+        generatorsPanels.clear();
+        for(DataMap dataMap : dataMaps) {
+            CgenPanel cgenPanel = new CgenPanel(dataMap);
+            initListenersForPanel(cgenPanel);
+            generatorsPanels.put(dataMap, cgenPanel);
+        }
+        selectedDataMaps.forEach(dataMap -> {
+            if(generatorsPanels.get(dataMap) != null) {
+                CgenPanel currPanel = generatorsPanels.get(dataMap);
+                currPanel.getCheckConfig().setSelected(true);
+            }
+        });
+    }
+
+    private void initListenersForPanel(CgenPanel cgenPanel) {
+        cgenPanel.getCheckConfig().addItemListener(e -> {
+            if(e.getStateChange() == ItemEvent.SELECTED) {
+                selectedDataMaps.add(cgenPanel.getDataMap());
+            } else if(e.getStateChange() == ItemEvent.DESELECTED) {
+                selectedDataMaps.remove(cgenPanel.getDataMap());
+            }
+            setGenerateButtonDisabled();
+        });
+
+        cgenPanel.getToConfigButton().addActionListener(action -> showConfig(cgenPanel.getDataMap()));
+
+        view.getSelectAll().addItemListener(e -> {
+            if(e.getStateChange() == ItemEvent.SELECTED) {
+                getGeneratorsPanels().forEach((key, value) -> value.getCheckConfig().setSelected(true));
+            } else if(e.getStateChange() == ItemEvent.DESELECTED) {
+                getGeneratorsPanels().forEach((key, value) -> value.getCheckConfig().setSelected(false));
+            }
+            setGenerateButtonDisabled();
+        });
+    }
+
+    private void setGenerateButtonDisabled() {
+        if(selectedDataMaps.size() == 0) {
+            view.getGenerateAll().setEnabled(false);
+        } else {
+            view.getGenerateAll().setEnabled(true);
+        }
+    }
+
+    private Collection<DataMap> getDataMaps() {
+        Project project = projectController.getProject();
+        return  ((DataChannelDescriptor) project.getRootNode()).getDataMaps();
+    }
+
+    public CgenTab getView() {
+        return view;
+    }
+
+    void runGenerators(Set<DataMap> dataMaps) {
+        DataChannelMetaData metaData = Application.getInstance().getMetaData();
+        if(dataMaps.isEmpty()) {
+            view.showEmptyMessage();
+            return;
+        }
+        boolean generationFail = false;
+        for(DataMap dataMap : dataMaps) {
+            try {
+                CgenConfiguration cgenConfiguration = metaData.get(dataMap, CgenConfiguration.class);
+                if(cgenConfiguration == null) {
+                    cgenConfiguration = createConfiguration(dataMap);
+                }
+                if(cgenConfiguration.getRootPath() == null) {
+                    URL url = projectController.getProject().getConfigurationResource().getURL();
+                    Path resourcePath = Paths.get(url.getPath());
+                    if(Files.isRegularFile(resourcePath)) {
+                        resourcePath = resourcePath.getParent();
+                    }
+                    cgenConfiguration.setRootPath(resourcePath);
+                }
+                ClassGenerationAction classGenerationAction = cgenConfiguration.isClient() ? new ClientClassGenerationAction(cgenConfiguration) :
+                        new ClassGenerationAction(cgenConfiguration);
+                classGenerationAction.prepareArtifacts();
+                classGenerationAction.execute();
+            } catch (Exception e) {
+                logObj.error("Error generating classes", e);
+                generationFail = true;
+                view.showErrorMessage(e.getMessage());
+            }
+        }
+        if(!generationFail) {
+            view.showSuccessMessage();
+        }
+    }
+
+    private CgenConfiguration createConfiguration(DataMap dataMap) {
+        CgenConfiguration cgenConfiguration = new CgenConfiguration();
+        Application.getInstance().getInjector().injectMembers(cgenConfiguration);
+        cgenConfiguration.setDataMap(dataMap);
+        Path basePath = Paths.get(ModelerUtil.initOutputFolder());
+
+        // no destination folder
+        if (basePath == null) {
+            JOptionPane.showMessageDialog(this.getView(), "Select directory for source files.");
+            return null;
+        }
+
+        // no such folder
+        if (!Files.exists(basePath)) {
+            try {
+                Files.createDirectories(basePath);
+            } catch (IOException e) {
+                JOptionPane.showMessageDialog(this.getView(), "Can't create directory. " +
+                        ". Select a different one.");
+                return null;
+            }
+        }
+
+        // not a directory
+        if (!Files.isDirectory(basePath)) {
+            JOptionPane.showMessageDialog(this.getView(), basePath + " is not a valid directory.");
+            return null;
+        }
+
+        cgenConfiguration.setRootPath(basePath);
+        Preferences preferences = Application.getInstance().getPreferencesNode(GeneralPreferences.class, "");
+        if (preferences != null) {
+            cgenConfiguration.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));
+        }
+        cgenConfiguration.resolveExcludeEntities();
+        cgenConfiguration.resolveExcludeEmbeddables();
+        return cgenConfiguration;
+    }
+
+    private void showConfig(DataMap dataMap) {
+        if (dataMap != null) {
+            projectController.fireDataMapDisplayEvent(new DataMapDisplayEvent(this.getView(), dataMap, dataMap.getDataChannelDescriptor()));
+        }
+    }
+
+    public ProjectController getProjectController() {
+        return projectController;
+    }
+
+    ConcurrentMap<DataMap, CgenPanel> getGeneratorsPanels() {
+        return generatorsPanels;
+    }
+
+    public Set<DataMap> getSelectedDataMaps() {
+        return selectedDataMaps;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerUtil.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerUtil.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerUtil.java
index f750752..90c6d19 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerUtil.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerUtil.java
@@ -28,6 +28,7 @@ import org.apache.cayenne.modeler.ModelerConstants;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.action.ActionManager;
 import org.apache.cayenne.modeler.action.MultipleObjectsAction;
+import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.reflect.PropertyUtils;
 import org.apache.cayenne.util.CayenneMapEntry;
 
@@ -36,6 +37,7 @@ import javax.swing.ImageIcon;
 import java.awt.Dimension;
 import java.awt.Point;
 import java.awt.Window;
+import java.io.File;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -212,4 +214,45 @@ public final class ModelerUtil {
 
         child.setLocation(x, y);
     }
+
+    public static String initOutputFolder() {
+        String path;
+        if (System.getProperty("cayenne.cgen.destdir") != null) {
+            return System.getProperty("cayenne.cgen.destdir");
+        } else {
+            // init default directory..
+            FSPath lastPath = Application.getInstance().getFrameController().getLastDirectory();
+
+            path = checkDefaultMavenResourceDir(lastPath, "test");
+
+            if (path != null || (path = checkDefaultMavenResourceDir(lastPath, "main")) != null) {
+                return path;
+            } else {
+                File lastDir = lastPath.getExistingDirectory(false);
+                return lastDir != null ? lastDir.getAbsolutePath() : ".";
+            }
+        }
+    }
+
+    private static String checkDefaultMavenResourceDir(FSPath lastPath, String dirType) {
+        String path = lastPath.getPath();
+        String resourcePath = buildFilePath("src", dirType, "resources");
+        int idx = path.indexOf(resourcePath);
+        if (idx < 0) {
+            return null;
+        }
+        return path.substring(0, idx) + buildFilePath("src", dirType, "java");
+    }
+
+    private static String buildFilePath(String... pathElements) {
+        if (pathElements.length == 0) {
+            return "";
+        }
+        StringBuilder path = new StringBuilder(pathElements[0]);
+        for (int i = 1; i < pathElements.length; i++) {
+            path.append(File.separator).append(pathElements[i]);
+        }
+        return path.toString();
+    }
+
 }


Mime
View raw message