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 javax
.transaction
.UserTransaction
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.ArgeoException
;
26 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
27 import org
.argeo
.jcr
.ArgeoNames
;
28 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
29 import org
.argeo
.security
.ui
.admin
.internal
.ColumnDefinition
;
30 import org
.argeo
.security
.ui
.admin
.internal
.CommonNameLP
;
31 import org
.argeo
.security
.ui
.admin
.internal
.MailLP
;
32 import org
.argeo
.security
.ui
.admin
.internal
.UserNameLP
;
33 import org
.argeo
.security
.ui
.admin
.internal
.UserTableDefaultDClickListener
;
34 import org
.argeo
.security
.ui
.admin
.internal
.UserTableViewer
;
35 import org
.eclipse
.jface
.viewers
.TableViewer
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.ui
.part
.ViewPart
;
39 import org
.osgi
.framework
.InvalidSyntaxException
;
40 import org
.osgi
.service
.useradmin
.Role
;
41 import org
.osgi
.service
.useradmin
.User
;
42 import org
.osgi
.service
.useradmin
.UserAdmin
;
44 /** List all users with filter - based on Ldif userAdmin */
45 public class UsersView
extends ViewPart
implements ArgeoNames
{
46 private final static Log log
= LogFactory
.getLog(UsersView
.class);
47 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
50 /* DEPENDENCY INJECTION */
51 private UserAdmin userAdmin
;
52 private UserTransaction userTransaction
;
55 private UserTableViewer userTableViewerCmp
;
56 private TableViewer userViewer
;
57 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
60 public void createPartControl(Composite parent
) {
61 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
62 // Define the displayed columns
63 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
65 columnDefs
.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
66 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
67 "Distinguished Name", 300));
69 // Create and configure the table
70 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
71 | SWT
.H_SCROLL
| SWT
.V_SCROLL
, userAdmin
);
72 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
74 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
75 userTableViewerCmp
.populate(true, false);
78 userViewer
= userTableViewerCmp
.getTableViewer();
79 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
80 getViewSite().setSelectionProvider(userViewer
);
83 userTableViewerCmp
.refresh();
86 // if (userTransaction != null)
87 // userTransaction.begin();
88 // } catch (Exception e) {
89 // throw new ArgeoException("Cannot begin transaction", e);
93 private class MyUserTableViewer
extends UserTableViewer
{
94 private static final long serialVersionUID
= 8467999509931900367L;
96 public MyUserTableViewer(Composite parent
, int style
,
97 UserAdmin userAdmin
) {
98 super(parent
, style
, userAdmin
);
102 protected List
<User
> listFilteredElements(String filter
) {
105 roles
= userAdmin
.getRoles(filter
);
106 } catch (InvalidSyntaxException e
) {
107 throw new ArgeoException("Unable to get roles with filter: "
110 List
<User
> users
= new ArrayList
<User
>();
111 for (Role role
: roles
)
112 if (role
.getType() == Role
.USER
&& role
.getType() != Role
.GROUP
)
113 users
.add((User
) role
);
118 public void refresh() {
119 userTableViewerCmp
.refresh();
122 // Override generic view methods
124 public void dispose() {
127 // if (userTransaction != null
128 // && userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION)
129 // userTransaction.rollback();
130 // } catch (Exception e) {
131 // log.error("Cannot clean transaction", e);
136 public void setFocus() {
137 userTableViewerCmp
.setFocus();
140 /* DEPENDENCY INJECTION */
141 public void setUserAdmin(UserAdmin userAdmin
) {
142 this.userAdmin
= userAdmin
;
145 public void setUserTransaction(UserTransaction userTransaction
) {
146 this.userTransaction
= userTransaction
;