1 package org
.argeo
.app
.ui
.people
;
3 import java
.util
.Arrays
;
7 import org
.argeo
.api
.acr
.Content
;
8 import org
.argeo
.app
.ui
.SuiteMsg
;
9 import org
.argeo
.app
.ui
.SuiteStyle
;
10 import org
.argeo
.app
.ui
.SuiteUiUtils
;
11 import org
.argeo
.cms
.CmsUserManager
;
12 import org
.argeo
.cms
.Localized
;
13 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
14 import org
.argeo
.cms
.swt
.acr
.SwtSection
;
15 import org
.argeo
.cms
.swt
.widgets
.EditableText
;
16 import org
.argeo
.cms
.ui
.CmsUiProvider
;
17 import org
.argeo
.util
.naming
.LdapAttrs
;
18 import org
.argeo
.util
.naming
.LdapObjs
;
19 import org
.argeo
.util
.naming
.QNamed
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.events
.MouseAdapter
;
22 import org
.eclipse
.swt
.events
.MouseEvent
;
23 import org
.eclipse
.swt
.events
.SelectionEvent
;
24 import org
.eclipse
.swt
.events
.SelectionListener
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.Text
;
31 import org
.osgi
.service
.useradmin
.User
;
33 /** Edit a suite user. */
34 public class PersonUiProvider
implements CmsUiProvider
{
35 private String
[] availableRoles
;
36 private CmsUserManager cmsUserManager
;
39 public Control
createUiPart(Composite parent
, Content context
) {
40 SwtSection main
= new SwtSection(parent
, SWT
.NONE
, context
);
41 main
.setLayoutData(CmsSwtUtils
.fillAll());
43 main
.setLayout(new GridLayout(2, false));
45 User user
= context
.adapt(User
.class);
47 if (context
.hasContentClass(LdapObjs
.person
.qName())) {
48 addFormLine(main
, SuiteMsg
.firstName
, context
, LdapAttrs
.givenName
);
49 addFormLine(main
, SuiteMsg
.lastName
, context
, LdapAttrs
.sn
);
50 addFormLine(main
, SuiteMsg
.email
, context
, LdapAttrs
.mail
);
52 Composite rolesSection
= new Composite(main
, SWT
.NONE
);
53 // rolesSection.setText("Roles");
54 rolesSection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
55 rolesSection
.setLayout(new GridLayout());
56 // new Label(rolesSection, SWT.NONE).setText("Roles:");
57 List
<String
> roles
= Arrays
.asList(cmsUserManager
.getUserRoles(user
.getName()));
58 for (String role
: roles
) {
59 // new Label(rolesSection, SWT.NONE).setText(role);
60 Button radio
= new Button(rolesSection
, SWT
.CHECK
);
62 if (roles
.contains(role
))
63 radio
.setSelection(true);
66 // Composite facetsSection = new Composite(main, SWT.NONE);
67 // facetsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
68 // facetsSection.setLayout(new GridLayout());
69 // if (context.hasContentClass(LdapObjs.groupOfNames.qName())) {
70 // String[] members = context.attr(LdapAttrs.member.qName()).split("\n");
71 // for (String member : members) {
72 // new Label(facetsSection, SWT.NONE).setText(member);
77 // if (user instanceof Group) {
78 // String cn = context.getName().getLocalPart();
79 // Text cnT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
83 // String uid = context.getName().getLocalPart();
85 //// Text givenName = new Text(main, SWT.SINGLE);
86 //// givenName.setText(getUserProperty(user, LdapAttrs.givenName.name()));
87 // Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(),
88 // getUserProperty(user, LdapAttrs.givenName.name()));
90 // Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(),
91 // getUserProperty(user, LdapAttrs.sn.name()));
92 // // sn.setText(getUserProperty(user, LdapAttrs.sn.name()));
94 // Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(),
95 // getUserProperty(user, LdapAttrs.mail.name()));
96 // // email.setText(getUserProperty(user, LdapAttrs.mail.name()));
98 // Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
101 //// Label dnL = new Label(main, SWT.NONE);
102 //// dnL.setText(user.getName());
105 // // Section rolesSection = new Section(main, SWT.NONE, context);
106 // Composite rolesSection = new Composite(main, SWT.NONE);
107 // // rolesSection.setText("Roles");
108 // rolesSection.setLayoutData(CmsSwtUtils.fillWidth());
109 // rolesSection.setLayout(new GridLayout());
110 // // new Label(rolesSection, SWT.NONE).setText("Roles:");
111 // List<String> roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName()));
112 // for (String role : availableRoles) {
113 // // new Label(rolesSection, SWT.NONE).setText(role);
114 // Button radio = new Button(rolesSection, SWT.CHECK);
115 // radio.setText(role);
116 // if (roles.contains(role))
117 // radio.setSelection(true);
124 private void addFormLine(SwtSection parent
, Localized msg
, Content context
, QNamed attr
) {
125 SuiteUiUtils
.addFormLabel(parent
, msg
.lead());
126 EditableText text
= new EditableText(parent
, SWT
.SINGLE
| SWT
.FLAT
);
127 text
.setLayoutData(CmsSwtUtils
.fillWidth());
128 text
.setStyle(SuiteStyle
.simpleInput
);
129 String txt
= context
.attr(attr
.qName());
130 if (txt
== null) // FIXME understand why email is not found in IPA
133 text
.setMouseListener(new MouseAdapter() {
136 public void mouseDoubleClick(MouseEvent e
) {
137 String currentTxt
= text
.getText();
139 text
.setText(currentTxt
);
140 ((Text
) text
.getControl()).addSelectionListener(new SelectionListener() {
143 public void widgetSelected(SelectionEvent e
) {
147 public void widgetDefaultSelected(SelectionEvent e
) {
148 String editedTxt
= text
.getText();
150 text
.setText(editedTxt
);
151 text
.getParent().layout(new Control
[] { text
.getControl() });
159 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
160 this.cmsUserManager
= cmsUserManager
;
163 private String
getUserProperty(Object element
, String key
) {
164 Object value
= ((User
) element
).getProperties().get(key
);
165 return value
!= null ? value
.toString() : null;
168 public void init(Map
<String
, Object
> properties
) {
169 availableRoles
= (String
[]) properties
.get("availableRoles");
170 // cmsUserManager.getRoles(null);