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

    
Pops up a dialog and blocks current thread until the dialog is closed.
    public FSPath startupAction() {
        // this should handle closing via ESC
         = true;
        .setModal(true);
        .pack();
        .setResizable(false);
        makeCloseableOnEscape();
        centerView();
        .setVisible(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