--- /dev/null
+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();
+ }
+ }
+}
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.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;
@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;
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);
}
|| 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);
}
}
@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;
}
});
- 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)));
}
});
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();
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;
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;
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);
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();
text.setText(currentTxt);
((Text) text.getControl()).addSelectionListener(new SelectionListener() {
+ private static final long serialVersionUID = 1L;
+
@Override
public void widgetSelected(SelectionEvent e) {
}
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)) {
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());
}