1 package org
.argeo
.app
.ui
.people
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.api
.acr
.Content
;
7 import org
.argeo
.api
.acr
.ContentRepository
;
8 import org
.argeo
.api
.acr
.ContentSession
;
9 import org
.argeo
.api
.acr
.ldap
.LdapAttr
;
10 import org
.argeo
.api
.cms
.directory
.CmsUserManager
;
11 import org
.argeo
.api
.cms
.directory
.HierarchyUnit
;
12 import org
.argeo
.api
.cms
.ux
.CmsView
;
13 import org
.argeo
.app
.ux
.SuiteIcon
;
14 import org
.argeo
.app
.ux
.SuiteMsg
;
15 import org
.argeo
.app
.ux
.SuiteUxEvent
;
16 import org
.argeo
.cms
.CurrentUser
;
17 import org
.argeo
.cms
.acr
.ContentUtils
;
18 import org
.argeo
.cms
.auth
.CmsRole
;
19 import org
.argeo
.cms
.jcr
.acr
.JcrContent
;
20 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
21 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
22 import org
.argeo
.cms
.swt
.Selected
;
23 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
24 import org
.argeo
.cms
.swt
.dialogs
.CmsFeedback
;
25 import org
.argeo
.cms
.swt
.widgets
.SwtGuidedFormDialog
;
26 import org
.argeo
.cms
.swt
.widgets
.SwtTableView
;
27 import org
.argeo
.cms
.swt
.widgets
.SwtTreeView
;
28 import org
.argeo
.cms
.ui
.CmsUiProvider
;
29 import org
.argeo
.cms
.ux
.widgets
.CmsDialog
;
30 import org
.argeo
.cms
.ux
.widgets
.Column
;
31 import org
.argeo
.cms
.ux
.widgets
.GuidedForm
;
32 import org
.eclipse
.swt
.SWT
;
33 import org
.eclipse
.swt
.custom
.SashForm
;
34 import org
.eclipse
.swt
.graphics
.Point
;
35 import org
.eclipse
.swt
.graphics
.Rectangle
;
36 import org
.eclipse
.swt
.layout
.GridData
;
37 import org
.eclipse
.swt
.layout
.GridLayout
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Control
;
40 import org
.eclipse
.swt
.widgets
.Display
;
41 import org
.eclipse
.swt
.widgets
.Menu
;
42 import org
.eclipse
.swt
.widgets
.MenuItem
;
43 import org
.eclipse
.swt
.widgets
.ToolBar
;
44 import org
.eclipse
.swt
.widgets
.ToolItem
;
46 /** Entry to the admin area. */
47 public class PeopleEntryArea
implements SwtUiProvider
, CmsUiProvider
{
49 private CmsUserManager cmsUserManager
;
51 private ContentRepository contentRepository
;
54 public Control
createUiPart(Composite parent
, Content context
) {
55 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
56 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
57 parent
.setLayout(new GridLayout());
59 ContentSession contentSession
= contentRepository
.get();
60 SashForm sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
61 CmsSwtUtils
.fill(sashForm
);
64 HierarchyUnitPart hierarchyPart
= new HierarchyUnitPart(contentSession
, cmsUserManager
);
65 SwtTreeView
<HierarchyUnit
> directoriesView
= new SwtTreeView
<>(sashForm
, SWT
.BORDER
, hierarchyPart
);
67 UsersPart usersPart
= new UsersPart(contentSession
, cmsUserManager
);
68 usersPart
.addColumn(new Column
<Content
>() {
71 public String
getText(Content role
) {
72 return role
.attr(LdapAttr
.mail
);
76 public int getWidth() {
81 Composite bottom
= new Composite(sashForm
, SWT
.NONE
);
82 bottom
.setLayoutData(CmsSwtUtils
.fillWidth());
83 bottom
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
84 ToolBar bottomToolBar
= new ToolBar(bottom
, SWT
.NONE
);
85 bottomToolBar
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
87 // ToolItem deleteItem = new ToolItem(bottomToolBar, SWT.FLAT);
88 // deleteItem.setEnabled(false);
89 // deleteItem.setImage(theme.getSmallIcon(SuiteIcon.delete));
91 Menu menu
= new Menu(Display
.getCurrent().getActiveShell(), SWT
.POP_UP
);
92 // TODO display add user only if hierarchy unit is a POSIX group
93 // hierarchyUnit.hasContentClass(LdapObjs.posixGroup.qName())
94 MenuItem addUserItem
= new MenuItem(menu
, SWT
.PUSH
);
95 addUserItem
.setImage(theme
.getSmallIcon(SuiteIcon
.user
));
96 addUserItem
.setText(SuiteMsg
.user
.lead());
97 addUserItem
.addSelectionListener((Selected
) (e
) -> {
98 HierarchyUnit hierarchyUnit
= usersPart
.getInput();
99 Content huContent
= ContentUtils
.hierarchyUnitToContent(contentSession
, hierarchyUnit
);
100 GuidedForm wizard
= new NewUserForm(cmsUserManager
, huContent
);
101 SwtGuidedFormDialog dialog
= new SwtGuidedFormDialog(parent
.getShell(), wizard
);
102 if (dialog
.open() == CmsDialog
.OK
) {
103 CmsFeedback
.show(SuiteMsg
.personWizardFeedback
.lead());
108 MenuItem addOrgItem
= new MenuItem(menu
, SWT
.PUSH
);
109 addOrgItem
.setImage(theme
.getSmallIcon(SuiteIcon
.organisation
));
110 addOrgItem
.setText(SuiteMsg
.org
.lead());
111 addOrgItem
.addSelectionListener((Selected
) (e
) -> {
112 HierarchyUnit hierarchyUnit
= usersPart
.getInput();
113 Content huContent
= ContentUtils
.hierarchyUnitToContent(contentSession
, hierarchyUnit
);
114 GuidedForm wizard
= new NewOrgForm(cmsUserManager
, huContent
);
115 SwtGuidedFormDialog dialog
= new SwtGuidedFormDialog(parent
.getShell(), wizard
);
116 if (dialog
.open() == CmsDialog
.OK
) {
117 CmsFeedback
.show(SuiteMsg
.orgWizardFeedback
.lead());
122 ToolItem addItem
= new ToolItem(bottomToolBar
, SWT
.PUSH
);
123 addItem
.setEnabled(false);
124 addItem
.setImage(theme
.getSmallIcon(SuiteIcon
.add
));
126 sashForm
.setWeights(new int[] { 30, 70 });
128 SwtTableView
<?
, ?
> usersView
= new SwtTableView
<>(bottom
, SWT
.BORDER
, usersPart
);
129 usersView
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
132 hierarchyPart
.onSelected((o
) -> {
133 if (o
instanceof HierarchyUnit
) {
134 HierarchyUnit hierarchyUnit
= (HierarchyUnit
) o
;
135 usersPart
.setInput(hierarchyUnit
);
136 addItem
.setEnabled(true);
138 addOrgItem
.setEnabled(usersPart
.getInput() != null
139 && CurrentUser
.implies(CmsRole
.groupAdmin
, usersPart
.getInput().getBase()));
140 // cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent
141 // .eventProperties(ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit)));
145 usersPart
.onSelected((o
) -> {
146 Content user
= (Content
) o
;
148 cmsView
.sendEvent(SuiteUxEvent
.refreshPart
.topic(), SuiteUxEvent
.eventProperties(user
));
149 // deleteItem.setEnabled(true);
151 // deleteItem.setEnabled(false);
155 usersPart
.onAction((o
) -> {
156 Content user
= (Content
) o
;
158 cmsView
.sendEvent(SuiteUxEvent
.openNewPart
.topic(), SuiteUxEvent
.eventProperties(user
));
162 addItem
.addSelectionListener((Selected
) (e
) -> {
163 // if (e.detail == SWT.ARROW) {
164 Rectangle rect
= addItem
.getBounds();
165 Point pt
= new Point(rect
.x
, rect
.y
+ rect
.height
);
166 pt
= bottomToolBar
.toDisplay(pt
);
167 menu
.setLocation(pt
.x
, pt
.y
);
168 menu
.setVisible(true);
172 directoriesView
.refresh();
173 // usersView.refresh();
178 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
179 this.cmsUserManager
= cmsUserManager
;
183 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
184 return createUiPart(parent
, JcrContent
.nodeToContent(context
));
187 public void setContentRepository(ContentRepository contentRepository
) {
188 this.contentRepository
= contentRepository
;