]> git.argeo.org Git - lgpl/argeo-commons.git/blob - useradmin/UserLP.java
Prepare next development cycle
[lgpl/argeo-commons.git] / useradmin / UserLP.java
1 package org.argeo.cms.ui.workbench.useradmin;
2
3 import javax.naming.InvalidNameException;
4 import javax.naming.ldap.LdapName;
5
6 import org.argeo.cms.ui.workbench.internal.useradmin.UsersImages;
7 import org.argeo.cms.ui.workbench.internal.useradmin.UsersUtils;
8 import org.argeo.eclipse.ui.EclipseUiException;
9 import org.eclipse.jface.resource.JFaceResources;
10 import org.eclipse.jface.viewers.ColumnLabelProvider;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.graphics.Font;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.widgets.Display;
15 import org.osgi.service.useradmin.Role;
16 import org.osgi.service.useradmin.User;
17
18 /** Centralize label providers for the group table */
19 class UserLP extends ColumnLabelProvider {
20 private static final long serialVersionUID = -4645930210988368571L;
21
22 final static String COL_ICON = "colID.icon";
23 final static String COL_DN = "colID.dn";
24 final static String COL_DISPLAY_NAME = "colID.displayName";
25 final static String COL_DOMAIN = "colID.domain";
26
27 final String currType;
28
29 // private Font italic;
30 private Font bold;
31
32 UserLP(String colId) {
33 this.currType = colId;
34 }
35
36 @Override
37 public Font getFont(Object element) {
38 // Self as bold
39 try {
40 LdapName selfUserName = UsersUtils.getLdapName();
41 String userName = ((User) element).getName();
42 LdapName userLdapName = new LdapName(userName);
43 if (userLdapName.equals(selfUserName)) {
44 if (bold == null)
45 bold = JFaceResources.getFontRegistry()
46 .defaultFontDescriptor().setStyle(SWT.BOLD)
47 .createFont(Display.getCurrent());
48 return bold;
49 }
50 } catch (InvalidNameException e) {
51 throw new EclipseUiException("cannot parse dn for " + element, e);
52 }
53
54 // Disabled as Italic
55 // Node userProfile = (Node) elem;
56 // if (!userProfile.getProperty(ARGEO_ENABLED).getBoolean())
57 // return italic;
58
59 return null;
60 // return super.getFont(element);
61 }
62
63 @Override
64 public Image getImage(Object element) {
65 if (COL_ICON.equals(currType)) {
66 User user = (User) element;
67 String dn = user.getName();
68 if (dn.endsWith(UsersUtils.ROLES_BASEDN))
69 return UsersImages.ICON_ROLE;
70 else if (user.getType() == Role.GROUP)
71 return UsersImages.ICON_GROUP;
72 else
73 return UsersImages.ICON_USER;
74 } else
75 return null;
76 }
77
78 @Override
79 public String getText(Object element) {
80 User user = (User) element;
81 return getText(user);
82
83 }
84
85 public String getText(User user) {
86 if (COL_DN.equals(currType))
87 return user.getName();
88 else if (COL_DISPLAY_NAME.equals(currType))
89 return UsersUtils.getCommonName(user);
90 else if (COL_DOMAIN.equals(currType))
91 return UsersUtils.getDomainName(user);
92 else
93 return "";
94 }
95 }