]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/DeleteGroups.java
b655cd136bdc9dc5c2ac424f39c7becbad149c4a
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / commands / DeleteGroups.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.argeo.security.ui.admin.internal.UserAdminConstants;
25 import org.eclipse.core.commands.AbstractHandler;
26 import org.eclipse.core.commands.ExecutionEvent;
27 import org.eclipse.core.commands.ExecutionException;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.IStructuredSelection;
31 import org.eclipse.ui.handlers.HandlerUtil;
32 import org.osgi.service.useradmin.Group;
33
34 /** Deletes the selected groups */
35 public class DeleteGroups extends AbstractHandler {
36 public final static String ID = SecurityAdminPlugin.PLUGIN_ID + ".deleteGroups";
37
38
39 @SuppressWarnings("unchecked")
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41 ISelection selection = HandlerUtil.getCurrentSelection(event);
42 if (selection.isEmpty())
43 return null;
44
45 Map<String, Group> toDelete = new TreeMap<String, Group>();
46 Iterator<Group> it = ((IStructuredSelection) selection).iterator();
47 groups: while (it.hasNext()) {
48 Group currGroup = it.next();
49 String groupName = UiAdminUtils.getProperty(currGroup,
50 UserAdminConstants.KEY_CN);
51
52 // TODO add checks
53 // if (userName.equals(profileNode.getSession().getUserID())) {
54 // log.warn("Cannot delete its own user: " + userName);
55 // continue groups;
56 // }
57 toDelete.put(groupName, currGroup);
58 }
59
60 if (!MessageDialog
61 .openQuestion(
62 HandlerUtil.getActiveShell(event),
63 "Delete Groups",
64 "Are you sure that you want to delete groups "
65 + toDelete.keySet()
66 + "?\n"
67 + "This might lead to inconsistencies in the application."))
68 return null;
69
70 for (String groupName : toDelete.keySet()) {
71 }
72 MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
73 "Unimplemented method",
74 "The effective deletion is not yet implemented");
75 // TODO refresh?
76 // JcrUsersView view = (JcrUsersView) HandlerUtil
77 // .getActiveWorkbenchWindow(event).getActivePage()
78 // .findView(JcrUsersView.ID);
79 // view.refresh();
80 return null;
81 }
82
83 // public void setUserAdmin(UserAdmin userAdmin) {
84 // this.userAdmin = userAdmin;
85 // }
86 }