Search in sources :

Example 31 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project cayenne by apache.

the class MainDataNodeEditor method refreshLocalDataSources.

protected void refreshLocalDataSources() {
    localDataSources.clear();
    Map sources = getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).getChildrenPreferences();
    int len = sources.size();
    Object[] keys = new Object[len + 1];
    // a slight chance that a real datasource is called
    // NO_LOCAL_DATA_SOURCE...
    keys[0] = NO_LOCAL_DATA_SOURCE;
    Object[] dataSources = sources.keySet().toArray();
    localDataSources.add(dataSources);
    for (int i = 0; i < dataSources.length; i++) {
        keys[i + 1] = dataSources[i];
    }
    view.getLocalDataSources().setModel(new DefaultComboBoxModel(keys));
    localDataSourceBinding.updateView();
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) HashMap(java.util.HashMap) Map(java.util.Map) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 32 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project cayenne by apache.

the class DataSourcePreferences method duplicateDataSourceAction.

/**
 * Shows a dialog to duplicate an existing local DataSource configuration.
 */
public void duplicateDataSourceAction() {
    Object selected = view.getDataSources().getSelectedItem();
    if (selected != null) {
        DataSourceDuplicator wizard = new DataSourceDuplicator(this, selected.toString());
        DBConnectionInfo dataSource = wizard.startupAction();
        if (dataSource != null) {
            dataSourcePreferences.create(wizard.getName(), dataSource);
            dataSources = dataSourcePreferences.getChildrenPreferences();
            Object[] keys = dataSources.keySet().toArray();
            Arrays.sort(keys);
            view.getDataSources().setModel(new DefaultComboBoxModel(keys));
            view.getDataSources().setSelectedItem(wizard.getName());
            editDataSourceAction();
            fireEvent(wizard.getName(), MapEvent.ADD);
        }
    }
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 33 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project cayenne by apache.

the class EncodingSelector method initBindings.

protected void initBindings() {
    // init static models...
    this.systemEncoding = detectPlatformEncoding();
    Vector allEncodings = supportedEncodings(systemEncoding);
    view.getEncodingChoices().setModel(new DefaultComboBoxModel(allEncodings));
    view.getDefaultEncodingLabel().setText("Default (" + systemEncoding + ")");
    view.getDefaultEncoding().setSelected(true);
    // create bindings...
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    this.defaultEncodingBinding = builder.bindToStateChange(view.getDefaultEncoding(), "defaultEncoding");
    this.otherEncodingBinding = builder.bindToStateChange(view.getOtherEncoding(), "otherEncoding");
    this.selectedEncodingBinding = builder.bindToComboSelection(view.getEncodingChoices(), "encoding");
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Vector(java.util.Vector)

Example 34 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project cayenne by apache.

the class PKDBGeneratorPanel method updateView.

void updateView(final DbEntity entity) {
    for (ItemListener listener : attributes.getItemListeners()) {
        attributes.removeItemListener(listener);
    }
    Collection<DbAttribute> pkAttributes = entity.getPrimaryKeys();
    if (pkAttributes.isEmpty()) {
        attributes.removeAllItems();
        attributes.addItem("<Entity has no PK columns>");
        attributes.setSelectedIndex(0);
        attributes.setEnabled(false);
    } else {
        attributes.setEnabled(true);
        MutableComboBoxModel model = new DefaultComboBoxModel(pkAttributes.toArray());
        String noSelection = "<Select Generated Column>";
        model.insertElementAt(noSelection, 0);
        model.setSelectedItem(noSelection);
        attributes.setModel(model);
        for (DbAttribute a : pkAttributes) {
            if (a.isGenerated()) {
                model.setSelectedItem(a);
                break;
            }
        }
        // listen for selection changes of the new entity
        attributes.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                Object item = e.getItem();
                if (item instanceof DbAttribute) {
                    boolean generated = e.getStateChange() == ItemEvent.SELECTED;
                    DbAttribute a = (DbAttribute) item;
                    if (a.isGenerated() != generated) {
                        a.setGenerated(generated);
                        mediator.fireDbEntityEvent(new EntityEvent(this, entity));
                    }
                }
            }
        });
    }
    // revalidate as children layout has changed...
    revalidate();
}
Also used : ItemEvent(java.awt.event.ItemEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbAttribute(org.apache.cayenne.map.DbAttribute) MutableComboBoxModel(javax.swing.MutableComboBoxModel) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 35 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project cayenne by apache.

the class InferRelationshipsController method strategyComboAction.

public void strategyComboAction() {
    try {
        String strategyClass = (String) view.getStrategyCombo().getSelectedItem();
        this.strategy = createNamingStrategy(strategyClass);
        /**
         * Be user-friendly and update preferences with specified strategy
         */
        if (strategy == null) {
            return;
        }
        NameGeneratorPreferences.getInstance().addToLastUsedStrategies(strategyClass);
        view.getStrategyCombo().setModel(new DefaultComboBoxModel(NameGeneratorPreferences.getInstance().getLastUsedStrategies()));
    } catch (Throwable th) {
        logObj.error("Error in " + getClass().getName(), th);
        return;
    }
    setNamingStrategy(strategy);
    createNames();
    entitySelector.initBindings();
    view.setChoice(SELECT);
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Aggregations

DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)119 JComboBox (javax.swing.JComboBox)22 JPanel (javax.swing.JPanel)21 JLabel (javax.swing.JLabel)17 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 JButton (javax.swing.JButton)15 Insets (java.awt.Insets)14 GridBagConstraints (java.awt.GridBagConstraints)13 GridBagLayout (java.awt.GridBagLayout)12 Dimension (java.awt.Dimension)11 JTextField (javax.swing.JTextField)11 JCheckBox (javax.swing.JCheckBox)10 JScrollPane (javax.swing.JScrollPane)10 ArrayList (java.util.ArrayList)9 Vector (java.util.Vector)9 JList (javax.swing.JList)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 BorderLayout (java.awt.BorderLayout)8 ItemEvent (java.awt.event.ItemEvent)8