2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.ui
.admin
.commands
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
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
;
32 /** Deletes the selected roles */
33 public class DeleteRole
extends AbstractHandler
{
34 private UserAdminService userAdminService
;
36 @SuppressWarnings("unchecked")
37 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
38 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
39 if (selection
.isEmpty())
42 List
<String
> toDelete
= new ArrayList
<String
>();
43 Iterator
<String
> it
= ((IStructuredSelection
) selection
).iterator();
44 while (it
.hasNext()) {
45 toDelete
.add(it
.next());
50 HandlerUtil
.getActiveShell(event
),
52 "Are you sure that you want to delete "
55 + "This may lead to inconsistencies in the application."))
58 for (String role
: toDelete
) {
59 userAdminService
.deleteRole(role
);
62 RolesView view
= (RolesView
) HandlerUtil
63 .getActiveWorkbenchWindow(event
).getActivePage()
64 .findView(RolesView
.ID
);
69 public void setUserAdminService(UserAdminService userAdminService
) {
70 this.userAdminService
= userAdminService
;