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.db;
 
 
 
 import  org.apache.cayenne.access.DbLoader;
 import  org.apache.cayenne.map.naming.NamingStrategy;
 
 import  com.jgoodies.forms.builder.DefaultFormBuilder;
 import  com.jgoodies.forms.layout.FormLayout;

Dialog for selecting database reverse-engineering parameters.
 
 public class DbLoaderOptionsDialog extends CayenneDialog {
     private static final Log logObj = LogFactory.getLog(DbLoaderOptionsDialog.class);
 
     public static final int CANCEL = 0;
     public static final int SELECT = 1;
 
     protected JLabel schemaLabel;
     protected JComboBox schemaSelector;
     protected JTextField tableNamePatternField;
     protected JCheckBox loadProcedures;
     protected JCheckBox meaningfulPk;
     protected JTextField procNamePatternField;
     protected JLabel procedureLabel;
     protected JButton selectButton;
     protected JButton cancelButton;
    
    
Combobox for naming strategy
 
     protected JComboBox strategyCombo;
     
     protected NamingStrategy strategy;
     
     protected int choice;

    
Creates and initializes new ChooseSchemaDialog.
 
     public DbLoaderOptionsDialog(Collection schemasString dbUserName,
             boolean loadProcedures) {
         super(Application.getFrame(), "Reengineer DB Schema: Select Options");
 
         init();
         initController();
         initFromModel(schemasdbUserNameloadProcedures);
 
         pack();
         setModal(true);
         centerWindow();
     }

    
Sets up the graphical components.
 
     protected void init() {
        // create widgets...
         = new JButton("Continue");
         = new JButton("Cancel");
         = new JComboBox();
         = new JTextField();
         = new JTextField();
         = new JCheckBox();
         = new JCheckBox(); 
         = new JComboBox();
        .setEditable(true);
        // assemble
        FormLayout layout = new FormLayout(
                "right:pref, 3dlu, fill:max(170dlu;pref):grow",
                "");
        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
        builder.setDefaultDialogBorder();
         = builder.append("Select Schema:");
        builder.append("Table Name Pattern:");
        builder.append("Load Procedures:");
         = builder.append("Procedure Name Pattern:");
        builder.append("Naming Strategy:");
        builder.append("Meaningful PK",);
        
        JPanel buttons = new JPanel(new FlowLayout(.));
        buttons.add();
        buttons.add();
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(builder.getPanel(), .);
        getContentPane().add(buttons.);
    }
    protected void initController() {
            public void actionPerformed(ActionEvent e) {
                processSelect();
            }
        });
            public void actionPerformed(ActionEvent e) {
                processCancel();
            }
        });
            public void stateChanged(ChangeEvent e) {
                .setEnabled(.isSelected());
                .setEnabled(.isSelected());
            }
        });
    }
    protected void initFromModel(
            Collection<Stringschemas,
            String dbUserName,
            boolean shouldLoadProcedures) {
        this. = ;
        this..setText(DbLoader.WILDCARD);
        this..setSelected(shouldLoadProcedures);
        this..setText(DbLoader.WILDCARD);
        this..setEnabled(shouldLoadProcedures);
        this..setEnabled(shouldLoadProcedures);
        
        Vector<Stringarr = NamingStrategyPreferences.getInstance().getLastUsedStrategies();
        .setModel(new DefaultComboBoxModel(arr));
        boolean showSchemaSelector = schemas != null && !schemas.isEmpty();
        .setVisible(showSchemaSelector);
        .setVisible(showSchemaSelector);
        if (showSchemaSelector) {
            .setModel(new DefaultComboBoxModel(schemas.toArray()));
            // select schema belonging to the user
            if (dbUserName != null) {
                for (String schema : schemas) {
                    if (dbUserName.equalsIgnoreCase(schema)) {
                        .setSelectedItem(schema);
                        break;
                    }
                }
            }
        }
    }
    public int getChoice() {
        return ;
    }
    private void processSelect() {
        try {
            ClassLoadingService classLoader = Application.getInstance().getClassLoadingService();
            String strategyClass = (String.getSelectedItem();
            
            this. = (NamingStrategy) classLoader.loadClass(strategyClass).newInstance();
            
            
Be user-friendly and update preferences with specified strategy
            NamingStrategyPreferences.getInstance().addToLastUsedStrategies(strategyClass);
        }
        catch (Throwable th) {
            .error("Error in " + getClass().getName(), th);
     
            JOptionPane.showMessageDialog(this,
                    "Naming Strategy Initialization Error: " + th.getMessage(),
                    "Naming Strategy Initialization Error",
                    .);
                    
            return;
        }
        
         = ;
        setVisible(false);
    }
    private void processCancel() {
         = ;
        setVisible(false);
    }

    
Returns selected schema.
    public String getSelectedSchema() {
        String schema = (String.getSelectedItem();
        return "".equals(schema) ? null : schema;
    }

    
Returns the tableNamePattern.
    public String getTableNamePattern() {
        return "".equals(.getText()) ? null : 
                .getText();
    }
    public boolean isLoadingProcedures() {
        return .isSelected();
    }
    
    public boolean isMeaningfulPk() {
        return .isSelected();
    }

    
Returns the procedure name pattern.
    public String getProcedureNamePattern() {
        return "".equals(.getText()) ? null : 
                .getText();
    }
    
    
Returns configured naming strategy
    public NamingStrategy getNamingStrategy() {
        return ;
    }
New to GrepCode? Check out our FAQ X