cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [11/32] cayenne git commit: Add cgen tab.
Date Wed, 14 Nov 2018 14:27:42 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a43436a/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 2824685..ef290a6 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
@@ -21,25 +21,47 @@ package org.apache.cayenne.modeler.editor.cgen;
 
 import org.apache.cayenne.gen.ClassGenerationAction;
 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.Component;
+import java.awt.*;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  */
 public class GeneratorTabController extends CayenneController {
 
+    private static final String STANDARD_OBJECTS_MODE = "Standard Persistent Objects";
+    private static final String CLIENT_OBJECTS_MODE = "Client Persistent Objects";
+    private static final String ADVANCED_MODE = "Advanced";
+
     public static final String GENERATOR_PROPERTY = "generator";
 
+    private static final String[] GENERATION_MODES = new String[] {
+            STANDARD_OBJECTS_MODE, CLIENT_OBJECTS_MODE, ADVANCED_MODE
+    };
+
     protected GeneratorTabPanel view;
+    protected Map<String, GeneratorController> controllers;
     protected PreferenceDetail preferences;
 
-    protected CustomModeController customModeController;
-
     public GeneratorTabController(CodeGeneratorControllerBase parent) {
         super(parent);
-        customModeController = new CustomModeController(parent);
-        this.view = new GeneratorTabPanel(customModeController.getView());
+        this.controllers = new HashMap<>(3);
+        controllers.put(STANDARD_OBJECTS_MODE, new StandardModeController(parent));
+        controllers.put(CLIENT_OBJECTS_MODE, new ClientModeController(parent));
+        controllers.put(ADVANCED_MODE, new CustomModeController(parent));
+        Component[] modePanels = new Component[GENERATION_MODES.length];
+        for (int i = 0; i < GENERATION_MODES.length; i++) {
+            modePanels[i] = controllers.get(GENERATION_MODES[i])
+                    .getView();
+        }
+        this.view = new GeneratorTabPanel(GENERATION_MODES, modePanels);
+        initBindings();
+        view.setPreferredSize(new Dimension(600, 480));
     }
 
     public Component getView() {
@@ -54,8 +76,36 @@ public class GeneratorTabController extends CayenneController {
         return preferences;
     }
 
-    public GeneratorController getGeneratorController() {
-        return customModeController;
+    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 getGeneratorController() {
+        String name = (String)view.getGenerationMode().getSelectedItem();
+        return controllers.get(name);
     }
 
     public ClassGenerationAction getGenerator() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a43436a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabPanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabPanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabPanel.java
index ab25218..9cfd542 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabPanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorTabPanel.java
@@ -19,17 +19,77 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import javax.swing.JPanel;
-import java.awt.BorderLayout;
-import java.awt.Component;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+import org.apache.cayenne.swing.components.TopBorder;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.Objects;
 
 /**
  * @since 4.1
  */
 public class GeneratorTabPanel extends JPanel {
 
-    public GeneratorTabPanel(Component modePanels) {
+    private JComboBox<String> generationMode;
+    private CardLayout modeLayout;
+    private JPanel modesPanel;
+
+    private JButton generateButton;
+    private JLabel classesCount;
+
+    public GeneratorTabPanel(String[] modeNames, Component[] modePanels) {
         setLayout(new BorderLayout());
-        add(modePanels, BorderLayout.CENTER);
+        this.generateButton = new JButton("Generate");
+        generateButton.setIcon(ModelerUtil.buildIcon("icon-gen_java.png"));
+        generateButton.setPreferredSize(new Dimension(180, 30));
+        this.classesCount = new JLabel("No classes selected");
+        classesCount.setFont(classesCount.getFont().deriveFont(10f));
+        JPanel messages = new JPanel(new BorderLayout());
+        messages.add(classesCount, BorderLayout.WEST);
+        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+        buttons.setBorder(TopBorder.create());
+        buttons.add(classesCount);
+        buttons.add(Box.createHorizontalStrut(50));
+        buttons.add(generateButton);
+        add(buttons, BorderLayout.NORTH);
+
+        JPanel panel = new JPanel();
+        this.generationMode = new JComboBox<>(modeNames);
+        this.modeLayout = new CardLayout();
+        this.modesPanel = new JPanel(modeLayout);
+
+        generationMode.addItemListener(e -> modeLayout.show(modesPanel, Objects.requireNonNull(generationMode.getSelectedItem()).toString()));
+
+        // assemble
+        FormLayout layout = new FormLayout("right:77dlu, 3dlu, fill:300, fill:300dlu:grow",
"");
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder.setDefaultDialogBorder();
+        builder.append("Type:", generationMode, 1);
+        builder.appendSeparator();
+
+        for (int i = 0; i < modeNames.length; i++) {
+            modesPanel.add(modePanels[i], modeNames[i]);
+        }
+
+        panel.setLayout(new BorderLayout());
+        panel.add(builder.getPanel(), BorderLayout.NORTH);
+        panel.add(modesPanel, BorderLayout.CENTER);
+
+        add(panel, BorderLayout.CENTER);
+    }
+
+    public JComboBox getGenerationMode() {
+        return generationMode;
+    }
+
+    public JButton getGenerateButton() {
+        return generateButton;
+    }
+
+    public JLabel getClassesCount() {
+        return classesCount;
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a43436a/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
new file mode 100644
index 0000000..6985896
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModeController.java
@@ -0,0 +1,61 @@
+/*****************************************************************
+ *   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.cgen;
+
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.modeler.pref.DataMapDefaults;
+
+import java.awt.*;
+
+public class StandardModeController extends GeneratorController {
+
+    protected StandardModePanel view;
+    protected DataMapDefaults preferences;
+
+    public StandardModeController(CodeGeneratorControllerBase parent) {
+        super(parent);
+    }
+
+    protected GeneratorControllerPanel createView() {
+        this.view = new StandardModePanel();
+        return view;
+    }
+
+    public Component getView() {
+        return view;
+    }
+
+    @Override
+    protected ClassGenerationAction newGenerator() {
+        ClassGenerationAction action = new ClassGenerationAction();
+        getApplication().getInjector().injectMembers(action);
+        return action;
+    }
+
+    @Override
+    protected void initForm(ClassGenerationAction classGenerationAction) {
+        super.initForm(classGenerationAction);
+    }
+
+    @Override
+    public ClassGenerationAction createGenerator() {
+        return super.createGenerator();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a43436a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModePanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModePanel.java
new file mode 100644
index 0000000..0ddf1e2
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardModePanel.java
@@ -0,0 +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.editor.cgen;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import org.apache.cayenne.modeler.Application;
+
+import java.awt.*;
+
+public class StandardModePanel extends GeneratorControllerPanel {
+
+    public StandardModePanel() {
+        super(Application.getInstance().getFrameController().getProjectController());
+        FormLayout layout = new FormLayout(
+                "right:88dlu, 1dlu, fill:300:grow, 1dlu, left:100dlu, 100dlu", "");
+
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder.append("Output Directory:", outputFolder.getComponent(), 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/6a43436a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardPanelComponent.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardPanelComponent.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardPanelComponent.java
new file mode 100644
index 0000000..8170548
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/StandardPanelComponent.java
@@ -0,0 +1,63 @@
+/*****************************************************************
+ *   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.cgen;
+
+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.*;
+import java.awt.*;
+
+public class StandardPanelComponent extends JComponent {
+
+    private DataMap dataMap;
+    private DataMapDefaults preferences;
+
+    public StandardPanelComponent() {
+        super();
+
+        FormLayout layout = new FormLayout(
+                "right:77dlu, 3dlu, fill:100:grow, 3dlu", "");
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder.nextLine();
+
+        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;
+    }
+
+}


Mime
View raw message