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
.Iterator
;
20 import java
.util
.TreeMap
;
22 import javax
.transaction
.UserTransaction
;
24 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
25 import org
.argeo
.security
.ui
.admin
.internal
.UiAdminUtils
;
26 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminConstants
;
27 import org
.argeo
.security
.ui
.admin
.views
.GroupsView
;
28 import org
.eclipse
.core
.commands
.AbstractHandler
;
29 import org
.eclipse
.core
.commands
.ExecutionEvent
;
30 import org
.eclipse
.core
.commands
.ExecutionException
;
31 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
32 import org
.eclipse
.jface
.viewers
.ISelection
;
33 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
34 import org
.eclipse
.ui
.IWorkbenchPage
;
35 import org
.eclipse
.ui
.IWorkbenchPart
;
36 import org
.eclipse
.ui
.IWorkbenchWindow
;
37 import org
.eclipse
.ui
.PlatformUI
;
38 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
39 import org
.osgi
.service
.useradmin
.Group
;
40 import org
.osgi
.service
.useradmin
.UserAdmin
;
42 /** Deletes the selected groups */
43 public class DeleteGroups
extends AbstractHandler
{
44 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
47 /* DEPENDENCY INJECTION */
48 private UserAdmin userAdmin
;
49 private UserTransaction userTransaction
;
51 @SuppressWarnings("unchecked")
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
54 if (selection
.isEmpty())
57 Map
<String
, String
> toDelete
= new TreeMap
<String
, String
>();
58 // List<String> names = new ArrayList<String>();
59 Iterator
<Group
> it
= ((IStructuredSelection
) selection
).iterator();
60 while (it
.hasNext()) {
61 Group currGroup
= it
.next();
62 String groupName
= UiAdminUtils
.getProperty(currGroup
,
63 UserAdminConstants
.KEY_CN
);
65 toDelete
.put(groupName
, currGroup
.getName());
70 HandlerUtil
.getActiveShell(event
),
72 "Are you sure that you want to delete groups "
75 + "This might lead to inconsistencies in the application."))
78 UiAdminUtils
.beginTransactionIfNeeded(userTransaction
);
79 for (String name
: toDelete
.values())
80 userAdmin
.removeRole(name
);
82 // TODO rather notify the update listener
87 private void forceRefresh(ExecutionEvent event
) {
88 IWorkbenchWindow iww
= HandlerUtil
.getActiveWorkbenchWindow(event
);
91 IWorkbenchPage activePage
= iww
.getActivePage();
92 IWorkbenchPart part
= activePage
.getActivePart();
93 if (part
instanceof GroupsView
)
94 ((GroupsView
) part
).refresh();
97 /* DEPENDENCY INJECTION */
98 public void setUserAdmin(UserAdmin userAdmin
) {
99 this.userAdmin
= userAdmin
;
102 public void setUserTransaction(UserTransaction userTransaction
) {
103 this.userTransaction
= userTransaction
;