use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class EntityCombinedScreen method initBrowseEditAction.
/**
* Adds an EditAction that enables controls for editing.
*/
protected void initBrowseEditAction() {
ListComponent table = getTable();
table.addAction(new EditAction(table) {
@Override
public void actionPerform(Component component) {
if (table.getSelected().size() == 1) {
if (lockIfNeeded((Entity) table.getSelected().iterator().next())) {
super.actionPerform(component);
}
}
}
@Override
protected void internalOpenEditor(CollectionDatasource datasource, Entity existingItem, Datasource parentDs, Map<String, Object> params) {
refreshOptionsForLookupFields();
enableEditControls(false);
}
@Override
public void refreshState() {
if (target != null) {
CollectionDatasource ds = target.getDatasource();
if (ds != null && !captionInitialized) {
setCaption(messages.getMainMessage("actions.Edit"));
}
}
super.refreshState();
}
@Override
protected boolean isPermitted() {
CollectionDatasource ownerDatasource = target.getDatasource();
boolean entityOpPermitted = security.isEntityOpPermitted(ownerDatasource.getMetaClass(), EntityOp.UPDATE);
if (!entityOpPermitted) {
return false;
}
return super.isPermitted();
}
});
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class EntityCombinedScreen method releaseLock.
/**
* Release pessimistic lock if it was applied.
*/
protected void releaseLock() {
if (justLocked) {
Datasource ds = getFieldGroup().getDatasource();
Entity entity = ds.getItem();
if (entity != null) {
MetaClass metaClass = getMetaClassForLocking(entity);
AppBeans.get(LockService.class).unlock(metaClass.getName(), entity.getId().toString());
}
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class EntityCombinedScreen method initBrowseRemoveAction.
/**
* Adds AfterRemoveHandler for table's Remove action to reset the record contained in editDs.
*/
@SuppressWarnings("unchecked")
protected void initBrowseRemoveAction() {
ListComponent table = getTable();
Datasource editDs = getFieldGroup().getDatasource();
RemoveAction removeAction = (RemoveAction) table.getAction(RemoveAction.ACTION_ID);
if (removeAction != null)
removeAction.setAfterRemoveHandler(removedItems -> editDs.setItem(null));
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class EntityCombinedScreen method cancel.
/**
* Method that is invoked by clicking Cancel button, discards changes and disables controls for editing.
*/
@SuppressWarnings("unchecked")
public void cancel() {
CollectionDatasource browseDs = getTable().getDatasource();
Datasource editDs = getFieldGroup().getDatasource();
Entity selectedItem = browseDs.getItem();
if (selectedItem != null) {
Entity reloadedItem = getDsContext().getDataSupplier().reload(selectedItem, editDs.getView());
browseDs.setItem(reloadedItem);
} else {
editDs.setItem(null);
}
releaseLock();
disableEditControls();
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class WindowDelegate method getDatasource.
public Datasource getDatasource() {
Datasource ds = null;
Element element = ((Component.HasXmlDescriptor) window).getXmlDescriptor();
String datasourceName = element.attributeValue("datasource");
if (!StringUtils.isEmpty(datasourceName)) {
DsContext context = window.getDsContext();
if (context != null) {
ds = context.get(datasourceName);
}
}
if (ds == null) {
throw new GuiDevelopmentException("Can't find main datasource", window.getId());
}
return ds;
}
Aggregations