Search in sources :

Example 6 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class SequenceGeneratorValueHandler method createAnnotation.

public static Annotation createAnnotation(String name, String sequenceName, Integer initialValue, Integer allocationSize, Map<String, AnnotationDefinition> annotationDefinitions) {
    SequenceGeneratorValueHandler valueHandler = new SequenceGeneratorValueHandler(new AnnotationImpl(annotationDefinitions.get(JPADomainAnnotations.JAVAX_PERSISTENCE_SEQUENCE_GENERATOR_ANNOTATION)));
    valueHandler.setName(name);
    valueHandler.setSequenceName(sequenceName);
    valueHandler.setInitialValue(initialValue);
    valueHandler.setAllocationSize(allocationSize);
    return valueHandler.getAnnotation();
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Example 7 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class SequenceGeneratorValueHandler method createAnnotation.

public static Annotation createAnnotation(String name, String sequenceName, Map<String, AnnotationDefinition> annotationDefinitions) {
    SequenceGeneratorValueHandler valueHandler = new SequenceGeneratorValueHandler(new AnnotationImpl(annotationDefinitions.get(JPADomainAnnotations.JAVAX_PERSISTENCE_SEQUENCE_GENERATOR_ANNOTATION)));
    valueHandler.setName(name);
    valueHandler.setSequenceName(sequenceName);
    return valueHandler.getAnnotation();
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Example 8 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class MethodAddAnnotationCommand method execute.

@Override
public void execute() {
    if (annotation == null) {
        annotation = new AnnotationImpl(context.getAnnotationDefinition(annotationClassName));
        if (valuePairs != null) {
            for (ValuePair valuePair : valuePairs) {
                annotation.setValue(valuePair.getName(), valuePair.getValue());
            }
        }
    }
    Annotation existingAnnotation = method.getAnnotation(annotation.getClassName());
    if (existingAnnotation != null) {
        method.removeAnnotation(annotation.getClassName());
    }
    method.addAnnotation(annotation);
    DataModelerEvent event = new DataObjectChangeEvent().withChangeType(ChangeType.METHOD_ANNOTATION_ADD_CHANGE).withOldValue(null).withNewValue(this.annotation).withContextId(getContext().getContextId()).withSource(getSource()).withCurrentDataObject(getDataObject()).withCurrentMethod(method);
    notifyChange(event);
}
Also used : DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObjectChangeEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectChangeEvent) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 9 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class DataObjectAnnotationValueChangeCommand method execute.

@Override
public void execute() {
    Object oldValue = null;
    Annotation annotation = dataObject.getAnnotation(annotationClassName);
    if (annotation != null) {
        oldValue = annotation.getValue(valuePair);
        if (newValue != null && !newValue.equals(oldValue)) {
            // notify annotation value change
            annotation.setValue(valuePair, newValue);
            notifyObjectChange(ChangeType.TYPE_ANNOTATION_VALUE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
        } else if (newValue == null && oldValue != null) {
            if (removeAnnotationIfValueIsNull) {
                dataObject.removeAnnotation(annotationClassName);
                // notify annotation removed
                notifyObjectChange(ChangeType.TYPE_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
            } else {
                annotation.setValue(valuePair, newValue);
                // notify annotation value change
                notifyObjectChange(ChangeType.TYPE_ANNOTATION_VALUE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
            }
        }
    } else if (newValue != null) {
        annotation = new AnnotationImpl(context.getAnnotationDefinitions().get(annotationClassName));
        annotation.setValue(valuePair, newValue);
        dataObject.addAnnotation(annotation);
        // notify annotation added
        notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 10 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.

the class FieldAddAnnotationCommand method execute.

@Override
public void execute() {
    if (annotation == null) {
        annotation = new AnnotationImpl(context.getAnnotationDefinition(annotationClassName));
        if (valuePairs != null) {
            for (ValuePair valuePair : valuePairs) {
                annotation.setValue(valuePair.getName(), valuePair.getValue());
            }
        }
    }
    field.addAnnotation(annotation);
    notifyFieldChange(ChangeType.FIELD_ANNOTATION_ADD_CHANGE, context, source, dataObject, field, annotation.getClassName(), null, null, null);
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Aggregations

AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)34 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)24 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)11 Test (org.junit.Test)10 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)10 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)7 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)5 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)4 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)4 Entity (javax.persistence.Entity)2 Before (org.junit.Before)2 AnnotationDefinitionImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Id (javax.persistence.Id)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 Module (org.guvnor.common.services.project.model.Module)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)1