use of javax.swing.MutableComboBoxModel 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();
}
Aggregations