Group management
[gpl/argeo-suite.git] / swt / org.argeo.app.ui / src / org / argeo / app / ui / people / PeopleEntryArea.java
index d54a9d82d7ccb38fa68965fecb39c8333a204642..e2339919bec00a17f3c7eee8e3b0e6612ddc8777 100644 (file)
@@ -1,29 +1,19 @@
 package org.argeo.app.ui.people;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 import org.argeo.api.acr.Content;
 import org.argeo.api.acr.ContentRepository;
 import org.argeo.api.acr.ContentSession;
-import org.argeo.api.acr.ldap.LdapAttrs;
-import org.argeo.api.acr.ldap.LdapObjs;
-import org.argeo.api.cms.directory.CmsDirectory;
+import org.argeo.api.acr.ldap.LdapAttr;
+import org.argeo.api.cms.directory.CmsUserManager;
 import org.argeo.api.cms.directory.HierarchyUnit;
-import org.argeo.api.cms.directory.UserDirectory;
-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;
-import org.argeo.cms.auth.CmsRole;
-import org.argeo.cms.auth.CurrentUser;
-import org.argeo.cms.auth.UserAdminUtils;
 import org.argeo.cms.jcr.acr.JcrContent;
 import org.argeo.cms.swt.CmsSwtTheme;
 import org.argeo.cms.swt.CmsSwtUtils;
@@ -33,12 +23,9 @@ import org.argeo.cms.swt.widgets.SwtGuidedFormDialog;
 import org.argeo.cms.swt.widgets.SwtTableView;
 import org.argeo.cms.swt.widgets.SwtTreeView;
 import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.cms.ux.widgets.AbstractHierarchicalPart;
+import org.argeo.cms.ux.widgets.CmsDialog;
 import org.argeo.cms.ux.widgets.Column;
-import org.argeo.cms.ux.widgets.DefaultTabularPart;
 import org.argeo.cms.ux.widgets.GuidedForm;
-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;
@@ -52,8 +39,6 @@ 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;
-import org.osgi.service.useradmin.User;
 
 /** Entry to the admin area. */
 public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
@@ -73,121 +58,15 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
                CmsSwtUtils.fill(sashForm);
 
                // VIEW
-               HierarchicalPart<HierarchyUnit> hierarchyPart = new AbstractHierarchicalPart<>() {
-
-                       @Override
-                       public List<HierarchyUnit> getChildren(HierarchyUnit parent) {
-                               List<HierarchyUnit> visible = new ArrayList<>();
-                               if (parent != null) {
-                                       if (parent instanceof CmsDirectory) // do no show children of the directories
-                                               return visible;
-                                       for (HierarchyUnit hu : parent.getDirectHierarchyUnits(true)) {
-                                               visible.add(hu);
-                                       }
-                               } else {
-                                       for (UserDirectory directory : cmsUserManager.getUserDirectories()) {
-                                               if (CurrentUser.implies(CmsRole.userAdmin, directory.getBase())) {
-                                                       visible.add(directory);
-                                               }
-                                               for (HierarchyUnit hu : directory.getDirectHierarchyUnits(true)) {
-                                                       if (CurrentUser.implies(CmsRole.userAdmin, hu.getBase())) {
-                                                               visible.add(hu);
-                                                       }
-                                               }
-
-                                       }
-                               }
-                               return visible;
-                       }
-
-                       @Override
-                       public String getText(HierarchyUnit model) {
-                               return model.getHierarchyUnitLabel(CurrentUser.locale());
-                       }
-
-                       @Override
-                       public CmsIcon getIcon(HierarchyUnit model) {
-                               Content content = ContentUtils.hierarchyUnitToContent(contentSession, model);
-                               if (content.hasContentClass(LdapObjs.organization))
-                                       return SuiteIcon.organisation;
-                               else if (content.hasContentClass(LdapObjs.posixGroup))
-                                       return SuiteIcon.users;
-                               else
-                                       return SuiteIcon.addressBook;
-                       }
-
-               };
+               HierarchyUnitPart hierarchyPart = new HierarchyUnitPart(contentSession, cmsUserManager);
                SwtTreeView<HierarchyUnit> directoriesView = new SwtTreeView<>(sashForm, SWT.BORDER, hierarchyPart);
 
