Search in sources :

Example 1 with DataSupplier

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

the class WindowManager method loadDsContext.

protected DsContext loadDsContext(Element element) {
    DataSupplier dataSupplier;
    String dataSupplierClass = element.attributeValue("dataSupplier");
    if (StringUtils.isEmpty(dataSupplierClass)) {
        dataSupplier = defaultDataSupplier;
    } else {
        Class<Object> aClass = ReflectionHelper.getClass(dataSupplierClass);
        try {
            dataSupplier = (DataSupplier) aClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Unable to create data supplier for screen", e);
        }
    }
    // noinspection UnnecessaryLocalVariable
    DsContext dsContext = new DsContextLoader(dataSupplier).loadDatasources(element.element("dsContext"), null);
    return dsContext;
}
Also used : DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 2 with DataSupplier

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

the class EntityParamsDatasource method reloadInstance.

protected Entity reloadInstance(Entity instance) {
    View reloadView = new View(instance.getMetaClass().getJavaClass(), true);
    LoadContext loadContext = new LoadContext(instance.getMetaClass());
    loadContext.setSoftDeletion(false);
    loadContext.setId(instance.getId());
    loadContext.setView(reloadView);
    DataSupplier supplier = getDataSupplier();
    return supplier.load(loadContext);
}
Also used : DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 3 with DataSupplier

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

the class DatasourceImpl method commit.

@SuppressWarnings("unchecked")
@Override
public void commit() {
    backgroundWorker.checkUIAccess();
    if (!allowCommit) {
        return;
    }
    if (getCommitMode() == CommitMode.DATASTORE) {
        final DataSupplier supplier = getDataSupplier();
        Entity committedItem = supplier.commit(item, getView());
        committed(Collections.singleton(committedItem));
    } else if (getCommitMode() == CommitMode.PARENT) {
        if (parentDs == null) {
            throw new IllegalStateException("parentDs is null while commitMode=PARENT");
        }
        if (parentDs instanceof CollectionDatasource) {
            CollectionDatasource ds = (CollectionDatasource) parentDs;
            if (ds.containsItem(item.getId())) {
                ds.modifyItem(item);
            } else {
                ds.addItem(item);
                // This is necessary for nested property datasources to work correctly
                ds.setItem(item);
            }
        } else {
            parentDs.setItem(item);
            if (AppBeans.get(EntityStates.class).isNew(item)) {
                ((DatasourceImplementation) parentDs).modified(item);
            }
        }
        clearCommitLists();
        modified = false;
    } else {
        throw new UnsupportedOperationException("Unsupported commitMode: " + getCommitMode());
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 4 with DataSupplier

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

the class WebEntityLinkField method openEntityEditor.

protected void openEntityEditor() {
    Object value = getValue();
    Entity entity;
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else {
        entity = datasource.getItem();
    }
    if (entity == null) {
        return;
    }
    WindowManager wm;
    Window window = ComponentsHelper.getWindow(this);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for EntityLinkField");
    } else {
        wm = window.getWindowManager();
    }
    if (screenOpenType.getOpenMode() == OpenMode.DIALOG && screenDialogParams != null) {
        wm.getDialogParams().copyFrom(screenDialogParams);
    }
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        Messages messages = AppBeans.get(Messages.NAME);
        wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
        return;
    }
    DataSupplier dataSupplier = window.getDsContext().getDataSupplier();
    entity = dataSupplier.reload(entity, View.MINIMAL);
    String windowAlias = screen;
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    if (windowAlias == null) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    final Window.Editor editor = wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType, screenParams != null ? screenParams : Collections.<String, Object>emptyMap());
    editor.addCloseListener(actionId -> {
        // move focus to component
        component.focus();
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            Entity item = editor.getItem();
            afterCommitOpenedEntity(item);
        }
        if (screenCloseListener != null) {
            screenCloseListener.windowClosed(editor, actionId);
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Entity(com.haulmont.cuba.core.entity.Entity) Messages(com.haulmont.cuba.core.global.Messages) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 5 with DataSupplier

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

the class SuggestionFieldQueryLoader method loadQuery.

protected void loadQuery(SuggestionField suggestionField, Element element) {
    Element queryElement = element.element("query");
    if (queryElement != null) {
        final boolean escapeValue;
        String stringQuery = queryElement.getStringValue();
        String searchFormat = queryElement.attributeValue("searchStringFormat");
        String view = queryElement.attributeValue("view");
        String escapeValueForLike = queryElement.attributeValue("escapeValueForLike");
        if (StringUtils.isNotEmpty(escapeValueForLike)) {
            escapeValue = Boolean.valueOf(escapeValueForLike);
        } else {
            escapeValue = false;
        }
        String entityClassName = queryElement.attributeValue("entityClass");
        if (StringUtils.isNotEmpty(entityClassName)) {
            suggestionField.setSearchExecutor((searchString, searchParams) -> {
                DataSupplier supplier = suggestionField.getFrame().getDsContext().getDataSupplier();
                Class<Entity> entityClass = ReflectionHelper.getClass(entityClassName);
                if (escapeValue) {
                    searchString = QueryUtils.escapeForLike(searchString);
                }
                searchString = applySearchFormat(searchString, searchFormat);
                LoadContext loadContext = LoadContext.create(entityClass);
                if (StringUtils.isNotEmpty(view)) {
                    loadContext.setView(view);
                }
                loadContext.setQuery(LoadContext.createQuery(stringQuery).setParameter("searchString", searchString));
                // noinspection unchecked
                return supplier.loadList(loadContext);
            });
        } else {
            throw new GuiDevelopmentException(String.format("Field 'entityClass' is empty in component %s.", suggestionField.getId()), getContext().getFullFrameId());
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Aggregations

DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)5 Entity (com.haulmont.cuba.core.entity.Entity)3 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 Messages (com.haulmont.cuba.core.global.Messages)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 Window (com.haulmont.cuba.gui.components.Window)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 GenericDataSupplier (com.haulmont.cuba.gui.data.impl.GenericDataSupplier)1 DsContextLoader (com.haulmont.cuba.gui.xml.data.DsContextLoader)1 Element (org.dom4j.Element)1