http://git-wip-us.apache.org/repos/asf/cayenne/blob/52ea45b5/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 9e3897e..0225d3b 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 @@ -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 org.apache.cayenne.gen.ClassGenerationAction; -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.validation.BeanValidationFailure; -import org.apache.cayenne.validation.ValidationResult; - -import java.util.ArrayList; -import java.util.TreeMap; - -public class ClientModeController extends StandardModeController { - - public ClientModeController(CodeGeneratorControllerBase parent) { - super(parent); - } - - public void validateEntity(ValidationResult validationBuffer, ObjEntity entity) { - if (!entity.isClientAllowed()) { - validationBuffer.addFailure(new BeanValidationFailure( - entity.getName(), - "clientAllowed", - "Not a client entity")); - } else { - super.validateEntity(validationBuffer, entity, true); - } - } - - protected void createDefaults() { - TreeMap<DataMap, DataMapDefaults> map = new TreeMap<DataMap, DataMapDefaults>(); - ArrayList<DataMap> dataMaps = (ArrayList<DataMap>) getParentController().getDataMaps(); - for (DataMap dataMap : dataMaps) { - DataMapDefaults preferences = getApplication() - .getFrameController() - .getProjectController() - .getDataMapPreferences(this.getClass().getName().replace(".", "/"), dataMap); - - preferences.setSuperclassPackage(""); - preferences.updateSuperclassPackage(dataMap, true); - - map.put(dataMap, preferences); - - if (getOutputPath() == null) { - setOutputPath(preferences.getOutputPath()); - } - } - - setMapPreferences(map); - } - - protected GeneratorControllerPanel createView() { - this.view = new StandardModePanel(); - return view; - } - - @Override - protected ClassGenerationAction newGenerator() { - return new ClientClassGenerationAction(); - } -} \ 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 org.apache.cayenne.gen.ClassGenerationAction; +//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.validation.BeanValidationFailure; +//import org.apache.cayenne.validation.ValidationResult; +// +//import java.util.ArrayList; +//import java.util.TreeMap; +// +//public class ClientModeController extends StandardModeController { +// +// public ClientModeController(CodeGeneratorControllerBase parent) { +// super(parent); +// } +// +// public void validateEntity(ValidationResult validationBuffer, ObjEntity entity) { +// if (!entity.isClientAllowed()) { +// validationBuffer.addFailure(new BeanValidationFailure( +// entity.getName(), +// "clientAllowed", +// "Not a client entity")); +// } else { +// super.validateEntity(validationBuffer, entity, true); +// } +// } +// +// protected void createDefaults() { +// TreeMap<DataMap, DataMapDefaults> map = new TreeMap<DataMap, DataMapDefaults>(); +// ArrayList<DataMap> dataMaps = (ArrayList<DataMap>) getParentController().getDataMaps(); +// for (DataMap dataMap : dataMaps) { +// DataMapDefaults preferences = getApplication() +// .getFrameController() +// .getProjectController() +// .getDataMapPreferences(this.getClass().getName().replace(".", "/"), dataMap); +// +// preferences.setSuperclassPackage(""); +// preferences.updateSuperclassPackage(dataMap, true); +// +// map.put(dataMap, preferences); +// +// if (getOutputPath() == null) { +// setOutputPath(preferences.getOutputPath()); +// } +// } +// +// setMapPreferences(map); +// } +// +// protected GeneratorControllerPanel createView() { +// this.view = new StandardModePanel(); +// return view; +// } +// +// @Override +// protected ClassGenerationAction newGenerator() { +// return new ClientClassGenerationAction(); +// } +//} \ 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/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 55817a6..a5ac549 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 @@ -1,169 +1,169 @@ -/***************************************************************** - * 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 org.apache.cayenne.gen.ClassGenerationAction; -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.modeler.dialog.ErrorDebugDialog; -import org.apache.cayenne.modeler.util.CayenneController; -import org.apache.cayenne.swing.BindingBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.swing.JOptionPane; -import java.awt.Component; -import java.util.Collection; -import java.util.function.Predicate; - -/** - * A controller for the class generator dialog. - */ -public class CodeGeneratorController extends CodeGeneratorControllerBase { - /** - * Logger to print stack traces - */ - private static Logger logObj = LoggerFactory.getLogger(ErrorDebugDialog.class); - - protected CodeGeneratorDialog view; - - protected ClassesTabController classesSelector; - protected GeneratorTabController generatorSelector; - - public CodeGeneratorController(CayenneController parent, Collection<DataMap> dataMaps) { - super(parent, dataMaps); - - this.classesSelector = new ClassesTabController(this, dataMaps); - this.generatorSelector = new GeneratorTabController(this); - } - - @Override - public Component getView() { - return view; - } - - public void startup() { - // show dialog even on empty DataMap, as custom generation may still take - // advantage of it - - view = new CodeGeneratorDialog(generatorSelector.getView(), classesSelector.getView()); - initBindings(); - - view.pack(); - view.setModal(true); - centerView(); - makeCloseableOnEscape(); - view.setVisible(true); - } - - protected void initBindings() { - BindingBuilder builder = new BindingBuilder( - getApplication().getBindingFactory(), - this); - - builder.bindToAction(view.getCancelButton(), "cancelAction()"); - builder.bindToAction(view.getGenerateButton(), "generateAction()"); - builder.bindToAction(this, "classesSelectedAction()", SELECTED_PROPERTY); - builder.bindToAction(generatorSelector, "generatorSelectedAction()", - GeneratorTabController.GENERATOR_PROPERTY); - - generatorSelectedAction(); - } - - public void generatorSelectedAction() { - GeneratorController controller = generatorSelector.getGeneratorController(); - validate(controller); - - Predicate<Object> predicate = controller != null - ? controller.getDefaultClassFilter() - : o -> false; - - updateSelection(predicate); - classesSelector.classSelectedAction(); - } - - public void classesSelectedAction() { - int size = getSelectedEntitiesSize(); - String label; - - if (size == 0) { - label = "No entities selected"; - } - else if (size == 1) { - label = "One entity selected"; - } - else { - label = size + " entities selected"; - } - - label = label.concat("; "); - - int sizeEmb = getSelectedEmbeddablesSize(); - - if (sizeEmb == 0) { - label = label + "No embeddables selected"; - } - else if (sizeEmb == 1) { - label = label + "One embeddable selected"; - } - else { - 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); - } - - public void cancelAction() { - view.dispose(); - } - - public void generateAction() { - Collection<ClassGenerationAction> generators = generatorSelector.getGenerator(); - - if (generators != null) { - try { - for (ClassGenerationAction generator : generators) { - 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()); - } - } - - view.dispose(); - } -} \ 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 org.apache.cayenne.gen.ClassGenerationAction; +//import org.apache.cayenne.map.DataMap; +//import org.apache.cayenne.modeler.dialog.ErrorDebugDialog; +//import org.apache.cayenne.modeler.util.CayenneController; +//import org.apache.cayenne.swing.BindingBuilder; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import javax.swing.JOptionPane; +//import java.awt.Component; +//import java.util.Collection; +//import java.util.function.Predicate; +// +///** +// * A controller for the class generator dialog. +// */ +//public class CodeGeneratorController extends CodeGeneratorControllerBase { +// /** +// * Logger to print stack traces +// */ +// private static Logger logObj = LoggerFactory.getLogger(ErrorDebugDialog.class); +// +// protected CodeGeneratorDialog view; +// +// protected ClassesTabController classesSelector; +// protected GeneratorTabController generatorSelector; +// +// public CodeGeneratorController(CayenneController parent, Collection<DataMap> dataMaps) { +// super(parent, dataMaps); +// +// this.classesSelector = new ClassesTabController(this, dataMaps); +// this.generatorSelector = new GeneratorTabController(this); +// } +// +// @Override +// public Component getView() { +// return view; +// } +// +// public void startup() { +// // show dialog even on empty DataMap, as custom generation may still take +// // advantage of it +// +// view = new CodeGeneratorDialog(generatorSelector.getView(), classesSelector.getView()); +// initBindings(); +// +// view.pack(); +// view.setModal(true); +// centerView(); +// makeCloseableOnEscape(); +// view.setVisible(true); +// } +// +// protected void initBindings() { +// BindingBuilder builder = new BindingBuilder( +// getApplication().getBindingFactory(), +// this); +// +// builder.bindToAction(view.getCancelButton(), "cancelAction()"); +// builder.bindToAction(view.getGenerateButton(), "generateAction()"); +// builder.bindToAction(this, "classesSelectedAction()", SELECTED_PROPERTY); +// builder.bindToAction(generatorSelector, "generatorSelectedAction()", +// GeneratorTabController.GENERATOR_PROPERTY); +// +// generatorSelectedAction(); +// } +// +// public void generatorSelectedAction() { +// GeneratorController controller = generatorSelector.getGeneratorController(); +// validate(controller); +// +// Predicate<Object> predicate = controller != null +// ? controller.getDefaultClassFilter() +// : o -> false; +// +// updateSelection(predicate); +// classesSelector.classSelectedAction(); +// } +// +// public void classesSelectedAction() { +// int size = getSelectedEntitiesSize(); +// String label; +// +// if (size == 0) { +// label = "No entities selected"; +// } +// else if (size == 1) { +// label = "One entity selected"; +// } +// else { +// label = size + " entities selected"; +// } +// +// label = label.concat("; "); +// +// int sizeEmb = getSelectedEmbeddablesSize(); +// +// if (sizeEmb == 0) { +// label = label + "No embeddables selected"; +// } +// else if (sizeEmb == 1) { +// label = label + "One embeddable selected"; +// } +// else { +// 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); +// } +// +// public void cancelAction() { +// view.dispose(); +// } +// +// public void generateAction() { +// Collection<ClassGenerationAction> generators = generatorSelector.getConfiguration(); +// +// if (generators != null) { +// try { +// for (ClassGenerationAction generator : generators) { +// 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()); +// } +// } +// +// view.dispose(); +// } +//} \ 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/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 91d87e4..3848126 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 @@ -1,380 +1,380 @@ -/***************************************************************** - * 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 org.apache.cayenne.map.DataMap; -import org.apache.cayenne.map.Embeddable; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.modeler.util.CayenneController; -import org.apache.cayenne.modeler.util.CellRenderers; -import org.apache.cayenne.validation.ValidationFailure; -import org.apache.cayenne.validation.ValidationResult; - -import javax.swing.Icon; -import javax.swing.JLabel; -import java.awt.Component; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; - -/** - * A base superclass of a top controller for the code generator. Defines all common model - * parts used in class generation. - * - */ -public abstract class CodeGeneratorControllerBase extends CayenneController { - - public static final String SELECTED_PROPERTY = "selected"; - - protected Collection<DataMap> dataMaps; - - protected ValidationResult validation; - - protected List<Object> classes; - - private Set<String> selectedEntities; - private Set<String> selectedEmbeddables; - private Set<String> selectedDataMaps; - - private transient Object currentClass; - - public CodeGeneratorControllerBase(CayenneController parent, Collection<DataMap> dataMaps) { - super(parent); - - this.dataMaps = dataMaps; - this.classes = new ArrayList<>(); - - 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() { - return classes; - } - - public abstract Component getView(); - - public void validate(GeneratorController validator) { - - ValidationResult validationBuffer = new ValidationResult(); - - if (validator != null) { - for (Object classObj : classes) { - if (classObj instanceof ObjEntity) { - validator.validateEntity( - validationBuffer, - (ObjEntity) classObj, - false); - } - else if (classObj instanceof Embeddable) { - validator.validateEmbeddable(validationBuffer, (Embeddable) classObj); - } - } - - } - - this.validation = validationBuffer; - } - - public boolean updateSelection(Predicate<Object> predicate) { - - boolean modified = false; - - for (Object classObj : classes) { - boolean select = predicate.test(classObj); - if (classObj instanceof ObjEntity) { - - 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 (select) { - if (selectedEmbeddables.add(((Embeddable) classObj).getClassName())) { - modified = true; - } - } - else { - if (selectedEmbeddables - .remove(((Embeddable) classObj).getClassName())) { - 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; - } - } - } - } - - } - - if (modified) { - firePropertyChange(SELECTED_PROPERTY, null, null); - } - - return modified; - } - - public List<Embeddable> getSelectedEmbeddables() { - - List<Embeddable> selected = new ArrayList<>(selectedEmbeddables.size()); - - for (Object classObj : classes) { - if (classObj instanceof Embeddable - && selectedEmbeddables.contains(((Embeddable) classObj) - .getClassName())) { - selected.add((Embeddable) classObj); - } - } - - return selected; - } - - public List<ObjEntity> getSelectedEntities() { - List<ObjEntity> selected = new ArrayList<>(selectedEntities.size()); - for (Object classObj : classes) { - if (classObj instanceof ObjEntity - && selectedEntities.contains(((ObjEntity) classObj).getName())) { - selected.add(((ObjEntity) classObj)); - } - } - - 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(); - } - - public int getSelectedEmbeddablesSize() { - 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. - */ - public String getProblem(Object obj) { - - String name = null; - - if (obj instanceof ObjEntity) { - name = ((ObjEntity) obj).getName(); - } - else if (obj instanceof Embeddable) { - name = ((Embeddable) obj).getClassName(); - } - - if (validation == null) { - return null; - } - - List failures = validation.getFailures(name); - if (failures.isEmpty()) { - return null; - } - - return ((ValidationFailure) failures.get(0)).getDescription(); - } - - public boolean isSelected() { - if (currentClass instanceof ObjEntity) { - return selectedEntities - .contains(((ObjEntity) currentClass).getName()); - } - if (currentClass instanceof Embeddable) { - return selectedEmbeddables - .contains(((Embeddable) currentClass).getClassName()); - } - if(currentClass instanceof DataMap) { - return selectedDataMaps - .contains(((DataMap) currentClass).getName()); - } - return false; - - } - - public void setSelected(boolean selectedFlag) { - if (currentClass == null) { - return; - } - if (currentClass instanceof ObjEntity) { - if (selectedFlag) { - if (selectedEntities.add(((ObjEntity) currentClass).getName())) { - firePropertyChange(SELECTED_PROPERTY, null, null); - } - } - else { - if (selectedEntities.remove(((ObjEntity) currentClass).getName())) { - firePropertyChange(SELECTED_PROPERTY, null, null); - } - } - } - if (currentClass instanceof Embeddable) { - if (selectedFlag) { - if (selectedEmbeddables.add(((Embeddable) currentClass).getClassName())) { - firePropertyChange(SELECTED_PROPERTY, null, null); - } - } - else { - if (selectedEmbeddables - .remove(((Embeddable) currentClass).getClassName())) { - firePropertyChange(SELECTED_PROPERTY, null, null); - } - } - } - 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() { - return currentClass; - } - - public void setCurrentClass(Object currentClass) { - this.currentClass = currentClass; - } - - public Collection<DataMap> getDataMaps() { - return dataMaps; - } - - public JLabel getItemName(Object obj) { - String className; - Icon icon; - if (obj instanceof Embeddable) { - className = ((Embeddable) obj).getClassName(); - icon = CellRenderers.iconForObject(new Embeddable()); - } 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); - labelIcon.setVisible(true); - labelIcon.setText(className); - return labelIcon; - } - -} \ 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 org.apache.cayenne.map.DataMap; +//import org.apache.cayenne.map.Embeddable; +//import org.apache.cayenne.map.ObjEntity; +//import org.apache.cayenne.modeler.util.CayenneController; +//import org.apache.cayenne.modeler.util.CellRenderers; +//import org.apache.cayenne.validation.ValidationFailure; +//import org.apache.cayenne.validation.ValidationResult; +// +//import javax.swing.Icon; +//import javax.swing.JLabel; +//import java.awt.Component; +//import java.util.ArrayList; +//import java.util.Collection; +//import java.util.HashSet; +//import java.util.List; +//import java.util.Set; +//import java.util.function.Predicate; +// +///** +// * A base superclass of a top controller for the code generator. Defines all common model +// * parts used in class generation. +// * +// */ +//public abstract class CodeGeneratorControllerBase extends CayenneController { +// +// public static final String SELECTED_PROPERTY = "selected"; +// +// protected Collection<DataMap> dataMaps; +// +// protected ValidationResult validation; +// +// protected List<Object> classes; +// +// private Set<String> selectedEntities; +// private Set<String> selectedEmbeddables; +// private Set<String> selectedDataMaps; +// +// private transient Object currentClass; +// +// public CodeGeneratorControllerBase(CayenneController parent, Collection<DataMap> dataMaps) { +// super(parent); +// +// this.dataMaps = dataMaps; +// this.classes = new ArrayList<>(); +// +// 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() { +// return classes; +// } +// +// public abstract Component getView(); +// +// public void validate(GeneratorController validator) { +// +// ValidationResult validationBuffer = new ValidationResult(); +// +// if (validator != null) { +// for (Object classObj : classes) { +// if (classObj instanceof ObjEntity) { +// validator.validateEntity( +// validationBuffer, +// (ObjEntity) classObj, +// false); +// } +// else if (classObj instanceof Embeddable) { +// validator.validateEmbeddable(validationBuffer, (Embeddable) classObj); +// } +// } +// +// } +// +// this.validation = validationBuffer; +// } +// +// public boolean updateSelection(Predicate<Object> predicate) { +// +// boolean modified = false; +// +// for (Object classObj : classes) { +// boolean select = predicate.test(classObj); +// if (classObj instanceof ObjEntity) { +// +// 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 (select) { +// if (selectedEmbeddables.add(((Embeddable) classObj).getClassName())) { +// modified = true; +// } +// } +// else { +// if (selectedEmbeddables +// .remove(((Embeddable) classObj).getClassName())) { +// 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; +// } +// } +// } +// } +// +// } +// +// if (modified) { +// firePropertyChange(SELECTED_PROPERTY, null, null); +// } +// +// return modified; +// } +// +// public List<Embeddable> getSelectedEmbeddables() { +// +// List<Embeddable> selected = new ArrayList<>(selectedEmbeddables.size()); +// +// for (Object classObj : classes) { +// if (classObj instanceof Embeddable +// && selectedEmbeddables.contains(((Embeddable) classObj) +// .getClassName())) { +// selected.add((Embeddable) classObj); +// } +// } +// +// return selected; +// } +// +// public List<ObjEntity> getSelectedEntities() { +// List<ObjEntity> selected = new ArrayList<>(selectedEntities.size()); +// for (Object classObj : classes) { +// if (classObj instanceof ObjEntity +// && selectedEntities.contains(((ObjEntity) classObj).getName())) { +// selected.add(((ObjEntity) classObj)); +// } +// } +// +// 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(); +// } +// +// public int getSelectedEmbeddablesSize() { +// 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. +// */ +// public String getProblem(Object obj) { +// +// String name = null; +// +// if (obj instanceof ObjEntity) { +// name = ((ObjEntity) obj).getName(); +// } +// else if (obj instanceof Embeddable) { +// name = ((Embeddable) obj).getClassName(); +// } +// +// if (validation == null) { +// return null; +// } +// +// List failures = validation.getFailures(name); +// if (failures.isEmpty()) { +// return null; +// } +// +// return ((ValidationFailure) failures.get(0)).getDescription(); +// } +// +// public boolean isSelected() { +// if (currentClass instanceof ObjEntity) { +// return selectedEntities +// .contains(((ObjEntity) currentClass).getName()); +// } +// if (currentClass instanceof Embeddable) { +// return selectedEmbeddables +// .contains(((Embeddable) currentClass).getClassName()); +// } +// if(currentClass instanceof DataMap) { +// return selectedDataMaps +// .contains(((DataMap) currentClass).getName()); +// } +// return false; +// +// } +// +// public void setSelected(boolean selectedFlag) { +// if (currentClass == null) { +// return; +// } +// if (currentClass instanceof ObjEntity) { +// if (selectedFlag) { +// if (selectedEntities.add(((ObjEntity) currentClass).getName())) { +// firePropertyChange(SELECTED_PROPERTY, null, null); +// } +// } +// else { +// if (selectedEntities.remove(((ObjEntity) currentClass).getName())) { +// firePropertyChange(SELECTED_PROPERTY, null, null); +// } +// } +// } +// if (currentClass instanceof Embeddable) { +// if (selectedFlag) { +// if (selectedEmbeddables.add(((Embeddable) currentClass).getClassName())) { +// firePropertyChange(SELECTED_PROPERTY, null, null); +// } +// } +// else { +// if (selectedEmbeddables +// .remove(((Embeddable) currentClass).getClassName())) { +// firePropertyChange(SELECTED_PROPERTY, null, null); +// } +// } +// } +// 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() { +// return currentClass; +// } +// +// public void setCurrentClass(Object currentClass) { +// this.currentClass = currentClass; +// } +// +// public Collection<DataMap> getDataMaps() { +// return dataMaps; +// } +// +// public JLabel getItemName(Object obj) { +// String className; +// Icon icon; +// if (obj instanceof Embeddable) { +// className = ((Embeddable) obj).getClassName(); +// icon = CellRenderers.iconForObject(new Embeddable()); +// } 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); +// labelIcon.setVisible(true); +// labelIcon.setText(className); +// return labelIcon; +// } +// +//} \ 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/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 2bb635f..c4f4bd1 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 @@ -1,99 +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.dialog.codegen; - -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.swing.components.TopBorder; - -import javax.swing.Box; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.ScrollPaneConstants; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.FlowLayout; - -/** - */ -public class CodeGeneratorDialog extends JDialog { - - private JButton generateButton; - protected JButton cancelButton; - private JLabel classesCount; - - CodeGeneratorDialog(Component generatorPanel, Component entitySelectorPanel) { - super(Application.getFrame()); - - 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(630, 500)); - - splitPane.setLeftComponent(entitySelectorPanel); - splitPane.setRightComponent(scrollPane); - - 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(cancelButton); - buttons.add(generateButton); - - Container contentPane = getContentPane(); - contentPane.setLayout(new BorderLayout()); - contentPane.add(splitPane, BorderLayout.CENTER); - contentPane.add(buttons, BorderLayout.SOUTH); - - setTitle("Code Generation"); - } - - public JButton getCancelButton() { - return cancelButton; - } - - public JButton getGenerateButton() { - return generateButton; - } - - public JLabel getClassesCount() { - return classesCount; - } -} \ 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 org.apache.cayenne.modeler.Application; +//import org.apache.cayenne.swing.components.TopBorder; +// +//import javax.swing.Box; +//import javax.swing.JButton; +//import javax.swing.JDialog; +//import javax.swing.JLabel; +//import javax.swing.JPanel; +//import javax.swing.JScrollPane; +//import javax.swing.JSplitPane; +//import javax.swing.ScrollPaneConstants; +//import java.awt.BorderLayout; +//import java.awt.Component; +//import java.awt.Container; +//import java.awt.Dimension; +//import java.awt.FlowLayout; +// +///** +// */ +//public class CodeGeneratorDialog extends JDialog { +// +// private JButton generateButton; +// protected JButton cancelButton; +// private JLabel classesCount; +// +// CodeGeneratorDialog(Component generatorPanel, Component entitySelectorPanel) { +// super(Application.getFrame()); +// +// 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(630, 500)); +// +// splitPane.setLeftComponent(entitySelectorPanel); +// splitPane.setRightComponent(scrollPane); +// +// 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(cancelButton); +// buttons.add(generateButton); +// +// Container contentPane = getContentPane(); +// contentPane.setLayout(new BorderLayout()); +// contentPane.add(splitPane, BorderLayout.CENTER); +// contentPane.add(buttons, BorderLayout.SOUTH); +// +// setTitle("Code Generation"); +// } +// +// public JButton getCancelButton() { +// return cancelButton; +// } +// +// public JButton getGenerateButton() { +// return generateButton; +// } +// +// public JLabel getClassesCount() { +// return classesCount; +// } +//} \ 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/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 bb87006..344bd72 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 @@ -1,235 +1,235 @@ -/***************************************************************** - * 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 org.apache.cayenne.gen.ClassGenerationAction; -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.modeler.CodeTemplateManager; -import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog; -import org.apache.cayenne.modeler.pref.DataMapDefaults; -import org.apache.cayenne.swing.BindingBuilder; -import org.apache.cayenne.swing.ObjectBinding; -import org.apache.cayenne.util.Util; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import java.awt.Component; -import java.util.List; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.TreeMap; - -import static org.apache.cayenne.modeler.CodeTemplateManager.SINGLE_SERVER_CLASS; -import static org.apache.cayenne.modeler.CodeTemplateManager.STANDARD_SERVER_SUBCLASS; -import static org.apache.cayenne.modeler.CodeTemplateManager.STANDARD_SERVER_SUPERCLASS; -import static org.apache.cayenne.modeler.dialog.pref.PreferenceDialog.TEMPLATES_KEY; - -/** - * A controller for the custom generation mode. - */ -public class CustomModeController extends GeneratorController { - - // correspond to non-public constants on MapClassGenerator. - private static final String MODE_ENTITY = "entity"; - - protected CustomModePanel view; - private CodeTemplateManager templateManager; - - private ObjectBinding superTemplate; - private ObjectBinding subTemplate; - - private CustomPreferencesUpdater preferencesUpdater; - - public CustomPreferencesUpdater getCustomPreferencesUpdater() { - return preferencesUpdater; - } - - public CustomModeController(CodeGeneratorControllerBase parent) { - super(parent); - - // bind preferences and init defaults... - - Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); - - for (Entry<DataMap, DataMapDefaults> entry : entities) { - - if (Util.isEmptyString(entry.getValue().getSuperclassTemplate())) { - entry.getValue().setSuperclassTemplate(STANDARD_SERVER_SUPERCLASS); - } - - if (Util.isEmptyString(entry.getValue().getSubclassTemplate())) { - entry.getValue().setSubclassTemplate(STANDARD_SERVER_SUBCLASS); - } - - if (Util.isEmptyString(entry.getValue().getProperty("mode"))) { - entry.getValue().setProperty("mode", MODE_ENTITY); - } - - if (Util.isEmptyString(entry.getValue().getProperty("overwrite"))) { - entry.getValue().setBooleanProperty("overwrite", false); - } - - if (Util.isEmptyString(entry.getValue().getProperty("pairs"))) { - entry.getValue().setBooleanProperty("pairs", true); - } - - if (Util.isEmptyString(entry.getValue().getProperty("usePackagePath"))) { - entry.getValue().setBooleanProperty("usePackagePath", true); - } - - if (Util.isEmptyString(entry.getValue().getProperty("outputPattern"))) { - entry.getValue().setProperty("outputPattern", "*.java"); - } - } - - BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this); - - builder.bindToAction(view.getManageTemplatesLink(), "popPreferencesAction()"); - - builder.bindToStateChange(view.getOverwrite(), "customPreferencesUpdater.overwrite").updateView(); - - builder.bindToStateChange(view.getPairs(), "customPreferencesUpdater.pairs").updateView(); - - builder.bindToStateChange(view.getUsePackagePath(), "customPreferencesUpdater.usePackagePath").updateView(); - - subTemplate = builder.bindToComboSelection(view.getSubclassTemplate(), - "customPreferencesUpdater.subclassTemplate"); - - superTemplate = builder.bindToComboSelection(view.getSuperclassTemplate(), - "customPreferencesUpdater.superclassTemplate"); - - builder.bindToTextField(view.getOutputPattern(), "customPreferencesUpdater.outputPattern").updateView(); - - builder.bindToStateChange(view.getCreatePropertyNames(), "customPreferencesUpdater.createPropertyNames") - .updateView(); - - builder.bindToStateChange(view.getCreatePKProperties(), "customPreferencesUpdater.createPKProperties") - .updateView(); - - updateTemplates(); - } - - protected void createDefaults() { - TreeMap<DataMap, DataMapDefaults> map = new TreeMap<DataMap, DataMapDefaults>(); - Collection<DataMap> dataMaps = getParentController().getDataMaps(); - for (DataMap dataMap : dataMaps) { - DataMapDefaults preferences; - preferences = getApplication().getFrameController().getProjectController() - .getDataMapPreferences(this.getClass().getName().replace(".", "/"), dataMap); - preferences.setSuperclassPackage(""); - preferences.updateSuperclassPackage(dataMap, false); - - map.put(dataMap, preferences); - - if (getOutputPath() == null) { - setOutputPath(preferences.getOutputPath()); - } - } - - setMapPreferences(map); - preferencesUpdater = new CustomPreferencesUpdater(map); - } - - protected GeneratorControllerPanel createView() { - this.view = new CustomModePanel(); - return view; - } - - private void updateTemplates() { - this.templateManager = getApplication().getCodeTemplateManager(); - - List<String> customTemplates = new ArrayList<>(templateManager.getCustomTemplates().keySet()); - Collections.sort(customTemplates); - - List<String> superTemplates = new ArrayList<>(templateManager.getStandardSuperclassTemplates()); - Collections.sort(superTemplates); - superTemplates.addAll(customTemplates); - - List<String> subTemplates = new ArrayList<>(templateManager.getStandardSubclassTemplates()); - Collections.sort(subTemplates); - subTemplates.addAll(customTemplates); - - this.view.getSubclassTemplate().setModel(new DefaultComboBoxModel<>(subTemplates.toArray(new String[0]))); - this.view.getSuperclassTemplate().setModel(new DefaultComboBoxModel<>(superTemplates.toArray(new String[0]))); - - JCheckBox pairs = this.view.getPairs(); - updateView(); - pairs.addItemListener(e -> updateView()); - - superTemplate.updateView(); - subTemplate.updateView(); - } - - private void updateView() { - boolean selected = view.getPairs().isSelected(); - JComboBox<String> subclassTemplate = view.getSubclassTemplate(); - subclassTemplate.setSelectedItem(selected ? STANDARD_SERVER_SUBCLASS : SINGLE_SERVER_CLASS); - view.getSuperclassTemplate().setEnabled(selected); - view.getOverwrite().setEnabled(!selected); - } - - public Component getView() { - return view; - } - - public Collection<ClassGenerationAction> createGenerator() { - - Collection<ClassGenerationAction> generators = super.createGenerator(); - - String superKey = Objects.requireNonNull(view.getSuperclassTemplate().getSelectedItem()).toString(); - String superTemplate = templateManager.getTemplatePath(superKey); - - String subKey = Objects.requireNonNull(view.getSubclassTemplate().getSelectedItem()).toString(); - String subTemplate = templateManager.getTemplatePath(subKey); - - for (ClassGenerationAction generator : generators) { - generator.setSuperTemplate(superTemplate); - generator.setTemplate(subTemplate); - generator.setOverwrite(view.getOverwrite().isSelected()); - generator.setUsePkgPath(view.getUsePackagePath().isSelected()); - generator.setMakePairs(view.getPairs().isSelected()); - generator.setCreatePropertyNames(view.getCreatePropertyNames().isSelected()); - generator.setCreatePKProperties(view.getCreatePKProperties().isSelected()); - - if (!Util.isEmptyString(view.getOutputPattern().getText())) { - generator.setOutputPattern(view.getOutputPattern().getText()); - } - } - - return generators; - } - - public void popPreferencesAction() { - new PreferenceDialog(getApplication().getFrameController()).startupAction(TEMPLATES_KEY); - updateTemplates(); - } - - @Override - protected ClassGenerationAction newGenerator() { - ClassGenerationAction action = new ClassGenerationAction(); - getApplication().getInjector().injectMembers(action); - return action; - } -} \ 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 org.apache.cayenne.gen.ClassGenerationAction; +//import org.apache.cayenne.map.DataMap; +//import org.apache.cayenne.modeler.CodeTemplateManager; +//import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog; +//import org.apache.cayenne.modeler.pref.DataMapDefaults; +//import org.apache.cayenne.swing.BindingBuilder; +//import org.apache.cayenne.swing.ObjectBinding; +//import org.apache.cayenne.util.Util; +// +//import javax.swing.DefaultComboBoxModel; +//import javax.swing.JCheckBox; +//import javax.swing.JComboBox; +//import java.awt.Component; +//import java.util.List; +//import java.util.ArrayList; +//import java.util.Collection; +//import java.util.Collections; +//import java.util.Map.Entry; +//import java.util.Objects; +//import java.util.Set; +//import java.util.TreeMap; +// +//import static org.apache.cayenne.modeler.CodeTemplateManager.SINGLE_SERVER_CLASS; +//import static org.apache.cayenne.modeler.CodeTemplateManager.STANDARD_SERVER_SUBCLASS; +//import static org.apache.cayenne.modeler.CodeTemplateManager.STANDARD_SERVER_SUPERCLASS; +//import static org.apache.cayenne.modeler.dialog.pref.PreferenceDialog.TEMPLATES_KEY; +// +///** +// * A controller for the custom generation mode. +// */ +//public class CustomModeController extends GeneratorController { +// +// // correspond to non-public constants on MapClassGenerator. +// private static final String MODE_ENTITY = "entity"; +// +// protected CustomModePanel view; +// private CodeTemplateManager templateManager; +// +// private ObjectBinding superTemplate; +// private ObjectBinding subTemplate; +// +// private CustomPreferencesUpdater preferencesUpdater; +// +// public CustomPreferencesUpdater getCustomPreferencesUpdater() { +// return preferencesUpdater; +// } +// +// public CustomModeController(CodeGeneratorControllerBase parent) { +// super(parent); +// +// // bind preferences and init defaults... +// +// Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet(); +// +// for (Entry<DataMap, DataMapDefaults> entry : entities) { +// +// if (Util.isEmptyString(entry.getValue().getSuperclassTemplate())) { +// entry.getValue().setSuperclassTemplate(STANDARD_SERVER_SUPERCLASS); +// } +// +// if (Util.isEmptyString(entry.getValue().getSubclassTemplate())) { +// entry.getValue().setSubclassTemplate(STANDARD_SERVER_SUBCLASS); +// } +// +// if (Util.isEmptyString(entry.getValue().getProperty("mode"))) { +// entry.getValue().setProperty("mode", MODE_ENTITY); +// } +// +// if (Util.isEmptyString(entry.getValue().getProperty("overwrite"))) { +// entry.getValue().setBooleanProperty("overwrite", false); +// } +// +// if (Util.isEmptyString(entry.getValue().getProperty("pairs"))) { +// entry.getValue().setBooleanProperty("pairs", true); +// } +// +// if (Util.isEmptyString(entry.getValue().getProperty("usePackagePath"))) { +// entry.getValue().setBooleanProperty("usePackagePath", true); +// } +// +// if (Util.isEmptyString(entry.getValue().getProperty("outputPattern"))) { +// entry.getValue().setProperty("outputPattern", "*.java"); +// } +// } +// +// BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this); +// +// builder.bindToAction(view.getManageTemplatesLink(), "popPreferencesAction()"); +// +// builder.bindToStateChange(view.getOverwrite(), "customPreferencesUpdater.overwrite").updateView(); +// +// builder.bindToStateChange(view.getPairs(), "customPreferencesUpdater.pairs").updateView(); +// +// builder.bindToStateChange(view.getUsePackagePath(), "customPreferencesUpdater.usePackagePath").updateView(); +// +// subTemplate = builder.bindToComboSelection(view.getSubclassTemplate(), +// "customPreferencesUpdater.subclassTemplate"); +// +// superTemplate = builder.bindToComboSelection(view.getSuperclassTemplate(), +// "customPreferencesUpdater.superclassTemplate"); +// +// builder.bindToTextField(view.getOutputPattern(), "customPreferencesUpdater.outputPattern").updateView(); +// +// builder.bindToStateChange(view.getCreatePropertyNames(), "customPreferencesUpdater.createPropertyNames") +// .updateView(); +// +// builder.bindToStateChange(view.getCreatePKProperties(), "customPreferencesUpdater.createPKProperties") +// .updateView(); +// +// updateTemplates(); +// } +// +// protected void createDefaults() { +// TreeMap<DataMap, DataMapDefaults> map = new TreeMap<DataMap, DataMapDefaults>(); +// Collection<DataMap> dataMaps = getParentController().getDataMaps(); +// for (DataMap dataMap : dataMaps) { +// DataMapDefaults preferences; +// preferences = getApplication().getFrameController().getProjectController() +// .getDataMapPreferences(this.getClass().getName().replace(".", "/"), dataMap); +// preferences.setSuperclassPackage(""); +// preferences.updateSuperclassPackage(dataMap, false); +// +// map.put(dataMap, preferences); +// +// if (getOutputPath() == null) { +// setOutputPath(preferences.getOutputPath()); +// } +// } +// +// setMapPreferences(map); +// preferencesUpdater = new CustomPreferencesUpdater(map); +// } +// +// protected GeneratorControllerPanel createView() { +// this.view = new CustomModePanel(); +// return view; +// } +// +// private void updateTemplates() { +// this.templateManager = getApplication().getCodeTemplateManager(); +// +// List<String> customTemplates = new ArrayList<>(templateManager.getCustomTemplates().keySet()); +// Collections.sort(customTemplates); +// +// List<String> superTemplates = new ArrayList<>(templateManager.getStandardSuperclassTemplates()); +// Collections.sort(superTemplates); +// superTemplates.addAll(customTemplates); +// +// List<String> subTemplates = new ArrayList<>(templateManager.getStandardSubclassTemplates()); +// Collections.sort(subTemplates); +// subTemplates.addAll(customTemplates); +// +// this.view.getSubclassTemplate().setModel(new DefaultComboBoxModel<>(subTemplates.toArray(new String[0]))); +// this.view.getSuperclassTemplate().setModel(new DefaultComboBoxModel<>(superTemplates.toArray(new String[0]))); +// +// JCheckBox pairs = this.view.getPairs(); +// updateView(); +// pairs.addItemListener(e -> updateView()); +// +// superTemplate.updateView(); +// subTemplate.updateView(); +// } +// +// private void updateView() { +// boolean selected = view.getPairs().isSelected(); +// JComboBox<String> subclassTemplate = view.getSubclassTemplate(); +// subclassTemplate.setSelectedItem(selected ? STANDARD_SERVER_SUBCLASS : SINGLE_SERVER_CLASS); +// view.getSuperclassTemplate().setEnabled(selected); +// view.getOverwrite().setEnabled(!selected); +// } +// +// public Component getView() { +// return view; +// } +// +// public Collection<ClassGenerationAction> createConfiguration() { +// +// Collection<ClassGenerationAction> generators = super.createConfiguration(); +// +// String superKey = Objects.requireNonNull(view.getSuperclassTemplate().getSelectedItem()).toString(); +// String superTemplate = templateManager.getTemplatePath(superKey); +// +// String subKey = Objects.requireNonNull(view.getSubclassTemplate().getSelectedItem()).toString(); +// String subTemplate = templateManager.getTemplatePath(subKey); +// +// for (ClassGenerationAction generator : generators) { +// generator.setSuperTemplate(superTemplate); +// generator.setTemplate(subTemplate); +// generator.setOverwrite(view.getOverwrite().isSelected()); +// generator.setUsePkgPath(view.getUsePackagePath().isSelected()); +// generator.setMakePairs(view.getPairs().isSelected()); +// generator.setCreatePropertyNames(view.getCreatePropertyNames().isSelected()); +// generator.setCreatePKProperties(view.getCreatePKProperties().isSelected()); +// +// if (!Util.isEmptyString(view.getOutputPattern().getText())) { +// generator.setOutputPattern(view.getOutputPattern().getText()); +// } +// } +// +// return generators; +// } +// +// public void popPreferencesAction() { +// new PreferenceDialog(getApplication().getFrameController()).startupAction(TEMPLATES_KEY); +// updateTemplates(); +// } +// +// @Override +// protected ClassGenerationAction newGenerator() { +// ClassGenerationAction action = new ClassGenerationAction(); +// getApplication().getInjector().injectMembers(action); +// return action; +// } +//} \ 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/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 406e1d2..6396abd 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 @@ -1,137 +1,137 @@ -/***************************************************************** - * 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.swing.control.ActionLink; - -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import javax.swing.JTextField; -import java.awt.BorderLayout; -import java.awt.FlowLayout; - -public class CustomModePanel extends GeneratorControllerPanel { - - private JComboBox<String> subclassTemplate; - private JComboBox<String> superclassTemplate; - protected JCheckBox pairs; - private JCheckBox overwrite; - private JCheckBox usePackagePath; - private JTextField outputPattern; - private JCheckBox createPropertyNames; - private JCheckBox createPKProperties; - - private ActionLink manageTemplatesLink; - - CustomModePanel() { - - this.superclassTemplate = new JComboBox<>(); - this.subclassTemplate = new JComboBox<>(); - this.pairs = new JCheckBox(); - this.overwrite = new JCheckBox(); - this.usePackagePath = new JCheckBox(); - this.outputPattern = new JTextField(); - this.createPropertyNames = new JCheckBox(); - this.createPKProperties = new JCheckBox(); - this.manageTemplatesLink = new ActionLink("Customize Templates..."); - manageTemplatesLink.setFont(manageTemplatesLink.getFont().deriveFont(10f)); - - // assemble - FormLayout layout = new FormLayout( - "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("Subclass Template:", subclassTemplate); - builder.nextLine(); - - builder.append("Superclass Template:", superclassTemplate); - builder.nextLine(); - - builder.append("Output Pattern:", outputPattern); - builder.nextLine(); - - builder.append("Make Pairs:", pairs); - builder.nextLine(); - - builder.append("Use Package Path:", usePackagePath); - builder.nextLine(); - - builder.append("Overwrite Subclasses:", overwrite); - builder.nextLine(); - - builder.append("Create Property Names:", createPropertyNames); - builder.nextLine(); - - builder.append("Create PK Properties:", createPKProperties); - builder.nextLine(); - - setLayout(new BorderLayout()); - add(builder.getPanel(), BorderLayout.CENTER); - - JPanel links = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - links.add(manageTemplatesLink); - add(links, BorderLayout.SOUTH); - - add(builder.getPanel(), BorderLayout.CENTER); - } - - public ActionLink getManageTemplatesLink() { - return manageTemplatesLink; - } - - public JComboBox<String> getSubclassTemplate() { - return subclassTemplate; - } - - public JComboBox<String> getSuperclassTemplate() { - return superclassTemplate; - } - - public JCheckBox getOverwrite() { - return overwrite; - } - - public JCheckBox getPairs() { - return pairs; - } - - public JCheckBox getUsePackagePath() { - return usePackagePath; - } - - public JTextField getOutputPattern() { - return outputPattern; - } - - public JCheckBox getCreatePropertyNames() { - return createPropertyNames; - } - - public JCheckBox getCreatePKProperties() { - return createPKProperties; - } -} \ 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.swing.control.ActionLink; +// +//import javax.swing.JCheckBox; +//import javax.swing.JComboBox; +//import javax.swing.JPanel; +//import javax.swing.JTextField; +//import java.awt.BorderLayout; +//import java.awt.FlowLayout; +// +//public class CustomModePanel extends GeneratorControllerPanel { +// +// private JComboBox<String> subclassTemplate; +// private JComboBox<String> superclassTemplate; +// protected JCheckBox pairs; +// private JCheckBox overwrite; +// private JCheckBox usePackagePath; +// private JTextField outputPattern; +// private JCheckBox createPropertyNames; +// private JCheckBox createPKProperties; +// +// private ActionLink manageTemplatesLink; +// +// CustomModePanel() { +// +// this.superclassTemplate = new JComboBox<>(); +// this.subclassTemplate = new JComboBox<>(); +// this.pairs = new JCheckBox(); +// this.overwrite = new JCheckBox(); +// this.usePackagePath = new JCheckBox(); +// this.outputPattern = new JTextField(); +// this.createPropertyNames = new JCheckBox(); +// this.createPKProperties = new JCheckBox(); +// this.manageTemplatesLink = new ActionLink("Customize Templates..."); +// manageTemplatesLink.setFont(manageTemplatesLink.getFont().deriveFont(10f)); +// +// // assemble +// FormLayout layout = new FormLayout( +// "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("Subclass Template:", subclassTemplate); +// builder.nextLine(); +// +// builder.append("Superclass Template:", superclassTemplate); +// builder.nextLine(); +// +// builder.append("Output Pattern:", outputPattern); +// builder.nextLine(); +// +// builder.append("Make Pairs:", pairs); +// builder.nextLine(); +// +// builder.append("Use Package Path:", usePackagePath); +// builder.nextLine(); +// +// builder.append("Overwrite Subclasses:", overwrite); +// builder.nextLine(); +// +// builder.append("Create Property Names:", createPropertyNames); +// builder.nextLine(); +// +// builder.append("Create PK Properties:", createPKProperties); +// builder.nextLine(); +// +// setLayout(new BorderLayout()); +// add(builder.getPanel(), BorderLayout.CENTER); +// +// JPanel links = new JPanel(new FlowLayout(FlowLayout.RIGHT)); +// links.add(manageTemplatesLink); +// add(links, BorderLayout.SOUTH); +// +// add(builder.getPanel(), BorderLayout.CENTER); +// } +// +// public ActionLink getManageTemplatesLink() { +// return manageTemplatesLink; +// } +// +// public JComboBox<String> getSubclassTemplate() { +// return subclassTemplate; +// } +// +// public JComboBox<String> getSuperclassTemplate() { +// return superclassTemplate; +// } +// +// public JCheckBox getOverwrite() { +// return overwrite; +// } +// +// public JCheckBox getPairs() { +// return pairs; +// } +// +// public JCheckBox getUsePackagePath() { +// return usePackagePath; +// } +// +// public JTextField getOutputPattern() { +// return outputPattern; +// } +// +// public JCheckBox getCreatePropertyNames() { +// return createPropertyNames; +// } +// +// public JCheckBox getCreatePKProperties() { +// return createPKProperties; +// } +//} \ No newline at end of file