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