Improve people wizards
authorMathieu <mbaudier@argeo.org>
Tue, 8 Nov 2022 08:58:22 +0000 (09:58 +0100)
committerMathieu <mbaudier@argeo.org>
Tue, 8 Nov 2022 08:58:22 +0000 (09:58 +0100)
swt/org.argeo.app.ui/OSGI-INF/l10n/bundle.properties
swt/org.argeo.app.ui/OSGI-INF/l10n/bundle_fr.properties
swt/org.argeo.app.ui/config/peopleLayer.properties
swt/org.argeo.app.ui/src/org/argeo/app/ui/SuiteMsg.java
swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewOrgForm.java [new file with mode: 0644]
swt/org.argeo.app.ui/src/org/argeo/app/ui/people/NewUserForm.java
swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PeopleEntryArea.java
swt/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java

index b99fff652816795dd4a8350ecd07f4b50bcd0da8..764f93de817d02f428e422f08a9057787d714f92 100644 (file)
@@ -11,7 +11,8 @@ appTitle=Argeo Suite
 # org.argeo.people.ui.PeopleMsg
 #
 person=Person
-organisation=Organisation
+user=user
+org=organisation
 
 # NewPersonWizard
 firstName=First Name
index 6744ee877f217022128f756b831ecabb4020196e..eb9e741da17de7338c9f7d2e4f51ef60f03cc498 100644 (file)
@@ -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
index 2faf1728b3adfaecc1cbb240d8ae1654592e1ab6..9224d1bd4e739402039a30fc238c84f68de35d24 100644 (file)
@@ -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
index 6fc72c6d34c2638913b77db2ba220d53938d3004..305d242e39610c35722d9e6cbb461e2b87b11bb4 100644 (file)
@@ -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 (file)
index 0000000..b8c259b
--- /dev/null
@@ -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();
+               }
+       }
+}
index cdd2dc07dc04d1bf5b13d4c9f0806f9ba79f615c..41b790742556de6a539ecd9c228c214d1ba5518b 100644 (file)
@@ -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);
index 81463a2417431cba75a03f9fbe5da95ae34ad43c..a8c50f1f65d0bb161a5505cef607491b58b9663f 100644 (file)
@@ -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<Content>) (role) -> role.attr(LdapAttrs.mail.qName()));
+//             usersPart.addColumn((Column<Content>) (role) -> role.attr(LdapAttrs.mail));
+               usersPart.addColumn(new Column<Content>() {
 
-               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();
index e296315ea9abf9b51e3dd2af6a3808e1aec82879..6343c1bca15238a8bbe5a1508e0541ac7ec233e5 100644 (file)
@@ -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<String> 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<String> 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());
 
        }