Search in sources :

Example 11 with DatasourceImplementation

use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.

the class FileBrowser method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    filesTable.addAction(new ItemTrackingAction("download").withCaption(getMessage("download")).withHandler(event -> {
        FileDescriptor fileDescriptor = filesTable.getSingleSelected();
        if (fileDescriptor != null) {
            exportDisplay.show(fileDescriptor, null);
        }
    }));
    BaseAction multiUploadAction = new BaseAction("multiupload").withCaption(getMessage("multiupload")).withHandler(event -> {
        if (!security.isEntityOpPermitted(FileDescriptor.class, EntityOp.READ)) {
            throw new AccessDeniedException(PermissionType.ENTITY_OP, FileDescriptor.class.getSimpleName());
        }
        Window window = openWindow("multiuploadDialog", OpenType.DIALOG);
        window.addCloseListener(actionId -> {
            if (COMMIT_ACTION_ID.equals(actionId)) {
                Collection<FileDescriptor> items = ((MultiUploader) window).getFiles();
                for (FileDescriptor fdesc : items) {
                    boolean modified = filesDs.isModified();
                    filesDs.addItem(fdesc);
                    ((DatasourceImplementation) filesDs).setModified(modified);
                }
                filesTable.focus();
            }
        });
    });
    multiUploadAction.setEnabled(security.isEntityOpPermitted(FileDescriptor.class, EntityOp.CREATE));
    multiUploadBtn.setAction(multiUploadAction);
}
Also used : Security(com.haulmont.cuba.core.global.Security) Table(com.haulmont.cuba.gui.components.Table) Collection(java.util.Collection) Button(com.haulmont.cuba.gui.components.Button) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) PermissionType(com.haulmont.cuba.security.entity.PermissionType) UUID(java.util.UUID) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) Inject(javax.inject.Inject) AbstractLookup(com.haulmont.cuba.gui.components.AbstractLookup) EntityOp(com.haulmont.cuba.security.entity.EntityOp) Window(com.haulmont.cuba.gui.components.Window) Map(java.util.Map) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) AccessDeniedException(com.haulmont.cuba.core.global.AccessDeniedException) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Window(com.haulmont.cuba.gui.components.Window) AccessDeniedException(com.haulmont.cuba.core.global.AccessDeniedException) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 12 with DatasourceImplementation

use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.

the class WebEntityLinkField method afterCommitOpenedEntity.

protected void afterCommitOpenedEntity(Entity item) {
    MetaProperty metaProperty = getMetaPropertyForEditedValue();
    if (metaProperty != null && metaProperty.getRange().isClass()) {
        if (getValueSource() != null) {
            boolean ownerDsModified = false;
            boolean nonModifiedInTable = false;
            DatasourceImplementation ownerDs = null;
            CollectionContainer ownerCollectionCont = null;
            if (getCollectionDatasourceFromOwner() != null) {
                ownerDs = ((DatasourceImplementation) getCollectionDatasourceFromOwner());
                nonModifiedInTable = !ownerDs.getItemsToUpdate().contains(((EntityValueSource) getValueSource()).getItem());
                ownerDsModified = ownerDs.isModified();
            } else if (getCollectionContainerFromOwner() != null) {
                ownerCollectionCont = ((ContainerDataUnit) owner.getItems()).getContainer();
                ownerCollectionCont.mute();
            }
            // noinspection unchecked
            setValueSilently((V) item);
            // remove from items to update if it was not modified before setValue
            if (ownerDs != null) {
                if (nonModifiedInTable) {
                    ownerDs.getItemsToUpdate().remove(getDatasource().getItem());
                }
                ownerDs.setModified(ownerDsModified);
            } else if (ownerCollectionCont != null) {
                ownerCollectionCont.unmute();
            }
        } else {
            // noinspection unchecked
            setValue((V) item);
        }
    // if we edit property with non Entity type and set ListComponent owner
    } else if (owner != null) {
        if (getCollectionDatasourceFromOwner() != null) {
            // noinspection unchecked
            getCollectionDatasourceFromOwner().updateItem(item);
        } else if (getCollectionContainerFromOwner() != null) {
            // do not listen changes in collection
            getCollectionContainerFromOwner().mute();
            // noinspection unchecked
            getCollectionContainerFromOwner().replaceItem(item);
            setValueSilently(item.getValueEx(getMetaPropertyPath()));
            // listen changes
            getCollectionContainerFromOwner().unmute();
        }
        if (owner instanceof Focusable) {
            // focus owner
            ((Focusable) owner).focus();
        }
    // if we edit property with non Entity type
    } else {
        // noinspection unchecked
        setValueSilently((V) item);
    }
}
Also used : DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 13 with DatasourceImplementation