-               DefaultTabularPart<HierarchyUnit, Content> usersPart = new DefaultTabularPart<>() {
-
-                       @Override
-                       protected List<Content> asList(HierarchyUnit hu) {
-                               List<Content> roles = new ArrayList<>();
-                               UserDirectory ud = (UserDirectory) hu.getDirectory();
-                               if (ud.getRealm().isPresent()) {
-                                       for (Role r : ud.getHierarchyUnitRoles(ud, null, true)) {
-                                               Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r);
-                                               if (content.hasContentClass(LdapObjs.inetOrgPerson, LdapObjs.organization))
-                                                       roles.add(content);
-                                       }
-
-                               } else {
-                                       for (HierarchyUnit directChild : hu.getDirectHierarchyUnits(false)) {
-                                               if (!(directChild.isType(HierarchyUnit.Type.FUNCTIONAL)
-                                                               || 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, LdapObjs.organization,
-                                                                               LdapObjs.groupOfNames))
-                                                                       roles.add(content);
-                                                       }
-                                               }
-                                       }
-                               }
-                               return roles;
-                       }
-               };
-               usersPart.addColumn(new Column<Content>() {
-
-                       @Override
-                       public String getText(Content role) {
-                               if (role.hasContentClass(LdapObjs.inetOrgPerson))
-                                       return UserAdminUtils.getUserDisplayName(role.adapt(User.class));
-                               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))
-                                       return SuiteIcon.user;
-                               else if (role.hasContentClass(LdapObjs.inetOrgPerson))
-                                       return SuiteIcon.person;
-                               else if (role.hasContentClass(LdapObjs.organization))
-                                       return SuiteIcon.organisationContact;
-                               else if (role.hasContentClass(LdapObjs.groupOfNames))
-                                       return SuiteIcon.group;
-                               else
-                                       return null;
-                       }
-
-                       @Override
-                       public int getWidth() {
-                               return 300;
-                       }
-
-               });
-//             usersPart.addColumn((Column<Content>) (role) -> role.attr(LdapAttrs.mail));
+               UsersPart usersPart = new UsersPart(contentSession, cmsUserManager);
                usersPart.addColumn(new Column<Content>() {
 
                        @Override
                        public String getText(Content role) {
-                               return role.attr(LdapAttrs.mail);
+                               return role.attr(LdapAttr.mail);
                        }
 
                        @Override
@@ -204,7 +83,6 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
 
                ToolItem deleteItem = new ToolItem(bottomToolBar, SWT.FLAT);
                deleteItem.setEnabled(false);
-//             CmsUiUtils.style(deleteItem, SuiteStyle.recentItems);
                deleteItem.setImage(theme.getSmallIcon(SuiteIcon.delete));
 
                Menu menu = new Menu(Display.getCurrent().getActiveShell(), SWT.POP_UP);
@@ -218,7 +96,7 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
                        Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit);
                        GuidedForm wizard = new NewUserForm(cmsUserManager, huContent);
                        SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard);
-                       if (dialog.open() == Window.OK) {
+                       if (dialog.open() == CmsDialog.OK) {
                                // TODO create
                        }
                });
@@ -231,7 +109,7 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
                        Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit);
                        GuidedForm wizard = new NewOrgForm(cmsUserManager, huContent);
                        SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard);
-                       if (dialog.open() == Window.OK) {
+                       if (dialog.open() == CmsDialog.OK) {
                                // TODO create
                        }
                });
@@ -242,8 +120,8 @@ public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
 
                sashForm.setWeights(new int[] { 30, 70 });
 
-               SwtTableView<?, ?> usersTable = new SwtTableView<>(bottom, SWT.BORDER, usersPart);
-               usersTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               SwtTableView<?, ?> usersView = new SwtTableView<>(bottom, SWT.BORDER, usersPart);
+               usersView.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
                // CONTROLLER
                hierarchyPart.onSelected((o) -> {