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
.views
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.argeo
.ArgeoException
;
22 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
23 import org
.argeo
.jcr
.ArgeoNames
;
24 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
25 import org
.argeo
.security
.ui
.admin
.internal
.ColumnDefinition
;
26 import org
.argeo
.security
.ui
.admin
.internal
.CommonNameLP
;
27 import org
.argeo
.security
.ui
.admin
.internal
.UserNameLP
;
28 import org
.argeo
.security
.ui
.admin
.internal
.UserTableDefaultDClickListener
;
29 import org
.argeo
.security
.ui
.admin
.internal
.UserTableViewer
;
30 import org
.eclipse
.jface
.viewers
.TableViewer
;
31 import org
.eclipse
.swt
.SWT
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.osgi
.framework
.InvalidSyntaxException
;
34 import org
.osgi
.service
.useradmin
.Role
;
35 import org
.osgi
.service
.useradmin
.User
;
36 import org
.osgi
.service
.useradmin
.UserAdmin
;
38 /** List all groups with filter */
39 public class GroupsView
extends UsersView
implements ArgeoNames
{
40 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
43 /* DEPENDENCY INJECTION */
44 private UserAdmin userAdmin
;
47 private UserTableViewer userTableViewerCmp
;
48 private TableViewer userViewer
;
49 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
52 public void createPartControl(Composite parent
) {
53 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
54 // Define the displayed columns
55 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
56 "Distinguished Name", 200));
57 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
60 // Create and configure the table
61 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
62 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
64 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
65 userTableViewerCmp
.populate(true, false);
66 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
69 userViewer
= userTableViewerCmp
.getTableViewer();
70 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
71 getViewSite().setSelectionProvider(userViewer
);
74 userTableViewerCmp
.refresh();
77 private class MyUserTableViewer
extends UserTableViewer
{
78 private static final long serialVersionUID
= 8467999509931900367L;
80 public MyUserTableViewer(Composite parent
, int style
,
81 UserAdmin userAdmin
) {
82 super(parent
, style
, userAdmin
);
86 protected List
<User
> listFilteredElements(String filter
) {
89 roles
= userAdmin
.getRoles(filter
);
90 } catch (InvalidSyntaxException e
) {
91 throw new ArgeoException("Unable to get roles with filter: "
94 List
<User
> users
= new ArrayList
<User
>();
95 for (Role role
: roles
)
96 if (role
.getType() == Role
.GROUP
)
97 users
.add((User
) role
);
102 // Override generic view methods
104 public void dispose() {
109 public void setFocus() {
110 userTableViewerCmp
.setFocus();
113 /* DEPENDENCY INJECTION */
114 public void setUserAdmin(UserAdmin userAdmin
) {
115 this.userAdmin
= userAdmin
;