use of org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler in project kie-wb-common by kiegroup.
the class JPADataObjectFieldEditor method updateRelationshipField.
private void updateRelationshipField(Annotation annotation) {
clearRelationshipField();
if (annotation != null) {
RelationshipAnnotationValueHandler valueHandler = new RelationshipAnnotationValueHandler(annotation);
DataModelerPropertyEditorFieldInfo fieldInfo = getField(JPADataObjectFieldEditorView.RELATIONSHIP_TYPE_FIELD);
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.RELATION_TYPE, valueHandler.getRelationType());
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.CASCADE, valueHandler.getCascade());
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.FETCH, valueHandler.getFetch());
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL, valueHandler.getOptional());
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.MAPPED_BY, valueHandler.getMappedBy());
fieldInfo.setCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL, valueHandler.getOrphanRemoval());
if (valueHandler.isOneToMany()) {
fieldInfo.removeCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL);
} else if (valueHandler.isManyToOne()) {
fieldInfo.removeCurrentValue(RelationshipAnnotationValueHandler.MAPPED_BY);
fieldInfo.removeCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL);
} else if (valueHandler.isManyToMany()) {
fieldInfo.removeCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL);
fieldInfo.removeCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL);
}
updatePropertyEditorField(JPADataObjectFieldEditorView.RELATIONSHIP_TYPE_FIELD, annotation, valueHandler.getRelationType().name());
}
}
use of org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler in project kie-wb-common by kiegroup.
the class JPADataObjectFieldEditor method onRelationTypeFieldChange.
@Override
public void onRelationTypeFieldChange(DataModelerPropertyEditorFieldInfo fieldInfo, String newValue) {
if (getObjectField() != null) {
Annotation oldRelation = getCurrentRelationshipAnnotation(getObjectField());
RelationshipAnnotationValueHandler oldRelationHandler = oldRelation != null ? new RelationshipAnnotationValueHandler(oldRelation) : null;
Annotation newRelation;
RelationType newRelationType = (RelationType) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.RELATION_TYPE);
List<CascadeType> newCascadeTypes = (List<CascadeType>) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.CASCADE);
FetchMode newFetchMode = (FetchMode) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.FETCH);
Boolean newOptional = (Boolean) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL);
String newMappedBy = DataModelerUtils.nullTrim((String) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.MAPPED_BY));
Boolean newOrphanRemoval = (Boolean) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL);
// and add the new one. This may alter the annotations order for the given field, but it's not a problem.
if (oldRelationHandler != null) {
commandBuilder.buildFieldAnnotationRemoveCommand(getContext(), getName(), getDataObject(), getObjectField(), oldRelationHandler.getClassName()).execute();
}
newRelation = RelationshipAnnotationValueHandler.createAnnotation(newRelationType, newCascadeTypes, newFetchMode, newOptional, newMappedBy, newOrphanRemoval, getContext().getAnnotationDefinitions());
if (newRelation != null) {
getObjectField().addAnnotation(newRelation);
commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), getDataObject(), getObjectField(), newRelation).execute();
}
}
}
Aggregations