From 4f10468a32db84b4a3d799f116e6ef73a7b4d158 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 5 Dec 2020 13:28:16 +0100 Subject: [PATCH] User management UI. --- .../OSGI-INF/l10n/bundle.properties | 93 ++++++++++- .../OSGI-INF/l10n/bundle_de.properties | 98 ++++++++++++ .../OSGI-INF/l10n/bundle_fr.properties | 102 ++++++++++++ org.argeo.suite.ui/bnd.bnd | 1 + .../org/argeo/suite/ui/AdminEntryArea.java | 19 ++- .../src/org/argeo/suite/ui/SuiteApp.java | 29 +++- .../src/org/argeo/suite/ui/SuiteMsg.java | 28 +++- .../src/org/argeo/suite/ui/SuiteUiUtils.java | 16 +- .../argeo/suite/ui/SuiteUserUiProvider.java | 55 +++++-- .../argeo/suite/ui/dialogs/NewPersonPage.java | 72 +++++++++ .../suite/ui/dialogs/NewPersonWizard.java | 151 ++++++++++++++++++ .../argeo/suite/ui/dialogs/NewUserWizard.java | 151 ++++++++++++++++++ 12 files changed, 782 insertions(+), 33 deletions(-) create mode 100644 org.argeo.suite.ui/OSGI-INF/l10n/bundle_de.properties create mode 100644 org.argeo.suite.ui/OSGI-INF/l10n/bundle_fr.properties create mode 100644 org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonPage.java create mode 100644 org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonWizard.java create mode 100644 org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewUserWizard.java diff --git a/org.argeo.suite.ui/OSGI-INF/l10n/bundle.properties b/org.argeo.suite.ui/OSGI-INF/l10n/bundle.properties index 4792ded..3d08155 100644 --- a/org.argeo.suite.ui/OSGI-INF/l10n/bundle.properties +++ b/org.argeo.suite.ui/OSGI-INF/l10n/bundle.properties @@ -4,4 +4,95 @@ documents=documents locations=locations recentItems=recent items -appTitle=Argeo Suite \ No newline at end of file +appTitle=Argeo Suite + +# +# PEOPLE +# org.argeo.people.ui.PeopleMsg +# +person=Person +organisation=Organisation + +# NewPersonWizard +firstName=First Name +lastName=Last Name +salutation=Salutation +email=Email +personWizardWindowTitle=New person +personWizardPageTitle=Create a contact + +# NewOrgWizard +legalName=Legal name +legalForm=Legal form +vatId=VAT ID +orgWizardWindowTitle=New organisation +orgWizardPageTitle=Create an organisation + + +# ContextAddressComposite +chooseAnOrganisation=Choose an organisation +street=Street +streetComplement=Street complement +zipCode=Zip code +city=City +state=State +country=Country +geopoint=Geopoint + +# FilteredOrderableEntityTable +filterHelp=Type filter criterion separated by a space + +# BankAccountComposite +accountHolder=Account holder +bankName=Bank name +currency=Currency +accountNumber=Account number +bankNumber=Bank number +BIC=BIC +IBAN=IBAN + +# EditJobDialog +position=Role +chosenItem=Chose item +department=Department +isPrimary=Is primary +searchAndChooseEntity=Search and choose a corresponding entity + +# ContactListCTab (e4) +notes=Notes +addAContact=Add a contact +contactValue=Contact value +linkedCompany=Linked company + +# OrgAdminInfoCTab (e4) +paymentAccount=Payment account + +# OrgEditor (e4) +orgDetails=Details +orgActivityLog=Activity log +team=Team +orgAdmin=Admin. + +# PersonEditor (e4) +personDetails=Contact details +personActivityLog=Activity log +personOrgs=Organisations +personSecurity=Security + +# PersonSecurityCTab (e4) +resetPassword=Reset password + +# Generic +label=Label +aCustomLabel=A custom label +description=Description +value=Value +name=Name +primary=Primary +add=Add +save=Save +pickUp=Pick up + +# Tags +confirmNewTag=Tag #{0} is not yet registered. Are you sure you want to create it? +cannotCreateTag=Tag #{0} is not yet registered and you don't have enough rights to create it. diff --git a/org.argeo.suite.ui/OSGI-INF/l10n/bundle_de.properties b/org.argeo.suite.ui/OSGI-INF/l10n/bundle_de.properties new file mode 100644 index 0000000..0af19c2 --- /dev/null +++ b/org.argeo.suite.ui/OSGI-INF/l10n/bundle_de.properties @@ -0,0 +1,98 @@ +dashboard=dashboard +people=Kontakte +documents=Dokumente +locations=Orte +recentItems=neulich + +appTitle=Argeo Suite + +# +# PEOPLE +# org.argeo.people.ui.PeopleMsg +# +person=Person +organisation=Organisation + +# NewPersonWizard +firstName=Vorname +lastName=Nachname +salutation=Salutation +email=E-Mail +personWizardWindowTitle=Neue Person +personWizardPageTitle=Kontakt erstellen + +# NewOrgWizard +legalName=Name +legalForm=Geschäftsform +vatId=Ust ID +orgWizardWindowTitle=Neue Organisation +orgWizardPageTitle=Organisation erstellen + + +# ContextAddressComposite +chooseAnOrganisation=Organisation wählen +street=Strasse +streetComplement=Strasse Zusatz +zipCode=PLZ +city=Stadt +state=Bundesland +country=Land +geopoint=Geopoint + +# FilteredOrderableEntityTable +filterHelp=Type filter criterion separated by a space + +# BankAccountComposite +accountHolder=Kontoinhaber +bankName=Name der Bank +currency=Währung +accountNumber=Kontonummer +bankNumber=BLZ +BIC=BIC +IBAN=IBAN + +# EditJobDialog +position=Rolle +chosenItem=Auswahl +department=Abteilung +isPrimary=Ist Primär +searchAndChooseEntity=Suche und wähle ein zugehöriges Objekt + +# ContactListCTab (e4) +notes=Bemerkungen +addAContact=Kontakt hinzufügen +contactValue=Kontakt value +linkedCompany=zugehörige Firma + +# OrgAdminInfoCTab (e4) +paymentAccount=Geschäftskonto + +# OrgEditor (e4) +orgDetails=Details +orgActivityLog=Aktivitäten Log +team=Team +orgAdmin=Admin. + +# PersonEditor (e4) +personDetails=Kontakt Daten +personActivityLog=Aktivitäten Log +personOrgs=Organisationen +personSecurity=Sicherheit + +# PersonSecurityCTab (e4) +resetPassword=Passwort zurücksetzen + +# Generic +label=Beschriftung +aCustomLabel=Eine spezifische Beschriftung +description=Beschreibung +value=Wert +name=Name +primary=Haupt- +add=Hinzufügen +save=Speichern +pickUp=Aussuchen + +# Tags +confirmNewTag=Das Hashtag '{0}' existiert noch nicht. WollenSie es hinzufügen? +cannotCreateTag=Das Hashtag '{0}' existiert nicht uns Sie haben nicht die Rechte, um es hinzufügen. diff --git a/org.argeo.suite.ui/OSGI-INF/l10n/bundle_fr.properties b/org.argeo.suite.ui/OSGI-INF/l10n/bundle_fr.properties new file mode 100644 index 0000000..225e5fd --- /dev/null +++ b/org.argeo.suite.ui/OSGI-INF/l10n/bundle_fr.properties @@ -0,0 +1,102 @@ +dashboard=dashboard +people=contacts +documents=documents +locations=lieux +recentItems=récent + +appTitle=Argeo Suite + +# +# GENERIC +# + +# +# PEOPLE +# org.argeo.people.ui.PeopleMsg +# +person=Personne +organisation=Organisation + +# NewPersonWizard +firstName=Prénom +lastName=Nom +salutation=Salutation +email=Email +personWizardWindowTitle=Nouvelle personne +personWizardPageTitle=Créer un contact + +# NewOrgWizard +legalName=Nom +legalForm=Forme légale +vatId=ID TVA +orgWizardWindowTitle=Nouvelle organisation +orgWizardPageTitle=Créer une organisation + + +# ContextAddressComposite +chooseAnOrganisation=Choisir une organisation +street=Rue +streetComplement=Complément rue +zipCode=Code postal +city=Ville +state=État +country=Pays +geopoint=Géocoordonnées + +# FilteredOrderableEntityTable +filterHelp=Sasir les critères de filtrage séparés par des espaces + +# BankAccountComposite +accountHolder=Propriétaire du compte +bankName=Nom de la banque +currency=Devise +accountNumber=Numéro de compte +bankNumber=Numéro de banque +BIC=BIC +IBAN=IBAN + +# EditJobDialog +position=Rôle +chosenItem=Choisir une élément +department=Service +isPrimary=Principal +searchAndChooseEntity=Cherhcer et choisir l'entitée correspondante + +# ContactListCTab (e4) +notes=Notes +addAContact=Ajouter un contact +contactValue=Valeur +linkedCompany=Entreprise liée + +# OrgAdminInfoCTab (e4) +paymentAccount=Compte de paiement + +# OrgEditor (e4) +orgDetails=Détails +orgActivityLog=Activités +team=Équipe +orgAdmin=Admin. + +# PersonEditor (e4) +personDetails=Détails du contact +personActivityLog=Activités +personOrgs=Organisations +personSecurity=Accès + +# PersonSecurityCTab (e4) +resetPassword=Force le mot de passe + +# Generic +label=Étiquette +aCustomLabel=Une étiquette spécifique +description=Description +value=Valeur +name=Nom +primary=Principal +add=Ajouter +save=Sauver +pickUp=Choisir + +# Tags +confirmNewTag=Le tag #{0} n'existe pas encore. Voulez-vous le créer? +cannotCreateTag=Le tag #{0} n'existe pas encore et vous n'avez pas les droits pour le créer. diff --git a/org.argeo.suite.ui/bnd.bnd b/org.argeo.suite.ui/bnd.bnd index a7bd575..3b2d6fc 100644 --- a/org.argeo.suite.ui/bnd.bnd +++ b/org.argeo.suite.ui/bnd.bnd @@ -14,5 +14,6 @@ org.osgi.framework,\ org.argeo.entity,\ org.eclipse.core.commands.common,\ org.eclipse.jface.window,\ +org.eclipse.jface.dialogs,\ org.argeo.eclipse.ui.dialogs,\ * diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/AdminEntryArea.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/AdminEntryArea.java index 170bf83..ce0f271 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/AdminEntryArea.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/AdminEntryArea.java @@ -5,17 +5,16 @@ import java.util.Set; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.api.NodeConstants; import org.argeo.cms.CmsUserManager; import org.argeo.cms.ui.CmsTheme; import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ui.CmsView; +import org.argeo.cms.ui.dialogs.CmsWizardDialog; import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.entity.EntityType; -import org.argeo.jcr.Jcr; -import org.argeo.jcr.JcrUtils; +import org.argeo.eclipse.ui.Selected; import org.argeo.naming.LdapAttrs; import org.argeo.suite.SuiteRole; +import org.argeo.suite.ui.dialogs.NewUserWizard; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; @@ -25,6 +24,8 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.Wizard; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -128,6 +129,16 @@ public class AdminEntryArea implements CmsUiProvider { } }); + addItem.addSelectionListener((Selected) (e) -> { + //SuiteUtils.getOrCreateUserNode(adminSession, userDn); + Wizard wizard = new NewUserWizard(null); + CmsWizardDialog dialog = new CmsWizardDialog(parent.getShell(), wizard); + // WizardDialog dialog = new WizardDialog(shell, wizard); + if (dialog.open() == Window.OK) { + // TODO create + } + }); + usersViewer.getTable().setLayoutData(CmsUiUtils.fillAll()); usersViewer.setInput(cmsUserManager); diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java index 799fb91..4f5a333 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteApp.java @@ -226,8 +226,22 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { @Override public void setState(Composite parent, String state) { - if (state == null || !state.startsWith("/")) + if (state == null) + return; + if (!state.startsWith("/")) { + if (parent instanceof SuiteUi) { + SuiteUi ui = (SuiteUi) parent; + String currentLayerId = ui.getCurrentLayerId(); + if (state.equals(currentLayerId)) + return; // does nothing + else { + Map properties = new HashMap<>(); + properties.put(SuiteEvent.LAYER, state); + ui.getCmsView().sendEvent(SuiteEvent.switchLayer.topic(), properties); + } + } return; + } SuiteUi suiteUi = (SuiteUi) parent; Node node = stateToNode(suiteUi, state); if (node == null) { @@ -245,7 +259,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { private Node stateToNode(SuiteUi suiteUi, String state) { if (suiteUi == null) return null; - if (state == null) + if (state == null || !state.startsWith("/")) return null; String path = state.substring(1); @@ -293,7 +307,7 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { CmsUiProvider uiProvider = findByType(uiProvidersByType, node); SuiteLayer layer = findByType(layersByType, node); ui.switchToLayer(layer, node); - layer.view(uiProvider, ui.getCurrentWorkArea(), node); + ui.getCmsView().runAs(() -> layer.view(uiProvider, ui.getCurrentWorkArea(), node)); ui.getCmsView().stateChanged(nodeToState(node), Jcr.getTitle(node)); } else if (isTopic(event, SuiteEvent.openNewPart)) { Node node = getNode(ui, event); @@ -302,18 +316,19 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { CmsUiProvider uiProvider = findByType(uiProvidersByType, node); SuiteLayer layer = findByType(layersByType, node); ui.switchToLayer(layer, node); - layer.open(uiProvider, ui.getCurrentWorkArea(), node); + ui.getCmsView().runAs(() -> layer.open(uiProvider, ui.getCurrentWorkArea(), node)); ui.getCmsView().stateChanged(nodeToState(node), Jcr.getTitle(node)); } else if (isTopic(event, SuiteEvent.switchLayer)) { String layerId = get(event, SuiteEvent.LAYER); if (layerId != null) { - ui.switchToLayer(layerId, ui.getUserDir()); - // ui.getCmsView().navigateTo("~"); +// ui.switchToLayer(layerId, ui.getUserDir()); + ui.getCmsView().runAs(() -> ui.switchToLayer(layerId, ui.getUserDir())); + ui.getCmsView().navigateTo(layerId); } else { Node node = getNode(ui, event); if (node != null) { SuiteLayer layer = findByType(layersByType, node); - ui.switchToLayer(layer, node); + ui.getCmsView().runAs(() -> ui.switchToLayer(layer, node)); } } } diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteMsg.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteMsg.java index 037864f..3b376db 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteMsg.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteMsg.java @@ -4,5 +4,31 @@ import org.argeo.cms.Localized; /** Localized messages. */ public enum SuiteMsg implements Localized { - dashboard,people,documents,locations,recentItems; + dashboard, people, documents, locations, recentItems, + // NewPersonWizard + firstName, lastName, salutation, email, personWizardWindowTitle, personWizardPageTitle, + // NewOrgWizard + orgWizardWindowTitle, orgWizardPageTitle, legalName, legalForm, vatId, + // ContextAddressComposite + chooseAnOrganisation, street, streetComplement, zipCode, city, state, country, geopoint, + // FilteredOrderableEntityTable + filterHelp, + // BankAccountComposite + accountHolder, bankName, currency, accountNumber, bankNumber, BIC, IBAN, + // EditJobDialog + position, chosenItem, department, isPrimary, searchAndChooseEntity, + // ContactListCTab (e4) + notes, addAContact, contactValue, linkedCompany, + // OrgAdminInfoCTab (e4) + paymentAccount, + // OrgEditor (e4) + orgDetails, orgActivityLog, team, orgAdmin, + // PersonEditor (e4) + personDetails, personActivityLog, personOrgs, personSecurity, + // PersonSecurityCTab (e4) + resetPassword, + // Generic + label, aCustomLabel, description, value, name, primary, add, save, pickup, + // Tag + confirmNewTag, cannotCreateTag; } diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java index 28d7753..ace189c 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java @@ -8,8 +8,10 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import org.argeo.api.NodeConstants; +import org.argeo.cms.Localized; import org.argeo.cms.ui.dialogs.CmsWizardDialog; import org.argeo.cms.ui.util.CmsUiUtils; +import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.entity.EntityNames; import org.argeo.entity.EntityType; import org.argeo.jcr.JcrException; @@ -56,7 +58,7 @@ public class SuiteUiUtils { public static Label addFormLabel(Composite parent, String label) { Label lbl = new Label(parent, SWT.WRAP); lbl.setText(label); - lbl.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, true)); + //lbl.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, true)); CmsUiUtils.style(lbl, SuiteStyle.simpleLabel); return lbl; } @@ -89,7 +91,7 @@ public class SuiteUiUtils { public static Text addFormLine(Composite parent, String label, String text) { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - lineComposite.setLayout(new GridLayout(2, true)); + lineComposite.setLayout(new GridLayout(2, false)); CmsUiUtils.style(lineComposite, SuiteStyle.formLine); addFormLabel(lineComposite, label); Text txt = addFormTextField(lineComposite, text, null); @@ -100,7 +102,7 @@ public class SuiteUiUtils { public static Text addFormInput(Composite parent, String label, String placeholder) { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - lineComposite.setLayout(new GridLayout(2, true)); + lineComposite.setLayout(new GridLayout(2, false)); CmsUiUtils.style(lineComposite, SuiteStyle.formLine); addFormLabel(lineComposite, label); Text txt = addFormInputField(lineComposite, placeholder); @@ -138,6 +140,14 @@ public class SuiteUiUtils { return txt; } + public static Label createBoldLabel(Composite parent, Localized localized) { + Label label = new Label(parent, SWT.LEAD); + label.setText(localized.lead()); + label.setFont(EclipseUiUtils.getBoldFont(parent)); + label.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false)); + return label; + } + public static Label addFormPicture(Composite parent, String label, Node fileNode) throws RepositoryException { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUserUiProvider.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUserUiProvider.java index 0a35161..04d7a7b 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUserUiProvider.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUserUiProvider.java @@ -1,5 +1,9 @@ package org.argeo.suite.ui; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + import javax.jcr.Node; import javax.jcr.RepositoryException; @@ -9,14 +13,17 @@ import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.cms.ui.viewers.Section; import org.argeo.naming.LdapAttrs; import org.eclipse.swt.SWT; +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.Group; import org.eclipse.swt.widgets.Text; import org.osgi.service.useradmin.User; /** Edit a suite user. */ public class SuiteUserUiProvider implements CmsUiProvider { + private String[] availableRoles; private CmsUserManager cmsUserManager; @Override @@ -27,30 +34,41 @@ public class SuiteUserUiProvider implements CmsUiProvider { String uid = context.getName(); User user = cmsUserManager.getUserFromLocalId(uid); - Text givenName = new Text(main, SWT.SINGLE); - givenName.setText(getUserProperty(user, LdapAttrs.givenName.name())); +// Text givenName = new Text(main, SWT.SINGLE); +// givenName.setText(getUserProperty(user, LdapAttrs.givenName.name())); + Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(), + getUserProperty(user, LdapAttrs.givenName.name())); - Text sn = new Text(main, SWT.SINGLE); - sn.setText(getUserProperty(user, LdapAttrs.sn.name())); + Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(), getUserProperty(user, LdapAttrs.sn.name())); + // sn.setText(getUserProperty(user, LdapAttrs.sn.name())); - Text email = new Text(main, SWT.SINGLE); - email.setText(getUserProperty(user, LdapAttrs.mail.name())); + Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(), + getUserProperty(user, LdapAttrs.mail.name())); + // email.setText(getUserProperty(user, LdapAttrs.mail.name())); - Label lbl = new Label(main, SWT.NONE); - lbl.setText(uid); + Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name())); + uidT.setText(uid); - Label dnL = new Label(main, SWT.NONE); - dnL.setText(user.getName()); +// Label dnL = new Label(main, SWT.NONE); +// dnL.setText(user.getName()); // roles - Section rolesSection = new Section(main, SWT.NONE, context); - new Label(rolesSection, SWT.NONE).setText("Roles:"); - String[] roles = cmsUserManager.getUserRoles(user.getName()); - for (String role : roles) { - new Label(rolesSection, SWT.NONE).setText(role); + // Section rolesSection = new Section(main, SWT.NONE, context); + Group rolesSection = new Group(main, SWT.NONE); + rolesSection.setText("Roles"); + rolesSection.setLayoutData(CmsUiUtils.fillWidth()); + rolesSection.setLayout(new GridLayout()); + // new Label(rolesSection, SWT.NONE).setText("Roles:"); + List roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName())); + for (String role : availableRoles) { + // new Label(rolesSection, SWT.NONE).setText(role); + Button radio = new Button(rolesSection, SWT.CHECK); + radio.setText(role); + if (roles.contains(role)) + radio.setSelection(true); } - return lbl; + return main; } public void setCmsUserManager(CmsUserManager cmsUserManager) { @@ -62,4 +80,7 @@ public class SuiteUserUiProvider implements CmsUiProvider { return value != null ? value.toString() : null; } + public void init(Map properties) { + availableRoles = (String[]) properties.get("availableRoles"); + } } diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonPage.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonPage.java new file mode 100644 index 0000000..ddd4488 --- /dev/null +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonPage.java @@ -0,0 +1,72 @@ +package org.argeo.suite.ui.dialogs; + +import org.argeo.suite.ui.SuiteMsg; +import org.argeo.suite.ui.SuiteUiUtils; +import org.eclipse.jface.wizard.WizardPage; +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; + +public class NewPersonPage extends WizardPage { + private static final long serialVersionUID = -944349994177526468L; + protected Text lastNameTxt; + protected Text firstNameTxt; + protected Text emailTxt; + + protected NewPersonPage(String pageName) { + super(pageName); + setTitle(SuiteMsg.personWizardPageTitle.lead()); + } + + @Override + public void createControl(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + + // FirstName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.firstName); + firstNameTxt = new Text(parent, SWT.BORDER); + firstNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // LastName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.lastName); + lastNameTxt = new Text(parent, SWT.BORDER); + lastNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.email); + emailTxt = new Text(parent, SWT.BORDER); + emailTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + ModifyListener ml = new ModifyListener() { + private static final long serialVersionUID = -1628130380128946886L; + + @Override + public void modifyText(ModifyEvent event) { + getContainer().updateButtons(); + } + }; + + firstNameTxt.addModifyListener(ml); + lastNameTxt.addModifyListener(ml); + emailTxt.addModifyListener(ml); + + // Don't forget this. + setControl(firstNameTxt); + firstNameTxt.setFocus(); + + } + +// public void updateNode(Node node, PeopleService peopleService, ResourcesService resourcesService) { +// ConnectJcrUtils.setJcrProperty(node, PeopleNames.PEOPLE_LAST_NAME, PropertyType.STRING, lastNameTxt.getText()); +// ConnectJcrUtils.setJcrProperty(node, PeopleNames.PEOPLE_FIRST_NAME, PropertyType.STRING, +// firstNameTxt.getText()); +// ConnectJcrUtils.setJcrProperty(node, PeopleNames.PEOPLE_DISPLAY_NAME, PropertyType.STRING, +// firstNameTxt.getText() + " " + lastNameTxt.getText()); +// String email = emailTxt.getText(); +// ConnectJcrUtils.setJcrProperty(node, PeopleNames.PEOPLE_PRIMARY_EMAIL, PropertyType.STRING, email); +// PeopleJcrUtils.createEmail(resourcesService, peopleService, node, email, true, null, null); +// } +} diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonWizard.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonWizard.java new file mode 100644 index 0000000..9db5e04 --- /dev/null +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonWizard.java @@ -0,0 +1,151 @@ +package org.argeo.suite.ui.dialogs; + +import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty; + +import javax.jcr.Node; + +import org.argeo.eclipse.ui.EclipseUiUtils; +import org.argeo.suite.ui.SuiteMsg; +import org.argeo.suite.ui.SuiteUiUtils; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; +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 NewPersonWizard extends Wizard { + // private final static Log log = LogFactory.getLog(NewPersonWizard.class); + + // Context + private Node person; + + // This page widgets + protected Text lastNameTxt; + protected Text firstNameTxt; + // private Button useDistinctDisplayNameBtn; + // private Text displayNameTxt; + + public NewPersonWizard(Node person) { + this.person = person; + } + + @Override + public void addPages() { + try { + MainInfoPage page = new MainInfoPage("Main page"); + addPage(page); + } catch (Exception e) { + throw new RuntimeException("Cannot add page to wizard", e); + } + setWindowTitle(SuiteMsg.personWizardWindowTitle.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() { + String lastName = lastNameTxt.getText(); + String firstName = firstNameTxt.getText(); + // String displayName = displayNameTxt.getText(); + // boolean useDistinct = useDistinctDisplayNameBtn.getSelection(); + if (EclipseUiUtils.isEmpty(lastName) && EclipseUiUtils.isEmpty(firstName)) { + MessageDialog.openError(getShell(), "Non-valid information", + "Please enter at least a name that is not empty."); + return false; + } else { +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_LAST_NAME, PropertyType.STRING, lastName); +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_FIRST_NAME, PropertyType.STRING, firstName); +// String fullName = firstName + " " + lastName; +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_DISPLAY_NAME, PropertyType.STRING, fullName); + return true; + } + } + + @Override + public boolean performCancel() { + return true; + } + + @Override + public boolean canFinish() { + String lastName = lastNameTxt.getText(); + String firstName = firstNameTxt.getText(); + if (isEmpty(lastName) && isEmpty(firstName)) { + return false; + } else + return true; + } + + protected class MainInfoPage extends WizardPage { + private static final long serialVersionUID = 1L; + + public MainInfoPage(String pageName) { + super(pageName); + setTitle(SuiteMsg.personWizardPageTitle.lead()); + // setMessage("Please enter a last name and/or a first name."); + } + + public void createControl(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + + // FirstName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.firstName); + firstNameTxt = new Text(parent, SWT.BORDER); + // firstNameTxt.setMessage("a first name"); + firstNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // LastName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.lastName); + lastNameTxt = new Text(parent, SWT.BORDER); + // lastNameTxt.setMessage("a last name"); + lastNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // Display Name + // useDistinctDisplayNameBtn = new Button(parent, SWT.CHECK); + // useDistinctDisplayNameBtn.setText("Define a disting display name"); + // useDistinctDisplayNameBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + // true, false, 2, 1)); + // + // ConnectWorkbenchUtils.createBoldLabel(parent, "Display Name"); + // displayNameTxt = new Text(parent, SWT.BORDER); + // displayNameTxt.setMessage("an optional display name"); + // displayNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + // false)); + // displayNameTxt.setEnabled(false); + // + // useDistinctDisplayNameBtn.addSelectionListener(new SelectionAdapter() { + // private static final long serialVersionUID = 1L; + // + // @Override + // public void widgetSelected(SelectionEvent e) { + // displayNameTxt.setEnabled(useDistinctDisplayNameBtn.getSelection()); + // } + // }); + + ModifyListener ml = new ModifyListener() { + private static final long serialVersionUID = -1628130380128946886L; + + @Override + public void modifyText(ModifyEvent event) { + getContainer().updateButtons(); + } + }; + + firstNameTxt.addModifyListener(ml); + lastNameTxt.addModifyListener(ml); + // displayNameTxt.addModifyListener(ml); + + // Don't forget this. + setControl(firstNameTxt); + firstNameTxt.setFocus(); + } + } +} diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewUserWizard.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewUserWizard.java new file mode 100644 index 0000000..5b4575d --- /dev/null +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewUserWizard.java @@ -0,0 +1,151 @@ +package org.argeo.suite.ui.dialogs; + +import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty; + +import javax.jcr.Node; + +import org.argeo.eclipse.ui.EclipseUiUtils; +import org.argeo.suite.ui.SuiteMsg; +import org.argeo.suite.ui.SuiteUiUtils; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; +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 NewUserWizard extends Wizard { + // private final static Log log = LogFactory.getLog(NewPersonWizard.class); + + // Context + private Node person; + + // This page widgets + protected Text lastNameTxt; + protected Text firstNameTxt; + // private Button useDistinctDisplayNameBtn; + // private Text displayNameTxt; + + public NewUserWizard(Node person) { + this.person = person; + } + + @Override + public void addPages() { + try { + MainInfoPage page = new MainInfoPage("Main page"); + addPage(page); + } catch (Exception e) { + throw new RuntimeException("Cannot add page to wizard", e); + } + setWindowTitle(SuiteMsg.personWizardWindowTitle.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() { + String lastName = lastNameTxt.getText(); + String firstName = firstNameTxt.getText(); + // String displayName = displayNameTxt.getText(); + // boolean useDistinct = useDistinctDisplayNameBtn.getSelection(); + if (EclipseUiUtils.isEmpty(lastName) && EclipseUiUtils.isEmpty(firstName)) { + MessageDialog.openError(getShell(), "Non-valid information", + "Please enter at least a name that is not empty."); + return false; + } else { +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_LAST_NAME, PropertyType.STRING, lastName); +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_FIRST_NAME, PropertyType.STRING, firstName); +// String fullName = firstName + " " + lastName; +// ConnectJcrUtils.setJcrProperty(person, PEOPLE_DISPLAY_NAME, PropertyType.STRING, fullName); + return true; + } + } + + @Override + public boolean performCancel() { + return true; + } + + @Override + public boolean canFinish() { + String lastName = lastNameTxt.getText(); + String firstName = firstNameTxt.getText(); + if (isEmpty(lastName) && isEmpty(firstName)) { + return false; + } else + return true; + } + + protected class MainInfoPage extends WizardPage { + private static final long serialVersionUID = 1L; + + public MainInfoPage(String pageName) { + super(pageName); + setTitle(SuiteMsg.personWizardPageTitle.lead()); + // setMessage("Please enter a last name and/or a first name."); + } + + public void createControl(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + + // FirstName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.firstName); + firstNameTxt = new Text(parent, SWT.BORDER); + // firstNameTxt.setMessage("a first name"); + firstNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // LastName + SuiteUiUtils.createBoldLabel(parent, SuiteMsg.lastName); + lastNameTxt = new Text(parent, SWT.BORDER); + // lastNameTxt.setMessage("a last name"); + lastNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // Display Name + // useDistinctDisplayNameBtn = new Button(parent, SWT.CHECK); + // useDistinctDisplayNameBtn.setText("Define a disting display name"); + // useDistinctDisplayNameBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + // true, false, 2, 1)); + // + // ConnectWorkbenchUtils.createBoldLabel(parent, "Display Name"); + // displayNameTxt = new Text(parent, SWT.BORDER); + // displayNameTxt.setMessage("an optional display name"); + // displayNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + // false)); + // displayNameTxt.setEnabled(false); + // + // useDistinctDisplayNameBtn.addSelectionListener(new SelectionAdapter() { + // private static final long serialVersionUID = 1L; + // + // @Override + // public void widgetSelected(SelectionEvent e) { + // displayNameTxt.setEnabled(useDistinctDisplayNameBtn.getSelection()); + // } + // }); + + ModifyListener ml = new ModifyListener() { + private static final long serialVersionUID = -1628130380128946886L; + + @Override + public void modifyText(ModifyEvent event) { + getContainer().updateButtons(); + } + }; + + firstNameTxt.addModifyListener(ml); + lastNameTxt.addModifyListener(ml); + // displayNameTxt.addModifyListener(ml); + + // Don't forget this. + setControl(firstNameTxt); + firstNameTxt.setFocus(); + } + } +} -- 2.30.2