From 072fa21aaf70e9f67f6bf5781257b58995b720e4 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Tue, 8 Nov 2022 09:58:22 +0100 Subject: [PATCH] Improve people wizards --- .../OSGI-INF/l10n/bundle.properties | 3 +- .../OSGI-INF/l10n/bundle_fr.properties | 5 +- .../config/peopleLayer.properties | 2 +- .../src/org/argeo/app/ui/SuiteMsg.java | 3 + .../org/argeo/app/ui/people/NewOrgForm.java | 95 ++++++++++++++++ .../org/argeo/app/ui/people/NewUserForm.java | 3 +- .../argeo/app/ui/people/PeopleEntryArea.java | 102 +++++++++++++----- .../argeo/app/ui/people/PersonUiProvider.java | 22 ++-- 8 files changed, 196 insertions(+), 39 deletions(-) create mode 100644 swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewOrgForm.java diff --git a/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle.properties b/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle.properties index b99fff6..764f93d 100644 --- a/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle.properties +++ b/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle.properties @@ -11,7 +11,8 @@ appTitle=Argeo Suite # org.argeo.people.ui.PeopleMsg # person=Person -organisation=Organisation +user=user +org=organisation # NewPersonWizard firstName=First Name diff --git a/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle_fr.properties b/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle_fr.properties index 6744ee8..eb9e741 100644 --- a/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle_fr.properties +++ b/swt/org.argeo.app.ui/OSGI-INF/l10n/bundle_fr.properties @@ -14,8 +14,9 @@ appTitle=Argeo Suite # PEOPLE # org.argeo.people.ui.PeopleMsg # -person=Personne -organisation=Organisation +person=personne +user=utilisateur +org=organisation # NewPersonWizard firstName=Prénom diff --git a/swt/org.argeo.app.ui/config/peopleLayer.properties b/swt/org.argeo.app.ui/config/peopleLayer.properties index 2faf172..9224d1b 100644 --- a/swt/org.argeo.app.ui/config/peopleLayer.properties +++ b/swt/org.argeo.app.ui/config/peopleLayer.properties @@ -1,7 +1,7 @@ service.pid=argeo.people.ui.peopleLayer icon=people -weights=5000,5000 +weights=4000,6000 title=%people entity.type=ldap:inetOrgPerson,ldap:groupOfNames,ldap:organizationalUnit,ldap:nsContainer,ldap:dcObject \ No newline at end of file diff --git a/swt/org.argeo.app.ui/src/org/argeo/app/ui/SuiteMsg.java b/swt/org.argeo.app.ui/src/org/argeo/app/ui/SuiteMsg.java index 6fc72c6..305d242 100644 --- a/swt/org.argeo.app.ui/src/org/argeo/app/ui/SuiteMsg.java +++ b/swt/org.argeo.app.ui/src/org/argeo/app/ui/SuiteMsg.java @@ -4,6 +4,9 @@ import org.argeo.cms.Localized; /** Localized messages. */ public enum SuiteMsg implements Localized { + // Entities + user, org, person, + // UI parts dashboard, people, documents, locations, recentItems, // NewPersonWizard firstName, lastName, salutation, email, personWizardWindowTitle, personWizardPageTitle, diff --git a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewOrgForm.java b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewOrgForm.java new file mode 100644 index 0000000..b8c259b --- /dev/null +++ b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewOrgForm.java @@ -0,0 +1,95 @@ +package org.argeo.app.ui.people; + +import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty; + +import org.argeo.api.acr.Content; +import org.argeo.app.ui.SuiteMsg; +import org.argeo.app.ui.SuiteUiUtils; +import org.argeo.cms.CmsUserManager; +import org.argeo.cms.swt.widgets.SwtGuidedFormPage; +import org.argeo.cms.ux.widgets.AbstractGuidedForm; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +/** Ask first & last name. Update the passed node on finish */ +public class NewOrgForm extends AbstractGuidedForm { + private Content hierarchyUnit; + private CmsUserManager cmsUserManager; + + protected Text firstNameT; + + public NewOrgForm(CmsUserManager cmsUserManager, Content hierarchyUnit) { + this.hierarchyUnit = hierarchyUnit; + this.cmsUserManager = cmsUserManager; + } + + @Override + public void addPages() { + try { + MainInfoPage page = new MainInfoPage("main"); + addPage(page); + } catch (Exception e) { + throw new RuntimeException("Cannot add page to wizard", e); + } + setFormTitle(SuiteMsg.orgWizardWindowTitle.lead()); + } + + /** + * Called when the user click on 'Finish' in the wizard. The task is then + * created and the corresponding session saved. + */ + @Override + public boolean performFinish() { + return false; + } + + @Override + public boolean performCancel() { + return true; + } + + @Override + public boolean canFinish() { + String firstName = firstNameT.getText(); + if (isEmpty(firstName)) { + return false; + } else + return true; + } + + protected class MainInfoPage extends SwtGuidedFormPage { + + public MainInfoPage(String pageName) { + super(pageName); + setTitle(SuiteMsg.orgWizardPageTitle.lead()); + } + + public void createControl(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + + // FirstName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.org); + firstNameT = new Text(parent, SWT.BORDER); + // firstNameTxt.setMessage("a first name"); + firstNameT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + ModifyListener ml = new ModifyListener() { + private static final long serialVersionUID = 1939491923843870844L; + + @Override + public void modifyText(ModifyEvent event) { + getView().updateButtons(); + } + }; + + firstNameT.addModifyListener(ml); + + firstNameT.setFocus(); + } + } +} diff --git a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewUserForm.java b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewUserForm.java index cdd2dc0..41b7907 100644 --- a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewUserForm.java +++ b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewUserForm.java @@ -16,7 +16,6 @@ import org.argeo.app.core.SuiteUtils; import org.argeo.app.ui.SuiteMsg; import org.argeo.app.ui.SuiteUiUtils; import org.argeo.cms.CmsUserManager; -import org.argeo.cms.acr.ContentUtils; import org.argeo.cms.swt.dialogs.CmsFeedback; import org.argeo.cms.swt.widgets.SwtGuidedFormPage; import org.argeo.cms.ux.widgets.AbstractGuidedForm; @@ -49,7 +48,7 @@ public class NewUserForm extends AbstractGuidedForm { @Override public void addPages() { try { - MainInfoPage page = new MainInfoPage("Main page"); + MainInfoPage page = new MainInfoPage("main"); addPage(page); } catch (Exception e) { throw new RuntimeException("Cannot add page to wizard", e); diff --git a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PeopleEntryArea.java b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PeopleEntryArea.java index 81463a2..a8c50f1 100644 --- a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PeopleEntryArea.java +++ b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PeopleEntryArea.java @@ -16,6 +16,7 @@ import org.argeo.api.cms.directory.HierarchyUnit; import org.argeo.api.cms.ux.CmsIcon; import org.argeo.api.cms.ux.CmsView; import org.argeo.app.ui.SuiteIcon; +import org.argeo.app.ui.SuiteMsg; import org.argeo.app.ui.SuiteUxEvent; import org.argeo.cms.CmsUserManager; import org.argeo.cms.acr.ContentUtils; @@ -40,10 +41,15 @@ import org.argeo.cms.ux.widgets.HierarchicalPart; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.osgi.service.useradmin.Role; @@ -102,9 +108,9 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { @Override public CmsIcon getIcon(HierarchyUnit model) { Content content = ContentUtils.hierarchyUnitToContent(contentSession, model); - if (content.hasContentClass(LdapObjs.organization.qName())) + if (content.hasContentClass(LdapObjs.organization)) return SuiteIcon.organisation; - else if (content.hasContentClass(LdapObjs.posixGroup.qName())) + else if (content.hasContentClass(LdapObjs.posixGroup)) return SuiteIcon.users; else return SuiteIcon.addressBook; @@ -122,7 +128,7 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { if (ud.getRealm().isPresent()) { for (Role r : ud.getHierarchyUnitRoles(ud, null, true)) { Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r); - if (content.hasContentClass(LdapObjs.inetOrgPerson.qName(), LdapObjs.organization.qName())) + if (content.hasContentClass(LdapObjs.inetOrgPerson, LdapObjs.organization)) roles.add(content); } @@ -132,8 +138,8 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { || directChild.isType(HierarchyUnit.Type.ROLES))) { for (Role r : ud.getHierarchyUnitRoles(directChild, null, false)) { Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r); - if (content.hasContentClass(LdapObjs.inetOrgPerson.qName(), - LdapObjs.organization.qName(), LdapObjs.groupOfNames.qName())) + if (content.hasContentClass(LdapObjs.inetOrgPerson, LdapObjs.organization, + LdapObjs.groupOfNames)) roles.add(content); } } @@ -146,25 +152,25 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { @Override public String getText(Content role) { - if (role.isContentClass(LdapObjs.inetOrgPerson.qName())) + if (role.hasContentClass(LdapObjs.inetOrgPerson)) return UserAdminUtils.getUserDisplayName(role.adapt(User.class)); - else if (role.isContentClass(LdapObjs.organization.qName())) - return role.attr(LdapAttrs.o.qName()); - else if (role.isContentClass(LdapObjs.groupOfNames.qName())) - return role.attr(LdapAttrs.cn.qName()); + else if (role.hasContentClass(LdapObjs.organization)) + return role.attr(LdapAttrs.o); + else if (role.hasContentClass(LdapObjs.groupOfNames)) + return role.attr(LdapAttrs.cn); else return null; } @Override public CmsIcon getIcon(Content role) { - if (role.hasContentClass(LdapObjs.posixAccount.qName())) + if (role.hasContentClass(LdapObjs.posixAccount)) return SuiteIcon.user; - else if (role.isContentClass(LdapObjs.inetOrgPerson.qName())) + else if (role.hasContentClass(LdapObjs.inetOrgPerson)) return SuiteIcon.person; - else if (role.isContentClass(LdapObjs.organization.qName())) + else if (role.hasContentClass(LdapObjs.organization)) return SuiteIcon.organisationContact; - else if (role.isContentClass(LdapObjs.groupOfNames.qName())) + else if (role.hasContentClass(LdapObjs.groupOfNames)) return SuiteIcon.group; else return null; @@ -176,30 +182,75 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { } }); - usersPart.addColumn((Column) (role) -> role.attr(LdapAttrs.mail.qName())); +// usersPart.addColumn((Column) (role) -> role.attr(LdapAttrs.mail)); + usersPart.addColumn(new Column() { - new SwtTableView<>(sashForm, SWT.BORDER, usersPart); + @Override + public String getText(Content role) { + return role.attr(LdapAttrs.mail); + } + @Override + public int getWidth() { + return 300; + } + }); // toolbar - Composite bottom = new Composite(parent, SWT.NONE); + Composite bottom = new Composite(sashForm, SWT.NONE); bottom.setLayoutData(CmsSwtUtils.fillWidth()); bottom.setLayout(CmsSwtUtils.noSpaceGridLayout()); ToolBar bottomToolBar = new ToolBar(bottom, SWT.NONE); bottomToolBar.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false)); + ToolItem deleteItem = new ToolItem(bottomToolBar, SWT.FLAT); deleteItem.setEnabled(false); // CmsUiUtils.style(deleteItem, SuiteStyle.recentItems); deleteItem.setImage(theme.getSmallIcon(SuiteIcon.delete)); - ToolItem addItem = new ToolItem(bottomToolBar, SWT.FLAT); + + Menu menu = new Menu(Display.getCurrent().getActiveShell(), SWT.POP_UP); + // TODO display add user only if hierarchy unit is a POSIX group + // hierarchyUnit.hasContentClass(LdapObjs.posixGroup.qName()) + MenuItem addUserItem = new MenuItem(menu, SWT.PUSH); + addUserItem.setImage(theme.getSmallIcon(SuiteIcon.user)); + addUserItem.setText(SuiteMsg.user.lead()); + addUserItem.addSelectionListener((Selected) (e) -> { + HierarchyUnit hierarchyUnit = usersPart.getInput(); + Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit); + GuidedForm wizard = new NewUserForm(cmsUserManager, huContent); + SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard); + if (dialog.open() == Window.OK) { + // TODO create + } + }); + + MenuItem addOrgItem = new MenuItem(menu, SWT.PUSH); + addOrgItem.setImage(theme.getSmallIcon(SuiteIcon.organisation)); + addOrgItem.setText(SuiteMsg.org.lead()); + addOrgItem.addSelectionListener((Selected) (e) -> { + HierarchyUnit hierarchyUnit = usersPart.getInput(); + Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit); + GuidedForm wizard = new NewOrgForm(cmsUserManager, huContent); + SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard); + if (dialog.open() == Window.OK) { + // TODO create + } + }); + + ToolItem addItem = new ToolItem(bottomToolBar, SWT.PUSH); + addItem.setEnabled(false); addItem.setImage(theme.getSmallIcon(SuiteIcon.add)); sashForm.setWeights(new int[] { 30, 70 }); + SwtTableView usersTable = new SwtTableView<>(bottom, SWT.BORDER, usersPart); + usersTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + // CONTROLLER hierarchyPart.onSelected((o) -> { if (o instanceof HierarchyUnit) { HierarchyUnit hierarchyUnit = (HierarchyUnit) o; usersPart.setInput(hierarchyUnit); + addItem.setEnabled(true); // cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent // .eventProperties(ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit))); } @@ -223,14 +274,13 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider { }); addItem.addSelectionListener((Selected) (e) -> { - HierarchyUnit hierarchyUnit = usersPart.getInput(); - Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit); - GuidedForm wizard = new NewUserForm(cmsUserManager, huContent); - SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard); - // WizardDialog dialog = new WizardDialog(shell, wizard); - if (dialog.open() == Window.OK) { - // TODO create - } +// if (e.detail == SWT.ARROW) { + Rectangle rect = addItem.getBounds(); + Point pt = new Point(rect.x, rect.y + rect.height); + pt = bottomToolBar.toDisplay(pt); + menu.setLocation(pt.x, pt.y); + menu.setVisible(true); +// } }); directoriesView.refresh(); diff --git a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java index e296315..6343c1b 100644 --- a/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java +++ b/swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import org.argeo.api.acr.Content; +import org.argeo.api.acr.QNamed; import org.argeo.api.acr.ldap.LdapAttrs; import org.argeo.api.acr.ldap.LdapObjs; import org.argeo.app.api.SuiteRole; @@ -34,6 +35,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.osgi.service.useradmin.User; @@ -63,7 +65,7 @@ public class PersonUiProvider implements SwtUiProvider { SwtSection rolesSection = new SwtSection(main, SWT.NONE); rolesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); - rolesSection.setLayout(new GridLayout()); + rolesSection.setLayout(new GridLayout(2, false)); List roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName())); addRoleCheckBox(rolesSection, SuiteMsg.coworkerRole, SuiteRole.coworker, roleContext, roles); addRoleCheckBox(rolesSection, SuiteMsg.publisherRole, SuiteRole.publisher, roleContext, roles); @@ -115,17 +117,19 @@ public class PersonUiProvider implements SwtUiProvider { return main; } - private void addFormLine(SwtSection parent, Localized msg, Content context, LdapAttrs attr) { + private void addFormLine(SwtSection parent, Localized msg, Content content, QNamed attr) { SuiteUiUtils.addFormLabel(parent, msg.lead()); EditableText text = new EditableText(parent, SWT.SINGLE | SWT.FLAT); text.setLayoutData(CmsSwtUtils.fillWidth()); text.setStyle(SuiteStyle.simpleInput); - String txt = context.attr(attr.qName()); + String txt = content.attr(attr); if (txt == null) // FIXME understand why email is not found in IPA txt = ""; text.setText(txt); text.setMouseListener(new MouseAdapter() { + private static final long serialVersionUID = 1L; + @Override public void mouseDoubleClick(MouseEvent e) { String currentTxt = text.getText(); @@ -133,6 +137,8 @@ public class PersonUiProvider implements SwtUiProvider { text.setText(currentTxt); ((Text) text.getControl()).addSelectionListener(new SelectionListener() { + private static final long serialVersionUID = 1L; + @Override public void widgetSelected(SelectionEvent e) { } @@ -153,7 +159,6 @@ public class PersonUiProvider implements SwtUiProvider { private void addRoleCheckBox(SwtSection parent, Localized msg, SystemRole systemRole, String roleContext, List roles) { Button radio = new Button(parent, SWT.CHECK); - radio.setText(msg.lead()); radio.setSelection(false); roles: for (String dn : roles) { if (systemRole.implied(dn, roleContext)) { @@ -161,10 +166,13 @@ public class PersonUiProvider implements SwtUiProvider { break roles; } } - if (CurrentUser.implies(CmsRole.userAdmin, roleContext)) - radio.setEnabled(true); + + if (systemRole.equals(CmsRole.userAdmin)) + radio.setEnabled(CurrentUser.implies(CmsRole.groupAdmin, roleContext)); else - radio.setEnabled(false); + radio.setEnabled(CurrentUser.implies(CmsRole.userAdmin, roleContext)); + + new Label(parent, 0).setText(msg.lead()); } -- 2.30.2