From 229806b40268d2b2cdbe265fbfe98da729c79f47 Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 13 Apr 2009 06:15:10 +0000 Subject: [PATCH] git-svn-id: https://svn.libreccm.org/ccm/trunk@130 8810af33-2d31-482b-a856-94f89814c4df --- .../contenttypes/ui/PersonPropertiesStep.java | 66 ++++++++++ .../contenttypes/ui/PersonPropertyForm.java | 118 ++++++++++++++++++ .../util/PersonGlobalizationUtil.java | 16 +++ .../util/PersonResourceBundle.java | 16 +++ 4 files changed, 216 insertions(+) create mode 100644 ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertiesStep.java create mode 100644 ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertyForm.java create mode 100644 ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonGlobalizationUtil.java create mode 100644 ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonResourceBundle.java diff --git a/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertiesStep.java b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertiesStep.java new file mode 100644 index 000000000..c8008a4e2 --- /dev/null +++ b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertiesStep.java @@ -0,0 +1,66 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; +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; +import com.arsdigita.cms.contenttypes.util.PersonGlobalizationUtil; + +import java.text.DateFormat; + +public class PersonPropertiesStep extends SimpleEditStep { + public static final String EDIT_SHEET_NAME = "edit"; + + public PersonPropertiesStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + super(itemModel, parent); + + setDefaultEditKey(EDIT_SHEET_NAME); + BasicPageForm editSheet; + + editSheet = new PersonPropertyForm(itemModel, this); + add(EDIT_SHEET_NAME, "Edit", + new WorkflowLockedComponentAccess(editSheet, itemModel), + editSheet.getSaveCancelSection().getCancelButton()); + + setDisplayComponent(getPersonPropertySheet(itemModel)); + } + + public static Component getPersonPropertySheet(ItemSelectionModel itemModel) { + DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); + + sheet.add((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.name").localize(), Person.SURNAME); + sheet.add((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.name").localize(), Person.GIVENNAME); + sheet.add((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.name").localize(), Person.TITLEPRE); + sheet.add((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.name").localize(), Person.TITLEPOST); + + if(!ContentSection.getConfig().getHideLaunchDate()) { + sheet.add((String)PersonGlobalizationUtil.globalize("cms.ui.authoring.page_launch_date").localize(), + ContentPage.LAUNCH_DATE, + new DomainObjectPropertySheet.AttributeFormatter() { + public String format(DomainObject item, + String attribute, + PageState state) { + ContentPage page = (ContentPage)item; + if (page.getLaunchDate() != null) { + return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate()); + } + else { + return (String)PersonGlobalizationUtil.globalize("cms.ui.unknown").localize(); + } + } + }); + } + + return sheet; + } +} \ No newline at end of file diff --git a/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertyForm.java b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertyForm.java new file mode 100644 index 000000000..bde22180e --- /dev/null +++ b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/ui/PersonPropertyForm.java @@ -0,0 +1,118 @@ +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.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.event.ParameterEvent; +import com.arsdigita.bebop.event.ParameterListener; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.SingleSelect; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.StringInRangeValidationListener; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.bebop.parameters.URLValidationListener; +import com.arsdigita.bebop.parameters.ParameterData; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.cms.contenttypes.util.PersonGlobalizationUtil; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.domain.DomainCollection; +import org.apache.log4j.Logger; + +/** + * Form to edit the properties of a person. + * + * @author: Jens Pelzetter + */ +public class PersonPropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener { + private static final Logger s_log = Logger.getLogger(PersonPropertyForm.class); + + private PersonPropertiesStep m_step; + + public static final String PERSON = Person.PERSON; + public static final String SURNAME = Person.SURNAME; + public static final String GIVENNAME = Person.GIVENNAME; + public static final String TITLEPRE = Person.TITLEPRE; + public static final String TITLEPOST = Person.TITLEPOST; + + public static final String ID = "Person_edit"; + + public PersonPropertyForm(ItemSelectionModel itemModel) { + this(itemModel,null); + } + + public PersonPropertyForm(ItemSelectionModel itemModel, PersonPropertiesStep step) { + super(ID, itemModel); + m_step = step; + addSubmissionListener (this); + } + + protected void addWidgets() { + super.addWidgets (); + + add(new Label((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.person.surname").localize())); + ParameterModel surnameParam = new StringParameter(SURNAME); + TextField surname = new TextField (surnameParam); + add(surname); + + add(new Label((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.person.givenname").localize())); + ParameterModel givennameParam = new StringParameter(GIVENNAME); + TextField givenname = new TextField (givennameParam); + add(givenname); + + add(new Label((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepre").localize())); + ParameterModel titlepreParam = new StringParameter(TITLEPRE); + TextField titlepre = new TextField (titlepreParam); + add(titlepre); + + add(new Label((String)PersonGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepost").localize())); + ParameterModel titlepostParam = new StringParameter(TITLEPOST); + TextField titlepost = new TextField (titlepostParam); + add(titlepost); + } + + public void init(FormSectionEvent fse) { + FormData data = fse.getFormData(); + Person person = (Person)super.initBasicWidgets(fse); + + data.put(SURNAME,person.getSurname()); + data.put(GIVENNAME, person.getGivenName()); + data.put(TITLEPRE, person.getTitlePre()); + data.put(TITLEPOST, person.getTitlePost()); + } + + public void submitted(FormSectionEvent fse) { + if (m_step != null && + getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { + m_step.cancelStreamlinedCreation(fse.getPageState()); + } + } + + public void process(FormSectionEvent fse) { + FormData data = fse.getFormData(); + + Person person = (Person)super.processBasicWidgets(fse); + + if (person != null && + getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) { + person.setSurname ((String)data.get(SURNAME)); + person.setGivenName ((String)data.get(GIVENNAME)); + person.setTitlePre ((String)data.get(TITLEPRE)); + person.setTitlePost ((String)data.get(TITLEPOST)); + + person.save(); + } + + if (m_step != null) { + m_step.maybeForwardToNextStep(fse.getPageState()); + } + } +} + \ No newline at end of file diff --git a/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonGlobalizationUtil.java b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonGlobalizationUtil.java new file mode 100644 index 000000000..30141a4bf --- /dev/null +++ b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonGlobalizationUtil.java @@ -0,0 +1,16 @@ +package com.arsdigita.cms.contenttypes.util; + +import com.arsdigita.globalization.GlobalizedMessage; + +public class PersonGlobalizationUtil { + final public static String BUNDLE_NAME = + "com.arsdigita.cms.contenttypes.util.PersonResourceBundle"; + + public static GlobalizedMessage globalize (String key) { + return new GlobalizedMessage(key, BUNDLE_NAME); + } + + public static GlobalizedMessage globalize (String key, Object[] args) { + return new GlobalizedMessage(key, BUNDLE_NAME, args); + } +} \ No newline at end of file diff --git a/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonResourceBundle.java b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonResourceBundle.java new file mode 100644 index 000000000..1d18d1e52 --- /dev/null +++ b/ccm-cms-types-person/src/com/arsdigita/cms/contenttypes/util/PersonResourceBundle.java @@ -0,0 +1,16 @@ +package com.arsdigita.cms.contenttypes.util; + +import java.util.PropertyResourceBundle; +import com.arsdigita.globalization.ChainedResourceBundle; +import com.arsdigita.cms.CMSGlobalized; + +public class PersonResourceBundle extends ChainedResourceBundle implements CMSGlobalized { + public static final String PERSON_BUNDLE_NAME = + "com.arsdigita.cms.contenttypes.PersonResources"; + + public PersonResourceBundle() { + super(); + addBundle((PropertyResourceBundle)getBundle(PERSON_BUNDLE_NAME)); + addBundle((PropertyResourceBundle)getBundle(BUNDLE_NAME)); + } +} \ No newline at end of file