1 package org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.parts
;
3 import java
.util
.ArrayList
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.api
.NodeConstants
;
9 import org
.argeo
.cms
.ArgeoNames
;
10 import org
.argeo
.cms
.CmsException
;
11 import org
.argeo
.cms
.auth
.CurrentUser
;
12 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
13 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.UiUserAdminListener
;
14 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.UserAdminWrapper
;
15 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.CommonNameLP
;
16 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.DomainNameLP
;
17 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.RoleIconLP
;
18 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.UserDragListener
;
19 import org
.argeo
.cms
.ui
.workbench
.internal
.useradmin
.providers
.UserTableDefaultDClickListener
;
20 import org
.argeo
.eclipse
.ui
.ColumnDefinition
;
21 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
22 import org
.argeo
.eclipse
.ui
.parts
.LdifUsersTable
;
23 import org
.argeo
.naming
.LdapAttrs
;
24 import org
.argeo
.naming
.LdapObjs
;
25 import org
.eclipse
.jface
.viewers
.TableViewer
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.dnd
.DND
;
28 import org
.eclipse
.swt
.dnd
.TextTransfer
;
29 import org
.eclipse
.swt
.dnd
.Transfer
;
30 import org
.eclipse
.swt
.events
.SelectionAdapter
;
31 import org
.eclipse
.swt
.events
.SelectionEvent
;
32 import org
.eclipse
.swt
.layout
.GridData
;
33 import org
.eclipse
.swt
.layout
.GridLayout
;
34 import org
.eclipse
.swt
.widgets
.Button
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Display
;
37 import org
.eclipse
.ui
.part
.ViewPart
;
38 import org
.osgi
.framework
.InvalidSyntaxException
;
39 import org
.osgi
.service
.useradmin
.Role
;
40 import org
.osgi
.service
.useradmin
.User
;
41 import org
.osgi
.service
.useradmin
.UserAdminEvent
;
42 import org
.osgi
.service
.useradmin
.UserAdminListener
;
44 /** List all groups with filter */
45 public class GroupsView
extends ViewPart
implements ArgeoNames
{
46 private final static Log log
= LogFactory
.getLog(GroupsView
.class);
47 public final static String ID
= WorkbenchUiPlugin
.PLUGIN_ID
+ ".groupsView";
49 /* DEPENDENCY INJECTION */
50 private UserAdminWrapper userAdminWrapper
;
53 private LdifUsersTable groupTableViewerCmp
;
54 private TableViewer userViewer
;
55 private List
<ColumnDefinition
> columnDefs
= new ArrayList
<ColumnDefinition
>();
57 private UserAdminListener listener
;
60 public void createPartControl(Composite parent
) {
61 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
63 // boolean isAdmin = CurrentUser.isInRole(NodeConstants.ROLE_ADMIN);
65 // Define the displayed columns
66 columnDefs
.add(new ColumnDefinition(new RoleIconLP(), "", 19));
67 columnDefs
.add(new ColumnDefinition(new CommonNameLP(), "Name", 150));
68 columnDefs
.add(new ColumnDefinition(new DomainNameLP(), "Domain", 100));
69 // Only show technical DN to admin
71 // columnDefs.add(new ColumnDefinition(new UserNameLP(),
72 // "Distinguished Name", 300));
74 // Create and configure the table
75 groupTableViewerCmp
= new MyUserTableViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
77 groupTableViewerCmp
.setColumnDefinitions(columnDefs
);
79 // groupTableViewerCmp.populateWithStaticFilters(false, false);
81 groupTableViewerCmp
.populate(true, false);
83 groupTableViewerCmp
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 userViewer
= groupTableViewerCmp
.getTableViewer();
87 userViewer
.addDoubleClickListener(new UserTableDefaultDClickListener());
88 getViewSite().setSelectionProvider(userViewer
);
91 groupTableViewerCmp
.refresh();
94 int operations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
95 Transfer
[] tt
= new Transfer
[] { TextTransfer
.getInstance() };
96 userViewer
.addDragSupport(operations
, tt
, new UserDragListener(userViewer
));
98 // // Register a useradmin listener
99 // listener = new UserAdminListener() {
101 // public void roleChanged(UserAdminEvent event) {
102 // if (userViewer != null && !userViewer.getTable().isDisposed())
106 // userAdminWrapper.addListener(listener);
109 // Register a useradmin listener
110 listener
= new MyUiUAListener(parent
.getDisplay());
111 userAdminWrapper
.addListener(listener
);
114 private class MyUiUAListener
extends UiUserAdminListener
{
115 public MyUiUAListener(Display display
) {
120 public void roleChangedToUiThread(UserAdminEvent event
) {
121 if (userViewer
!= null && !userViewer
.getTable().isDisposed())
126 private class MyUserTableViewer
extends LdifUsersTable
{
127 private static final long serialVersionUID
= 8467999509931900367L;
129 private boolean showSystemRoles
= true;
131 private final String
[] knownProps
= { LdapAttrs
.uid
.name(), LdapAttrs
.cn
.name(), LdapAttrs
.DN
};
133 public MyUserTableViewer(Composite parent
, int style
) {
134 super(parent
, style
);
135 showSystemRoles
= CurrentUser
.isInRole(NodeConstants
.ROLE_ADMIN
);
138 protected void populateStaticFilters(Composite staticFilterCmp
) {
139 staticFilterCmp
.setLayout(new GridLayout());
140 final Button showSystemRoleBtn
= new Button(staticFilterCmp
, SWT
.CHECK
);
141 showSystemRoleBtn
.setText("Show system roles");
142 showSystemRoles
= CurrentUser
.isInRole(NodeConstants
.ROLE_ADMIN
);
143 showSystemRoleBtn
.setSelection(showSystemRoles
);
145 showSystemRoleBtn
.addSelectionListener(new SelectionAdapter() {
146 private static final long serialVersionUID
= -7033424592697691676L;
149 public void widgetSelected(SelectionEvent e
) {
150 showSystemRoles
= showSystemRoleBtn
.getSelection();
158 protected List
<User
> listFilteredElements(String filter
) {
161 StringBuilder builder
= new StringBuilder();
162 StringBuilder tmpBuilder
= new StringBuilder();
163 if (EclipseUiUtils
.notEmpty(filter
))
164 for (String prop
: knownProps
) {
165 tmpBuilder
.append("(");
166 tmpBuilder
.append(prop
);
167 tmpBuilder
.append("=*");
168 tmpBuilder
.append(filter
);
169 tmpBuilder
.append("*)");
171 if (tmpBuilder
.length() > 1) {
172 builder
.append("(&(").append(LdapAttrs
.objectClass
.name()).append("=")
173 .append(LdapObjs
.groupOfNames
.name()).append(")");
174 if (!showSystemRoles
)
175 builder
.append("(!(").append(LdapAttrs
.DN
).append("=*").append(NodeConstants
.ROLES_BASEDN
)
177 builder
.append("(|");
178 builder
.append(tmpBuilder
.toString());
179 builder
.append("))");
181 if (!showSystemRoles
)
182 builder
.append("(&(").append(LdapAttrs
.objectClass
.name()).append("=")
183 .append(LdapObjs
.groupOfNames
.name()).append(")(!(").append(LdapAttrs
.DN
).append("=*")
184 .append(NodeConstants
.ROLES_BASEDN
).append(")))");
186 builder
.append("(").append(LdapAttrs
.objectClass
.name()).append("=")
187 .append(LdapObjs
.groupOfNames
.name()).append(")");
190 roles
= userAdminWrapper
.getUserAdmin().getRoles(builder
.toString());
191 } catch (InvalidSyntaxException e
) {
192 throw new CmsException("Unable to get roles with filter: " + filter
, e
);
194 List
<User
> users
= new ArrayList
<User
>();
195 for (Role role
: roles
)
196 if (!users
.contains(role
))
197 users
.add((User
) role
);
199 log
.warn("Duplicated role: " + role
);
205 public void refresh() {
206 groupTableViewerCmp
.refresh();
209 // Override generic view methods
211 public void dispose() {
212 userAdminWrapper
.removeListener(listener
);
217 public void setFocus() {
218 groupTableViewerCmp
.setFocus();
221 /* DEPENDENCY INJECTION */
222 public void setUserAdminWrapper(UserAdminWrapper userAdminWrapper
) {
223 this.userAdminWrapper
= userAdminWrapper
;