Search in sources :

Example 1 with FieldComponentState

use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.

the class FormComponentState method copyFieldMessages.

private void copyFieldMessages(final EntityMessagesHolder messagesHolder) {
    for (Map.Entry<String, FieldComponentState> fieldComponentEntry : getFieldComponents().entrySet()) {
        ErrorMessage message = messagesHolder.getError(fieldComponentEntry.getKey());
        copyMessage(fieldComponentEntry.getValue(), message);
    }
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FieldComponentState

use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.

the class FormComponentState method copyEntityToFields.

private void copyEntityToFields(final Entity entity, final boolean requestUpdateState) {
    for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
        ErrorMessage message = entity.getError(field.getKey());
        copyMessage(field.getValue(), message);
        if (fieldIsGridCorrespondingLookup(field.getValue(), field.getKey(), entity)) {
            continue;
        }
        if (fieldIsDetachedEntityTree(field.getValue(), field.getKey(), entity)) {
            EntityTree tree = entity.getTreeField(field.getKey());
            if (tree != null) {
                ((TreeComponentState) field.getValue()).setRootNode(tree.getRoot());
            }
        }
        field.getValue().setFieldValue(convertFieldToString(entity.getField(field.getKey()), field.getKey()));
        if (requestUpdateState) {
            field.getValue().requestComponentUpdateState();
        }
    }
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) TreeComponentState(com.qcadoo.view.internal.components.tree.TreeComponentState) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map) EntityTree(com.qcadoo.model.api.EntityTree)

Example 3 with FieldComponentState

use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.

the class FormComponentStateTest method init.

@Before
public void init() throws Exception {
    entity = mock(Entity.class);
    given(entity.getField("name")).willReturn("text");
    viewDefinitionState = mock(ViewDefinitionState.class);
    translationService = mock(TranslationService.class);
    fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(new StringType());
    given(fieldDefinition.getName()).willReturn("name");
    dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    given(dataDefinition.get(12L)).willReturn(null);
    given(dataDefinition.get(13L)).willReturn(entity);
    given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(dataDefinition.getName()).willReturn("name");
    given(dataDefinition.getField("name")).willReturn(fieldDefinition);
    given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
    given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            Long id = (Long) invocation.getArguments()[0];
            return new DefaultEntity(dataDefinition, id);
        }
    });
    FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
    given(namePattern.isRequired()).willReturn(false);
    given(namePattern.isPersistent()).willReturn(true);
    name = new FieldComponentState(namePattern);
    name.setTranslationService(translationService);
    name.setName("name");
    name.initialize(new JSONObject(), Locale.ENGLISH);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("'static expression'");
    applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    form = new FormComponentState(pattern);
    form.setDataDefinition(dataDefinition);
    form.setTranslationService(translationService);
    form.addFieldEntityIdChangeListener("name", name);
    form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    new ExpressionServiceImpl().init();
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Matchers.anyLong(org.mockito.Matchers.anyLong) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 4 with FieldComponentState

use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.

the class FormComponentState method setFormEnabled.

@Override
public void setFormEnabled(final boolean enabled) {
    for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
        FieldDefinition fieldDefinition = getDataDefinition().getField(field.getKey());
        if (!(fieldDefinition.isReadOnly())) {
            field.getValue().setEnabled(enabled);
            field.getValue().requestComponentUpdateState();
        }
    }
    setEnabled(enabled);
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) FieldDefinition(com.qcadoo.model.api.FieldDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FieldComponentState (com.qcadoo.view.internal.components.FieldComponentState)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 TranslationService (com.qcadoo.localization.api.TranslationService)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 Entity (com.qcadoo.model.api.Entity)1 EntityTree (com.qcadoo.model.api.EntityTree)1 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)1 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)1 StringType (com.qcadoo.model.internal.types.StringType)1 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 FieldComponentPattern (com.qcadoo.view.internal.components.FieldComponentPattern)1 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)1 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)1 TreeComponentState (com.qcadoo.view.internal.components.tree.TreeComponentState)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1