use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class EntityCombinedScreen method initBrowseItemChangeListener.
/**
* Adds a listener that reloads the selected record with the specified view and sets it to editDs.
*/
@SuppressWarnings("unchecked")
protected void initBrowseItemChangeListener() {
CollectionDatasource browseDs = getTable().getDatasource();
Datasource editDs = getFieldGroup().getDatasource();
browseDs.addItemChangeListener(e -> {
if (e.getItem() != null) {
Entity reloadedItem = getDsContext().getDataSupplier().reload(e.getDs().getItem(), editDs.getView());
editDs.setItem(reloadedItem);
}
});
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class EntityCombinedScreen method save.
/**
* Method that is invoked by clicking Ok button after editing an existing or creating a new record.
*/
@SuppressWarnings("unchecked")
public void save() {
if (!editing)
return;
FieldGroup fieldGroup = getFieldGroup();
List<Validatable> components = new ArrayList<>();
for (Component component : fieldGroup.getComponents()) {
if (component instanceof Validatable) {
components.add((Validatable) component);
}
}
if (!validate(components)) {
return;
}
getDsContext().commit();
ListComponent table = getTable();
CollectionDatasource browseDs = table.getDatasource();
Entity editedItem = fieldGroup.getDatasource().getItem();
if (creating) {
browseDs.includeItem(editedItem);
} else {
browseDs.updateItem(editedItem);
}
table.setSelected(editedItem);
releaseLock();
disableEditControls();
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class EntityCombinedScreen method initBrowseCreateAction.
/**
* Adds a CreateAction that removes selection in table, sets a newly created item to editDs
* and enables controls for record editing.
*/
protected void initBrowseCreateAction() {
ListComponent table = getTable();
table.addAction(new CreateAction(table) {
@SuppressWarnings("unchecked")
@Override
protected void internalOpenEditor(CollectionDatasource datasource, Entity newItem, Datasource parentDs, Map<String, Object> params) {
initNewItem(newItem);
table.setSelected(Collections.emptyList());
getFieldGroup().getDatasource().setItem(newItem);
refreshOptionsForLookupFields();
enableEditControls(true);
}
});
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class AddAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || target.getDatasource() == null) {
return false;
}
CollectionDatasource ownerDs = target.getDatasource();
if (ownerDs instanceof PropertyDatasource) {
PropertyDatasource datasource = (PropertyDatasource) ownerDs;
MetaClass parentMetaClass = datasource.getMaster().getMetaClass();
MetaProperty metaProperty = datasource.getProperty();
boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class RefreshAction method actionPerform.
/**
* This method is invoked by action owner component. Don't override it, there are special methods to
* customize behaviour below.
*
* @param component component invoking action
*/
@Override
public void actionPerform(Component component) {
if (beforeRefreshHandler != null) {
beforeRefreshHandler.run();
}
CollectionDatasource datasource = owner.getDatasource();
Map<String, Object> refreshParams = getRefreshParams();
Map<String, Object> supplierParams = null;
if (refreshParamsSupplier != null) {
supplierParams = refreshParamsSupplier.get();
}
Map<String, Object> params = null;
if (supplierParams != null || refreshParams != null) {
params = new HashMap<>();
params.putAll(refreshParams != null ? refreshParams : Collections.emptyMap());
params.putAll(supplierParams != null ? supplierParams : Collections.emptyMap());
}
if (params != null) {
datasource.refresh(params);
} else {
datasource.refresh();
}
if (afterRefreshHandler != null) {
afterRefreshHandler.run();
}
}
Aggregations