Search in sources :

Example 26 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebEntityLinkField method openEntityEditor.

protected void openEntityEditor() {
    V value = getValue();
    Entity entity = null;
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else if (getValueSource() instanceof EntityValueSource) {
        entity = ((EntityValueSource) getValueSource()).getItem();
    }
    if (entity == null) {
        return;
    }
    Window window = ComponentsHelper.getWindow(this);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for EntityLinkField");
    }
    ScreenContext context = ComponentsHelper.getScreenContext(this);
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        Messages messages = AppBeans.get(Messages.NAME);
        context.getNotifications().create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMainMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    if (window.getFrameOwner() instanceof LegacyFrame) {
        LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
        DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
        entity = dataSupplier.reload(entity, View.MINIMAL);
    } else {
        DataManager dataManager = beanLocator.get(DataManager.NAME);
        entity = dataManager.reload(entity, View.MINIMAL);
    }
    String windowAlias = screen;
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    if (windowAlias == null) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    Screen screenEditor = screenBuilders.editor(entity.getMetaClass().getJavaClass(), window.getFrameOwner()).withScreenId(windowAlias).editEntity(entity).withOpenMode(screenOpenMode).withOptions(new MapScreenOptions(screenParams != null ? screenParams : new HashMap<>())).build();
    screenEditor.addAfterCloseListener(event -> {
        // move focus to component
        component.focus();
        String closeActionId = null;
        CloseAction closeAction = event.getCloseAction();
        if (closeAction instanceof StandardCloseAction) {
            closeActionId = ((StandardCloseAction) closeAction).getActionId();
        }
        Screen screenSource = null;
        if (StringUtils.isNotEmpty(closeActionId) && Window.COMMIT_ACTION_ID.equals(closeActionId)) {
            Entity item = null;
            screenSource = event.getSource();
            if (screenSource instanceof EditorScreen) {
                item = ((EditorScreen) screenSource).getEditedEntity();
            }
            if (item != null) {
                afterCommitOpenedEntity(item);
            }
        }
        fireEditorCloseEvent(screenSource == null ? null : (EditorScreen) screenSource, closeActionId);
    });
    screenEditor.show();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) HashMap(java.util.HashMap) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 27 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebAbstractTextArea method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        dataAwareComponentsTools.setupCaseConversion(this, entityValueSource);
        dataAwareComponentsTools.setupMaxLength(this, entityValueSource);
    }
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataAwareComponentsTools(com.haulmont.cuba.gui.components.data.DataAwareComponentsTools)

Example 28 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class ReadOnlyScreensSupport method isEditableConsideringDataBinding.

protected boolean isEditableConsideringDataBinding(Component component, boolean editable) {
    boolean shouldBeEditable = true;
    if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() != null) {
        ValueSource valueSource = ((HasValueSource) component).getValueSource();
        shouldBeEditable = !valueSource.isReadOnly();
        if (valueSource instanceof EntityValueSource && ((EntityValueSource) valueSource).isDataModelSecurityEnabled()) {
            MetaPropertyPath metaPropertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath();
            if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !security.isEntityAttrReadPermitted(metaPropertyPath)) {
                shouldBeEditable = false;
            }
        }
    }
    return editable && shouldBeEditable;
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource)

Example 29 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class ClearAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    // remove entity if it is a composition
    Object value = pickerField.getValue();
    ValueSource valueSource = pickerField.getValueSource();
    if (value != null && !value.equals(pickerField.getEmptyValue()) && valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
        Entity entity = (Entity) pickerField.getValue();
        if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
            FrameOwner screen = pickerField.getFrame().getFrameOwner();
            DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
            dataContext.remove(entity);
        }
    }
    // Set the value as if the user had set it
    pickerField.setValueFromUser(pickerField.getEmptyValue());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataContext(com.haulmont.cuba.gui.model.DataContext) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource)

Example 30 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class ValueBinder method bind.

public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
    if (valueSource instanceof BeanLocatorAware) {
        ((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
    }
    ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
    if (component instanceof Component.Editable) {
        ((Component.Editable) component).setEditable(!valueSource.isReadOnly());
    }
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
        if (component instanceof Field) {
            initRequired((Field) component, metaPropertyPath);
            initBeanValidator((Field<?>) component, metaPropertyPath);
        }
        if (entityValueSource.isDataModelSecurityEnabled()) {
            if (component instanceof Component.Editable) {
                MetaClass metaClass = entityValueSource.getEntityMetaClass();
                boolean permittedIfEmbedded = true;
                if (entityValueSource instanceof ContainerValueSource) {
                    InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
                    if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
                        String embeddedProperty = ((Nested) container).getProperty();
                        MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
                        permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
                    }
                    if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
                        for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
                            if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
                                permittedIfEmbedded = false;
                                break;
                            }
                        }
                    }
                }
                if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
                    ((Component.Editable) component).setEditable(false);
                }
            }
            if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
                component.setVisible(false);
            }
        }
    }
    binding.bind();
    return binding;
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Field(com.haulmont.cuba.gui.components.Field) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanLocatorAware(com.haulmont.cuba.core.sys.BeanLocatorAware) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)39 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 DataAwareComponentsTools (com.haulmont.cuba.gui.components.data.DataAwareComponentsTools)10 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)9 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)9 HasValueSource (com.haulmont.cuba.gui.components.data.HasValueSource)6 Messages (com.haulmont.cuba.core.global.Messages)5 ConversionException (com.haulmont.cuba.gui.components.data.ConversionException)5 Datatype (com.haulmont.chile.core.datatypes.Datatype)4 ValueConversionException (com.haulmont.chile.core.datatypes.ValueConversionException)4 Entity (com.haulmont.cuba.core.entity.Entity)4 ParseException (java.text.ParseException)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 Range (com.haulmont.chile.core.model.Range)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Field (com.haulmont.cuba.gui.components.Field)2 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)2 Pair (com.haulmont.bali.datastruct.Pair)1 Subscription (com.haulmont.bali.events.Subscription)1 Preconditions (com.haulmont.bali.util.Preconditions)1