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 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.pref;
 import java.util.Set;
 public class TemplateCreator extends CayenneController {
     protected TemplateCreatorView view;
     protected boolean canceled;
     protected Set existingNames;
     protected PreferenceEditor editor;
     protected Domain domain;
     public TemplateCreator(TemplatePreferences parent) {
         JDialog parentDialog = (JDialog) SwingUtilities.getAncestorOfClass(
         this. = new TemplateCreatorView(parentDialog);
         this. = new HashSet();
         this. = parent.getEditor();
         this. = parent.getTemplateDomain();
         Iterator it = parent.getTemplateEntries().iterator();
         while (it.hasNext()) {
             FSPath path = (;
     public Component getView() {
         return ;
         // find start directory in preferences
         FSPath path = (FSPathgetViewDomain().getDetail(
         if (path.getPath() == null) {
         return path;
     protected void initBindings() {
         BindingBuilder builder = new BindingBuilder(
         builder.bindToAction(.getCancelButton(), "cancelAction()");
         builder.bindToAction(.getOkButton(), "okAction()");
         final FSPath path = getLastTemplateDirectory();
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        File directory = .getTemplateChooser().getCurrentDirectory();
    public void okAction() {
        String templateName = .getTemplateName().getText();
        if (Util.isEmptyString(templateName)) {
                    "Enter Template Name",
        else if (.contains(templateName)) {
                    "'" + templateName + "' is already taken, enter a different name",
        else if (.getTemplateChooser().getFile() == null) {
                    "Must select an existing template file",
        else {
             = false;
    public void cancelAction() {
         = true;

Pops up a dialog and blocks current thread until the dialog is closed.
    public FSPath startupAction() {
        // this should handle closing via ESC
         = true;
        return createTemplate();
    protected FSPath createTemplate() {
        if () {
            return null;
        String key = .getTemplateName().getText();
        File file = .getTemplateChooser().getFile();
        FSPath path = (FSPath.createDetail(keyFSPath.class);
        path.setPath(file != null ? file.getAbsolutePath() : null);
        return path;
New to GrepCode? Check out our FAQ X