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
.acr
.SwtUiProvider
;
16 import org
.argeo
.cms
.swt
.widgets
.EditableText
;
17 import org
.argeo
.util
.naming
.LdapAttrs
;
18 import org
.argeo
.util
.naming
.LdapObjs
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.MouseAdapter
;
21 import org
.eclipse
.swt
.events
.MouseEvent
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.events
.SelectionListener
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Button
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Control
;
29 import org
.eclipse
.swt
.widgets
.Text
;
30 import org
.osgi
.service
.useradmin
.User
;
32 /** Edit a suite user. */
33 public class PersonUiProvider
implements SwtUiProvider
{
34 private String
[] availableRoles
;
35 private CmsUserManager cmsUserManager
;
38 public Control
createUiPart(Composite parent
, Content context
) {
39 SwtSection main
= new SwtSection(parent
, SWT
.NONE
, context
);
40 main
.setLayoutData(CmsSwtUtils
.fillAll());
42 main
.setLayout(new GridLayout(2, false));
44 User user
= context
.adapt(User
.class);
46 if (context
.hasContentClass(LdapObjs
.person
.qName())) {
47 addFormLine(main
, SuiteMsg
.firstName
, context
, LdapAttrs
.givenName
);
48 addFormLine(main
, SuiteMsg
.lastName
, context
, LdapAttrs
.sn
);
49 addFormLine(main
, SuiteMsg
.email
, context
, LdapAttrs
.mail
);
51 Composite rolesSection
= new Composite(main
, SWT
.NONE
);
52 // rolesSection.setText("Roles");
53 rolesSection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
54 rolesSection
.setLayout(new GridLayout());
55 // new Label(rolesSection, SWT.NONE).setText("Roles:");
56 List
<String
> roles
= Arrays
.asList(cmsUserManager
.getUserRoles(user
.getName()));
57 for (String role
: roles
) {
58 // new Label(rolesSection, SWT.NONE).setText(role);
59 Button radio
= new Button(rolesSection
, SWT
.CHECK
);
61 if (roles
.contains(role
))
62 radio
.setSelection(true);
65 // Composite facetsSection = new Composite(main, SWT.NONE);
66 // facetsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
67 // facetsSection.setLayout(new GridLayout());
68 // if (context.hasContentClass(LdapObjs.groupOfNames.qName())) {
69 // String[] members = context.attr(LdapAttrs.member.qName()).split("\n");
70 // for (String member : members) {
71 // new Label(facetsSection, SWT.NONE).setText(member);
76 // if (user instanceof Group) {
77 // String cn = context.getName().getLocalPart();
78 // Text cnT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
82 // String uid = context.getName().getLocalPart();
84 //// Text givenName = new Text(main, SWT.SINGLE);
85 //// givenName.setText(getUserProperty(user, LdapAttrs.givenName.name()));
86 // Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(),
87 // getUserProperty(user, LdapAttrs.givenName.name()));
89 // Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(),
90 // getUserProperty(user, LdapAttrs.sn.name()));
91 // // sn.setText(getUserProperty(user, LdapAttrs.sn.name()));
93 // Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(),
94 // getUserProperty(user, LdapAttrs.mail.name()));
95 // // email.setText(getUserProperty(user, LdapAttrs.mail.name()));
97 // Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
100 //// Label dnL = new Label(main, SWT.NONE);
101 //// dnL.setText(user.getName());
104 // // Section rolesSection = new Section(main, SWT.NONE, context);
105 // Composite rolesSection = new Composite(main, SWT.NONE);
106 // // rolesSection.setText("Roles");
107 // rolesSection.setLayoutData(CmsSwtUtils.fillWidth());
108 // rolesSection.setLayout(new GridLayout());
109 // // new Label(rolesSection, SWT.NONE).setText("Roles:");
110 // List<String> roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName()));
111 // for (String role : availableRoles) {
112 // // new Label(rolesSection, SWT.NONE).setText(role);
113 // Button radio = new Button(rolesSection, SWT.CHECK);
114 // radio.setText(role);
115 // if (roles.contains(role))
116 // radio.setSelection(true);
123 private void addFormLine(SwtSection parent
, Localized msg
, Content context
, LdapAttrs attr
) {
124 SuiteUiUtils
.addFormLabel(parent
, msg
.lead());
125 EditableText text
= new EditableText(parent
, SWT
.SINGLE
| SWT
.FLAT
);
126 text
.setLayoutData(CmsSwtUtils
.fillWidth());
127 text
.setStyle(SuiteStyle
.simpleInput
);
128 String txt
= context
.attr(attr
.qName());
129 if (txt
== null) // FIXME understand why email is not found in IPA
132 text
.setMouseListener(new MouseAdapter() {
135 public void mouseDoubleClick(MouseEvent e
) {
136 String currentTxt
= text
.getText();
138 text
.setText(currentTxt
);
139 ((Text
) text
.getControl()).addSelectionListener(new SelectionListener() {
142 public void widgetSelected(SelectionEvent e
) {
146 public void widgetDefaultSelected(SelectionEvent e
) {
147 String editedTxt
= text
.getText();
149 text
.setText(editedTxt
);
150 text
.getParent().layout(new Control
[] { text
.getControl() });
158 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
159 this.cmsUserManager
= cmsUserManager
;
162 private String
getUserProperty(Object element
, String key
) {
163 Object value
= ((User
) element
).getProperties().get(key
);
164 return value
!= null ? value
.toString() : null;
167 public void init(Map
<String
, Object
> properties
) {
168 availableRoles
= (String
[]) properties
.get("availableRoles");
169 // cmsUserManager.getRoles(null);