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
.UiAdminUtils
;
29 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminConstants
;
30 import org
.argeo
.security
.ui
.admin
.internal
.UserNameLP
;
31 import org
.argeo
.security
.ui
.admin
.internal
.UserTableDefaultDClickListener
;
32 import org
.argeo
.security
.ui
.admin
.internal
.UserTableViewer
;
33 import org
.eclipse
.jface
.viewers
.TableViewer
;
34 import org
.eclipse
.swt
.SWT
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.ui
.part
.ViewPart
;
37 import org
.osgi
.framework
.InvalidSyntaxException
;
38 import org
.osgi
.service
.useradmin
.Role
;
39 import org
.osgi
.service
.useradmin
.User
;
40 import org
.osgi
.service
.useradmin
.UserAdmin
;
42 /** List all users with filter - based on Ldif userAdmin */
43 public class UsersView
extends ViewPart
implements ArgeoNames
{
44 // private final static Log log = LogFactory.getLog(UsersView.class);
45 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
48 /* DEPENDENCY INJECTION */
49 private UserAdmin userAdmin
;
52 private UserTableViewer userTableViewerCmp
;
53 private TableViewer userViewer
;
54 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
57 public void createPartControl(Composite parent
) {
58 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
59 // Define the displayed columns
60 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
62 columnDefs
.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
63 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
64 "Distinguished Name", 300));
66 // Create and configure the table
67 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
68 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
69 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
71 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
72 userTableViewerCmp
.populate(true, false);
75 userViewer
= userTableViewerCmp
.getTableViewer();
76 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
77 getViewSite().setSelectionProvider(userViewer
);
80 userTableViewerCmp
.refresh();
83 // if (userTransaction != null)
84 // userTransaction.begin();
85 // } catch (Exception e) {
86 // throw new ArgeoException("Cannot begin transaction", e);
90 private class MyUserTableViewer
extends UserTableViewer
{
91 private static final long serialVersionUID
= 8467999509931900367L;
93 private final String
[] knownProps
= { UserAdminConstants
.KEY_UID
,
94 UserAdminConstants
.KEY_DN
, UserAdminConstants
.KEY_CN
,
95 UserAdminConstants
.KEY_FIRSTNAME
,
96 UserAdminConstants
.KEY_LASTNAME
, UserAdminConstants
.KEY_MAIL
};
98 public MyUserTableViewer(Composite parent
, int style
,
99 UserAdmin userAdmin
) {
100 super(parent
, style
, userAdmin
);
104 protected List
<User
> listFilteredElements(String filter
) {
108 StringBuilder builder
= new StringBuilder();
110 StringBuilder tmpBuilder
= new StringBuilder();
111 if (UiAdminUtils
.notNull(filter
))
112 for (String prop
: knownProps
) {
113 tmpBuilder
.append("(");
114 tmpBuilder
.append(prop
);
115 tmpBuilder
.append("=*");
116 tmpBuilder
.append(filter
);
117 tmpBuilder
.append("*)");
119 if (tmpBuilder
.length() > 1) {
120 builder
.append("(&(objectclass=inetOrgPerson)(|");
121 builder
.append(tmpBuilder
.toString());
122 builder
.append("))");
124 builder
.append("(objectclass=inetOrgPerson)");
125 roles
= userAdmin
.getRoles(builder
.toString());
126 } catch (InvalidSyntaxException e
) {
127 throw new ArgeoException("Unable to get roles with filter: "
130 List
<User
> users
= new ArrayList
<User
>();
131 for (Role role
: roles
)
132 // if (role.getType() == Role.USER && role.getType() !=
134 users
.add((User
) role
);
139 public void refresh() {
140 userTableViewerCmp
.refresh();
143 // Override generic view methods
145 public void dispose() {
148 // if (userTransaction != null
149 // && userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION)
150 // userTransaction.rollback();
151 // } catch (Exception e) {
152 // log.error("Cannot clean transaction", e);
157 public void setFocus() {
158 userTableViewerCmp
.setFocus();
161 /* DEPENDENCY INJECTION */
162 public void setUserAdmin(UserAdmin userAdmin
) {
163 this.userAdmin
= userAdmin
;