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();
}
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);
}
}
}
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");
}
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();
}
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);
}
Aggregations