From 82083d7608cd0d2cd8cecae13079e03f04e98ea9 Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 28 Jun 2017 19:25:28 +0000 Subject: [PATCH] CCM NG/ccm-cms: Some progress for editing git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4822 8810af33-2d31-482b-a856-94f89814c4df Former-commit-id: b1f2c7ff98a0644248e6dfabd32eb9ef26e382e8 --- .../ui/ArticlePropertiesStep.java | 26 +++- .../contenttypes/ui/ArticlePropertyForm.java | 78 ++++++++--- .../contenttypes/ui/EventPropertiesStep.java | 4 +- .../contenttypes/ui/EventPropertyForm.java | 58 ++++++-- .../ui/GenericArticlePropertiesStep.java | 18 ++- .../ui/GenericArticlePropertyForm.java | 20 ++- .../contenttypes/ui/NewsPropertiesStep.java | 6 +- .../cms/contenttypes/ui/NewsPropertyForm.java | 73 +++++++--- .../cms/ui/authoring/AuthoringKitWizard.java | 9 +- .../cms/ui/authoring/BasicItemForm.java | 131 ++++++++++-------- .../cms/ui/authoring/BasicPageForm.java | 78 +++++++---- .../cms/ui/authoring/PageCreateForm.java | 17 ++- .../cms/ui/authoring/SimpleEditStep.java | 4 + .../cms/ui/contenttypes/EventCreateForm.java | 7 +- .../cms/ui/contenttypes/NewsCreateForm.java | 8 +- 15 files changed, 368 insertions(+), 169 deletions(-) diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertiesStep.java index 2f4baf01d..1050ca5f5 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertiesStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertiesStep.java @@ -30,6 +30,8 @@ import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; import org.librecms.CmsConstants; +import java.util.Objects; + /** * Authoring step to edit the simple attributes of the Article content type (and * its subclasses). The attributes edited are 'name', 'title', 'article date', @@ -43,18 +45,27 @@ public class ArticlePropertiesStep extends GenericArticlePropertiesStep { */ public final static String EDIT_SHEET_NAME = "edit"; - private StringParameter selectedLanuageParam; + private final StringParameter selectedLanguageParam; public ArticlePropertiesStep(final ItemSelectionModel itemModel, final AuthoringKitWizard parent, final StringParameter selectedLanguageParam) { + super(itemModel, parent, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); + + this.selectedLanguageParam = selectedLanguageParam; } @Override - protected void createEditSheet(final ItemSelectionModel itemModel) { - BasicPageForm editSheet; - editSheet = new ArticlePropertyForm(itemModel, this); + protected void createEditSheet(final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { + + final BasicPageForm editSheet = new ArticlePropertyForm( + itemModel, + this, + selectedLanguageParam); add(EDIT_SHEET_NAME, new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), new WorkflowLockedComponentAccess(editSheet, itemModel), @@ -64,15 +75,16 @@ public class ArticlePropertiesStep extends GenericArticlePropertiesStep { @Override protected void setDisplayComponent( final ItemSelectionModel itemModel) { - setDisplayComponent(getArticlePropertySheet(itemModel, - selectedLanuageParam)); + setDisplayComponent(getArticlePropertySheet(itemModel, + selectedLanguageParam)); } /** * Returns a component that displays the properties of the Article specified * by the ItemSelectionModel passed in. * - * @param itemModel The ItemSelectionModel to use + * @param itemModel The ItemSelectionModel to use + * @param selectedLanguageParam * * @pre itemModel != null * @return A component to display the state of the basic properties of the diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertyForm.java index 98137dbc5..68c19ba7e 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertyForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/ArticlePropertyForm.java @@ -20,6 +20,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSubmissionListener; @@ -30,7 +31,6 @@ import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.StringInRangeValidationListener; import com.arsdigita.bebop.parameters.StringParameter; - import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.KernelConfig; @@ -41,6 +41,9 @@ import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contenttypes.Article; +import java.util.Locale; +import java.util.Objects; + /** * Form to edit the basic properties of an article. This form can be extended to * create forms for Article subclasses. @@ -50,7 +53,8 @@ public class ArticlePropertyForm extends GenericArticlePropertyForm public static final String LEAD = "lead"; - private ArticlePropertiesStep propertyStep; + private final ArticlePropertiesStep propertiesStep; + private final StringParameter selectedLanguageParam; /** * Creates a new form to edit the Article object specified by the item @@ -58,23 +62,33 @@ public class ArticlePropertyForm extends GenericArticlePropertyForm * * @param itemModel The ItemSelectionModel to use to obtain the Article to * work on + * @param selectedLanguageParam */ - public ArticlePropertyForm(final ItemSelectionModel itemModel) { - this(itemModel, null); + public ArticlePropertyForm(final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { + this(itemModel, null, selectedLanguageParam); } /** * Creates a new form to edit the Article object specified by the item * selection model passed in. * - * @param itemModel The ItemSelectionModel to use to obtain the Article to - * work on - * @param step The ArticlePropertiesStep which controls this form. + * @param itemModel The ItemSelectionModel to use to obtain the Article + * to work on + * @param propertiesStep The ArticlePropertiesStep which controls this form. + * @param selectedLanguageParam */ - public ArticlePropertyForm(final ItemSelectionModel itemModel, - final ArticlePropertiesStep step) { - super(itemModel, step); - propertyStep = step; + public ArticlePropertyForm( + final ItemSelectionModel itemModel, + final ArticlePropertiesStep propertiesStep, + final StringParameter selectedLanguageParam) { + + super(itemModel, propertiesStep, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); + + this.propertiesStep = propertiesStep; + this.selectedLanguageParam = selectedLanguageParam; addSubmissionListener(this); } @@ -119,11 +133,20 @@ public class ArticlePropertyForm extends GenericArticlePropertyForm */ @Override public void init(final FormSectionEvent event) { - // Do some initialization hook stuff - FormData data = event.getFormData(); + final FormData data = event.getFormData(); + final PageState state = event.getPageState(); final Article article = (Article) super.initBasicWidgets(event); - data.put(LEAD, article.getDescription()); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + data.put(LEAD, article.getDescription().getValue(selectedLocale)); } /** @@ -131,9 +154,9 @@ public class ArticlePropertyForm extends GenericArticlePropertyForm */ @Override public void submitted(final FormSectionEvent event) { - if (propertyStep != null && getSaveCancelSection().getCancelButton() + if (propertiesStep != null && getSaveCancelSection().getCancelButton() .isSelected(event.getPageState())) { - propertyStep.cancelStreamlinedCreation(event.getPageState()); + propertiesStep.cancelStreamlinedCreation(event.getPageState()); } } @@ -144,25 +167,36 @@ public class ArticlePropertyForm extends GenericArticlePropertyForm */ @Override public void process(final FormSectionEvent event) { - FormData data = event.getFormData(); + final FormData data = event.getFormData(); + final PageState state = event.getPageState(); - Article article = (Article) super.processBasicWidgets(event); + final Article article = (Article) super.processBasicWidgets(event); // save only if save button was pressed if (article != null && getSaveCancelSection().getSaveButton() .isSelected(event.getPageState())) { - article.getDescription().addValue(KernelConfig.getConfig() - .getDefaultLocale(), (String) data.get(LEAD)); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + article + .getDescription() + .addValue(selectedLocale, (String) data.get(LEAD)); final ContentItemRepository itemRepo = CdiUtil .createCdiUtil() .findBean(ContentItemRepository.class); itemRepo.save(article); } - if (propertyStep != null) { - propertyStep.maybeForwardToNextStep(event.getPageState()); + if (propertiesStep != null) { + propertiesStep.maybeForwardToNextStep(event.getPageState()); } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertiesStep.java index 5f9236a4d..2e4624119 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertiesStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertiesStep.java @@ -85,7 +85,9 @@ public class EventPropertiesStep extends SimpleEditStep { setDefaultEditKey(EDIT_SHEET_NAME); BasicPageForm editSheet; - editSheet = new EventPropertyForm(itemSelectionModel, this); + editSheet = new EventPropertyForm(itemSelectionModel, + this, + selectedLanguageParam); add(EDIT_SHEET_NAME, new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), new WorkflowLockedComponentAccess(editSheet, itemSelectionModel), diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertyForm.java index a69ad98a7..23c90e575 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertyForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/EventPropertyForm.java @@ -20,6 +20,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; @@ -53,6 +54,8 @@ import org.librecms.contenttypes.EventConfig; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.Objects; /** * Form to edit the basic properties of an {@link Event} object. @@ -108,6 +111,8 @@ public class EventPropertyForm */ public static final String COST = "cost"; + private final StringParameter selectedLanguageParam; + /* DateWidgets have to be accessible later on */ private com.arsdigita.bebop.form.Date startDateField; private com.arsdigita.bebop.form.Date endDateField; @@ -116,28 +121,37 @@ public class EventPropertyForm * Creates a new form to edit the Event object specified by the item * selection model passed in. * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * Event to work on + * @param itemSelectionModel The ItemSelectionModel to use to obtain the + * Event to work on + * @param selectedLanguageParam * */ - public EventPropertyForm(final ItemSelectionModel itemSelectionModel) { - this(itemSelectionModel, null); + public EventPropertyForm(final ItemSelectionModel itemSelectionModel, + final StringParameter selectedLanguageParam) { + this(itemSelectionModel, null, selectedLanguageParam); } /** * Creates a new form to edit the Event object specified by the item * selection model passed in. * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * Event to work on - * @param eventPropertiesStep The EventPropertiesStep which controls this - * form. + * @param itemSelectionModel The ItemSelectionModel to use to obtain the + * Event to work on + * @param eventPropertiesStep The EventPropertiesStep which controls this + * form. + * @param selectedLanguageParam * */ public EventPropertyForm(final ItemSelectionModel itemSelectionModel, - final EventPropertiesStep eventPropertiesStep) { - super(ID, itemSelectionModel); + final EventPropertiesStep eventPropertiesStep, + final StringParameter selectedLanguageParam) { + + super(ID, itemSelectionModel, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); + this.eventPropertiesStep = eventPropertiesStep; + this.selectedLanguageParam = selectedLanguageParam; addSubmissionListener(this); } @@ -388,6 +402,7 @@ public class EventPropertyForm public void init(final FormSectionEvent event) { // Do some initialization hook stuff final FormData data = event.getFormData(); + final PageState state = event.getPageState(); final Event item = (Event) super.initBasicWidgets(event); final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); @@ -416,26 +431,39 @@ public class EventPropertyForm } endDateField.addYear(endDate); - data.put(LEAD, item.getDescription()); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + data.put(LEAD, item.getDescription().getValue(selectedLocale)); data.put(START_DATE, startDate); data.put(START_TIME, startDate.getTime()); data.put(END_DATE, endDate); data.put(END_TIME, endDate.getTime()); if (!eventConfig.isHideDateDescription()) { - data.put(EVENT_DATE, item.getEventDate()); + data.put(EVENT_DATE, + item.getEventDate().getValue(selectedLocale)); } data.put(LOCATION, item.getLocation()); if (!eventConfig.isHideMainContributor()) { - data.put(MAIN_CONTRIBUTOR, item.getMainContributor()); + data.put(MAIN_CONTRIBUTOR, + item.getMainContributor().getValue(selectedLocale)); } if (!eventConfig.isHideEventType()) { - data.put(EVENT_TYPE, item.getEventType()); + data.put(EVENT_TYPE, + item.getEventType().getValue(selectedLocale)); } if (!eventConfig.isHideLinkToMap()) { data.put(MAP_LINK, item.getMapLink()); } if (!eventConfig.isHideCost()) { - data.put(COST, item.getCost()); + data.put(COST, + item.getCost().getValue(selectedLocale)); } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertiesStep.java index 478ef4e41..0d89a9cd1 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertiesStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertiesStep.java @@ -36,6 +36,7 @@ import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import java.text.DateFormat; +import java.util.Objects; /** * Authoring step to edit the simple attributes of the GenericArticle content @@ -52,7 +53,7 @@ public class GenericArticlePropertiesStep extends SimpleEditStep { private DomainObjectPropertySheet domainObjectPropertySheet; - private StringParameter selectedLanguageParam; + private final StringParameter selectedLanguageParam; public GenericArticlePropertiesStep( final ItemSelectionModel itemModel, @@ -60,17 +61,24 @@ public class GenericArticlePropertiesStep extends SimpleEditStep { final StringParameter selectedLanguageParam) { super(itemModel, parent, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); + this.selectedLanguageParam = selectedLanguageParam; setDefaultEditKey(EDIT_SHEET_NAME); - createEditSheet(itemModel); + createEditSheet(itemModel, selectedLanguageParam); setDisplayComponent(itemModel); } - protected void createEditSheet(final ItemSelectionModel itemModel) { - BasicPageForm editSheet; - editSheet = new GenericArticlePropertyForm(itemModel, this); + protected void createEditSheet(final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { + + final BasicPageForm editSheet = new GenericArticlePropertyForm( + itemModel, + this, + selectedLanguageParam); add(EDIT_SHEET_NAME, new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), new WorkflowLockedComponentAccess(editSheet, itemModel), diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertyForm.java index 4fd8498d4..724e76ab7 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertyForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/GenericArticlePropertyForm.java @@ -24,6 +24,7 @@ import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ItemSelectionModel; import org.librecms.contenttypes.Article; @@ -33,7 +34,6 @@ import com.arsdigita.cms.ui.authoring.BasicPageForm; import org.libreccm.cdi.utils.CdiUtil; import org.librecms.contentsection.ContentItemRepository; - /** * Form to edit the basic properties of an article. This form can be extended to * create forms for Article subclasses. @@ -49,9 +49,13 @@ public class GenericArticlePropertyForm extends BasicPageForm * * @param itemModel The ItemSelectionModel to use to obtain the Article to * work on + * @param selectedLanguageParam */ - public GenericArticlePropertyForm(final ItemSelectionModel itemModel) { - this(itemModel, null); + public GenericArticlePropertyForm( + final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { + + this(itemModel, null, selectedLanguageParam); } /** @@ -62,10 +66,14 @@ public class GenericArticlePropertyForm extends BasicPageForm * GenericArticle to work on * @param step The GenericArticlePropertiesStep which controls this * form. + * @param selectedLanguageParam */ - public GenericArticlePropertyForm(final ItemSelectionModel itemModel, - final GenericArticlePropertiesStep step) { - super(ID, itemModel); + public GenericArticlePropertyForm( + final ItemSelectionModel itemModel, + final GenericArticlePropertiesStep step, + final StringParameter selectedLanguageParam) { + + super(ID, itemModel, selectedLanguageParam); propertiesStep = step; addSubmissionListener(this); } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertiesStep.java index 47f6b0daa..b89f81578 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertiesStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertiesStep.java @@ -46,6 +46,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.DateFormat; import java.util.Arrays; +import java.util.Objects; import java.util.Optional; /** @@ -69,11 +70,13 @@ public class NewsPropertiesStep extends SimpleEditStep { final StringParameter selectedLanguageParam) { super(itemModel, parent, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); setDefaultEditKey(EDIT_SHEET_NAME); BasicPageForm editSheet; - editSheet = new NewsPropertyForm(itemModel, this); + editSheet = new NewsPropertyForm(itemModel, this, selectedLanguageParam); add(EDIT_SHEET_NAME, new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), new WorkflowLockedComponentAccess(editSheet, itemModel), @@ -89,6 +92,7 @@ public class NewsPropertiesStep extends SimpleEditStep { * specified by the ItemSelectionModel passed in. * * @param itemModel The ItemSelectionModel to use + * @param selectedLanguageParam * * @pre itemModel != null * @return A component to display the state of the basic properties of the diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertyForm.java index e1e08374e..19821e3d7 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertyForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/NewsPropertyForm.java @@ -19,6 +19,7 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; @@ -44,6 +45,8 @@ import org.librecms.contenttypes.NewsConfig; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.Objects; /** * Form to edit the basic properties of a {@link News} item. These are name, @@ -71,32 +74,44 @@ public class NewsPropertyForm extends BasicPageForm */ public static final String ID = "news_item_edit"; + private final StringParameter selectedLanguageParam; + private com.arsdigita.bebop.form.Date releaseDateSelector; /** * Creates a new form to edit the NewsItem object specified by the item * selection model passed in. * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * NewsItem to work on + * @param itemSelectionModel The ItemSelectionModel to use to obtain the + * NewsItem to work on + * @param selectedLanguageParam */ - public NewsPropertyForm(final ItemSelectionModel itemSelectionModel) { - this(itemSelectionModel, null); + public NewsPropertyForm(final ItemSelectionModel itemSelectionModel, + final StringParameter selectedLanguageParam) { + + this(itemSelectionModel, null, selectedLanguageParam); } /** * Creates a new form to edit the NewsItem object specified by the item * selection model passed in. * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * NewsItem to work on - * @param propertiesStep The NewsPropertiesStep which controls this - form. + * @param itemSelectionModel The ItemSelectionModel to use to obtain the + * NewsItem to work on + * @param propertiesStep The NewsPropertiesStep which controls this + * form. + * @param selectedLanguageParam */ public NewsPropertyForm(final ItemSelectionModel itemSelectionModel, - final NewsPropertiesStep propertiesStep) { - super(ID, itemSelectionModel); + final NewsPropertiesStep propertiesStep, + final StringParameter selectedLanguageParam) { + + super(ID, itemSelectionModel, selectedLanguageParam); + + Objects.requireNonNull(selectedLanguageParam); + this.propertiesStep = propertiesStep; + this.selectedLanguageParam = selectedLanguageParam; addSubmissionListener(this); } @@ -148,18 +163,30 @@ public class NewsPropertyForm extends BasicPageForm @Override public void init(final FormSectionEvent event) { final FormData data = event.getFormData(); + final PageState state = event.getPageState(); final News item = (News) super.initBasicWidgets(event); // set a default item date, if none set - java.util.Date releaseDate = item.getReleaseDate(); - if (releaseDate == null) { + final java.util.Date releaseDate; + if (item.getReleaseDate() == null) { // new Date is initialised to current time releaseDate = new java.util.Date(); + } else { + releaseDate = item.getReleaseDate(); + } + + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); } releaseDateSelector.addYear(releaseDate); data.put(NEWS_DATE, releaseDate); - data.put(LEAD, item.getDescription()); + data.put(LEAD, item.getDescription().getValue(selectedLocale)); } /** @@ -185,7 +212,8 @@ public class NewsPropertyForm extends BasicPageForm @Override public void process(final FormSectionEvent event) { - FormData data = event.getFormData(); + final FormData data = event.getFormData(); + final PageState state = event.getPageState(); final News item = (News) super.processBasicWidgets(event); @@ -195,10 +223,21 @@ public class NewsPropertyForm extends BasicPageForm .getSaveButton() .isSelected(event.getPageState())) { + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + item.setReleaseDate((java.util.Date) data.get(NEWS_DATE)); - item.getDescription().addValue( - KernelConfig.getConfig().getDefaultLocale(), - (String) data.get(LEAD)); + item + .getDescription() + .addValue( + selectedLocale, + (String) data.get(LEAD)); final ContentItemRepository itemRepo = CdiUtil .createCdiUtil() diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java index a23631771..dfcd31284 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java @@ -430,6 +430,8 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable { page.setVisibleDefault(child, false); } + page.addGlobalStateParam(selectedLanguageParam); + page.addActionListener(new ActionListener() { @Override @@ -601,11 +603,11 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable { * @return The instance of the component. */ protected Component instantiateStep(final String className) { + LOGGER.debug("Instantiating kit wizard \"{}\" with arguments {}...", className, arguments); - Object[] vals; try { // Get the creation component final Class createClass = Class.forName(className); @@ -620,8 +622,11 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable { | InvocationTargetException | NoSuchMethodException | SecurityException ex) { + LOGGER.error("Failed to instantiate authoring kit component \"{}\"...", + className); + LOGGER.error("Exception is: ", ex); throw new UncheckedWrapperException(String.format( - "Failed to instantiate authoring kit component \"{}\".", + "Failed to instantiate authoring kit component \"%s\".", className), ex); } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicItemForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicItemForm.java index 55332a442..017470a22 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicItemForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicItemForm.java @@ -33,6 +33,7 @@ import com.arsdigita.bebop.event.FormValidationListener; import com.arsdigita.bebop.form.Hidden; import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.TrimmedStringParameter; import com.arsdigita.bebop.parameters.URLTokenValidationListener; import com.arsdigita.cms.ItemSelectionModel; @@ -41,12 +42,13 @@ import com.arsdigita.web.Web; import com.arsdigita.xml.Element; import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryRepository; import org.libreccm.cdi.utils.CdiUtil; import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemRepository; +import java.util.Objects; + /** * A form for editing subclasses of ContentItem. This is just a convenience * class. @@ -59,33 +61,50 @@ public abstract class BasicItemForm extends FormSection FormProcessListener, FormValidationListener { - private final ItemSelectionModel m_itemModel; - private SaveCancelSection m_saveCancelSection; - private final FormSection m_widgetSection; public static final String CONTENT_ITEM_ID = "ContentItemId"; public static final String NAME = "ContentItemName"; public static final String TITLE = "ContentPageTitle"; public static final String LANGUAGE = "ContentItemLanguage"; + private final ItemSelectionModel itemSelectionModel; + private final StringParameter selectedLanguageParam; + + private SaveCancelSection saveCancelSection; + private final FormSection widgetSection; + /** + * Currently, to insert JavaScript code the Label Widget is "abused". + */ + private final Label script = new Label(String + .format("", + Web.getWebappContextPath()), + false); + /** * Construct a new BasicItemForm with 2 ColumnPanels and add basic content. * The left Panel is used for Labels, the right Panel for values. * - * @param formName the name of this form - * @param itemModel The {@link ItemSelectionModel} which will be responsible - * for loading the current item + * @param formName the name of this form + * @param itemSelectionModel The {@link ItemSelectionModel} which will be + * responsible for loading the current item + * @param selectedLanguageParam */ - public BasicItemForm(String formName, ItemSelectionModel itemModel) { + public BasicItemForm(final String formName, + final ItemSelectionModel itemSelectionModel, + final StringParameter selectedLanguageParam) { super(new ColumnPanel(2)); - m_widgetSection = new FormSection(new ColumnPanel(2, true)); + Objects.requireNonNull(selectedLanguageParam); + + widgetSection = new FormSection(new ColumnPanel(2, true)); - super.add(m_widgetSection, ColumnPanel.INSERT); - m_itemModel = itemModel; + super.add(widgetSection, ColumnPanel.INSERT); + this.itemSelectionModel = itemSelectionModel; + this.selectedLanguageParam = selectedLanguageParam; - /* Prepare Panel design */ - ColumnPanel panel = (ColumnPanel) getPanel(); + /* Prepare Panel design */ + final ColumnPanel panel = (ColumnPanel) getPanel(); panel.setBorder(false); panel.setPadColor("#FFFFFF"); panel.setColumnWidth(1, "20%"); @@ -95,8 +114,8 @@ public abstract class BasicItemForm extends FormSection /* Add basic contents */ addWidgets(); - m_saveCancelSection = new SaveCancelSection(); - super.add(m_saveCancelSection, + saveCancelSection = new SaveCancelSection(); + super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); addInitListener(this); @@ -108,40 +127,38 @@ public abstract class BasicItemForm extends FormSection * Construct a new BasicItemForm with a specified number of ColumnPanels and * without any content. * - * @param formName the name of this form - * @param columnPanel the columnpanel of the form - * @param itemModel The {@link ItemSelectionModel} which will be - * responsible for loading the current item + * @param formName the name of this form + * @param columnPanel the column panel of the form + * @param itemSelectionModel The {@link ItemSelectionModel} which will be + * responsible for loading the current item + * @param selectedLanguageParam */ - public BasicItemForm(String formName, - ColumnPanel columnPanel, - ItemSelectionModel itemModel) { + public BasicItemForm(final String formName, + final ColumnPanel columnPanel, + final ItemSelectionModel itemSelectionModel, + final StringParameter selectedLanguageParam) { + super(columnPanel); - m_widgetSection = new FormSection(new ColumnPanel(columnPanel. + Objects.requireNonNull(selectedLanguageParam); + + widgetSection = new FormSection(new ColumnPanel(columnPanel. getNumCols(), - true)); - super.add(m_widgetSection, ColumnPanel.INSERT); - m_itemModel = itemModel; + true)); + super.add(widgetSection, ColumnPanel.INSERT); + this.itemSelectionModel = itemSelectionModel; + this.selectedLanguageParam = selectedLanguageParam; } /** - * instanciate and add the save/cancel section for this form + * create and add the save/cancel section for this form */ public void addSaveCancelSection() { - m_saveCancelSection = new SaveCancelSection(); - super.add(m_saveCancelSection, + saveCancelSection = new SaveCancelSection(); + super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); } - /** - * Currently, to insert javascript code the Label Widget is "abused". - */ - private final Label m_script = new Label(String.format( - "", - Web.getWebappContextPath()), - false); - /** * Add basic widgets to the form. * @@ -208,69 +225,70 @@ public abstract class BasicItemForm extends FormSection } @Override - public void generateXML(PageState ps, Element parent) { - m_script.generateXML(ps, parent); - super.generateXML(ps, parent); + public void generateXML(final PageState state, + final Element parent) { + script.generateXML(state, parent); + super.generateXML(state, parent); } /** * @return the item selection model used in this form */ public ItemSelectionModel getItemSelectionModel() { - return m_itemModel; + return itemSelectionModel; } /** * @return the save/cancel section for this form */ public SaveCancelSection getSaveCancelSection() { - return m_saveCancelSection; + return saveCancelSection; } /** * Perform form initialisation. Children should override this this method to * pre-fill the widgets with data, instantiate the content item, etc. * - * @param e + * @param event * * @throws FormProcessException */ @Override - public abstract void init(FormSectionEvent e) throws FormProcessException; + public abstract void init(final FormSectionEvent event) throws FormProcessException; /** * Process the form. Children have to override this method to save the * user's changes to the database. * - * @param e + * @param event * * @throws FormProcessException */ @Override - public abstract void process(FormSectionEvent e) throws FormProcessException; + public abstract void process(final FormSectionEvent event) throws FormProcessException; /** * Validate the form. Children have to override this method to provide * context form validation, specifically name (url) uniqueness in a folder! * - * @param e + * @param event * * @throws com.arsdigita.bebop.FormProcessException */ @Override - public void validate(FormSectionEvent e) throws FormProcessException { + public void validate(final FormSectionEvent event) throws FormProcessException { // do nothing } /** * Adds a component to this container. * - * @param pc the component to add to this BasicPageForm + * @param component the component to add to this BasicPageForm * */ @Override - public void add(Component pc) { - m_widgetSection.add(pc); + public void add(final Component component) { + widgetSection.add(component); } /** @@ -278,21 +296,22 @@ public abstract class BasicItemForm extends FormSection * Layout constraints are defined in each layout container as static ints. * Use a bitwise OR to specify multiple constraints. * - * @param pc the component to add to this container + * @param component the component to add to this container * @param constraints layout constraints (a bitwise OR of static ints in the * particular layout) */ @Override - public void add(Component pc, int constraints) { - m_widgetSection.add(pc, constraints); + public void add(final Component component, + final int constraints) { + widgetSection.add(component, constraints); } /** * This method can be overridden to change the label of the title field. To * change to label of the title field can be useful for some content types. - * For example, for an organization the label "Title" for the field may be + * For example, for an organisation the label "Title" for the field may be * confusing for the normal user. For such a content type, the label would - * be changed to something like "Name of the organization". + * be changed to something like "Name of the organisation". * * @return (Content for the) Label for the title field as string */ diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java index de45d6cc2..a266a716b 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java @@ -30,6 +30,7 @@ import com.arsdigita.bebop.event.ParameterListener; import com.arsdigita.bebop.parameters.DateParameter; import com.arsdigita.bebop.parameters.ParameterData; import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; @@ -42,6 +43,7 @@ import com.arsdigita.util.Assert; import org.arsdigita.cms.CMSConfig; import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.workflow.WorkflowTemplate; import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItemInitializer; @@ -50,6 +52,7 @@ import org.librecms.contentsection.ContentType; import java.util.Date; import java.util.Locale; +import java.util.Objects; import java.util.Optional; /** @@ -73,32 +76,41 @@ public abstract class BasicPageForm extends BasicItemForm { private static final String LAUNCH_DATE = "launch_date"; + private final StringParameter selectedLanguageParam; + /** * Construct a new BasicPageForm * - * @param formName the name of this form - * @param itemModel The {@link ItemSelectionModel} which will be responsible - * for loading the current item + * @param formName the name of this form + * @param itemModel The {@link ItemSelectionModel} which will be + * responsible for loading the current item + * @param selectedLanguageParam */ public BasicPageForm(final String formName, - final ItemSelectionModel itemModel) { + final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { - super(formName, itemModel); + super(formName, itemModel, selectedLanguageParam); + Objects.requireNonNull(selectedLanguageParam); + this.selectedLanguageParam = selectedLanguageParam; } /** * Construct a new BasicPageForm with nothing on it * - * @param formName the name of this form - * @param columnPanel the column panel of the form - * @param itemModel The {@link ItemSelectionModel} which will be - * responsible for loading the current item + * @param formName the name of this form + * @param columnPanel the column panel of the form + * @param itemModel The {@link ItemSelectionModel} which will be + * responsible for loading the current item + * @param selectedLanguageParam */ public BasicPageForm(final String formName, final ColumnPanel columnPanel, - final ItemSelectionModel itemModel) { + final ItemSelectionModel itemModel, + final StringParameter selectedLanguageParam) { - super(formName, columnPanel, itemModel); + super(formName, columnPanel, itemModel, selectedLanguageParam); + this.selectedLanguageParam = selectedLanguageParam; } /** @@ -151,11 +163,20 @@ public abstract class BasicPageForm extends BasicItemForm { final ContentItem item = getItemSelectionModel() .getSelectedObject(state); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + if (item != null) { // Preset fields data.put(CONTENT_ITEM_ID, Long.toString(item.getObjectId())); - data.put(NAME, item.getName()); - data.put(TITLE, item.getTitle()); + data.put(NAME, item.getName().getValue(selectedLocale)); + data.put(TITLE, item.getTitle().getValue(selectedLocale)); final CMSConfig cmsConfig = CMSConfig.getConfig(); if (!cmsConfig.isHideLaunchDate()) { data.put(LAUNCH_DATE, item.getLaunchDate()); @@ -219,10 +240,17 @@ public abstract class BasicPageForm extends BasicItemForm { if (item != null) { // Update attributes - final KernelConfig kernelConfig = KernelConfig.getConfig(); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - item.getName().addValue(defaultLocale, (String) data.get(NAME)); - item.getTitle().addValue(defaultLocale, (String) data.get(TITLE)); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + item.getName().addValue(selectedLocale, (String) data.get(NAME)); + item.getTitle().addValue(selectedLocale, (String) data.get(TITLE)); if (!CMSConfig.getConfig().isHideLaunchDate()) { item.setLaunchDate((Date) data.get(LAUNCH_DATE)); } @@ -238,6 +266,7 @@ public abstract class BasicPageForm extends BasicItemForm { * Creation components may call this method in the process listener of their * form. See {@link PageCreate} for an example. * + * @param * @param state * @param name * @param section @@ -331,8 +360,9 @@ public abstract class BasicPageForm extends BasicItemForm { // folder, // clazz, // initializer); - item = controller.createContentItem(name, section, folder, clazz, - initializer); + item = controller + .createContentItem(name, section, folder, clazz, + initializer); } else { // item = itemManager.createContentItem(name, // section, @@ -341,11 +371,11 @@ public abstract class BasicPageForm extends BasicItemForm { // clazz, // initializer); item = controller.createContentItem(name, - section, - folder, - workflowTemplate, - clazz, - initializer); + section, + folder, + workflowTemplate, + clazz, + initializer); } } catch (ClassNotFoundException ex) { throw new FormProcessException( diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java index f582e326f..201b0bcfe 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java @@ -27,6 +27,7 @@ import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.parameters.StringParameter; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentType; @@ -78,18 +79,20 @@ public class PageCreateForm /** * Construct a new PageCreationForm * - * @param itemModel The {@link ItemSelectionModel} which will be - * responsible for loading the current item - * @param creationSelector The {@link CreationSelector} parent. This class - * should call either the {@link + * @param itemModel The {@link ItemSelectionModel} which will be + * responsible for loading the current item + * @param creationSelector The {@link CreationSelector} parent. This + * class should call either the {@link * CreationSelector#redirectBack(PageState)} or {@link * CreationSelector#editItem(PageState, ContentItem)} methods on the parent - * eventually + * eventually + * @param selectedLanguageParam */ public PageCreateForm(final ItemSelectionModel itemModel, - final CreationSelector creationSelector) { + final CreationSelector creationSelector, + final StringParameter selectedLanguageParam) { - super("PageCreate", itemModel); + super("PageCreate", itemModel, selectedLanguageParam); this.creationSelector = creationSelector; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/SimpleEditStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/SimpleEditStep.java index 66089b2be..fa44a872b 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/SimpleEditStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/SimpleEditStep.java @@ -50,6 +50,7 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Objects; import java.util.Optional; /** @@ -136,6 +137,9 @@ public class SimpleEditStep extends SecurityPropertyEditor final String parameterSuffix) { super(); + + Objects.requireNonNull(selectedLanguageParam); + this.authoringKitWizard = authoringKitWizard; this.itemSelectionModel = itemSelectionModel; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/EventCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/EventCreateForm.java index a9100888d..2dcfe31bd 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/EventCreateForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/EventCreateForm.java @@ -23,6 +23,7 @@ import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.form.Date; import com.arsdigita.bebop.parameters.NotEmptyValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.authoring.CreationSelector; import com.arsdigita.cms.ui.authoring.PageCreateForm; @@ -43,8 +44,10 @@ public class EventCreateForm extends PageCreateForm { private Date startDate; public EventCreateForm(final ItemSelectionModel itemSelectionModel, - final CreationSelector creationSelector) { - super(itemSelectionModel, creationSelector); + final CreationSelector creationSelector, + final StringParameter selectedLanguageParam) { + + super(itemSelectionModel, creationSelector, selectedLanguageParam); } @Override diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/NewsCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/NewsCreateForm.java index 2210c48be..89f314ade 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/NewsCreateForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/contenttypes/NewsCreateForm.java @@ -21,10 +21,9 @@ package com.arsdigita.cms.ui.contenttypes; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.form.Date; import com.arsdigita.bebop.parameters.NotEmptyValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.authoring.CreationSelector; import com.arsdigita.cms.ui.authoring.PageCreateForm; @@ -45,9 +44,10 @@ public class NewsCreateForm extends PageCreateForm { private Date newsDate; public NewsCreateForm(final ItemSelectionModel itemSelectionModel, - final CreationSelector creationSelector) { + final CreationSelector creationSelector, + final StringParameter selectedLanguageParam) { - super(itemSelectionModel, creationSelector); + super(itemSelectionModel, creationSelector, selectedLanguageParam); } @Override