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.gen.ClassGenerator;
 import  org.apache.cayenne.gen.DefaultClassGenerator;
 import  org.apache.cayenne.util.Util;

A controller for the custom generation mode.

Author(s):
Andrus Adamchik
 
 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 DATA_MAP_MODE_LABEL = "One run per DataMap";
     static final String ENTITY_MODE_LABEL = "One run per each selected Entity";
 
     static final Map modesByLabel = new HashMap();
     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[] {
                 ClassGenerator.VERSION_1_1, ClassGenerator.VERSION_1_2
         };
         .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", ClassGenerator.VERSION_1_1);
         }
 
         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 customTemplates = new ArrayList(
                .getCustomTemplates()
                .keySet());
        Collections.sort(customTemplates);
        List superTemplates = new ArrayList(
                .getStandardSuperclassTemplates()
                .keySet());
        Collections.sort(superTemplates);
        superTemplates.addAll(customTemplates);
        List subTemplates = new ArrayList(
                .getStandardSubclassTemplates()
                .keySet());
        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 ;
    }
    public DefaultClassGenerator createGenerator() {
        DefaultClassGenerator generator = super.createGenerator();
        String mode = 
                .get(.getGenerationMode().getSelectedItem())
                .toString();
        generator.setMode(mode);
        String superKey = .getSuperclassTemplate().getSelectedItem().toString();
        String superTemplate = .getTemplatePath(superKey);
        generator.setSuperTemplate(superTemplate);
        String subKey = .getSubclassTemplate().getSelectedItem().toString();
        String subTemplate = .getTemplatePath(subKey);
        generator.setTemplate(subTemplate);
        if (.getGeneratorVersion().getSelectedItem() != null) {
            generator.setVersionString(
                    .getGeneratorVersion()
                    .getSelectedItem()
                    .toString());
        }
        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