use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class SetPrimaryKeyToModel method execute.
@Override
public void execute(MergerContext mergerContext) {
DbEntity e = getEntity();
for (DbAttribute attr : e.getAttributes()) {
boolean wasPrimaryKey = attr.isPrimaryKey();
boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr.getName().toUpperCase());
if (wasPrimaryKey != willBePrimaryKey) {
attr.setPrimaryKey(willBePrimaryKey);
e.dbAttributeChanged(new AttributeEvent(this, attr, e));
mergerContext.getDelegate().dbAttributeModified(attr);
}
}
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class ObjAttributeTableModel method setObjAttributeType.
private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
String oldType = attribute.getType();
String newType = value != null ? value.toString() : null;
attribute.setType(newType);
if (oldType == null || newType == null) {
return;
}
String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
return;
}
ObjEntity entity = attribute.getEntity();
ObjAttribute attributeNew;
if (registeredTypesList.contains(newType) || !mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
attributeNew = new ObjAttribute();
attributeNew.setDbAttributePath(attribute.getDbAttributePath());
} else {
attributeNew = new EmbeddedAttribute();
attributeNew.setDbAttributePath(null);
}
attributeNew.setName(attribute.getName());
attributeNew.setEntity(entity);
attributeNew.setParent(attribute.getParent());
attributeNew.setType(attribute.getType());
attributeNew.setUsedForLocking(attribute.isUsedForLocking());
entity.updateAttribute(attributeNew);
mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeNew, entity, MapEvent.CHANGE));
mediator.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(this, attributeNew, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbAttributeTableModel method setUpdatedValueAt.
public void setUpdatedValueAt(Object newVal, int row, int col) {
DbAttribute attr = getAttribute(row);
if (attr == null) {
return;
}
AttributeEvent e = new AttributeEvent(eventSource, attr, entity);
switch(col) {
case DB_ATTRIBUTE_NAME:
e.setOldName(attr.getName());
attr.setName((String) newVal);
attr.getEntity().dbAttributeChanged(e);
fireTableCellUpdated(row, col);
break;
case DB_ATTRIBUTE_TYPE:
setAttributeType((String) newVal, attr);
break;
case DB_ATTRIBUTE_PRIMARY_KEY:
if (!setPrimaryKey(((Boolean) newVal), attr, row)) {
return;
}
break;
case DB_ATTRIBUTE_SCALE:
setScale((String) newVal, attr);
break;
case DB_ATTRIBUTE_MANDATORY:
setMandatory((Boolean) newVal, attr);
break;
case DB_ATTRIBUTE_MAX:
setMaxLength((String) newVal, attr);
break;
case DB_ATTRIBUTE_COMMENT:
setComment((String) newVal, attr);
break;
}
mediator.fireDbAttributeEvent(e);
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class CreateAttributeAction method fireDbAttributeEvent.
/**
* Fires events when a db attribute was added
*/
static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity, DbAttribute attr) {
mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD));
AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map, (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireDbAttributeDisplayEvent(ade);
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class RemoveAction method removeDbAttributes.
private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) {
if (dbAttrs != null && dbAttrs.length > 0) {
if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
DbEntity entity = mediator.getCurrentDbEntity();
application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
for (DbAttribute attrib : dbAttrs) {
entity.removeAttribute(attrib.getName());
AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
mediator.fireDbAttributeEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
}
}
Aggregations