From 3502f9dd4e6f23a033aae272c13ebe1e45357f5f Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 31 Aug 2011 07:20:21 +0000 Subject: [PATCH] =?UTF-8?q?Erg=C3=A4nzungen=20f=C3=BCr=20GenericPerson=20u?= =?UTF-8?q?nd=20damit=20alle=20anderen=20Personentypen:=20-=20Feld=20dabin?= =?UTF-8?q?Id,=20vor=C3=BCbergehend=20f=C3=BCr=20Import=20von=20DaBIn-Date?= =?UTF-8?q?n=20-=20Alias/Fr=C3=BCherer=20Name=20f=C3=BCr=20Personen.=20Es?= =?UTF-8?q?=20ist=20damit=20m=C3=B6glich=20von=20einem=20Personen-Datensat?= =?UTF-8?q?z=20auf=20einen=20anderen=20Personendatensatz=20=20=20mit=20ein?= =?UTF-8?q?em=20fr=C3=BCheren=20Namen=20der=20Person=20zu=20verweisen.=20D?= =?UTF-8?q?ies=20ist=20z.B.=20hilfreich=20bei=20Namens=C3=A4nderungen=20be?= =?UTF-8?q?i=20Heiraten=20etc.=20=20=20Verkn=C3=BCpfungen=20mit=20dem=20al?= =?UTF-8?q?ten=20Personendatensatz=20(z.B.=20Publikation->Autor-Verkn?= =?UTF-8?q?=C3=BCpfungen)=20k=C3=B6nnen=20bestehen=20bleiben,=20es=20ist?= =?UTF-8?q?=20aber=20=20=20m=C3=B6glich=20=C3=BCber=20die=20Alias-Beziehun?= =?UTF-8?q?g=20vom=20neuen=20Namen=20auf=20die=20Vern=C3=BCpfungen=20mit?= =?UTF-8?q?=20dem=20alten=20Namen=20zuzugreifen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Folgende Datenbank-Änderungen sind für vorhandene Datenbanken notwendig: ALTER TABLE cms_persons ADD COLUMN dabinId INTEGER; ALTER TABLE cms_persons ADD COLUMN aliasId INTEGER REFERENCES cms_persons; git-svn-id: https://svn.libreccm.org/ccm/trunk@1081 8810af33-2d31-482b-a856-94f89814c4df --- .../arsdigita/content-types/GenericPerson.pdl | 5 + .../com/arsdigita/cms/CMSResources.properties | 9 ++ .../arsdigita/cms/CMSResources_de.properties | 9 ++ .../cms/CMSResources_en_GB.properties | 9 ++ .../arsdigita/cms/CMSResources_fr.properties | 9 ++ .../cms/contenttypes/GenericPerson.java | 27 +++- .../GenericContactAddressPropertiesStep.java | 121 ++++++++++----- .../ui/GenericPersonAliasDeleteForm.java | 75 +++++++++ .../ui/GenericPersonAliasPropertiesStep.java | 144 +++++++++++++++++ .../ui/GenericPersonAliasSetForm.java | 146 ++++++++++++++++++ .../ui/GenericPersonPropertiesStep.java | 22 ++- 11 files changed, 530 insertions(+), 46 deletions(-) create mode 100644 ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasDeleteForm.java create mode 100644 ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasPropertiesStep.java create mode 100644 ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasSetForm.java diff --git a/ccm-cms/pdl/com/arsdigita/content-types/GenericPerson.pdl b/ccm-cms/pdl/com/arsdigita/content-types/GenericPerson.pdl index 6efeefdfa..0cd5d5c43 100644 --- a/ccm-cms/pdl/com/arsdigita/content-types/GenericPerson.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-types/GenericPerson.pdl @@ -30,5 +30,10 @@ object type GenericPerson extends ContentPage { Date[0..1] birthdate = cms_persons.birthdate DATE; String[0..1] gender = cms_persons.gender CHAR(1); + GenericPerson[0..1] alias = join cms_persons.alias_id + to cms_persons.person_id; + + Integer[0..1] dabinId = cms_persons.dabin_id INTEGER; + reference key (cms_persons.person_id); } diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources.properties index 0e0bf4a5d..39532efd8 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources.properties @@ -1076,3 +1076,12 @@ cms.ui.type.permissions.actions.restrict_to_this_role=Restrict to this role cms.ui.type.permissions.can_use.grant=Grant permissions to this role cms.ui.type.permissions.actions.revoke=Revoke permission cms.ui.type.permissions.can_use.no=No +cms.contenttypes.ui.person.set_alias=Set former name +cms.contenttypes.ui.person.delete_alias=Remove former name +cms.contenttypes.ui.person.alias.none=No former name +cms.contenttypes.ui.person.alias=Former name +cms.contenttypes.ui.person.alias.select=Select former name +cms.contenttypes.ui.contact.alias.select.add=Select former name +cms.contenttypes.person.alias.select.wrong_type=No person selected +cms.contenttypes.person.alias.select.same_as_person=Selected person is the same as the current person. Alias and person can't be identical. +cms.contenttypes.person.alias.select.no_suitable_language_variant=The selected item has no suitable language variant. diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties index 1f37e9a34..a9bba9a7c 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties @@ -1067,3 +1067,12 @@ cms.ui.type.permissions.actions.restrict_to_this_role=Auf diese Rolle beschr\u00 cms.ui.type.permissions.can_use.grant=Rolle berechtigen cms.ui.type.permissions.actions.revoke=Berechtigung widerrufen cms.ui.type.permissions.can_use.no=Nein +cms.contenttypes.ui.person.set_alias=Fr\u00fcheren Namen setzen +cms.contenttypes.ui.person.delete_alias=Fr\u00fcheren Namen entfernen +cms.contenttypes.ui.person.alias.none=Kein fr\u00fcherer Name +cms.contenttypes.ui.person.alias=Fr\u00fcherer Name +cms.contenttypes.ui.person.alias.select=Fr\u00fcheren Namen ausw\u00e4hlen +cms.contenttypes.ui.contact.alias.select.add=Fr\u00fcheren Namen ausw\u00e4hlen +cms.contenttypes.person.alias.select.wrong_type=Kein Personendatensatz ausgew\u00e4hlt +cms.contenttypes.person.alias.select.same_as_person=Der ausgew\u00e4hlte Datensatz ist der gleiche Datensatz wie der aktuelle Datensatz. Alias und Person k\u00f6nnen nicht identisch sein. +cms.contenttypes.person.alias.select.no_suitable_language_variant=Das ausgew\u00e4hlte Item hat keine passende Sprachvariante. diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties index 8e456de2f..73fb8f8d7 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties @@ -15,3 +15,12 @@ cms.ui.type.permissions.actions.restrict_to_this_role= cms.ui.type.permissions.can_use.grant= cms.ui.type.permissions.actions.revoke= cms.ui.type.permissions.can_use.no= +cms.contenttypes.ui.person.set_alias= +cms.contenttypes.ui.person.delete_alias= +cms.contenttypes.ui.person.alias.none= +cms.contenttypes.ui.person.alias= +cms.contenttypes.ui.person.alias.select= +cms.contenttypes.ui.contact.alias.select.add= +cms.contenttypes.person.alias.select.wrong_type= +cms.contenttypes.person.alias.select.same_as_person= +cms.contenttypes.person.alias.select.no_suitable_language_variant= diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties index f29649b7f..64de5c8a5 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties @@ -546,3 +546,12 @@ cms.ui.type.permissions.actions.restrict_to_this_role= cms.ui.type.permissions.can_use.grant= cms.ui.type.permissions.actions.revoke= cms.ui.type.permissions.can_use.no= +cms.contenttypes.ui.person.set_alias= +cms.contenttypes.ui.person.delete_alias= +cms.contenttypes.ui.person.alias.none= +cms.contenttypes.ui.person.alias= +cms.contenttypes.ui.person.alias.select= +cms.contenttypes.ui.contact.alias.select.add= +cms.contenttypes.person.alias.select.wrong_type= +cms.contenttypes.person.alias.select.same_as_person= +cms.contenttypes.person.alias.select.no_suitable_language_variant= diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java index 149816fd1..5c79e00ec 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java @@ -22,6 +22,7 @@ import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.RelationAttributeInterface; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; @@ -49,8 +50,10 @@ public class GenericPerson extends ContentPage implements public static final String CONTACTS = "contacts"; public static final String CONTACTS_KEY = "link_key"; public static final String CONTACTS_ORDER = "link_order"; + public static final String ALIAS = "alias"; + public static final String DABIN_ID = "dabinId"; private static final String RELATION_ATTRIBUTES = - "contacts.link_key:GenericContactType"; + "contacts.link_key:GenericContactType"; /** Data object type for this domain object */ public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericPerson"; @@ -138,8 +141,28 @@ public class GenericPerson extends ContentPage implements set(GENDER, gender); } + public GenericPerson getAlias() { + return (GenericPerson) DomainObjectFactory.newInstance((DataObject) get(ALIAS)); + } + + public void setAlias(final GenericPerson alias) { + set(ALIAS, alias); + } + + public void unsetAlias() { + set(ALIAS, null); + } + + public Integer getDabinId() { + return (Integer)get(DABIN_ID); + } + + public void setDabinId(final Integer dabinId) { + set(DABIN_ID, dabinId); + } + /** - * A convinient method which combines {@code titlePre}, {@code givenName), + * A convenient method which combines {@code titlePre}, {@code givenName), * {@code surname} and {@code titlePost}. * * @return {@code titlePre} {@code givenName) {@code surnameName} {@code titlePost} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAddressPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAddressPropertiesStep.java index a5dc3d14a..27970ae83 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAddressPropertiesStep.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAddressPropertiesStep.java @@ -17,7 +17,6 @@ import com.arsdigita.domain.DomainObject; import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.SimpleComponent; import com.arsdigita.cms.contenttypes.GenericAddress; import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; @@ -33,28 +32,54 @@ public class GenericContactAddressPropertiesStep extends SimpleEditStep { public static final String EDIT_ADDRESS_SHEET_NAME = "editAddress"; public static final String CHANGE_ADDRESS_SHEET_NAME = "changeAddress"; public static final String DELETE_ADDRESS_SHEET_NAME = "deleteAddress"; - private ItemSelectionModel itemModel; /** Creates a new instance of GenericContactAddressPropertiesStep */ - public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { this(itemModel, parent, ""); } - public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent, String prefix) { + public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { super(itemModel, parent, prefix); this.itemModel = itemModel; - BasicPageForm attachAddressSheet = new GenericContactAttachAddressPropertyForm(itemModel, this); - BasicPageForm reattachAddressSheet = new GenericContactAttachAddressPropertyForm(itemModel, this); - BasicPageForm editAddressSheet = new GenericContactEditAddressPropertyForm(itemModel, this); - BasicPageForm deleteAddressSheet = new GenericContactDeleteAddressForm(itemModel, this); + BasicPageForm attachAddressSheet = + new GenericContactAttachAddressPropertyForm(itemModel, + this); + BasicPageForm reattachAddressSheet = + new GenericContactAttachAddressPropertyForm(itemModel, + this); + BasicPageForm editAddressSheet = + new GenericContactEditAddressPropertyForm(itemModel, this); + BasicPageForm deleteAddressSheet = new GenericContactDeleteAddressForm( + itemModel, this); - add(ADD_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.attach_address").localize(), new AttachAddressWorkflowLockedComponentAccess(attachAddressSheet, itemModel), attachAddressSheet.getSaveCancelSection().getCancelButton()); - add(CHANGE_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.reattach_address").localize(), new EditAddressWorkflowLockedComponentAccess(reattachAddressSheet, itemModel), reattachAddressSheet.getSaveCancelSection().getCancelButton()); - add(EDIT_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.edit_address").localize(), new EditAddressWorkflowLockedComponentAccess(editAddressSheet, itemModel), editAddressSheet.getSaveCancelSection().getCancelButton()); - add(DELETE_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.delete_address").localize(), new EditAddressWorkflowLockedComponentAccess(deleteAddressSheet, itemModel), deleteAddressSheet.getSaveCancelSection().getCancelButton()); + add(ADD_ADDRESS_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.contact.attach_address").localize(), + new AttachAddressWorkflowLockedComponentAccess(attachAddressSheet, + itemModel), + attachAddressSheet.getSaveCancelSection().getCancelButton()); + add(CHANGE_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil. + globalize("cms.contenttypes.ui.contact.reattach_address"). + localize(), new EditAddressWorkflowLockedComponentAccess( + reattachAddressSheet, itemModel), reattachAddressSheet. + getSaveCancelSection().getCancelButton()); + add(EDIT_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil. + globalize("cms.contenttypes.ui.contact.edit_address").localize(), + new EditAddressWorkflowLockedComponentAccess(editAddressSheet, + itemModel), + editAddressSheet.getSaveCancelSection().getCancelButton()); + add(DELETE_ADDRESS_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.contact.delete_address").localize(), + new EditAddressWorkflowLockedComponentAccess(deleteAddressSheet, + itemModel), + deleteAddressSheet.getSaveCancelSection().getCancelButton()); /* Set the displayComponent for this step */ setDisplayComponent(getAddressPropertySheet(itemModel)); @@ -63,53 +88,71 @@ public class GenericContactAddressPropertiesStep extends SimpleEditStep { public static Component getAddressPropertySheet(ItemSelectionModel itemModel) { - DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); + DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( + itemModel); - sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.address.address").localize(), "address." + GenericAddress.ADDRESS); + sheet.add((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.address.address").localize(), + "address." + GenericAddress.ADDRESS); if (!GenericContact.getConfig().getHideAddressPostalCode()) { - sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.address.postal_code").localize(), "address." + GenericAddress.POSTAL_CODE); + sheet.add((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.address.postal_code").localize(), + "address." + GenericAddress.POSTAL_CODE); } - sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.address.city").localize(), "address." + GenericAddress.CITY); + sheet.add((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.address.city").localize(), + "address." + GenericAddress.CITY); if (!GenericContact.getConfig().getHideAddressState()) { - sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.address.state").localize(), "address." + GenericAddress.STATE); + sheet.add((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.address.state").localize(), + "address." + GenericAddress.STATE); } if (!GenericContact.getConfig().getHideAddressCountry()) { - sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.address.iso_country_code").localize(), - "address." + GenericAddress.ISO_COUNTRY_CODE, - new DomainObjectPropertySheet.AttributeFormatter() { + sheet.add((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.address.iso_country_code").localize(), + "address." + GenericAddress.ISO_COUNTRY_CODE, + new DomainObjectPropertySheet.AttributeFormatter() { - @Override - public String format(DomainObject item, - String attribute, - PageState state) { - GenericAddress Address = ((GenericContact) item).getAddress(); - if (Address != null && Address.getIsoCountryCode() != null) { - return GenericAddress.getCountryNameFromIsoCode(Address.getIsoCountryCode()); - } else { - return (String) ContenttypesGlobalizationUtil.globalize("cms.ui.unknown").localize(); - } - } - }); + @Override + public String format(DomainObject item, + String attribute, + PageState state) { + GenericAddress Address = + ((GenericContact) item).getAddress(); + if (Address != null && Address.getIsoCountryCode() != null) { + return GenericAddress.getCountryNameFromIsoCode(Address. + getIsoCountryCode()); + } else { + return (String) ContenttypesGlobalizationUtil.globalize( + "cms.ui.unknown").localize(); + } + } + }); } return sheet; } - public static Component getEmptyBaseAddressPropertySheet(ItemSelectionModel itemModel) { - return new Label(((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.emptyAddress").localize())); + public static Component getEmptyBaseAddressPropertySheet( + ItemSelectionModel itemModel) { + return new Label( + ((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.contact.emptyAddress").localize())); } private class EditAddressWorkflowLockedComponentAccess extends WorkflowLockedComponentAccess { - public EditAddressWorkflowLockedComponentAccess(Component c, ItemSelectionModel i) { + public EditAddressWorkflowLockedComponentAccess(Component c, + ItemSelectionModel i) { super(c, i); } @Override public boolean isVisible(PageState state) { - GenericContact contact = (GenericContact) itemModel.getSelectedObject(state); + GenericContact contact = (GenericContact) itemModel. + getSelectedObject(state); return contact.hasAddress(); } @@ -117,13 +160,15 @@ public class GenericContactAddressPropertiesStep extends SimpleEditStep { private class AttachAddressWorkflowLockedComponentAccess extends WorkflowLockedComponentAccess { - public AttachAddressWorkflowLockedComponentAccess(Component c, ItemSelectionModel i) { + public AttachAddressWorkflowLockedComponentAccess(Component c, + ItemSelectionModel i) { super(c, i); } @Override public boolean isVisible(PageState state) { - GenericContact contact = (GenericContact) itemModel.getSelectedObject(state); + GenericContact contact = (GenericContact) itemModel. + getSelectedObject(state); return !contact.hasAddress(); } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasDeleteForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasDeleteForm.java new file mode 100644 index 000000000..8c091a3a3 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasDeleteForm.java @@ -0,0 +1,75 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.util.UncheckedWrapperException; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class GenericPersonAliasDeleteForm + extends BasicPageForm + implements FormProcessListener { + + public static final String ID = "GenericPersonAliasDeleteForm"; + + public GenericPersonAliasDeleteForm( + final ItemSelectionModel itemModel, + final GenericPersonAliasPropertiesStep step) { + super(ID, itemModel); + addSaveCancelSection(); + } + + @Override + public void addWidgets() { + add(new Label((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.alias.delete.label").localize())); + } + + @Override + public void init(final FormSectionEvent fse) throws FormProcessException { + } + + @Override + public void process(final FormSectionEvent fse) throws FormProcessException { + final PageState state = fse.getPageState(); + final GenericPerson person = (GenericPerson) getItemSelectionModel().getSelectedObject(state); + + if ((person != null) && (person.getAlias() != null)) { + person.unsetAlias(); + } + } + + @Override + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(final PrintEvent event) { + GenericPerson person = + (GenericPerson) getItemSelectionModel(). + getSelectedObject(event.getPageState()); + Submit target = (Submit) event.getTarget(); + target.setButtonLabel((String) ContenttypesGlobalizationUtil. + globalize( + "cms.contenttypes.ui.person.alias.delete.label"). + localize()); + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasPropertiesStep.java new file mode 100644 index 000000000..9f14bb58f --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasPropertiesStep.java @@ -0,0 +1,144 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class GenericPersonAliasPropertiesStep extends SimpleEditStep { + + public static final String SET_ALIAS_SHEET_NAME = "setAlias"; + public static final String CHANGE_ALIAS_SHEET_NAME = "changeAlias"; + public static final String DELETE_ALIAS_SHEET_NAME = "deleteAlias"; + private final ItemSelectionModel itemModel; + + public GenericPersonAliasPropertiesStep(final ItemSelectionModel itemModel, + final AuthoringKitWizard parent) { + this(itemModel, parent, ""); + } + + public GenericPersonAliasPropertiesStep(final ItemSelectionModel itemModel, + final AuthoringKitWizard parent, + final String prefix) { + super(itemModel, parent, prefix); + + this.itemModel = itemModel; + + final BasicPageForm setAliasSheet = new GenericPersonAliasSetForm( + itemModel, + this); + /*final BasicPageForm changeAliasSheet = + new GenericPersonAliasSetForm(itemModel, + this);*/ + final BasicPageForm deleteAliasSheet = new GenericPersonAliasDeleteForm( + itemModel, + this); + + add(SET_ALIAS_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.set_alias").localize(), + new GenericPersonAliasSetWorkflowLockedComponentAccess(setAliasSheet, + itemModel), + setAliasSheet.getSaveCancelSection().getCancelButton()); + /*add(CHANGE_ALIAS_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.change_alias").localize(), + new GenericPersonAliasEditWorkflowLockedComponentAccess( + changeAliasSheet, + itemModel), + changeAliasSheet.getSaveCancelSection().getCancelButton());*/ + add(DELETE_ALIAS_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.delete_alias").localize(), + new GenericPersonAliasEditWorkflowLockedComponentAccess( + deleteAliasSheet, + itemModel), + deleteAliasSheet.getSaveCancelSection().getCancelButton()); + + setDisplayComponent(getAliasPropertySheet(itemModel)); + } + + public static Component getAliasPropertySheet( + final ItemSelectionModel itemModel) { + final Label label = new Label(new PrintListener() { + + public void prepare(final PrintEvent event) { + final PageState state = event.getPageState(); + + final GenericPerson person = (GenericPerson) itemModel. + getSelectedObject(state); + final GenericPerson alias = person.getAlias(); + + if (alias == null) { + ((Label) event.getTarget()).setLabel(ContenttypesGlobalizationUtil. + globalize("cms.contenttypes.ui.person.alias.none")); + } else { + ((Label) event.getTarget()).setLabel(alias.getFullName()); + } + } + }); + + return label; + } + + public static Component getEmptyAliasPropertySheet( + final ItemSelectionModel itemModel) { + return new Label((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.alias.none").localize()); + } + + private class GenericPersonAliasSetWorkflowLockedComponentAccess + extends WorkflowLockedComponentAccess { + + public GenericPersonAliasSetWorkflowLockedComponentAccess( + final Component component, final ItemSelectionModel itemModel) { + super(component, itemModel); + } + + @Override + public boolean isVisible(final PageState state) { + final GenericPerson person = (GenericPerson) itemModel. + getSelectedObject(state); + + if (person.getAlias() == null) { + return true; + } else { + return false; + } + } + } + + private class GenericPersonAliasEditWorkflowLockedComponentAccess + extends WorkflowLockedComponentAccess { + + public GenericPersonAliasEditWorkflowLockedComponentAccess( + final Component component, final ItemSelectionModel itemModel) { + super(component, itemModel); + } + + @Override + public boolean isVisible(final PageState state) { + final GenericPerson person = (GenericPerson) itemModel. + getSelectedObject(state); + + if (person.getAlias() == null) { + return false; + } else { + return true; + } + } + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasSetForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasSetForm.java new file mode 100644 index 000000000..1577ba7f3 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonAliasSetForm.java @@ -0,0 +1,146 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SaveCancelSection; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.util.UncheckedWrapperException; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class GenericPersonAliasSetForm + extends BasicPageForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget itemSearch; + private SaveCancelSection saveCancelSection; + private final String ITEM_SEARCH = "personAlias"; + public static final String ID = "GenericPersonAliasSetForm"; + + public GenericPersonAliasSetForm(final ItemSelectionModel itemModel) { + this(itemModel, null); + } + + public GenericPersonAliasSetForm(final ItemSelectionModel itemModel, + final GenericPersonAliasPropertiesStep step) { + super(ID, itemModel); + + addSaveCancelSection(); + + addInitListener(this); + addProcessListener(this); + } + + @Override + public void addWidgets() { + add(new Label((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.alias.select").localize())); + itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType. + findByAssociatedObjectType( + "com.arsdigita.cms.contenttypes.GenericPerson")); + add(itemSearch); + } + + @Override + public void init(final FormSectionEvent fse) throws FormProcessException { + final FormData data = fse.getFormData(); + final PageState state = fse.getPageState(); + final GenericPerson person = (GenericPerson) getItemSelectionModel(). + getSelectedObject(state); + + setVisible(state, true); + + if (person != null) { + data.put(ITEM_SEARCH, person.getAlias()); + } + } + + @Override + public void process(final FormSectionEvent fse) throws FormProcessException { + final FormData data = fse.getFormData(); + final PageState state = fse.getPageState(); + final GenericPerson person = (GenericPerson) getItemSelectionModel(). + getSelectedObject(state); + + if (this.getSaveCancelSection().getSaveButton().isSelected(state)) { + GenericPerson alias = (GenericPerson) data.get(ITEM_SEARCH); + + alias = (GenericPerson) alias.getContentBundle().getInstance(person. + getLanguage()); + + person.setAlias(alias); + } + + init(fse); + } + + @Override + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + @Override + public void prepare(PrintEvent event) { + GenericPerson person = + (GenericPerson) getItemSelectionModel(). + getSelectedObject(event.getPageState()); + Submit target = (Submit) event.getTarget(); + + if (person.getAlias() != null) { + target.setButtonLabel((String) ContenttypesGlobalizationUtil. + globalize( + "cms.contenttypes.ui.contact.alias.select.change"). + localize()); + } else { + target.setButtonLabel((String) ContenttypesGlobalizationUtil. + globalize( + "cms.contenttypes.ui.contact.alias.select.add"). + localize()); + } + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } + + @Override + public void validate(final FormSectionEvent fse) + throws FormProcessException { + final PageState state = fse.getPageState(); + final FormData data = fse.getFormData(); + + final GenericPerson person = (GenericPerson) getItemSelectionModel(). + getSelectedObject(state); + final GenericPerson alias = (GenericPerson) data.get(ITEM_SEARCH); + + if (data.get(ITEM_SEARCH) == null) { + data.addError(ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.person.alias.select.wrong_type")); + } else if (person.equals(data.get(ITEM_SEARCH))) { + data.addError(ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.person.alias.select.same_as_person")); + } else if (!alias.getContentBundle().hasInstance(person.getLanguage())) { + data.addError( + ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.person.alias.select.no_suitable_language_variant")); + } + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java index eba17aaf4..a0c090949 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java @@ -56,11 +56,13 @@ public class GenericPersonPropertiesStep extends SimpleEditStep { /* Create the edit component for this SimpleEditStep and the corresponding link */ BasicPageForm editBasicSheet = new GenericPersonPropertyForm(itemModel, this); - basicProperties.add(EDIT_SHEET_NAME, (String) ContenttypesGlobalizationUtil. - globalize("cms.contenttypes.ui.person.edit_basic_properties"). + basicProperties.add(EDIT_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.person.edit_basic_properties"). localize(), new WorkflowLockedComponentAccess(editBasicSheet, - itemModel), editBasicSheet. - getSaveCancelSection().getCancelButton()); + itemModel), + editBasicSheet.getSaveCancelSection(). + getCancelButton()); /* Set the displayComponent for this step */ basicProperties.setDisplayComponent(getGenericPersonPropertySheet( @@ -75,6 +77,13 @@ public class GenericPersonPropertiesStep extends SimpleEditStep { // GenericPersonContactPropertiesStep contactProperties = new GenericPersonContactPropertiesStep(itemModel, parent); // segmentedPanel.addSegment(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.contact").localize()), contactProperties); + GenericPersonAliasPropertiesStep aliasStep = + new GenericPersonAliasPropertiesStep( + itemModel, parent); + segmentedPanel.addSegment(new Label((String) ContenttypesGlobalizationUtil. + globalize("cms.contenttypes.ui.person.alias").localize()), + aliasStep); + /* Sets the composed segmentedPanel as display component */ setDisplayComponent(segmentedPanel); @@ -104,7 +113,7 @@ public class GenericPersonPropertiesStep extends SimpleEditStep { public String format(DomainObject item, String attribute, - PageState state) { + PageState state) { GenericPerson person = (GenericPerson) item; if (person.getBirthdate() != null) { return DateFormat.getDateInstance(DateFormat.LONG).format(person. @@ -127,7 +136,8 @@ public class GenericPersonPropertiesStep extends SimpleEditStep { //ContentPage page = (ContentPage) item; GenericPerson person = (GenericPerson) item; if (person.getGender() != null) { - return (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender." + person. + return (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender." + + person. getGender().toLowerCase()).localize(); } else { return (String) ContenttypesGlobalizationUtil.globalize(