use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class EditAction method isPermitted.
/**
* Check permissions for Action
*/
@Override
protected boolean isPermitted() {
if (target == null || target.getDatasource() == null) {
return false;
}
CollectionDatasource ownerDatasource = target.getDatasource();
boolean entityOpPermitted = security.isEntityOpPermitted(ownerDatasource.getMetaClass(), EntityOp.READ);
if (!entityOpPermitted) {
return false;
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class EditAction method actionPerform.
/**
* This method is invoked by the action owner component.
*
* @param component component invoking the action
*/
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
final Set selected = target.getSelected();
if (selected.size() == 1) {
Datasource parentDs = null;
final CollectionDatasource datasource = target.getDatasource();
if (datasource instanceof PropertyDatasource) {
MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
parentDs = datasource;
}
}
Map<String, Object> params = prepareWindowParams();
internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
} else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
if (isBulkEditorPermitted) {
// if bulk editor integration enabled and permitted for user
Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
Window bulkEditor = target.getFrame().openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
target.requestFocus();
Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
if (afterEditorCloseHandler != null) {
afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
}
});
}
}
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class ExcludeAction method doRemove.
@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
@SuppressWarnings({ "unchecked" }) CollectionDatasource ds = target.getDatasource();
if (ds instanceof NestedDatasource) {
// Clear reference to master entity
Datasource masterDs = ((NestedDatasource) ds).getMaster();
MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
for (Entity item : selected) {
item.setValue(inverseProp.getName(), null);
}
}
}
}
}
for (Entity item : selected) {
ds.modifyItem(item);
ds.excludeItem(item);
}
if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
try {
ds.commit();
} catch (RuntimeException e) {
ds.refresh();
throw e;
}
}
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class ExcludeAction method checkRemovePermission.
@Override
protected boolean checkRemovePermission() {
CollectionDatasource ds = target.getDatasource();
if (ds instanceof PropertyDatasource) {
PropertyDatasource propertyDatasource = (PropertyDatasource) ds;
MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
MetaProperty metaProperty = propertyDatasource.getProperty();
boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
if (!attrPermitted) {
return false;
}
}
return true;
}
use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.
the class DesktopTokenList method setLookup.
@Override
public void setLookup(boolean lookup) {
if (this.lookup != lookup) {
if (lookup) {
lookupAction = new PickerField.LookupAction(lookupPickerField) {
@Nonnull
@Override
protected Map<String, Object> prepareScreenParams() {
Map<String, Object> screenParams = super.prepareScreenParams();
if (isMultiSelect()) {
screenParams = new HashMap<>(screenParams);
WindowParams.MULTI_SELECT.set(screenParams, true);
// for backward compatibility
screenParams.put("multiSelect", "true");
}
return screenParams;
}
@SuppressWarnings("unchecked")
@Override
protected void handleLookupWindowSelection(Collection items) {
if (items.isEmpty()) {
return;
}
@SuppressWarnings("unchecked") Collection<Entity> selected = items;
CollectionDatasource optionsDatasource = lookupPickerField.getOptionsDatasource();
if (optionsDatasource != null && lookupPickerField.isRefreshOptionsOnLookupClose()) {
optionsDatasource.refresh();
if (datasource != null) {
for (Object obj : getDatasource().getItems()) {
Entity entity = (Entity) obj;
if (getOptionsDatasource().containsItem(entity.getId())) {
datasource.updateItem(getOptionsDatasource().getItem(entity.getId()));
}
}
}
}
// add all selected items to tokens
if (itemChangeHandler != null) {
for (Entity newItem : selected) {
itemChangeHandler.addItem(newItem);
}
} else if (datasource != null) {
// get master entity and inverse attribute in case of nested datasource
Entity masterEntity = getMasterEntity(datasource);
MetaProperty inverseProp = getInverseProperty(datasource);
for (Entity newItem : selected) {
if (!datasource.containsItem(newItem.getId())) {
// Initialize reference to master entity
if (inverseProp != null && isInitializeMasterReference(inverseProp)) {
newItem.setValue(inverseProp.getName(), masterEntity);
}
datasource.addItem(newItem);
}
}
}
afterSelect(items);
if (afterLookupSelectionHandler != null) {
afterLookupSelectionHandler.onSelect(items);
}
}
};
lookupPickerField.addAction(lookupAction);
if (getLookupScreen() != null) {
lookupAction.setLookupScreen(getLookupScreen());
}
lookupAction.setLookupScreenOpenType(lookupOpenMode);
lookupAction.setLookupScreenParams(lookupScreenParams);
lookupAction.setLookupScreenDialogParams(lookupScreenDialogParams);
} else {
lookupPickerField.removeAction(lookupAction);
}
lookupAction.setAfterLookupCloseHandler((window, actionId) -> {
if (afterLookupCloseHandler != null) {
afterLookupCloseHandler.onClose(window, actionId);
}
});
lookupAction.setAfterLookupSelectionHandler(items -> {
if (afterLookupSelectionHandler != null) {
afterLookupSelectionHandler.onSelect(items);
}
});
}
this.lookup = lookup;
rootPanel.refreshComponent();
}
Aggregations