use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.

the class AttributeEditor method initAttributesFieldGroup.

@SuppressWarnings("unchecked")
protected void initAttributesFieldGroup() {
    defaultBoolean.setOptionsMap(getBooleanOptions());
    dataType.setOptionsMap(getTypeOptions());
    entityClassField.setOptionsMap(getEntityOptions());
    defaultEntityId.addValueChangeListener(e -> {
        Entity entity = e.getValue();
        if (entity != null) {
            getItem().setObjectDefaultEntityId(referenceToEntitySupport.getReferenceId(entity));
        } else {
            getItem().setObjectDefaultEntityId(null);
        }
        ((DatasourceImplementation<CategoryAttribute>) attributeDs).modified(getItem());
    });
    enumerationListEditor = uiComponents.create(ListEditor.NAME);
    enumerationListEditor.setWidth("100%");
    enumerationListEditor.setItemType(ListEditor.ItemType.STRING);
    enumerationListEditor.setRequired(true);
    enumerationListEditor.setRequiredMessage(getMessage("enumRequired"));
    enumerationListEditor.addValueChangeListener(e -> {
        List<?> list = e.getValue() != null ? e.getValue() : Collections.emptyList();
        getItem().setEnumeration(Joiner.on(",").join(list));
    });
    if (localizedFrame != null) {
        enumerationListEditor.setEditorWindowId("localizedEnumerationWindow");
        enumerationListEditor.setEditorParamsSupplier(() -> ParamsMap.of("enumerationLocales", getItem().getEnumerationLocales()));
        enumerationListEditor.addEditorCloseListener(closeEvent -> {
            if (closeEvent.getActionId().equals(COMMIT_ACTION_ID)) {
                LocalizedEnumerationWindow enumerationWindow = (LocalizedEnumerationWindow) closeEvent.getWindow();
                getItem().setEnumerationLocales(enumerationWindow.getLocalizedValues());
            }
        });
    }
    optionalAttributeFieldGroup.getFieldNN("enumeration").setComponent(enumerationListEditor);
    validatorGroovyScript.setContextHelpIconClickHandler(e -> showMessageDialog(getMessage("validatorScript"), getMessage("validatorScriptHelp"), MessageType.CONFIRMATION_HTML.modal(false).width(560f)));
    validatorGroovyScript.setHeight(themeConstants.get("cuba.gui.AttributeEditor.validatorGroovyScriptField.height"));
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Aggregations

DatasourceImplementation (com.haulmont.cuba.gui.data.impl.DatasourceImplementation)13 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 Datasource (com.haulmont.cuba.gui.data.Datasource)4 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)2 Categorized (com.haulmont.cuba.core.entity.Categorized)2 Entity (com.haulmont.cuba.core.entity.Entity)2 DsContext (com.haulmont.cuba.gui.data.DsContext)2 CollectionPropertyDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl)2 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)2 DsContextLoader (com.haulmont.cuba.gui.xml.data.DsContextLoader)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 LockService (com.haulmont.cuba.core.app.LockService)1 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 AccessDeniedException (com.haulmont.cuba.core.global.AccessDeniedException)1 Security (com.haulmont.cuba.core.global.Security)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 AbstractLookup (com.haulmont.cuba.gui.components.AbstractLookup)1 Button (com.haulmont.cuba.gui.components.Button)1