Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Remove action is not cancellable on Role assignment screen #665
Browse files Browse the repository at this point in the history
  • Loading branch information
gorbunkov committed Oct 7, 2021
1 parent 134b433 commit 124bdad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import io.jmix.securityui.model.ResourceRoleModel;
import io.jmix.securityui.model.RowLevelRoleModel;
import io.jmix.ui.UiComponents;
import io.jmix.ui.action.Action;
import io.jmix.ui.component.Component;
import io.jmix.ui.component.Label;
import io.jmix.ui.component.Table;
import io.jmix.ui.model.CollectionContainer;
import io.jmix.ui.model.CollectionLoader;
import io.jmix.ui.model.DataContext;
Expand All @@ -36,6 +38,7 @@
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

@UiController("sec_RoleAssignmentFragment")
Expand Down Expand Up @@ -71,6 +74,15 @@ public class RoleAssignmentFragment extends ScreenFragment {

private UserDetails user;

@Autowired
private Table<RoleAssignmentEntity> resourceRoleAssignmentsTable;

@Autowired
private Table<RoleAssignmentEntity> rowLevelRoleAssignmentsTable;

@Autowired
private DataContext dataContext;

@Install(to = "resourceRoleAssignmentsTable.roleName", subject = "columnGenerator")
private Component resourceRoleAssignmentsTableRoleNameColumnGenerator(RoleAssignmentEntity roleAssignmentEntity) {
BaseRole role = resourceRoleRepository.findRoleByCode(roleAssignmentEntity.getRoleCode());
Expand Down Expand Up @@ -143,4 +155,20 @@ private Collection<RoleAssignmentEntity> rowLevelRoleAssignmentsTableAddRowLevel
})
.collect(Collectors.toList());
}

@Subscribe("resourceRoleAssignmentsTable.remove")
public void onResourceRoleAssignmentsTableRemove(Action.ActionPerformedEvent event) {
Set<RoleAssignmentEntity> selected = resourceRoleAssignmentsTable.getSelected();
resourceRoleAssignmentEntitiesDc.getMutableItems().removeAll(selected);
//do not immediately remove role assignments but do that only when role-assignment-screen is committed
selected.forEach(dataContext::remove);
}

@Subscribe("rowLevelRoleAssignmentsTable.remove")
public void onRowLevelRoleAssignmentsTableRemove(Action.ActionPerformedEvent event) {
Set<RoleAssignmentEntity> selected = rowLevelRoleAssignmentsTable.getSelected();
rowLevelRoleAssignmentEntitiesDc.getMutableItems().removeAll(selected);
//do not immediately remove role assignments but do that only when role-assignment-screen is committed
selected.forEach(dataContext::remove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.jmix.ui.icon.Icons;
import io.jmix.ui.icon.JmixIcon;
import io.jmix.ui.UiScreenProperties;
import io.jmix.ui.model.DataContext;
import io.jmix.ui.screen.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -42,7 +43,12 @@ public class RoleAssignmentScreen extends Screen {
@Autowired
private RoleAssignmentFragment roleAssignmentFragment;

@Autowired
private ScreenValidation screenValidation;

private UserDetails user;
@Autowired
private DataContext dataContext;

public RoleAssignmentScreen setUser(UserDetails user) {
this.user = user;
Expand Down Expand Up @@ -85,8 +91,14 @@ protected void initScreenActions() {
Action closeAction = new BaseAction(Window.CLOSE_ACTION_ID)
.withIcon(icons.get(JmixIcon.EDITOR_CANCEL))
.withCaption(messages.getMessage("actions.Cancel"))
.withHandler(actionPerformedEvent -> close(new StandardCloseAction(Window.CLOSE_ACTION_ID)));

.withHandler(actionPerformedEvent -> {
if (dataContext.hasChanges()) {
screenValidation.showUnsavedChangesDialog(this, WINDOW_CLOSE_ACTION)
.onDiscard(() -> close(WINDOW_CLOSE_ACTION));
} else {
close(WINDOW_CLOSE_ACTION);
}
});
window.addAction(closeAction);
}
}

0 comments on commit 124bdad

Please sign in to comment.