1 package org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.parts
;
3 import java
.util
.ArrayList
;
6 import org
.argeo
.api
.NodeConstants
;
7 import org
.argeo
.cms
.ArgeoNames
;
8 import org
.argeo
.cms
.CmsException
;
9 import org
.argeo
.cms
.auth
.CurrentUser
;
10 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
11 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.UiUserAdminListener
;
12 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.UserAdminWrapper
;
13 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.CommonNameLP
;
14 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.DomainNameLP
;
15 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.MailLP
;
16 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.UserDragListener
;
17 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.UserNameLP
;
18 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.UserTableDefaultDClickListener
;
19 import org
.argeo
.eclipse
.ui
.ColumnDefinition
;
20 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
21 import org
.argeo
.eclipse
.ui
.parts
.LdifUsersTable
;
22 import org
.argeo
.naming
.LdapAttrs
;
23 import org
.argeo
.naming
.LdapObjs
;
24 import org
.eclipse
.jface
.viewers
.TableViewer
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.dnd
.DND
;
27 import org
.eclipse
.swt
.dnd
.TextTransfer
;
28 import org
.eclipse
.swt
.dnd
.Transfer
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Display
;
31 import org
.eclipse
.ui
.part
.ViewPart
;
32 import org
.osgi
.framework
.InvalidSyntaxException
;
33 import org
.osgi
.service
.useradmin
.Role
;
34 import org
.osgi
.service
.useradmin
.User
;
35 import org
.osgi
.service
.useradmin
.UserAdminEvent
;
36 import org
.osgi
.service
.useradmin
.UserAdminListener
;
38 /** List all users with filter - based on Ldif userAdmin */
39 public class UsersView
extends ViewPart
implements ArgeoNames
{
40 // private final static Log log = LogFactory.getLog(UsersView.class);
42 public final static String ID
= WorkbenchUiPlugin
.PLUGIN_ID
+ ".usersView";
44 /* DEPENDENCY INJECTION */
45 private UserAdminWrapper userAdminWrapper
;
48 private LdifUsersTable userTableViewerCmp
;
49 private TableViewer userViewer
;
50 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
52 private UserAdminListener listener
;
55 public void createPartControl(Composite parent
) {
57 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
58 // Define the displayed columns
59 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Common Name",
61 columnDefs
.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
62 columnDefs
.add(new ColumnDefinition(new DomainNameLP(), "Domain", 200));
63 // Only show technical DN to admin
64 if (CurrentUser
.isInRole(NodeConstants
.ROLE_ADMIN
))
65 columnDefs
.add(new ColumnDefinition(new UserNameLP(),
66 "Distinguished Name", 300));
68 // Create and configure the table
69 userTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
70 | SWT
.H_SCROLL
| SWT
.V_SCROLL
);
71 userTableViewerCmp
.setLayoutData(EclipseUiUtils
.fillAll());
72 userTableViewerCmp
.setColumnDefinitions(columnDefs
);
73 userTableViewerCmp
.populate(true, false);
76 userViewer
= userTableViewerCmp
.getTableViewer();
77 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
78 getViewSite().setSelectionProvider(userViewer
);
81 userTableViewerCmp
.refresh();
84 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
85 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
86 userViewer
.addDragSupport(operations
, tt
, new UserDragListener(
89 // Register a useradmin listener
90 listener
= new MyUiUAListener(parent
.getDisplay());
91 userAdminWrapper
.addListener(listener
);
94 private class MyUiUAListener
extends UiUserAdminListener
{
95 public MyUiUAListener(Display display
) {
100 public void roleChangedToUiThread(UserAdminEvent event
) {
101 if (userViewer
!= null && !userViewer
.getTable().isDisposed())
106 private class MyUserTableViewer
extends LdifUsersTable
{
107 private static final long serialVersionUID
= 8467999509931900367L;
109 private final String
[] knownProps
= { LdapAttrs
.DN
,
110 LdapAttrs
.uid
.name(), LdapAttrs
.cn
.name(),
111 LdapAttrs
.givenName
.name(), LdapAttrs
.sn
.name(),
112 LdapAttrs
.mail
.name() };
114 public MyUserTableViewer(Composite parent
, int style
) {
115 super(parent
, style
);
119 protected List
<User
> listFilteredElements(String filter
) {
123 StringBuilder builder
= new StringBuilder();
125 StringBuilder tmpBuilder
= new StringBuilder();
126 if (EclipseUiUtils
.notEmpty(filter
))
127 for (String prop
: knownProps
) {
128 tmpBuilder
.append("(");
129 tmpBuilder
.append(prop
);
130 tmpBuilder
.append("=*");
131 tmpBuilder
.append(filter
);
132 tmpBuilder
.append("*)");
134 if (tmpBuilder
.length() > 1) {
135 builder
.append("(&(").append(LdapAttrs
.objectClass
.name())
136 .append("=").append(LdapObjs
.inetOrgPerson
.name())
138 builder
.append(tmpBuilder
.toString());
139 builder
.append("))");
141 builder
.append("(").append(LdapAttrs
.objectClass
.name())
142 .append("=").append(LdapObjs
.inetOrgPerson
.name())
144 roles
= userAdminWrapper
.getUserAdmin().getRoles(
146 } catch (InvalidSyntaxException e
) {
147 throw new CmsException("Unable to get roles with filter: "
150 List
<User
> users
= new ArrayList
<User
>();
151 for (Role role
: roles
)
152 // if (role.getType() == Role.USER && role.getType() !=
154 users
.add((User
) role
);
159 public void refresh() {
160 userTableViewerCmp
.refresh();
163 // Override generic view methods
165 public void dispose() {
166 userAdminWrapper
.removeListener(listener
);
171 public void setFocus() {
172 userTableViewerCmp
.setFocus();
175 /* DEPENDENCY INJECTION */
176 public void setUserAdminWrapper(UserAdminWrapper userAdminWrapper
) {
177 this.userAdminWrapper
= userAdminWrapper
;