1 package org
.argeo
.cms
.e4
.users
.handlers
;
5 import javax
.inject
.Inject
;
6 import javax
.inject
.Named
;
8 import org
.argeo
.cms
.auth
.UserAdminUtils
;
9 import org
.argeo
.cms
.e4
.users
.UserAdminWrapper
;
10 import org
.argeo
.cms
.e4
.users
.UsersView
;
11 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
12 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
13 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
14 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
15 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.osgi
.service
.useradmin
.User
;
19 import org
.osgi
.service
.useradmin
.UserAdmin
;
20 import org
.osgi
.service
.useradmin
.UserAdminEvent
;
22 /** Delete the selected users */
23 public class DeleteUsers
{
24 // public final static String ID = WorkbenchUiPlugin.PLUGIN_ID + ".deleteUsers";
26 /* DEPENDENCY INJECTION */
28 private UserAdminWrapper userAdminWrapper
;
30 @SuppressWarnings("unchecked")
32 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart part
, ESelectionService selectionService
) {
33 // ISelection selection = null;// HandlerUtil.getCurrentSelection(event);
34 // if (selection.isEmpty())
36 List
<User
> selection
= (List
<User
>) selectionService
.getSelection();
37 if (selection
== null)
40 // Iterator<User> it = ((IStructuredSelection) selection).iterator();
41 // List<User> users = new ArrayList<User>();
42 StringBuilder builder
= new StringBuilder();
44 for(User user
:selection
) {
46 // User currUser = it.next();
47 String userName
= UserAdminUtils
.getUserLocalId(currUser
.getName());
48 if (UserAdminUtils
.isCurrentUser(currUser
)) {
49 MessageDialog
.openError(Display
.getCurrent().getActiveShell(), "Deletion forbidden",
50 "You cannot delete your own user this way.");
53 builder
.append(userName
).append("; ");
54 // users.add(currUser);
57 if (!MessageDialog
.openQuestion(Display
.getCurrent().getActiveShell(), "Delete Users",
58 "Are you sure that you want to delete these users?\n" + builder
.substring(0, builder
.length() - 2)))
61 userAdminWrapper
.beginTransactionIfNeeded();
62 UserAdmin userAdmin
= userAdminWrapper
.getUserAdmin();
63 // IWorkbenchPage iwp =
64 // HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
66 for (User user
: selection
) {
67 String userName
= user
.getName();
68 // TODO find a way to close the editor cleanly if opened. Cannot be
69 // done through the UserAdminListeners, it causes a
70 // java.util.ConcurrentModificationException because disposing the
71 // editor unregisters and disposes the listener
72 // IEditorPart part = iwp.findEditor(new UserEditorInput(userName));
74 // iwp.closeEditor(part, false);
75 userAdmin
.removeRole(userName
);
77 userAdminWrapper
.commitOrNotifyTransactionStateChange();
79 for (User user
: selection
) {
80 userAdminWrapper
.notifyListeners(new UserAdminEvent(null, UserAdminEvent
.ROLE_REMOVED
, user
));
85 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_PART
) MPart part
, ESelectionService selectionService
) {
86 return part
.getObject() instanceof UsersView
&& selectionService
.getSelection() != null;