]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/DeleteUsers.java
Adapt commands to the new security model.
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / commands / DeleteUsers.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.admin.commands;
17
18 import java.util.Iterator;
19 import java.util.Map;
20 import java.util.TreeMap;
21
22 import org.argeo.security.ui.admin.SecurityAdminPlugin;
23 import org.argeo.security.ui.admin.internal.UiAdminUtils;
24 import org.eclipse.core.commands.AbstractHandler;
25 import org.eclipse.core.commands.ExecutionEvent;
26 import org.eclipse.core.commands.ExecutionException;
27 import org.eclipse.jface.dialogs.MessageDialog;
28 import org.eclipse.jface.viewers.ISelection;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.ui.handlers.HandlerUtil;
31 import org.osgi.service.useradmin.User;
32
33 /** Deletes the selected users */
34 public class DeleteUsers extends AbstractHandler {
35 public final static String ID = SecurityAdminPlugin.PLUGIN_ID + ".deleteUsers";
36
37 @SuppressWarnings("unchecked")
38 public Object execute(ExecutionEvent event) throws ExecutionException {
39 ISelection selection = HandlerUtil.getCurrentSelection(event);
40 if (selection.isEmpty())
41 return null;
42
43 Map<String, User> toDelete = new TreeMap<String, User>();
44 Iterator<User> it = ((IStructuredSelection) selection).iterator();
45 users: while (it.hasNext()) {
46 User currUser = it.next();
47 String userName = UiAdminUtils.getUsername(currUser);
48 // check not deleting own user
49 // if (userName.equals(profileNode.getSession().getUserID())) {
50 // log.warn("Cannot delete its own user: " + userName);
51 // continue nodes;
52 // }
53 toDelete.put(userName, currUser);
54 }
55
56 if (!MessageDialog
57 .openQuestion(
58 HandlerUtil.getActiveShell(event),
59 "Delete Users",
60 "Are you sure that you want to delete users "
61 + toDelete.keySet()
62 + "?\n"
63 + "This might lead to inconsistencies in the application."))
64 return null;
65
66 for (String username : toDelete.keySet()) {
67 // TODO perform real deletion
68 }
69 MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
70 "Unimplemented method",
71 "The effective deletion is not yet implemented");
72 // TODO refresh?
73 // JcrUsersView view = (JcrUsersView) HandlerUtil
74 // .getActiveWorkbenchWindow(event).getActivePage()
75 // .findView(JcrUsersView.ID);
76 // view.refresh();
77 return null;
78 }
79 }