Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 java.util.List;
 import java.util.Map;
 
 
 import  org.apache.cayenne.util.Util;

A controller for the custom generation mode.
 
 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<StringStringmodesByLabel = new HashMap<StringString>();
     static {
     }
 
     protected CustomModePanel view;
     protected CodeTemplateManager templateManager;
 
     protected ObjectBinding superTemplate;
     protected ObjectBinding subTemplate;
 
         super(parent);
 
         Object[] modeChoices = new Object[] {
                 
         };
         .getGenerationMode().setModel(new DefaultComboBoxModel(modeChoices));
 
         Object[] versionChoices = new Object[] {
                 ..
         };
         .getGeneratorVersion().setModel(new DefaultComboBoxModel(versionChoices));
 
         // bind preferences and init defaults...
 
         if (Util.isEmptyString(.getSuperclassTemplate())) {
             
                     .setSuperclassTemplate(.);
         }
 
         if (Util.isEmptyString(.getSubclassTemplate())) {
         }
 
         if (Util.isEmptyString(.getProperty("mode"))) {
             .setProperty("mode");
         }
 
         if (Util.isEmptyString(.getProperty("version"))) {
             .setProperty("version".);
         }
        if (Util.isEmptyString(.getProperty("overwrite"))) {
            .setBooleanProperty("overwrite"false);
        }
        if (Util.isEmptyString(.getProperty("pairs"))) {
            .setBooleanProperty("pairs"true);
        }
        if (Util.isEmptyString(.getProperty("usePackagePath"))) {
            .setBooleanProperty("usePackagePath"true);
        }
        if (Util.isEmptyString(.getProperty("outputPattern"))) {
            .setProperty("outputPattern""*.java");
        }
        BindingBuilder builder = new BindingBuilder(
                getApplication().getBindingFactory(),
                this);
        builder.bindToAction(.getManageTemplatesLink(), "popPreferencesAction()");
        builder.bindToTextField(
                .getSuperclassPackage(),
                "preferences.superclassPackage").updateView();
        builder.bindToComboSelection(
                .getGenerationMode(),
                "preferences.property['mode']").updateView();
        builder.bindToComboSelection(
                .getGeneratorVersion(),
                "preferences.property['version']").updateView();
        builder.bindToStateChange(
                .getOverwrite(),
                "preferences.booleanProperty['overwrite']").updateView();
        builder
                .bindToStateChange(
                        .getPairs(),
                        "preferences.booleanProperty['pairs']")
                .updateView();
        builder.bindToStateChange(
                .getUsePackagePath(),
                "preferences.booleanProperty['usePackagePath']").updateView();
         = builder.bindToComboSelection(
                .getSubclassTemplate(),
                "preferences.subclassTemplate");
         = builder.bindToComboSelection(
                .getSuperclassTemplate(),
                "preferences.superclassTemplate");
        builder.bindToTextField(
                .getOutputPattern(),
                "preferences.property['outputPattern']").updateView();
        updateTemplates();
    }
    protected DataMapDefaults createDefaults() {
        DataMapDefaults prefs = getApplication()
                .getFrameController()
                .getProjectController()
                .getDataMapPreferences("__custom");
        prefs.updateSuperclassPackage(getParentController().getDataMap(), false);
        this. = prefs;
        return prefs;
    }
    protected void updateTemplates() {
        List<StringcustomTemplates = new ArrayList<String>(
                .getCustomTemplates()
                .keySet());
        Collections.sort(customTemplates);
        List<StringsuperTemplates = new ArrayList<String>(
                .getStandardSuperclassTemplates());
        Collections.sort(superTemplates);
        superTemplates.addAll(customTemplates);
        List<StringsubTemplates = new ArrayList<String>(
                .getStandardSubclassTemplates());
        Collections.sort(subTemplates);
        subTemplates.addAll(customTemplates);
        this..getSubclassTemplate().setModel(
                new DefaultComboBoxModel(subTemplates.toArray()));
        this..getSuperclassTemplate().setModel(
                new DefaultComboBoxModel(superTemplates.toArray()));
        .updateView();
        .updateView();
    }
    protected GeneratorControllerPanel createView() {
        this. = new CustomModePanel();
        return ;
    }
    public Component getView() {
        return ;
    }
    private String getVersion() {
        return (String.getGeneratorVersion().getSelectedItem();
    }
    @Override
    protected ClassGenerationAction newGenerator() {
        return ..equals(getVersion())
                ? new ClassGenerationAction1_1()
                : new ClassGenerationAction();
    }
         = 
                .get(.getGenerationMode().getSelectedItem())
                .toString();
        
        ClassGenerationAction generator = super.createGenerator();
        String version = getVersion();
        String superKey = .getSuperclassTemplate().getSelectedItem().toString();
        String superTemplate = .getTemplatePath(superKeyversion);
        generator.setSuperTemplate(superTemplate);
        String subKey = .getSubclassTemplate().getSelectedItem().toString();
        String subTemplate = .getTemplatePath(subKeyversion);
        generator.setTemplate(subTemplate);
        generator.setOverwrite(.getOverwrite().isSelected());
        generator.setUsePkgPath(.getUsePackagePath().isSelected());
        generator.setMakePairs(.getPairs().isSelected());
        if (!Util.isEmptyString(.getOutputPattern().getText())) {
            generator.setOutputPattern(.getOutputPattern().getText());
        }
        return generator;
    }
    public void popPreferencesAction() {
                .startupAction(.);
        updateTemplates();
    }
New to GrepCode? Check out our FAQ X