use of org.apache.cayenne.map.DbAttribute 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 org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class PKDBGeneratorPanel method onInitInternal.
protected void onInitInternal(DbEntity entity) {
resetStrategy(entity, true, false);
Collection pkAttributes = entity.getPrimaryKeys();
// by default check the only numeric PK
if (pkAttributes.size() == 1) {
DbAttribute pk = (DbAttribute) pkAttributes.iterator().next();
if (TypesMapping.isNumeric(pk.getType()) && !pk.isGenerated()) {
pk.setGenerated(true);
mediator.fireDbEntityEvent(new EntityEvent(this, entity));
}
}
updateView(entity);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class PKGeneratorPanel method resetStrategy.
protected void resetStrategy(DbEntity entity, boolean resetCustomSequence, boolean resetDBGenerated) {
boolean hasChanges = false;
if (resetCustomSequence && entity.getPrimaryKeyGenerator() != null) {
entity.setPrimaryKeyGenerator(null);
hasChanges = true;
}
if (resetDBGenerated) {
for (DbAttribute a : entity.getPrimaryKeys()) {
if (a.isGenerated()) {
a.setGenerated(false);
hasChanges = true;
}
}
}
if (hasChanges) {
mediator.fireDbEntityEvent(new EntityEvent(this, entity));
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class FindAction method searchInDbEntities.
private void searchInDbEntities(Pattern pattern, List<SearchResultEntry> result, DataMap dataMap) {
for (DbEntity ent : dataMap.getDbEntities()) {
if (match(ent.getName(), pattern)) {
result.add(new SearchResultEntry(ent, ent.getName()));
}
for (DbAttribute attr : ent.getAttributes()) {
if (match(attr.getName(), pattern)) {
result.add(new SearchResultEntry(attr, ent.getName() + "." + attr.getName()));
}
}
for (DbRelationship rel : ent.getRelationships()) {
if (match(rel.getName(), pattern)) {
result.add(new SearchResultEntry(rel, ent.getName() + "." + rel.getName()));
}
}
checkCatalogOrSchema(pattern, result, ent, ent.getCatalog());
checkCatalogOrSchema(pattern, result, ent, ent.getSchema());
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class FindAction method jumpToAttributeResult.
private static void jumpToAttributeResult(SearchResultEntry searchResultEntry, EditorView editor, DataChannelDescriptor domain) {
DataMap map;
Entity entity;
if (searchResultEntry.getObject() instanceof Attribute) {
map = ((Attribute) searchResultEntry.getObject()).getEntity().getDataMap();
entity = ((Attribute) searchResultEntry.getObject()).getEntity();
} else {
map = ((Relationship) searchResultEntry.getObject()).getSourceEntity().getDataMap();
entity = ((Relationship) searchResultEntry.getObject()).getSourceEntity();
}
buildAndSelectTreePath(map, entity, editor);
if (searchResultEntry.getObject() instanceof Attribute) {
AttributeDisplayEvent event = new AttributeDisplayEvent(editor.getProjectTreeView(), (Attribute) searchResultEntry.getObject(), entity, map, domain);
event.setMainTabFocus(true);
if (searchResultEntry.getObject() instanceof DbAttribute) {
editor.getDbDetailView().currentDbAttributeChanged(event);
} else {
editor.getObjDetailView().currentObjAttributeChanged(event);
}
} else if (searchResultEntry.getObject() instanceof Relationship) {
RelationshipDisplayEvent event = new RelationshipDisplayEvent(editor.getProjectTreeView(), (Relationship) searchResultEntry.getObject(), entity, map, domain);
event.setMainTabFocus(true);
if (searchResultEntry.getObject() instanceof DbRelationship) {
editor.getDbDetailView().currentDbRelationshipChanged(event);
} else {
editor.getObjDetailView().currentObjRelationshipChanged(event);
}
}
}
Aggregations