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();
}
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);
}
}
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;
}
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());
}
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;
}
Aggregations