CCM NG/ccm-core: Group edit in the Vaadin prototype

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4749 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 3940b5e1bb
pull/2/head
jensp 2017-05-21 18:32:37 +00:00
parent ab47a14967
commit c24f333413
8 changed files with 345 additions and 20 deletions

View File

@ -39,6 +39,8 @@ import org.libreccm.admin.ui.usersgroupsroles.RolesTableDataProvider;
import org.libreccm.admin.ui.usersgroupsroles.UsersGroupsRoles;
import org.libreccm.admin.ui.usersgroupsroles.UsersTableDataProvider;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.GroupManager;
import org.libreccm.security.GroupRepository;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.UserManager;
import org.libreccm.security.UserRepository;
@ -61,8 +63,6 @@ public class AdminView extends CustomComponent implements View {
public static final String VIEWNAME = "admin";
@Inject
private ServletContext servletContext;
@Inject
private JpqlConsoleController jpqlConsoleController;
@ -77,24 +77,27 @@ public class AdminView extends CustomComponent implements View {
private GlobalizationHelper globalizationHelper;
@Inject
private UserRepository userRepository;
private UserRepository userRepo;
@Inject
private UserManager userManager;
@Inject
private GroupRepository groupRepo;
@Inject
private GroupManager groupManager;
@Inject
private UsersTableDataProvider usersTableDataProvider;
@Inject
private GroupsTableDataProvider groupsTableDataProvider;
@Inject
private RolesTableDataProvider rolesTableDataProvider;
private ResourceBundle bundle;
@Inject
private UserRepository userRepo;
private ResourceBundle bundle;
private final TabSheet tabSheet;
// private final Grid<User> usersTable;
@ -194,13 +197,21 @@ public class AdminView extends CustomComponent implements View {
protected JpqlConsoleController getJpqlConsoleController() {
return jpqlConsoleController;
}
public UserRepository getUserRepository() {
return userRepo;
}
public UserManager getUserManager() {
return userManager;
}
public GroupRepository getGroupRepository() {
return groupRepo;
}
public GroupManager getGroupManager() {
return groupManager;
}
}

View File

@ -0,0 +1,211 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.admin.ui.usersgroupsroles;
import com.arsdigita.ui.admin.AdminUiConstants;
import com.vaadin.data.HasValue;
import com.vaadin.server.Page;
import com.vaadin.server.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import org.libreccm.admin.ui.ConfirmDiscardDialog;
import org.libreccm.security.Group;
import org.libreccm.security.GroupManager;
import org.libreccm.security.GroupRepository;
import java.util.ResourceBundle;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class GroupEditor extends Window {
private static final long serialVersionUID = -5834095844674226692L;
private final UsersGroupsRoles usersGroupsRoles;
private final Group group;
private final GroupRepository groupRepo;
private final GroupManager groupManager;
private boolean dataHasChanged = false;
private TextField groupName;
public GroupEditor(final UsersGroupsRoles usersGroupsRoles,
final GroupRepository groupRepo,
final GroupManager groupManager) {
super("Create new group");
this.usersGroupsRoles = usersGroupsRoles;
group = null;
this.groupRepo = groupRepo;
this.groupManager = groupManager;
addWidgets();
}
public GroupEditor(final Group group,
final UsersGroupsRoles usersGroupsRoles,
final GroupRepository groupRepo,
final GroupManager groupManager) {
super(String.format("Edit group %s", group.getName()));
this.group = group;
this.usersGroupsRoles = usersGroupsRoles;
this.groupRepo = groupRepo;
this.groupManager = groupManager;
addWidgets();
}
private void addWidgets() {
final ResourceBundle bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
UI.getCurrent().getLocale());
final DataHasChangedListener dataHasChangedListener
= new DataHasChangedListener();
groupName = new TextField(bundle
.getString("ui.admin.group_edit.groupname.label"));
groupName.setRequiredIndicatorVisible(true);
groupName.addValueChangeListener(dataHasChangedListener);
final Button submit = new Button();
if (group == null) {
submit.setCaption(bundle
.getString("ui.admin.group.createpanel.header"));
} else {
submit.setCaption(bundle.getString("ui.admin.save"));
}
submit.addClickListener(event -> saveGroup());
final Button cancel = new Button(bundle.getString("ui.admin.cancel"));
cancel.addClickListener(event -> close());
final HorizontalLayout buttons = new HorizontalLayout(submit, cancel);
final FormLayout formLayout = new FormLayout(groupName);
final VerticalLayout layout = new VerticalLayout(formLayout, buttons);
final Panel panel = new Panel(layout);
if (group == null) {
panel.setCaption(bundle
.getString("ui.admin.group.createpanel.header"));
} else {
panel.setCaption(bundle
.getString("ui.admin.group_details.edit"));
}
if (group != null) {
groupName.setValue(group.getName());
}
setContent(panel);
}
@Override
public void close() {
if (dataHasChanged) {
final ResourceBundle bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
UI.getCurrent().getLocale());
final ConfirmDiscardDialog dialog = new ConfirmDiscardDialog(
this,
bundle.getString("ui.admin.group_edit.discard_confirm"));
dialog.setModal(true);
UI.getCurrent().addWindow(dialog);
} else {
super.close();
}
}
protected void saveGroup() {
final ResourceBundle bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
UI.getCurrent().getLocale());
boolean valid = true;
if (groupName.getValue() == null
|| groupName.getValue().trim().isEmpty()) {
groupName.setComponentError(new UserError(
bundle.getString("")));
valid = false;
}
if (!valid) {
return;
}
final Group currentGroup;
final String notificationText;
if (group == null) {
currentGroup = new Group();
currentGroup.setName(groupName.getValue());
notificationText = String.format("Created new group %s",
currentGroup.getName());
} else {
currentGroup = group;
group.setName(groupName.getValue());
notificationText = String.format("Saved changes to group %s",
currentGroup.getName());
}
groupRepo.save(currentGroup);
dataHasChanged = false;
if (usersGroupsRoles != null) {
usersGroupsRoles.refreshGroups();
}
close();
new Notification(notificationText, Notification.Type.TRAY_NOTIFICATION)
.show(Page.getCurrent());
}
private class DataHasChangedListener
implements HasValue.ValueChangeListener<String> {
private static final long serialVersionUID = -1410903365203533072L;
@Override
public void valueChange(final HasValue.ValueChangeEvent<String> event) {
dataHasChanged = true;
}
}
}

