use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbEntity method clearAttributes.
@Override
public void clearAttributes() {
super.clearAttributes();
// post dummy event for no specific attribute
this.dbAttributeRemoved(new AttributeEvent(this, null, this, MapEvent.REMOVE));
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class LockingUpdateController method updateAction.
public void updateAction() {
int defaultLockType = dataMap.getDefaultLockType();
boolean on = defaultLockType == ObjEntity.LOCK_TYPE_OPTIMISTIC;
boolean updateEntities = view.getEntities().isSelected();
boolean updateAttributes = view.getAttributes().isSelected();
boolean updateRelationships = view.getRelationships().isSelected();
ProjectController parent = (ProjectController) getParent();
for (ObjEntity entity : dataMap.getObjEntities()) {
if (updateEntities && defaultLockType != entity.getDeclaredLockType()) {
entity.setDeclaredLockType(defaultLockType);
parent.fireObjEntityEvent(new EntityEvent(this, entity));
}
if (updateAttributes) {
for (ObjAttribute a : entity.getAttributes()) {
if (a.isUsedForLocking() != on) {
a.setUsedForLocking(on);
parent.fireObjAttributeEvent(new AttributeEvent(this, a, entity));
}
}
}
if (updateRelationships) {
for (ObjRelationship r : entity.getRelationships()) {
if (r.isUsedForLocking() != on) {
r.setUsedForLocking(on);
parent.fireObjRelationshipEvent(new RelationshipEvent(this, r, entity));
}
}
}
}
if (view != null) {
view.dispose();
}
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class PackageUpdateController method updatePackage.
protected void updatePackage() {
boolean doAll = isAllEntities();
Map<String, String> oldNameEmbeddableToNewName = new HashMap<>();
// Create local copy to escape ConcurrentModificationException
Collection<Embeddable> embeddables = new ArrayList<>(dataMap.getEmbeddables());
for (Embeddable embeddable : embeddables) {
String oldName = embeddable.getClassName();
Pattern p = Pattern.compile("[.]");
String[] tokens = p.split(oldName);
String className = tokens[tokens.length - 1];
if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
String newClassName = getNameWithDefaultPackage(className);
oldNameEmbeddableToNewName.put(oldName, newClassName);
embeddable.setClassName(newClassName);
mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
}
}
for (ObjEntity entity : dataMap.getObjEntities()) {
String oldName = getClassName(entity);
if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
String className = extractClassName(Util.isEmptyString(oldName) ? entity.getName() : oldName);
setClassName(entity, getNameWithDefaultPackage(className));
}
for (ObjAttribute attribute : entity.getAttributes()) {
if (attribute instanceof EmbeddedAttribute) {
if (oldNameEmbeddableToNewName.size() > 0 && oldNameEmbeddableToNewName.containsKey(attribute.getType())) {
attribute.setType(oldNameEmbeddableToNewName.get(attribute.getType()));
AttributeEvent ev = new AttributeEvent(this, attribute, entity);
mediator.fireObjAttributeEvent(ev);
}
}
}
}
view.dispose();
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class ObjAttributeInfoDialog method changeAttributeObject.
private void changeAttributeObject() {
if (attributeSaved instanceof EmbeddedAttribute && embeddableModel.isAttributeOverrideChange()) {
Map<String, String> overrides = ((EmbeddedAttribute) attributeSaved).getAttributeOverrides();
Map<String, String> currentOverrAttr = getCurrentOverrideAttribute();
compareAndSetOverrideInEmbeddedAttribute(attributeSaved, overrides, currentOverrAttr);
}
if (attributeSaved instanceof EmbeddedAttribute) {
attributeSaved.setDbAttributePath(null);
model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
}
model.getEntity().removeAttribute(attribute.getName());
model.getEntity().addAttribute(attributeSaved);
mediator.fireObjEntityEvent(new EntityEvent(this, model.getEntity(), MapEvent.CHANGE));
EntityDisplayEvent event = new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireObjEntityDisplayEvent(event);
mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeSaved, model.getEntity(), MapEvent.CHANGE));
AttributeDisplayEvent eventAttr = new AttributeDisplayEvent(this, attributeSaved, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireObjAttributeDisplayEvent(eventAttr);
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class ObjAttributeTableModel method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int column) {
ObjAttributeWrapper attribute = getAttribute(row);
attribute.resetEdits();
AttributeEvent event = new AttributeEvent(eventSource, attribute.getValue(), entity);
switch(column) {
case OBJ_ATTRIBUTE:
event.setOldName(attribute.getName());
setObjAttribute(attribute, value);
fireTableCellUpdated(row, column);
break;
case OBJ_ATTRIBUTE_TYPE:
setObjAttributeType(attribute, value);
fireTableCellUpdated(row, column);
break;
case LOCKING:
setColumnLocking(attribute, value);
fireTableCellUpdated(row, column);
break;
case DB_ATTRIBUTE:
setDbAttribute(attribute, value);
fireTableRowsUpdated(row, row);
break;
case COMMENT:
setComment((String) value, attribute.getValue());
default:
fireTableRowsUpdated(row, row);
break;
}
mediator.fireObjAttributeEvent(event);
}
Aggregations