]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/DeleteRole.java
New project conventions (builds)
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / commands / DeleteRole.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.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.argeo.security.UserAdminService;
23 import org.argeo.security.ui.admin.views.RolesView;
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
32 /** Deletes the selected roles */
33 public class DeleteRole extends AbstractHandler {
34 private UserAdminService userAdminService;
35
36 @SuppressWarnings("unchecked")
37 public Object execute(ExecutionEvent event) throws ExecutionException {
38 ISelection selection = HandlerUtil.getCurrentSelection(event);
39 if (selection.isEmpty())
40 return null;
41
42 List<String> toDelete = new ArrayList<String>();
43 Iterator<String> it = ((IStructuredSelection) selection).iterator();
44 while (it.hasNext()) {
45 toDelete.add(it.next());
46 }
47
48 if (!MessageDialog
49 .openQuestion(
50 HandlerUtil.getActiveShell(event),
51 "Delete Role",
52 "Are you sure that you want to delete "
53 + toDelete
54 + "?\n"
55 + "This may lead to inconsistencies in the application."))
56 return null;
57
58 for (String role : toDelete) {
59 userAdminService.deleteRole(role);
60 }
61
62 RolesView view = (RolesView) HandlerUtil
63 .getActiveWorkbenchWindow(event).getActivePage()
64 .findView(RolesView.ID);
65 view.refresh();
66 return null;
67 }
68
69 public void setUserAdminService(UserAdminService userAdminService) {
70 this.userAdminService = userAdminService;
71 }
72 }