Repository: cayenne Updated Branches: refs/heads/master e980ed199 -> 01112fe60
Update cgen dialog (cherry picked from commit a799a39) Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/e452059b Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/e452059b Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/e452059b Branch: refs/heads/master Commit: e452059bb7a56e66bf3c2ee5fa202f66dbb7de5c Parents: 22c2e78 Author: Arseni Bulatski <ancars...@gmail.com> Authored: Fri Jul 6 15:59:27 2018 +0300 Committer: Arseni Bulatski <ancars...@gmail.com> Committed: Fri Jul 6 16:26:13 2018 +0300 ---------------------------------------------------------------------- .../modeler/action/GenerateCodeAction.java | 30 +---- .../dialog/codegen/ClassesTabController.java | 104 +++++++++++++++--- .../modeler/dialog/codegen/ClassesTabPanel.java | 96 ++++++++++++---- .../dialog/codegen/ClientModeController.java | 24 ---- .../dialog/codegen/CodeGeneratorController.java | 18 ++- .../codegen/CodeGeneratorControllerBase.java | 110 ++++++++++++++++++- .../dialog/codegen/CodeGeneratorDialog.java | 28 +++-- .../dialog/codegen/CustomModeController.java | 65 +++-------- .../modeler/dialog/codegen/CustomModePanel.java | 59 +++------- .../dialog/codegen/GeneratorController.java | 62 ++++------- .../dialog/codegen/GeneratorTabController.java | 13 +-- .../dialog/codegen/StandardModeController.java | 26 ----- .../dialog/codegen/StandardModePanel.java | 18 +-- .../modeler/editor/SelectQueryPrefetchTab.java | 4 +- 14 files changed, 359 insertions(+), 298 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GenerateCodeAction.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GenerateCodeAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GenerateCodeAction.java index 57ccca1..bdb2e15 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GenerateCodeAction.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GenerateCodeAction.java @@ -27,7 +27,6 @@ import org.apache.cayenne.modeler.util.CayenneAction; import org.apache.cayenne.project.Project; import java.awt.event.ActionEvent; -import java.util.ArrayList; import java.util.Collection; public class GenerateCodeAction extends CayenneAction { @@ -46,31 +45,8 @@ public class GenerateCodeAction extends CayenneAction { public void performAction(ActionEvent e) { Collection<DataMap> dataMaps; - DataMap dataMap = getProjectController().getCurrentDataMap(); - - if (dataMap != null) { - dataMaps = new ArrayList<>(); - dataMaps.add(dataMap); - - new CodeGeneratorController(getApplication().getFrameController(), dataMaps).startup(); - } else if (getProjectController().getCurrentDataNode() != null) { - Collection<String> nodeMaps = getProjectController().getCurrentDataNode().getDataMapNames(); - Project project = getProjectController().getProject(); - dataMaps = ((DataChannelDescriptor) project.getRootNode()).getDataMaps(); - - Collection<DataMap> resultMaps = new ArrayList<>(); - for (DataMap map : dataMaps) { - if (nodeMaps.contains(map.getName())) { - resultMaps.add(map); - } - } - - new CodeGeneratorController(getApplication().getFrameController(), resultMaps).startup(); - } else { - Project project = getProjectController().getProject(); - dataMaps = ((DataChannelDescriptor) project.getRootNode()).getDataMaps(); - - new CodeGeneratorController(getApplication().getFrameController(), dataMaps).startup(); - } + Project project = getProjectController().getProject(); + dataMaps = ((DataChannelDescriptor) project.getRootNode()).getDataMaps(); + new CodeGeneratorController(getApplication().getFrameController(), dataMaps).startup(); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabController.java index a5b2e6a..7e1671c 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabController.java @@ -19,27 +19,56 @@ package org.apache.cayenne.modeler.dialog.codegen; -import java.awt.Component; - -import javax.swing.JLabel; - +import org.apache.cayenne.map.DataMap; import org.apache.cayenne.modeler.util.CayenneController; import org.apache.cayenne.swing.BindingBuilder; import org.apache.cayenne.swing.ImageRendererColumn; import org.apache.cayenne.swing.ObjectBinding; import org.apache.cayenne.swing.TableBindingBuilder; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import java.awt.Component; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + public class ClassesTabController extends CayenneController { public static final String GENERATE_PROPERTY = "generate"; protected ClassesTabPanel view; - protected ObjectBinding tableBinding; - public ClassesTabController(CodeGeneratorControllerBase parent) { + private Map<DataMap, ObjectBinding> objectBindings; + + protected Collection<DataMap> dataMaps; + + protected Map<DataMap, List<Object>> objectList; + + private List<Object> currentCollection; + + public ClassesTabController(CodeGeneratorControllerBase parent, Collection<DataMap> dataMaps) { super(parent); - this.view = new ClassesTabPanel(); + currentCollection = new ArrayList<>(); + + this.objectList = new HashMap<>(); + for(DataMap dataMap : dataMaps) { + List<Object> list = new ArrayList<>(Arrays.asList(dataMap)); + list.addAll(Stream.concat(dataMap.getObjEntities().stream(), dataMap.getEmbeddables().stream()) + .collect(Collectors.toList())); + objectList.put(dataMap, list); + } + + this.objectBindings = new HashMap<>(); + this.dataMaps = dataMaps; + this.view = new ClassesTabPanel(dataMaps); + initBindings(); } @@ -67,6 +96,7 @@ public class ClassesTabController extends CayenneController { Boolean.class, true, Boolean.TRUE); + tableBuilder.addColumn( "Class", "parent.getItemName(#item)", @@ -79,10 +109,22 @@ public class ClassesTabController extends CayenneController { "parent.getProblem(#item)", String.class, false, - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); - - this.tableBinding = tableBuilder.bindToTable(view.getTable(), "parent.classes"); - view.getTable().getColumnModel().getColumn(1).setCellRenderer(new ImageRendererColumn()); + "XXXXXXXXXXXXXXXXXXXXXXXXXXX"); + + for(DataMap dataMap : dataMaps) { + if(view.getDataMapTables().get(dataMap) != null) { + currentCollection = objectList.get(dataMap); + objectBindings.put(dataMap, tableBuilder.bindToTable(view.getDataMapTables().get(dataMap), "currentCollection")); + view.getDataMapTables().get(dataMap).getColumnModel().getColumn(1).setCellRenderer(new ImageRendererColumn()); + } + if(view.getDataMapJCheckBoxMap().get(dataMap) != null) { + view.getDataMapJCheckBoxMap().get(dataMap).addActionListener(val -> checkDataMap(dataMap, ((JCheckBox)val.getSource()).isSelected())); + } + } + } + + public List<Object> getCurrentCollection() { + return currentCollection; } public boolean isSelected() { @@ -92,13 +134,21 @@ public class ClassesTabController extends CayenneController { public void setSelected(boolean selected) { getParentController().setSelected(selected); classSelectedAction(); + + for(DataMap dataMap : dataMaps) { + if(view.isAllCheckBoxesFromDataMapSelected(dataMap)) { + view.getDataMapJCheckBoxMap().get(dataMap).setSelected(true); + } else { + view.getDataMapJCheckBoxMap().get(dataMap).setSelected(false); + } + } } /** * A callback action that updates the state of Select All checkbox. */ public void classSelectedAction() { - int selectedCount = getParentController().getSelectedEntitiesSize() + getParentController().getSelectedEmbeddablesSize() ; + int selectedCount = getParentController().getSelectedEntitiesSize() + getParentController().getSelectedEmbeddablesSize() + getParentController().getSelectedDataMapsSize(); if (selectedCount == 0) { view.getCheckAll().setSelected(false); @@ -114,7 +164,35 @@ public class ClassesTabController extends CayenneController { */ public void checkAllAction() { if (getParentController().updateSelection(view.getCheckAll().isSelected() ? o -> true : o -> false)) { - tableBinding.updateView(); + dataMaps.forEach(dataMap -> { + if(objectBindings.get(dataMap) != null) { + currentCollection = objectList.get(dataMap); + objectBindings.get(dataMap).updateView(); + } + }); + } + } + + private void checkDataMap(DataMap dataMap, boolean selected) { + if (getParentController().updateDataMapSelection(selected ? o -> true : o -> false, dataMap)){ + if(objectBindings.get(dataMap) != null) { + currentCollection = objectList.get(dataMap); + objectBindings.get(dataMap).updateView(); + } + if(isAllMapsSelected()) { + view.getCheckAll().setSelected(true); + } + } + } + + private boolean isAllMapsSelected() { + for(DataMap dataMap : dataMaps) { + if(view.getDataMapJCheckBoxMap().get(dataMap) != null) { + if(!view.getDataMapJCheckBoxMap().get(dataMap).isSelected()) { + return false; + } + } } + return true; } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabPanel.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabPanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabPanel.java index ea164b1..f1a8132 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabPanel.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClassesTabPanel.java @@ -19,12 +19,9 @@ package org.apache.cayenne.modeler.dialog.codegen; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; +import org.apache.cayenne.map.DataMap; +import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; @@ -32,59 +29,110 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ScrollPaneConstants; import javax.swing.UIManager; +import javax.swing.border.EmptyBorder; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; /** */ public class ClassesTabPanel extends JPanel { - protected JTable table; protected JCheckBox checkAll; protected JLabel checkAllLabel; - public ClassesTabPanel() { + private Map<DataMap, JTable> dataMapTables; - this.table = new JTable(); - this.table.setRowHeight(22); + private Map<DataMap, JCheckBox> dataMapJCheckBoxMap; + + public ClassesTabPanel(Collection<DataMap> dataMaps) { + dataMapTables = new HashMap<>(); + dataMapJCheckBoxMap = new HashMap<>(); // TODO: andrus 04/07/2006 - is there an easy way to stick that checkbox in the // table header???? this.checkAll = new JCheckBox(); this.checkAllLabel = new JLabel("Check All Classes"); - checkAll.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent event) { - if (checkAll.isSelected()) { - checkAllLabel.setText("Uncheck All Classess"); - } - else { - checkAllLabel.setText("Check All Classes"); - } + checkAll.addItemListener(event -> { + if (checkAll.isSelected()) { + checkAllLabel.setText("Uncheck All Classess"); + dataMapJCheckBoxMap.keySet().forEach(val -> dataMapJCheckBoxMap.get(val).setSelected(true)); + } + else { + checkAllLabel.setText("Check All Classes"); + dataMapJCheckBoxMap.keySet().forEach(val -> dataMapJCheckBoxMap.get(val).setSelected(false)); } }); // assemble - JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); + JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); topPanel.setBorder(UIManager.getBorder("ToolBar.border")); topPanel.add(checkAll); topPanel.add(checkAllLabel); + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + for(DataMap dataMap : dataMaps) { + JTable table = new JTable(); + table.setRowHeight(22); + dataMapTables.put(dataMap, table); + JPanel scrollTable = new JPanel(new BorderLayout()); + scrollTable.add(dataMapTables.get(dataMap).getTableHeader(), BorderLayout.NORTH); + scrollTable.add(dataMapTables.get(dataMap), BorderLayout.CENTER); + scrollTable.setPreferredSize(new Dimension(dataMapTables.get(dataMap).getPreferredSize().width, + (dataMap.getEmbeddables().size() + dataMap.getObjEntities().size()) * dataMapTables.get(dataMap).getRowHeight() + 45)); + JPanel labelPanel = new JPanel(new BorderLayout()); + labelPanel.setPreferredSize(new Dimension(dataMapTables.get(dataMap).getPreferredSize().width, 20)); + JLabel dataMapLabel = new JLabel(dataMap.getName()); + dataMapLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + dataMapLabel.setBorder(new EmptyBorder(8, 8, 8, 0)); + labelPanel.add(dataMapLabel, BorderLayout.CENTER); + + JCheckBox dataMapCheckBox = new JCheckBox(); + dataMapJCheckBoxMap.put(dataMap, dataMapCheckBox); + labelPanel.add(dataMapCheckBox, BorderLayout.WEST); + + JPanel currPanel = new JPanel(new BorderLayout()); + currPanel.add(labelPanel, BorderLayout.NORTH); + currPanel.add(scrollTable, BorderLayout.CENTER); + + panel.add(currPanel); + } + JScrollPane tablePanel = new JScrollPane( - table, + panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); // set some minimal preferred size, so that it is smaller than other forms used in // the dialog... this way we get the right automated overall size - tablePanel.setPreferredSize(new Dimension(300, 200)); - + tablePanel.setPreferredSize(new Dimension(450, 400)); setLayout(new BorderLayout()); add(topPanel, BorderLayout.NORTH); add(tablePanel, BorderLayout.CENTER); } - public JTable getTable() { - return table; + public boolean isAllCheckBoxesFromDataMapSelected(DataMap dataMap) { + JTable table = dataMapTables.get(dataMap); + for(int i = 0; i < table.getRowCount(); i++) { + if(!(Boolean)table.getModel().getValueAt(i, 0)) { + return false; + } + } + return true; + } + + public Map<DataMap, JTable> getDataMapTables() { + return dataMapTables; + } + + public Map<DataMap, JCheckBox> getDataMapJCheckBoxMap() { + return dataMapJCheckBoxMap; } public JCheckBox getCheckAll() { http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java index 079d70c..4d5335f 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java @@ -24,15 +24,11 @@ import org.apache.cayenne.gen.ClientClassGenerationAction; import org.apache.cayenne.map.DataMap; import org.apache.cayenne.map.ObjEntity; import org.apache.cayenne.modeler.pref.DataMapDefaults; -import org.apache.cayenne.swing.BindingBuilder; import org.apache.cayenne.validation.BeanValidationFailure; import org.apache.cayenne.validation.ValidationResult; import java.util.ArrayList; -import java.util.Map.Entry; -import java.util.Set; import java.util.TreeMap; -import java.util.function.Predicate; public class ClientModeController extends StandardModeController { @@ -75,29 +71,9 @@ public class ClientModeController extends StandardModeController { protected GeneratorControllerPanel createView() { this.view = new StandardModePanel(); - - Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); - for (Entry<DataMap, DataMapDefaults> entry : entities) { - StandardPanelComponent dataMapLine = createDataMapLineBy(entry.getKey(), entry.getValue()); - dataMapLine.getDataMapName().setText(dataMapLine.getDataMap().getName()); - BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), dataMapLine); - builder.bindToTextField( - dataMapLine.getSuperclassPackage(), - "preferences.superclassPackage").updateView(); - this.view.addDataMapLine(dataMapLine); - } - return view; } - private StandardPanelComponent createDataMapLineBy(DataMap dataMap, DataMapDefaults preferences) { - StandardPanelComponent dataMapLine = new StandardPanelComponent(); - dataMapLine.setDataMap(dataMap); - dataMapLine.setPreferences(preferences); - - return dataMapLine; - } - @Override protected ClassGenerationAction newGenerator() { return new ClientClassGenerationAction(); http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java index d471682..f4395e9 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorController.java @@ -49,7 +49,7 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase { public CodeGeneratorController(CayenneController parent, Collection<DataMap> dataMaps) { super(parent, dataMaps); - this.classesSelector = new ClassesTabController(this); + this.classesSelector = new ClassesTabController(this, dataMaps); this.generatorSelector = new GeneratorTabController(this); } @@ -123,9 +123,21 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase { label = label + "One embeddable selected"; } else { - label =label + sizeEmb + " embeddables selected"; + label = label + sizeEmb + " embeddables selected"; } - + + label = label.concat("; "); + + int sizeDataMap = getSelectedDataMapsSize(); + + if(sizeDataMap == 0) { + label = label + "No datamaps selected"; + } else if(sizeDataMap == 1) { + label = label + "One datamap selected"; + } else { + label = label + sizeDataMap + " datamaps selected"; + } + view.getClassesCount().setText(label); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java index 34d208b..5d1201d 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorControllerBase.java @@ -52,10 +52,11 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { protected List<Object> classes; - protected Set<String> selectedEntities; - protected Set<String> selectedEmbeddables; + private Set<String> selectedEntities; + private Set<String> selectedEmbeddables; + private Set<String> selectedDataMaps; - protected transient Object currentClass; + private transient Object currentClass; public CodeGeneratorControllerBase(CayenneController parent, Collection<DataMap> dataMaps) { super(parent); @@ -66,9 +67,11 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { for(DataMap dataMap:dataMaps){ this.classes.addAll(dataMap.getObjEntities()); this.classes.addAll(dataMap.getEmbeddables()); + this.classes.add(dataMap); } this.selectedEntities = new HashSet<>(); this.selectedEmbeddables = new HashSet<>(); + this.selectedDataMaps = new HashSet<>(); } public List<Object> getClasses() { @@ -130,6 +133,71 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { modified = true; } } + } else if(classObj instanceof DataMap) { + if(select) { + if(selectedDataMaps.add(((DataMap) classObj).getName())) { + modified = true; + } + } else { + if(selectedDataMaps.remove(((DataMap) classObj).getName())) { + modified = true; + } + } + } + + } + + if (modified) { + firePropertyChange(SELECTED_PROPERTY, null, null); + } + + return modified; + } + + public boolean updateDataMapSelection(Predicate<Object> predicate, DataMap dataMap) { + + boolean modified = false; + + for (Object classObj : classes) { + boolean select = predicate.test(classObj); + if (classObj instanceof ObjEntity) { + if(dataMap.getObjEntities().contains(classObj)) { + if (select) { + if (selectedEntities.add(((ObjEntity) classObj).getName())) { + modified = true; + } + } else { + if (selectedEntities.remove(((ObjEntity) classObj).getName())) { + modified = true; + } + } + } + } + else if (classObj instanceof Embeddable) { + if(dataMap.getEmbeddables().contains(classObj)) { + if (select) { + if (selectedEmbeddables.add(((Embeddable) classObj).getClassName())) { + modified = true; + } + } else { + if (selectedEmbeddables + .remove(((Embeddable) classObj).getClassName())) { + modified = true; + } + } + } + } else { + if(dataMap == classObj) { + if (select) { + if (selectedDataMaps.add(((DataMap) classObj).getName())) { + modified = true; + } + } else { + if (selectedDataMaps.remove(((DataMap) classObj).getName())) { + modified = true; + } + } + } } } @@ -168,6 +236,17 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { return selected; } + public List<DataMap> getSelectedDataMaps() { + List<DataMap> selected = new ArrayList<>(selectedDataMaps.size()); + for(Object classObj : classes) { + if(classObj instanceof DataMap + && selectedDataMaps.contains(((DataMap) classObj).getName())) { + selected.add((DataMap) classObj); + } + } + return selected; + } + public int getSelectedEntitiesSize() { return selectedEntities.size(); } @@ -176,6 +255,10 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { return selectedEmbeddables.size(); } + public int getSelectedDataMapsSize() { + return selectedDataMaps.size(); + } + /** * Returns the first encountered validation problem for an antity matching the name or * null if the entity is valid or the entity is not present. @@ -212,6 +295,10 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { return selectedEmbeddables .contains(((Embeddable) currentClass).getClassName()); } + if(currentClass instanceof DataMap) { + return selectedDataMaps + .contains(((DataMap) currentClass).getName()); + } return false; } @@ -245,6 +332,17 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { } } } + if(currentClass instanceof DataMap) { + if(selectedFlag) { + if(selectedDataMaps.add(((DataMap) currentClass).getName())) { + firePropertyChange(SELECTED_PROPERTY, null, null); + } + } else { + if(selectedDataMaps.remove(((DataMap) currentClass).getName())) { + firePropertyChange(SELECTED_PROPERTY, null, null); + } + } + } } public Object getCurrentClass() { @@ -265,9 +363,12 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { if (obj instanceof Embeddable) { className = ((Embeddable) obj).getClassName(); icon = CellRenderers.iconForObject(new Embeddable()); - } else { + } else if(obj instanceof ObjEntity) { className = ((ObjEntity) obj).getName(); icon = CellRenderers.iconForObject(new ObjEntity()); + } else { + className = ((DataMap) obj).getName(); + icon = CellRenderers.iconForObject(new DataMap()); } JLabel labelIcon = new JLabel(); labelIcon.setIcon(icon); @@ -275,4 +376,5 @@ public abstract class CodeGeneratorControllerBase extends CayenneController { labelIcon.setText(className); return labelIcon; } + } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorDialog.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorDialog.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorDialog.java index 72d6167..7ed60e2 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorDialog.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CodeGeneratorDialog.java @@ -28,9 +28,8 @@ import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; +import javax.swing.JSplitPane; import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; @@ -41,33 +40,32 @@ import java.awt.FlowLayout; */ public class CodeGeneratorDialog extends JDialog { - protected JTabbedPane tabs; - - protected JButton generateButton; + private JButton generateButton; protected JButton cancelButton; - protected JLabel classesCount; + private JLabel classesCount; - public CodeGeneratorDialog(Component generatorPanel, Component entitySelectorPanel) { + CodeGeneratorDialog(Component generatorPanel, Component entitySelectorPanel) { super(Application.getFrame()); - this.tabs = new JTabbedPane(SwingConstants.TOP); - this.tabs.setFocusable(false); + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + splitPane.setFocusable(false); + this.generateButton = new JButton("Generate"); getRootPane().setDefaultButton(generateButton); + this.cancelButton = new JButton("Cancel"); this.classesCount = new JLabel("No classes selected"); classesCount.setFont(classesCount.getFont().deriveFont(10f)); + JScrollPane scrollPane = new JScrollPane( generatorPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane.setPreferredSize(new Dimension(800, 400)); - - // assemble + scrollPane.setPreferredSize(new Dimension(630, 500)); - tabs.addTab("Code Generator", scrollPane); - tabs.addTab("Classes", entitySelectorPanel); + splitPane.setLeftComponent(entitySelectorPanel); + splitPane.setRightComponent(scrollPane); JPanel messages = new JPanel(new BorderLayout()); messages.add(classesCount, BorderLayout.WEST); @@ -81,7 +79,7 @@ public class CodeGeneratorDialog extends JDialog { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); - contentPane.add(tabs, BorderLayout.CENTER); + contentPane.add(splitPane, BorderLayout.CENTER); contentPane.add(buttons, BorderLayout.SOUTH); setTitle("Code Generation"); http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java index 8d66407..3c5d047 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java @@ -28,15 +28,14 @@ import org.apache.cayenne.swing.BindingBuilder; import org.apache.cayenne.swing.ObjectBinding; import org.apache.cayenne.util.Util; -import javax.swing.*; -import java.awt.*; +import javax.swing.DefaultComboBoxModel; +import java.awt.Component; +import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; @@ -46,27 +45,13 @@ import java.util.TreeMap; public class CustomModeController extends GeneratorController { // correspond to non-public constants on MapClassGenerator. - static final String MODE_DATAMAP = "datamap"; - static final String MODE_ENTITY = "entity"; - static final String MODE_ALL = "all"; - - static final String DATA_MAP_MODE_LABEL = "DataMap generation"; - static final String ENTITY_MODE_LABEL = "Entity and Embeddable generation"; - static final String ALL_MODE_LABEL = "Generate all"; - - static final Map<String, String> modesByLabel = new HashMap<>(); - - static { - modesByLabel.put(DATA_MAP_MODE_LABEL, MODE_DATAMAP); - modesByLabel.put(ENTITY_MODE_LABEL, MODE_ENTITY); - modesByLabel.put(ALL_MODE_LABEL, MODE_ALL); - } + private static final String MODE_ENTITY = "entity"; protected CustomModePanel view; - protected CodeTemplateManager templateManager; + private CodeTemplateManager templateManager; - protected ObjectBinding superTemplate; - protected ObjectBinding subTemplate; + private ObjectBinding superTemplate; + private ObjectBinding subTemplate; private CustomPreferencesUpdater preferencesUpdater; @@ -77,9 +62,6 @@ public class CustomModeController extends GeneratorController { public CustomModeController(CodeGeneratorControllerBase parent) { super(parent); - Object[] modeChoices = new Object[] { ENTITY_MODE_LABEL, DATA_MAP_MODE_LABEL, ALL_MODE_LABEL }; - view.getGenerationMode().setModel(new DefaultComboBoxModel(modeChoices)); - // bind preferences and init defaults... Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); @@ -119,8 +101,6 @@ public class CustomModeController extends GeneratorController { builder.bindToAction(view.getManageTemplatesLink(), "popPreferencesAction()"); - builder.bindToComboSelection(view.getGenerationMode(), "customPreferencesUpdater.mode").updateView(); - builder.bindToStateChange(view.getOverwrite(), "customPreferencesUpdater.overwrite").updateView(); builder.bindToStateChange(view.getPairs(), "customPreferencesUpdater.pairs").updateView(); @@ -164,27 +144,10 @@ public class CustomModeController extends GeneratorController { protected GeneratorControllerPanel createView() { this.view = new CustomModePanel(); - - Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); - for (Entry<DataMap, DataMapDefaults> entry : entities) { - StandardPanelComponent dataMapLine = createDataMapLineBy(entry.getKey(), entry.getValue()); - dataMapLine.getDataMapName().setText(dataMapLine.getDataMap().getName()); - BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), dataMapLine); - builder.bindToTextField(dataMapLine.getSuperclassPackage(), "preferences.superclassPackage").updateView(); - this.view.addDataMapLine(dataMapLine); - } return view; } - private StandardPanelComponent createDataMapLineBy(DataMap dataMap, DataMapDefaults preferences) { - StandardPanelComponent dataMapLine = new StandardPanelComponent(); - dataMapLine.setDataMap(dataMap); - dataMapLine.setPreferences(preferences); - - return dataMapLine; - } - - protected void updateTemplates() { + private void updateTemplates() { this.templateManager = getApplication().getCodeTemplateManager(); List<String> customTemplates = new ArrayList<>(templateManager.getCustomTemplates().keySet()); @@ -198,8 +161,8 @@ public class CustomModeController extends GeneratorController { Collections.sort(subTemplates); subTemplates.addAll(customTemplates); - this.view.getSubclassTemplate().setModel(new DefaultComboBoxModel(subTemplates.toArray())); - this.view.getSuperclassTemplate().setModel(new DefaultComboBoxModel(superTemplates.toArray())); + this.view.getSubclassTemplate().setModel(new DefaultComboBoxModel<>(subTemplates.toArray(new String[0]))); + this.view.getSuperclassTemplate().setModel(new DefaultComboBoxModel<>(superTemplates.toArray(new String[0]))); superTemplate.updateView(); subTemplate.updateView(); @@ -211,14 +174,12 @@ public class CustomModeController extends GeneratorController { public Collection<ClassGenerationAction> createGenerator() { - mode = modesByLabel.get(view.getGenerationMode().getSelectedItem()).toString(); - Collection<ClassGenerationAction> generators = super.createGenerator(); - String superKey = view.getSuperclassTemplate().getSelectedItem().toString(); + String superKey = Objects.requireNonNull(view.getSuperclassTemplate().getSelectedItem()).toString(); String superTemplate = templateManager.getTemplatePath(superKey); - String subKey = view.getSubclassTemplate().getSelectedItem().toString(); + String subKey = Objects.requireNonNull(view.getSubclassTemplate().getSelectedItem()).toString(); String subTemplate = templateManager.getTemplatePath(subKey); for (ClassGenerationAction generator : generators) { http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModePanel.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModePanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModePanel.java index dcf8767..7571de0 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModePanel.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModePanel.java @@ -27,31 +27,25 @@ import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import java.awt.BorderLayout; import java.awt.FlowLayout; public class CustomModePanel extends GeneratorControllerPanel { - protected JComboBox generationMode; - protected JComboBox subclassTemplate; - protected JComboBox superclassTemplate; + private JComboBox<String> subclassTemplate; + private JComboBox<String> superclassTemplate; protected JCheckBox pairs; - protected JCheckBox overwrite; - protected JCheckBox usePackagePath; - protected JTextField outputPattern; - protected JCheckBox createPropertyNames; + private JCheckBox overwrite; + private JCheckBox usePackagePath; + private JTextField outputPattern; + private JCheckBox createPropertyNames; - private DefaultFormBuilder builder; + private ActionLink manageTemplatesLink; - protected ActionLink manageTemplatesLink; + CustomModePanel() { - public CustomModePanel() { - - this.generationMode = new JComboBox(); - this.superclassTemplate = new JComboBox(); - this.subclassTemplate = new JComboBox(); + this.superclassTemplate = new JComboBox<>(); + this.subclassTemplate = new JComboBox<>(); this.pairs = new JCheckBox(); this.overwrite = new JCheckBox(); this.usePackagePath = new JCheckBox(); @@ -60,27 +54,20 @@ public class CustomModePanel extends GeneratorControllerPanel { this.manageTemplatesLink = new ActionLink("Customize Templates..."); manageTemplatesLink.setFont(manageTemplatesLink.getFont().deriveFont(10f)); - pairs.addChangeListener(new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - superclassTemplate.setEnabled(pairs.isSelected()); - overwrite.setEnabled(!pairs.isSelected()); - } + pairs.addChangeListener(e -> { + superclassTemplate.setEnabled(pairs.isSelected()); + overwrite.setEnabled(!pairs.isSelected()); }); // assemble - FormLayout layout = new FormLayout( - "right:77dlu, 3dlu, fill:200:grow, 6dlu, fill:50dlu, 3dlu", ""); - builder = new DefaultFormBuilder(layout); + "right:77dlu, 1dlu, fill:100:grow, 1dlu, left:80dlu, 1dlu", ""); + DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.append("Output Directory:", outputFolder, selectOutputFolder); builder.nextLine(); - builder.append("Generation Mode:", generationMode); - builder.nextLine(); - builder.append("Subclass Template:", subclassTemplate); builder.nextLine(); @@ -105,32 +92,22 @@ public class CustomModePanel extends GeneratorControllerPanel { setLayout(new BorderLayout()); add(builder.getPanel(), BorderLayout.CENTER); - JPanel links = new JPanel(new FlowLayout(FlowLayout.TRAILING)); + JPanel links = new JPanel(new FlowLayout(FlowLayout.RIGHT)); links.add(manageTemplatesLink); add(links, BorderLayout.SOUTH); add(builder.getPanel(), BorderLayout.CENTER); } - public void addDataMapLine(StandardPanelComponent dataMapLine) { - dataMapLines.add(dataMapLine); - builder.append(dataMapLine, 4); - builder.nextLine(); - } - - public JComboBox getGenerationMode() { - return generationMode; - } - public ActionLink getManageTemplatesLink() { return manageTemplatesLink; } - public JComboBox getSubclassTemplate() { + public JComboBox<String> getSubclassTemplate() { return subclassTemplate; } - public JComboBox getSuperclassTemplate() { + public JComboBox<String> getSuperclassTemplate() { return superclassTemplate; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java index b369928..082a08f 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java @@ -49,7 +49,6 @@ import javax.swing.JTextField; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.Set; @@ -167,6 +166,13 @@ public abstract class GeneratorController extends CayenneController { for (DataMap map : getParentController().getDataMaps()) { try { ClassGenerationAction generator = newGenerator(); + + if(getParentController().getSelectedDataMaps().contains(map)) { + mode = ArtifactsGenerationMode.ALL.getLabel(); + } else { + mode = ArtifactsGenerationMode.ENTITY.getLabel(); + } + generator.setArtifactsGenerationMode(mode); generator.setDataMap(map); @@ -191,13 +197,6 @@ public abstract class GeneratorController extends CayenneController { generator.setMakePairs(true); generator.setForce(true); - for (StandardPanelComponent dataMapLine : dataMapLines) { - if (dataMapLine.getDataMap() == map && !Util.isEmptyString(dataMapLine.getSuperclassPackage().getText())) { - generator.setSuperPkg(dataMapLine.getSuperclassPackage().getText()); - break; - } - } - generators.add(generator); } catch (CayenneRuntimeException exception) { JOptionPane.showMessageDialog(this.getView(), exception.getUnlabeledMessage()); @@ -254,7 +253,7 @@ public abstract class GeneratorController extends CayenneController { return null; } - protected ValidationFailure validateEmbeddable(Embeddable embeddable) { + private ValidationFailure validateEmbeddable(Embeddable embeddable) { String name = embeddable.getClassName(); @@ -310,7 +309,7 @@ public abstract class GeneratorController extends CayenneController { } } - protected ValidationFailure validateEntity(ObjEntity entity) { + private ValidationFailure validateEntity(ObjEntity entity) { String name = entity.getName(); @@ -340,7 +339,7 @@ public abstract class GeneratorController extends CayenneController { return null; } - protected ValidationFailure validateAttribute(ObjAttribute attribute) { + private ValidationFailure validateAttribute(ObjAttribute attribute) { String name = attribute.getEntity().getName(); @@ -371,7 +370,7 @@ public abstract class GeneratorController extends CayenneController { return null; } - protected ValidationFailure validateEmbeddedAttribute(ObjAttribute attribute) { + private ValidationFailure validateEmbeddedAttribute(ObjAttribute attribute) { String name = attribute.getEntity().getName(); @@ -420,7 +419,7 @@ public abstract class GeneratorController extends CayenneController { return null; } - protected ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) { + private ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) { String name = relationship.getSourceEntity().getName(); @@ -469,37 +468,20 @@ public abstract class GeneratorController extends CayenneController { * Returns a predicate for default entity selection in a given mode. */ public Predicate getDefaultClassFilter() { - final ObjEntity selectedEntity = Application.getInstance().getFrameController().getProjectController() - .getCurrentObjEntity(); - - final Embeddable selectedEmbeddable = Application.getInstance().getFrameController().getProjectController() - .getCurrentEmbeddable(); - - if (selectedEntity != null) { - // select a single entity - final boolean hasProblem = getParentController().getProblem(selectedEntity.getName()) != null; - return object -> !hasProblem && object == selectedEntity; - } else if (selectedEmbeddable != null) { - // select a single embeddable - final boolean hasProblem = getParentController().getProblem(selectedEmbeddable.getClassName()) != null; - return object -> !hasProblem && object == selectedEmbeddable; - } else { - // select all entities - return object -> { - if (object instanceof ObjEntity) { - return getParentController().getProblem(((ObjEntity) object).getName()) == null; - } + return object -> { + if (object instanceof ObjEntity) { + return getParentController().getProblem(((ObjEntity) object).getName()) == null; + } - if (object instanceof Embeddable) { - return getParentController().getProblem(((Embeddable) object).getClassName()) == null; - } + if (object instanceof Embeddable) { + return getParentController().getProblem(((Embeddable) object).getClassName()) == null; + } - return false; - }; - } + return false; + }; } - public File getOutputDir() { + private File getOutputDir() { String dir = ((GeneratorControllerPanel) getView()).getOutputFolder().getText(); return dir != null ? new File(dir) : new File(System.getProperty("user.dir")); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java index ddc7d5b..5d7594f 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java @@ -27,6 +27,7 @@ import org.apache.cayenne.swing.BindingBuilder; import org.apache.cayenne.util.Util; import java.awt.Component; +import java.awt.Dimension; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -65,6 +66,7 @@ public class GeneratorTabController extends CayenneController { this.view = new GeneratorTabPanel(GENERATION_MODES, modePanels); initBindings(); + view.setPreferredSize(new Dimension(600, 480)); } public Component getView() { @@ -82,8 +84,6 @@ public class GeneratorTabController extends CayenneController { getApplication().getBindingFactory(), this); - builder.bindToAction(view.getGenerationMode(), "updateModeAction()"); - CayenneProjectPreferences cayPrPref = application.getCayenneProjectPreferences(); this.preferences = (PreferenceDetail) cayPrPref.getProjectDetailObject( @@ -97,21 +97,12 @@ public class GeneratorTabController extends CayenneController { builder.bindToComboSelection( view.getGenerationMode(), "preferences.property['mode']").updateView(); - - updateModeAction(); } public PreferenceDetail getPreferences() { return preferences; } - /** - * Resets selection to default values for a given controller. - */ - public void updateModeAction() { - firePropertyChange(GENERATOR_PROPERTY, null, getGeneratorController()); - } - public GeneratorController getGeneratorController() { Object name = view.getGenerationMode().getSelectedItem(); return (GeneratorController) controllers.get(name); http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java index 8443956..1c3a27a 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/StandardModeController.java @@ -19,17 +19,13 @@ package org.apache.cayenne.modeler.dialog.codegen; -import org.apache.cayenne.gen.ArtifactsGenerationMode; import org.apache.cayenne.gen.ClassGenerationAction; import org.apache.cayenne.map.DataMap; import org.apache.cayenne.modeler.pref.DataMapDefaults; -import org.apache.cayenne.swing.BindingBuilder; import java.awt.Component; import java.util.ArrayList; import java.util.Collection; -import java.util.Map.Entry; -import java.util.Set; import java.util.TreeMap; public class StandardModeController extends GeneratorController { @@ -65,28 +61,9 @@ public class StandardModeController extends GeneratorController { protected GeneratorControllerPanel createView() { this.view = new StandardModePanel(); - - Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); - for (Entry<DataMap, DataMapDefaults> entry : entities) { - StandardPanelComponent dataMapLine = createDataMapLineBy(entry.getKey(), entry.getValue()); - dataMapLine.getDataMapName().setText(dataMapLine.getDataMap().getName()); - BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), dataMapLine); - builder.bindToTextField( - dataMapLine.getSuperclassPackage(), - "preferences.superclassPackage").updateView(); - this.view.addDataMapLine(dataMapLine); - } return view; } - private StandardPanelComponent createDataMapLineBy(DataMap dataMap, DataMapDefaults preferences) { - StandardPanelComponent dataMapLine = new StandardPanelComponent(); - dataMapLine.setDataMap(dataMap); - dataMapLine.setPreferences(preferences); - - return dataMapLine; - } - public Component getView() { return view; } @@ -100,9 +77,6 @@ public class StandardModeController extends GeneratorController { @Override public Collection<ClassGenerationAction> createGenerator() { - mode = view.getCreateDataMapClass().isSelected() - ? ArtifactsGenerationMode.ALL.getLabel() - : ArtifactsGenerationMode.ENTITY.getLabel(); return super.createGenerator(); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/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 199d511..cbb3f35 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 @@ -22,37 +22,21 @@ package org.apache.cayenne.modeler.dialog.codegen; import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.layout.FormLayout; -import javax.swing.JCheckBox; import java.awt.BorderLayout; public class StandardModePanel extends GeneratorControllerPanel { private DefaultFormBuilder builder; - protected JCheckBox createDataMapClass; public StandardModePanel() { FormLayout layout = new FormLayout( - "right:77dlu, 3dlu, fill:200:grow, 6dlu, fill:50dlu, 3dlu", ""); + "right:77dlu, 1dlu, fill:100:grow, 1dlu, left:80dlu, 1dlu", ""); builder = new DefaultFormBuilder(layout); builder.append("Output Directory:", outputFolder, selectOutputFolder); builder.nextLine(); - createDataMapClass = new JCheckBox(); - builder.append("Create DataMap class:", createDataMapClass); - builder.nextLine(); - setLayout(new BorderLayout()); add(builder.getPanel(), BorderLayout.CENTER); } - - public void addDataMapLine(StandardPanelComponent dataMapLine) { - dataMapLines.add(dataMapLine); - builder.append(dataMapLine, 4); - builder.nextLine(); - } - - public JCheckBox getCreateDataMapClass() { - return createDataMapClass; - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/e452059b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java index 82719d8..6fd9fd0 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java @@ -61,7 +61,9 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { protected void initFromModel(){ super.initFromModel(); - setUpPrefetchBox(table.getColumnModel().getColumn(2)); + if(table.getColumnModel().getColumns().hasMoreElements()) { + setUpPrefetchBox(table.getColumnModel().getColumn(2)); + } } protected void setUpPrefetchBox(TableColumn column) {