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
.MailLP
;
28 import org
.argeo
.security
.ui
.admin
.internal
.UserNameLP
;
29 import org
.argeo
.security
.ui
.admin
.internal
.UserTableDefaultDClickListener
;
30 import org
.argeo
.security
.ui
.admin
.internal
.UserTableViewer
;
31 import org
.eclipse
.jface
.viewers
.TableViewer
;
32 import org
.eclipse
.swt
.SWT
;
33 import org
.eclipse
.swt
.widgets
.Composite
;
34 import org
.eclipse
.ui
.part
.ViewPart
;
35 import org
.osgi
.framework
.InvalidSyntaxException
;
36 import org
.osgi
.service
.useradmin
.Role
;
37 import org
.osgi
.service
.useradmin
.User
;
38 import org
.osgi
.service
.useradmin
.UserAdmin
;
40 /** List all users with filter - based on Ldif userAdmin */
41 public class UsersView
extends ViewPart
implements ArgeoNames
{
42 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
45 /* DEPENDENCY INJECTION */
46 private UserAdmin userAdmin
;
49 private UserTableViewer userTableViewerCmp
;
50 private TableViewer userViewer
;
51 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
54 public void createPartControl(Composite parent
) {
55 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
56 // Define the displayed columns
57 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
59 columnDefs
.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
60 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
61 "Distinguished Name", 300));
63 // Create and configure the table
64 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
65 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
66 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
68 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
69 userTableViewerCmp
.populate(true, false);
72 userViewer
= userTableViewerCmp
.getTableViewer();
73 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
74 getViewSite().setSelectionProvider(userViewer
);
77 userTableViewerCmp
.refresh();
80 private class MyUserTableViewer
extends UserTableViewer
{
81 private static final long serialVersionUID
= 8467999509931900367L;
83 public MyUserTableViewer(Composite parent
, int style
,
84 UserAdmin userAdmin
) {
85 super(parent
, style
, userAdmin
);
89 protected List
<User
> listFilteredElements(String filter
) {
92 roles
= userAdmin
.getRoles(filter
);
93 } catch (InvalidSyntaxException e
) {
94 throw new ArgeoException("Unable to get roles with filter: "
97 List
<User
> users
= new ArrayList
<User
>();
98 for (Role role
: roles
)
99 if (role
.getType() == Role
.USER
&& role
.getType() != Role
.GROUP
)
100 users
.add((User
) role
);
105 public void refresh() {
106 userTableViewerCmp
.refresh();
109 // Override generic view methods
111 public void dispose() {
116 public void setFocus() {
117 userTableViewerCmp
.setFocus();
120 /* DEPENDENCY INJECTION */
121 public void setUserAdmin(UserAdmin userAdmin
) {
122 this.userAdmin
= userAdmin
;