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
.cms
.e4
.users
.handlers
;
18 import java
.util
.List
;
20 import javax
.inject
.Inject
;
21 import javax
.inject
.Named
;
23 import org
.argeo
.cms
.e4
.users
.GroupsView
;
24 import org
.argeo
.cms
.e4
.users
.UserAdminWrapper
;
25 import org
.argeo
.cms
.util
.UserAdminUtils
;
26 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
27 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
28 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
29 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
30 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
31 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
32 import org
.eclipse
.swt
.widgets
.Display
;
33 import org
.osgi
.service
.useradmin
.Group
;
34 import org
.osgi
.service
.useradmin
.UserAdmin
;
35 import org
.osgi
.service
.useradmin
.UserAdminEvent
;
37 /** Delete the selected groups */
38 public class DeleteGroups
{
39 // public final static String ID = WorkbenchUiPlugin.PLUGIN_ID +
42 /* DEPENDENCY INJECTION */
44 private UserAdminWrapper userAdminWrapper
;
47 ESelectionService selectionService
;
49 @SuppressWarnings("unchecked")
51 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart part
, ESelectionService selectionService
) {
52 // ISelection selection = null;// HandlerUtil.getCurrentSelection(event);
53 // if (selection.isEmpty())
56 // List<Group> groups = new ArrayList<Group>();
57 // Iterator<Group> it = ((IStructuredSelection) selection).iterator();
59 List
<Group
> selection
= (List
<Group
>) selectionService
.getSelection();
60 if (selection
== null)
63 StringBuilder builder
= new StringBuilder();
64 for (Group group
: selection
) {
65 Group currGroup
= group
;
66 String groupName
= UserAdminUtils
.getUserLocalId(currGroup
.getName());
68 builder
.append(groupName
).append("; ");
69 // groups.add(currGroup);
72 if (!MessageDialog
.openQuestion(Display
.getCurrent().getActiveShell(), "Delete Groups", "Are you sure that you "
73 + "want to delete these groups?\n" + builder
.substring(0, builder
.length() - 2)))
76 userAdminWrapper
.beginTransactionIfNeeded();
77 UserAdmin userAdmin
= userAdminWrapper
.getUserAdmin();
78 // IWorkbenchPage iwp =
79 // HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
80 for (Group group
: selection
) {
81 String groupName
= group
.getName();
82 // TODO find a way to close the editor cleanly if opened. Cannot be
83 // done through the UserAdminListeners, it causes a
84 // java.util.ConcurrentModificationException because disposing the
85 // editor unregisters and disposes the listener
86 // IEditorPart part = iwp.findEditor(new UserEditorInput(groupName));
88 // iwp.closeEditor(part, false);
89 userAdmin
.removeRole(groupName
);
91 userAdminWrapper
.commitOrNotifyTransactionStateChange();
94 for (Group group
: selection
) {
95 userAdminWrapper
.notifyListeners(new UserAdminEvent(null, UserAdminEvent
.ROLE_REMOVED
, group
));
102 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_PART
) MPart part
, ESelectionService selectionService
) {
103 return part
.getObject() instanceof GroupsView
&& selectionService
.getSelection() != null;
106 /* DEPENDENCY INJECTION */
107 // public void setUserAdminWrapper(UserAdminWrapper userAdminWrapper) {
108 // this.userAdminWrapper = userAdminWrapper;