use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.
the class CategoryAttrsFrame method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
categoryAttrsTable.addAction(new CategoryAttributeCreateAction());
categoryAttrsTable.addAction(new CategoryAttributeEditAction());
categoryAttrsTable.addAction(new RemoveAction(categoryAttrsTable, false));
categoryAttrsTable.addAction(new RefreshAction(categoryAttrsTable));
categoryAttrsDs.addStateChangeListener(e -> {
if (e.getState() != Datasource.State.VALID) {
return;
}
initDataTypeColumn();
initDefaultValueColumn();
});
initMoveButtons();
}
use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.
the class EntityInspectorEditor method createRemoveAction.
/**
* Creates either Remove or Exclude action depending on property type
*/
protected RemoveAction createRemoveAction(MetaProperty metaProperty, Table table) {
RemoveAction result;
switch(metaProperty.getType()) {
case COMPOSITION:
result = new com.haulmont.cuba.gui.components.actions.RemoveAction(table);
break;
case ASSOCIATION:
result = new com.haulmont.cuba.gui.components.actions.ExcludeAction(table);
result.setShortcut(configuration.getConfig(ClientConfig.class).getTableRemoveShortcut());
break;
default:
throw new IllegalArgumentException("property must contain an entity");
}
result.setAutocommit(false);
return result;
}
use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.
the class GroupBrowser method init.
@Override
public void init(final Map<String, Object> params) {
CreateAction createAction = new CreateAction(groupsTree);
createAction.setAfterCommitHandler(entity -> {
groupsTree.expandTree();
});
groupsTree.addAction(createAction);
createAction.setCaption(getMessage("action.create"));
createAction.setOpenType(OpenType.DIALOG);
EditAction groupEditAction = new EditAction(groupsTree);
groupEditAction.setAfterCommitHandler(entity -> {
groupsTree.expandTree();
});
groupEditAction.setOpenType(OpenType.DIALOG);
groupsTree.addAction(groupEditAction);
groupCreateButton.addAction(createAction);
groupCreateButton.addAction(groupCopyAction);
userCreateAction = new GroupPropertyCreateAction(usersTable);
userCreateAction.setAfterCommitHandler(entity -> {
usersTable.getDatasource().refresh();
});
groupsTree.addAction(new RemoveAction(groupsTree) {
@Override
protected boolean isApplicable() {
if (target != null && target.getDatasource() != null && target.getSingleSelected() != null) {
@SuppressWarnings("unchecked") HierarchicalDatasource<Group, UUID> ds = (HierarchicalDatasource<Group, UUID>) target.getDatasource();
UUID selectedItemId = (UUID) target.getSingleSelected().getId();
return ds.getChildren(selectedItemId).isEmpty();
}
return false;
}
});
usersTable.addAction(userCreateAction);
RemoveAction removeAction = new UserRemoveAction(usersTable, userManagementService);
usersTable.addAction(removeAction);
Action moveToGroupAction = new ItemTrackingAction("moveToGroup").withIcon("icons/move.png").withCaption(getMessage("moveToGroup")).withHandler(event -> {
Set<User> selected = usersTable.getSelected();
if (!selected.isEmpty()) {
Map<String, Object> lookupParams = ParamsMap.of("exclude", groupsTree.getSelected().iterator().next(), "excludeChildren", false);
Lookup lookupWindow = openLookup(Group.class, items -> {
if (items.size() == 1) {
Group group = (Group) items.iterator().next();
List<UUID> usersForModify = new ArrayList<>();
for (User user : selected) {
usersForModify.add(user.getId());
}
userManagementService.moveUsersToGroup(usersForModify, group.getId());
if (selected.size() == 1) {
User user = selected.iterator().next();
showNotification(formatMessage("userMovedToGroup", user.getLogin(), group.getName()));
} else {
showNotification(formatMessage("usersMovedToGroup", group.getName()));
}
usersTable.getDatasource().refresh();
}
}, OpenType.DIALOG, lookupParams);
lookupWindow.addCloseListener(actionId -> {
usersTable.requestFocus();
});
}
});
MetaClass userMetaClass = metadata.getSession().getClass(User.class);
moveToGroupAction.setEnabled(security.isEntityOpPermitted(userMetaClass, EntityOp.UPDATE));
usersTable.addAction(moveToGroupAction);
tabsheet.addListener(newTab -> {
if ("constraintsTab".equals(newTab.getName())) {
initConstraintsTab();
} else if ("attributesTab".equals(newTab.getName())) {
initAttributesTab();
}
});
final boolean hasPermissionsToCreateGroup = security.isEntityOpPermitted(metadata.getSession().getClass(Group.class), EntityOp.CREATE);
// enable actions if group is selected
groupsDs.addItemChangeListener(e -> {
if (userCreateAction != null) {
userCreateAction.setEnabled(e.getItem() != null);
}
if (attributeCreateAction != null) {
attributeCreateAction.setEnabled(e.getItem() != null);
}
if (constraintCreateAction != null) {
constraintCreateAction.setEnabled(e.getItem() != null);
}
groupCopyAction.setEnabled(hasPermissionsToCreateGroup && e.getItem() != null);
CollectionDatasource ds = usersTable.getDatasource();
if (ds instanceof CollectionDatasource.SupportsPaging) {
((CollectionDatasource.SupportsPaging) ds).setFirstResult(0);
}
});
groupsDs.refresh();
groupsTree.expandTree();
final Collection<UUID> itemIds = groupsDs.getRootItemIds();
if (!itemIds.isEmpty()) {
groupsTree.setSelected(groupsDs.getItem(itemIds.iterator().next()));
}
groupCreateButton.setEnabled(hasPermissionsToCreateGroup);
groupCopyAction.setEnabled(hasPermissionsToCreateGroup);
importUpload.addFileUploadSucceedListener(event -> {
File file = fileUploadingAPI.getFile(importUpload.getFileId());
if (file == null) {
String errorMsg = String.format("Entities import upload error. File with id %s not found", importUpload.getFileId());
throw new RuntimeException(errorMsg);
}
byte[] fileBytes;
try (InputStream is = new FileInputStream(file)) {
fileBytes = IOUtils.toByteArray(is);
} catch (IOException e) {
throw new RuntimeException("Unable to import file", e);
}
try {
fileUploadingAPI.deleteFile(importUpload.getFileId());
} catch (FileStorageException e) {
log.error("Unable to delete temp file", e);
}
try {
Collection<Entity> importedEntities;
if ("json".equals(Files.getFileExtension(importUpload.getFileName()))) {
importedEntities = entityImportExportService.importEntitiesFromJSON(new String(fileBytes), createGroupsImportView());
} else {
importedEntities = entityImportExportService.importEntitiesFromZIP(fileBytes, createGroupsImportView());
}
long importedGroupsCount = importedEntities.stream().filter(entity -> entity instanceof Group).count();
showNotification(importedGroupsCount + " groups imported", NotificationType.HUMANIZED);
groupsDs.refresh();
} catch (Exception e) {
showNotification(formatMessage("importError", e.getMessage()), NotificationType.ERROR);
}
});
Companion companion = getCompanion();
if (companion != null) {
companion.initDragAndDrop(usersTable, groupsTree, (event) -> {
if (event.getUsers().size() == 1) {
if (moveSelectedUsersToGroup(event)) {
showNotification(formatMessage("userMovedToGroup", event.getUsers().get(0).getLogin(), event.getGroup().getName()));
}
} else {
showOptionDialog(messages.getMainMessage("dialogs.Confirmation"), formatMessage("dialogs.moveToGroup.message", event.getGroup().getName(), event.getUsers().size()), MessageType.CONFIRMATION, new Action[] { new DialogAction(Type.OK).withHandler(dialogEvent -> {
if (moveSelectedUsersToGroup(event)) {
showNotification(formatMessage("usersMovedToGroup", event.getGroup().getName()));
}
}), new DialogAction(Type.CANCEL, Action.Status.PRIMARY) });
}
});
}
}
use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.
the class UserBrowser method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
final boolean hasPermissionsToCreateUsers = security.isEntityOpPermitted(User.class, EntityOp.CREATE);
final boolean hasPermissionsToUpdateUsers = security.isEntityOpPermitted(User.class, EntityOp.CREATE);
final boolean hasPermissionsToCreateSettings = security.isEntityOpPermitted(UserSetting.class, EntityOp.CREATE);
changePasswAction.setEnabled(hasPermissionsToUpdateUsers);
changePasswAtLogonAction.setEnabled(hasPermissionsToUpdateUsers);
copySettingsAction.setEnabled(hasPermissionsToCreateSettings);
resetRememberMeAction.setEnabled(security.isEntityOpPermitted(RememberMeToken.class, EntityOp.DELETE));
usersDs.addItemChangeListener(e -> {
if (usersTable.getSelected().size() > 1) {
copyAction.setEnabled(false);
changePasswAction.setEnabled(false);
} else {
copyAction.setEnabled(hasPermissionsToCreateUsers && e.getItem() != null);
changePasswAction.setEnabled(hasPermissionsToUpdateUsers && e.getItem() != null);
}
changePasswAtLogonAction.setEnabled(hasPermissionsToUpdateUsers && e.getItem() != null);
copySettingsAction.setEnabled(hasPermissionsToCreateSettings && e.getItem() != null);
});
usersDs.addCollectionChangeListener(e -> {
if (e.getDs().getState() == Datasource.State.VALID) {
copyAction.setEnabled(hasPermissionsToCreateUsers && e.getDs().getItem() != null);
changePasswAction.setEnabled(hasPermissionsToUpdateUsers && e.getDs().getItem() != null);
changePasswAtLogonAction.setEnabled(hasPermissionsToUpdateUsers && e.getDs().getItem() != null);
copySettingsAction.setEnabled(hasPermissionsToCreateSettings && e.getDs().getItem() != null);
}
});
RemoveAction removeAction = new UserRemoveAction(usersTable, userManagementService);
usersTable.addAction(removeAction);
additionalActionsBtn.addAction(copySettingsAction);
additionalActionsBtn.addAction(changePasswAction);
additionalActionsBtn.addAction(changePasswAtLogonAction);
additionalActionsBtn.addAction(resetRememberMeAction);
if (WindowParams.MULTI_SELECT.getBool(getContext())) {
usersTable.setMultiSelect(true);
}
initTimeZoneColumn();
}
use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.
the class UserEditor method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
userDs.addItemPropertyChangeListener(new NameBuilderListener<>(userDs));
userDs.addItemPropertyChangeListener(e -> {
if ("timeZoneAuto".equals(e.getProperty())) {
timeZoneLookup.setEnabled(!Boolean.TRUE.equals(e.getValue()));
}
});
AddRoleAction addRoleAction = new AddRoleAction();
addRoleAction.setEnabled(security.isEntityOpPermitted(UserRole.class, EntityOp.CREATE));
rolesTable.addAction(addRoleAction);
EditRoleAction editRoleAction = new EditRoleAction();
rolesTable.addAction(editRoleAction);
RemoveRoleAction removeRoleAction = new RemoveRoleAction(rolesTable, false);
boolean isUserRoleDeletePermitted = security.isEntityOpPermitted(UserRole.class, EntityOp.DELETE);
boolean isUserUpdatePermitted = security.isEntityOpPermitted(User.class, EntityOp.UPDATE);
removeRoleAction.setEnabled(isUserRoleDeletePermitted && isUserUpdatePermitted);
rolesTable.addAction(removeRoleAction);
AddSubstitutedAction addSubstitutedAction = new AddSubstitutedAction();
addSubstitutedAction.setEnabled(security.isEntityOpPermitted(UserSubstitution.class, EntityOp.CREATE));
substTable.addAction(addSubstitutedAction);
EditSubstitutedAction editSubstitutedAction = new EditSubstitutedAction();
substTable.addAction(editSubstitutedAction);
RemoveAction removeSubstitutedAction = new RemoveAction(substTable, false);
substTable.addAction(removeSubstitutedAction);
boolean isUserRoleCreatePermitted = security.isEntityOpPermitted(UserRole.class, EntityOp.CREATE);
addRoleAction.setEnabled(isUserRoleCreatePermitted && isUserUpdatePermitted);
boolean isSubstitutedUserCreatePermitted = security.isEntityOpPermitted(UserSubstitution.class, EntityOp.CREATE);
addSubstitutedAction.setEnabled(isSubstitutedUserCreatePermitted && isUserUpdatePermitted);
boolean isSubstitutedUserDeletePermitted = security.isEntityOpPermitted(UserSubstitution.class, EntityOp.DELETE);
removeSubstitutedAction.setEnabled(isSubstitutedUserDeletePermitted && isUserUpdatePermitted);
boolean isRoleUpdatePermitted = security.isEntityOpPermitted(Role.class, EntityOp.UPDATE);
editRoleAction.setEnabled(isRoleUpdatePermitted);
boolean isSubstitutedUserUpdatePermitted = security.isEntityOpPermitted(UserSubstitution.class, EntityOp.UPDATE);
editSubstitutedAction.setEnabled(isSubstitutedUserUpdatePermitted);
initCustomFields(PersistenceHelper.isNew(WindowParams.ITEM.getEntity(params)));
dsContext.addAfterCommitListener((context, result) -> {
updateSessionSubstitutions(result);
if (passwField.getValue() != null) {
publishPasswordChangedEvent(getItem(), passwField.getValue());
}
});
}
Aggregations