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