Search in sources :

Example 1 with RelationshipAnnotationValueHandler

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());
    }
}
Also used : DataModelerPropertyEditorFieldInfo(org.kie.workbench.common.screens.datamodeller.client.model.DataModelerPropertyEditorFieldInfo) RelationshipAnnotationValueHandler(org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler)

Example 2 with RelationshipAnnotationValueHandler

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();
        }
    }
}
Also used : FetchMode(org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode) RelationType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) RelationshipAnnotationValueHandler(org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler) ArrayList(java.util.ArrayList) List(java.util.List) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

RelationshipAnnotationValueHandler (org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataModelerPropertyEditorFieldInfo (org.kie.workbench.common.screens.datamodeller.client.model.DataModelerPropertyEditorFieldInfo)1 CascadeType (org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType)1 FetchMode (org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode)1 RelationType (org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType)1 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)1