X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=swt%2Forg.argeo.app.ui%2Fsrc%2Forg%2Fargeo%2Fapp%2Fui%2Fpeople%2FPeopleEntryArea.java;h=a8c50f1f65d0bb161a5505cef607491b58b9663f;hp=81463a2417431cba75a03f9fbe5da95ae34ad43c;hb=072fa21aaf70e9f67f6bf5781257b58995b720e4;hpb=b4debb80c8209d35f546da421020449a5d84049a 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();