1 package org
.argeo
.app
.ui
.people
;
3 import org
.argeo
.api
.acr
.Content
;
4 import org
.argeo
.api
.acr
.ContentSession
;
5 import org
.argeo
.api
.acr
.ldap
.LdapAttr
;
6 import org
.argeo
.api
.acr
.ldap
.LdapObj
;
7 import org
.argeo
.api
.acr
.spi
.ProvidedContent
;
8 import org
.argeo
.api
.cms
.directory
.CmsGroup
;
9 import org
.argeo
.api
.cms
.directory
.CmsUser
;
10 import org
.argeo
.api
.cms
.directory
.CmsUserManager
;
11 import org
.argeo
.api
.cms
.directory
.HierarchyUnit
;
12 import org
.argeo
.app
.ui
.SuiteIcon
;
13 import org
.argeo
.app
.ui
.SuiteMsg
;
14 import org
.argeo
.app
.ui
.SuiteUiUtils
;
15 import org
.argeo
.cms
.CurrentUser
;
16 import org
.argeo
.cms
.acr
.ContentUtils
;
17 import org
.argeo
.cms
.auth
.CmsRole
;
18 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
19 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
20 import org
.argeo
.cms
.swt
.Selected
;
21 import org
.argeo
.cms
.swt
.acr
.SwtSection
;
22 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
23 import org
.argeo
.cms
.swt
.widgets
.SwtTableView
;
24 import org
.argeo
.cms
.ux
.widgets
.AbstractTabularPart
;
25 import org
.argeo
.cms
.ux
.widgets
.CmsDialog
;
26 import org
.argeo
.cms
.ux
.widgets
.TabularPart
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Control
;
32 import org
.eclipse
.swt
.widgets
.ToolBar
;
33 import org
.eclipse
.swt
.widgets
.ToolItem
;
34 import org
.osgi
.service
.useradmin
.Role
;
36 public class GroupUiProvider
implements SwtUiProvider
{
37 private CmsUserManager cmsUserManager
;
40 public Control
createUiPart(Composite parent
, Content context
) {
41 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
43 Content hierarchyUnitContent
= context
.getParent().getParent();
44 HierarchyUnit hierarchyUnit
= hierarchyUnitContent
.adapt(HierarchyUnit
.class);
46 ContentSession contentSession
= ((ProvidedContent
) context
).getSession();
48 TabularPart
<Content
, Content
> membersPart
= new AbstractTabularPart
<Content
, Content
>() {
52 public int getItemCount() {
53 roles
= context
.adapt(CmsGroup
.class).getMembers();
58 public Content
getData(int row
) {
59 Role role
= roles
[row
];
60 Content content
= ContentUtils
.roleToContent(cmsUserManager
, contentSession
, role
);
65 membersPart
.addColumn(new UserColumn());
68 SwtSection area
= new SwtSection(parent
, 0, context
);
69 area
.setLayoutData(CmsSwtUtils
.fillAll());
70 area
.setLayout(new GridLayout());
73 // TODO localise at content level
75 if (context
.hasContentClass(LdapObj
.organization
))
76 title
= SuiteMsg
.org
.lead() + " " + context
.attr(LdapAttr
.cn
) + " ("
77 + hierarchyUnit
.getHierarchyUnitLabel(CurrentUser
.locale()) + ")";
79 title
= SuiteMsg
.group
.lead() + " " + context
.attr(LdapAttr
.cn
) + " ("
80 + hierarchyUnit
.getHierarchyUnitLabel(CurrentUser
.locale()) + ")";
81 SuiteUiUtils
.addFormLabel(area
, title
);
84 ToolBar toolBar
= new ToolBar(area
, SWT
.NONE
);
85 toolBar
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
87 ToolItem deleteItem
= new ToolItem(toolBar
, SWT
.FLAT
);
88 deleteItem
.setEnabled(false);
89 deleteItem
.setImage(theme
.getSmallIcon(SuiteIcon
.delete
));
91 ToolItem addItem
= new ToolItem(toolBar
, SWT
.FLAT
);
92 addItem
.setImage(theme
.getSmallIcon(SuiteIcon
.add
));
93 addItem
.setEnabled(CurrentUser
.implies(CmsRole
.groupAdmin
, hierarchyUnit
.getBase()));
96 SwtTableView
<Content
, Content
> membersView
= new SwtTableView
<>(area
, SWT
.BORDER
, membersPart
);
97 membersView
.setLayoutData(CmsSwtUtils
.fillAll());
98 membersView
.refresh();
101 membersPart
.onSelected((model
) -> {
102 deleteItem
.setEnabled(CurrentUser
.implies(CmsRole
.groupAdmin
, hierarchyUnit
.getBase()));
103 deleteItem
.setData(model
);
106 addItem
.addSelectionListener((Selected
) (e
) -> {
107 ChooseUserDialog chooseUserDialog
= new ChooseUserDialog(parent
.getDisplay().getActiveShell(),
108 SuiteMsg
.chooseAMember
.lead(), contentSession
, cmsUserManager
, hierarchyUnit
);
109 if (chooseUserDialog
.open() == CmsDialog
.OK
) {
110 Content chosen
= chooseUserDialog
.getSelected();
111 cmsUserManager
.addMember(context
.adapt(CmsGroup
.class), chosen
.adapt(CmsUser
.class));
112 membersPart
.refresh();
116 deleteItem
.addSelectionListener((Selected
) (e
) -> {
117 if (deleteItem
.getData() != null) {
118 Content chosen
= (Content
) deleteItem
.getData();
119 cmsUserManager
.removeMember(context
.adapt(CmsGroup
.class), chosen
.adapt(CmsUser
.class));
120 membersPart
.refresh();
128 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
129 this.cmsUserManager
= cmsUserManager
;