View File

@ -24,15 +24,21 @@ import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.components.grid.HeaderCell;
import com.vaadin.ui.components.grid.HeaderRow;
import com.vaadin.ui.renderers.ButtonRenderer;
import com.vaadin.ui.themes.ValoTheme;
import org.libreccm.admin.ui.AdminView;
import org.libreccm.security.Group;
import org.libreccm.security.GroupRepository;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/**
@ -65,12 +71,24 @@ public class GroupsTable extends Grid<Group> {
.setCaption("Name");
addColumn(user -> bundle.getString("ui.admin.groups.table.edit"),
new ButtonRenderer<>(event -> {
//ToDo Open GroupEditor window
final GroupEditor groupEditor = new GroupEditor(
event.getItem(),
usersGroupsRoles,
view.getGroupRepository(),
view.getGroupManager());
groupEditor.center();
UI.getCurrent().addWindow(groupEditor);
}))
.setId(COL_EDIT);
addColumn(user -> bundle.getString("ui.admin.groups.table.delete"),
new ButtonRenderer<>(event -> {
//ToDo Display Confirm dialog
final ConfirmDeleteDialog dialog
= new ConfirmDeleteDialog(
event.getItem(),
usersGroupsRoles,
view.getGroupRepository());
dialog.center();
UI.getCurrent().addWindow(dialog);
}))
.setId(COL_DELETE);
@ -102,7 +120,12 @@ public class GroupsTable extends Grid<Group> {
createGroupButton.setStyleName(ValoTheme.BUTTON_TINY);
createGroupButton.setIcon(VaadinIcons.PLUS);
createGroupButton.addClickListener(event -> {
//ToDo Open GroupEditor
final GroupEditor groupEditor = new GroupEditor(
usersGroupsRoles,
view.getGroupRepository(),
view.getGroupManager());
groupEditor.center();
UI.getCurrent().addWindow(groupEditor);
});
final HorizontalLayout actionsLayout = new HorizontalLayout(
clearFiltersButton,
@ -129,4 +152,56 @@ public class GroupsTable extends Grid<Group> {
.getString("ui.admin.users.table.filter.clear"));
}
private class ConfirmDeleteDialog extends Window {
private static final long serialVersionUID = -1168912882249598278L;
private final Group group;
private final UsersGroupsRoles usersGroupsRoles;
private final GroupRepository groupRepo;
public ConfirmDeleteDialog(final Group group,
final UsersGroupsRoles usersGroupsRoles,
final GroupRepository groupRepo) {
this.group = group;
this.usersGroupsRoles = usersGroupsRoles;
this.groupRepo = groupRepo;
final ResourceBundle bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
UI.getCurrent().getLocale());
final MessageFormat messageFormat = new MessageFormat(
bundle.getString("ui.admin.groups.delete.confirm"));
final Label text = new Label(messageFormat
.format(new Object[]{group.getName()}));
final Button yesButton
= new Button(bundle.getString("ui.admin.yes"));
yesButton.addClickListener(event -> deleteGroup());
final Button noButton = new Button(bundle.getString("ui.admin.no"));
noButton.addClickListener(event -> close());
final HorizontalLayout buttons = new HorizontalLayout(yesButton,
noButton);
final VerticalLayout layout = new VerticalLayout(text, buttons);
// final Panel panel = new Panel(
// bundle.getString("ui.admin.groups.delete.confirm.title"),
// layout);
setContent(layout);
}
private void deleteGroup() {
groupRepo.delete(group);
usersGroupsRoles.refreshGroups();
close();
}
}
}

View File

@ -101,7 +101,7 @@ public class UserEditor extends Window {
addWidgets();
}
public UserEditor(final User user,
final UsersGroupsRoles usersGroupsRoles,
final UserRepository userRepo,
@ -252,8 +252,8 @@ public class UserEditor extends Window {
final Button submit = new Button();
if (user == null) {
submit.setCaption(bundle.getString(
"ui.admin.user.createpanel.header"));
submit.setCaption(bundle
.getString("ui.admin.user.createpanel.header"));
} else {
submit.setCaption(bundle.getString("ui.admin.save"));
}
@ -442,8 +442,8 @@ public class UserEditor extends Window {
close();
}
private class DataHasChangedListener implements
HasValue.ValueChangeListener<String> {
private class DataHasChangedListener
implements HasValue.ValueChangeListener<String> {
private static final long serialVersionUID = -4698658552890778877L;

View File

@ -579,3 +579,10 @@ ui.admin.user_edit.password_options.do_nothing=Do not change password
ui.admin.user_form.failed_to_send_password_challenge=Failed to send password challenge to user.
ui.admin.groups.table.edit=Edit
ui.admin.roles.table.edit=Edit
ui.admin.groups.delete.confirm=Are you sure to delete group {0}?
ui.admin.groups.delete.confirm.title=Are you sure?
ui.admin.group_edit.groupname.label=Name
ui.admin.group.createpanel.header=Create a new group
ui.admin.group_details.edit=Edit group
ui.admin.group_edit.groupname.error.not_empty=The name of a group can't be empty.
ui.admin.group_edit.discard_confirm=Are you sure to discard all changes made to this group?

View File

@ -583,3 +583,10 @@ ui.admin.user_edit.password_options.do_nothing=Password nicht ver\u00e4ndern
ui.admin.user_form.failed_to_send_password_challenge=Beim Senden des Passwortes ist ein Fehler aufgetreten.
ui.admin.groups.table.edit=Bearbeiten
ui.admin.roles.table.edit=Bearbeiten
ui.admin.groups.delete.confirm=Sind Sie sicher, dass die die Gruppe {0} l\u00f6schen wollen?
ui.admin.groups.delete.confirm.title=Sind Sie sicher?
ui.admin.group_edit.groupname.label=Name
ui.admin.group.createpanel.header=Neue Gruppe anlegen
ui.admin.group_details.edit=Gruppe bearbeiten
ui.admin.group_edit.groupname.error.not_empty=Der Name einer Gruppe darf nicht leer sein.
ui.admin.group_edit.discard_confirm=Sind Sie icher, dass die alle an der Gruppe vorgenommenen \u00c4nderungen verwerfen wollen?

View File

@ -576,3 +576,10 @@ ui.admin.user_edit.password_options.do_nothing=Do not change password
ui.admin.user_form.failed_to_send_password_challenge=Failed to send password challenge to user.
ui.admin.groups.table.edit=Edit
ui.admin.roles.table.edit=Edit
ui.admin.groups.delete.confirm=Are you sure to delete group {0}?
ui.admin.groups.delete.confirm.title=Are you sure?
ui.admin.group_edit.groupname.label=Name
ui.admin.group.createpanel.header=Create a new group
ui.admin.group_details.edit=Edit group
ui.admin.group_edit.groupname.error.not_empty=The name of a group can't be empty.
ui.admin.group_edit.discard_confirm=Are you sure to discard all changes made to this group?

View File

@ -567,3 +567,10 @@ ui.admin.user_edit.password_options.do_nothing=Do not change password
ui.admin.user_form.failed_to_send_password_challenge=Failed to send password challenge to user.
ui.admin.groups.table.edit=Edit
ui.admin.roles.table.edit=Edit
ui.admin.groups.delete.confirm=Are you sure to delete group {0}?
ui.admin.groups.delete.confirm.title=Are you sure?
ui.admin.group_edit.groupname.label=Name
ui.admin.group.createpanel.header=Create a new group
ui.admin.group_details.edit=Edit group
ui.admin.group_edit.groupname.error.not_empty=The name of a group can't be empty.
ui.admin.group_edit.discard_confirm=Are you sure to discard all changes made to this group?