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
.handlers
.HandlerUtil
;
38 import org
.osgi
.service
.useradmin
.Group
;
39 import org
.osgi
.service
.useradmin
.UserAdmin
;
41 /** Deletes the selected groups */
42 public class DeleteGroups
extends AbstractHandler
{
43 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
46 /* DEPENDENCY INJECTION */
47 private UserAdmin userAdmin
;
48 private UserTransaction userTransaction
;
50 @SuppressWarnings("unchecked")
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
53 if (selection
.isEmpty())
56 Map
<String
, String
> toDelete
= new TreeMap
<String
, String
>();
57 // List<String> names = new ArrayList<String>();
58 Iterator
<Group
> it
= ((IStructuredSelection
) selection
).iterator();
59 while (it
.hasNext()) {
60 Group currGroup
= it
.next();
61 String groupName
= UiAdminUtils
.getProperty(currGroup
,
62 UserAdminConstants
.KEY_CN
);
64 toDelete
.put(groupName
, currGroup
.getName());
69 HandlerUtil
.getActiveShell(event
),
71 "Are you sure that you want to delete groups "
74 + "This might lead to inconsistencies in the application."))
77 UiAdminUtils
.beginTransactionIfNeeded(userTransaction
);
78 for (String name
: toDelete
.values())
79 userAdmin
.removeRole(name
);
81 // TODO rather notify the update listener
86 private void forceRefresh(ExecutionEvent event
) {
87 IWorkbenchWindow iww
= HandlerUtil
.getActiveWorkbenchWindow(event
);
90 IWorkbenchPage activePage
= iww
.getActivePage();
91 IWorkbenchPart part
= activePage
.getActivePart();
92 if (part
instanceof GroupsView
)
93 ((GroupsView
) part
).refresh();
96 /* DEPENDENCY INJECTION */
97 public void setUserAdmin(UserAdmin userAdmin
) {
98 this.userAdmin
= userAdmin
;
101 public void setUserTransaction(UserTransaction userTransaction
) {
102 this.userTransaction
= userTransaction
;