From 62fe0207a0c5579476061c5dc0e780cc9259f6f7 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 8 Jun 2017 12:58:32 +0000 Subject: [PATCH] CCM NG/ccm-cms: MultiPartArticleEdit ported to CCM NG git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4763 8810af33-2d31-482b-a856-94f89814c4df --- .../ui/mparticle/MultiPartArticleEdit.java | 116 ++++++++++++++ .../mparticle/MultiPartArticleEditForm.java | 150 ++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEdit.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEditForm.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEdit.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEdit.java new file mode 100755 index 000000000..640084b94 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEdit.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.contenttypes.ui.mparticle; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.StringParameter; + +import org.librecms.contentsection.ContentSection; + +import com.arsdigita.cms.ItemSelectionModel; + +import org.librecms.contenttypes.MultiPartArticle; + +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.arsdigita.cms.CMSConfig; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.configuration.ConfigurationManager; +import org.librecms.CmsConstants; + +import java.text.DateFormat; + +/** + * A MultiPartArticle editing component. + * + * @author Dave Turner + * @author Jens Pelzetter + */ +public class MultiPartArticleEdit extends SimpleEditStep { + + /** + * Constructor. + * + * @param itemSelectionModel the ItemSelectionModel which holds the + * current MutliPartArticle + * @param authoringKitWizard the parent wizard which contains the form + * @param selectedLanguageParam + */ + public MultiPartArticleEdit(final ItemSelectionModel itemSelectionModel, + final AuthoringKitWizard authoringKitWizard, + final StringParameter selectedLanguageParam) { + + super(itemSelectionModel, authoringKitWizard, selectedLanguageParam); + + setDefaultEditKey("edit"); + MultiPartArticleForm form = getForm(itemSelectionModel); + add("edit", + new GlobalizedMessage("cms.ui.edit", + CmsConstants.CMS_BUNDLE), + new WorkflowLockedComponentAccess(form, itemSelectionModel), + form.getSaveCancelSection().getCancelButton() + ); + + setDisplayComponent(getMultiPartArticlePropertiesSheet( + itemSelectionModel)); + } + + protected MultiPartArticleForm getForm( + final ItemSelectionModel itemSelectionModel) { + + return new MultiPartArticleEditForm(itemSelectionModel, this); + } + + public Component getMultiPartArticlePropertiesSheet( + final ItemSelectionModel itemSelectionModel) { + + final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( + itemSelectionModel); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ConfigurationManager confManager = cdiUtil + .findBean(ConfigurationManager.class); + final CMSConfig cmsConfig = confManager + .findConfiguration(CMSConfig.class); + + sheet.add(new GlobalizedMessage("cms.contenttypes.ui.title", + CmsConstants.CMS_BUNDLE), + "title"); + sheet.add(new GlobalizedMessage("cms.contenttypes.ui.name", + CmsConstants.CMS_BUNDLE), + "name"); + if (!cmsConfig.isHideLaunchDate()) { + sheet.add(new GlobalizedMessage("cms.contenttypes.ui.launch_date", + CmsConstants.CMS_BUNDLE), + "launchDate", + new LaunchDateAttributeFormatter()); + } + sheet.add(new GlobalizedMessage("cms.contenttypes.ui.summary", + CmsConstants.CMS_BUNDLE), + "summary"); + + return sheet; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEditForm.java new file mode 100755 index 000000000..a3b0b1bce --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleEditForm.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.contenttypes.ui.mparticle; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; + +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.Folder; + +import com.arsdigita.cms.ItemSelectionModel; + +import org.librecms.contenttypes.MultiPartArticle; + +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.kernel.KernelConfig; +import com.arsdigita.util.Assert; + +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.CmsConstants; +import org.librecms.contentsection.ContentItemManager; +import org.librecms.contentsection.FolderManager; +import org.librecms.contentsection.FolderRepository; + +import java.util.Optional; + +/** + * Worker class to create the multipart article's edit form. + * + */ +public class MultiPartArticleEditForm extends MultiPartArticleForm + implements FormSubmissionListener { + + private final ItemSelectionModel itemSelectionModel; + private final SimpleEditStep editStep; + + /** + * Constructor. + * + * @param itemSelectionModel + * @param editStep + */ + public MultiPartArticleEditForm(final ItemSelectionModel itemSelectionModel, + final SimpleEditStep editStep) { + + super("MultiPartArticleEditForm", itemSelectionModel); + addSubmissionListener(this); + this.itemSelectionModel = itemSelectionModel; + this.editStep = editStep; + } + + @Override + public void init(final FormSectionEvent event) throws FormProcessException { + super.initBasicWidgets(event); + } + + /** + * Cancels streamlined editing. + * + * @param event + */ + @Override + public void submitted(final FormSectionEvent event) { + + if (getSaveCancelSection() + .getCancelButton() + .isSelected(event.getPageState())) { + editStep.cancelStreamlinedCreation(event.getPageState()); + } + } + + @Override + public void process(final FormSectionEvent event) throws + FormProcessException { + editStep.maybeForwardToNextStep(event.getPageState()); + } + + @Override + public void validate(final FormSectionEvent event) throws + FormProcessException { + + final PageState state = event.getPageState(); + final FormData data = event.getFormData(); + + final MultiPartArticle article = (MultiPartArticle) itemSelectionModel + .getSelectedObject(state); + + final String newName = (String) data.get(MultiPartArticleForm.NAME); + final String oldName = article + .getName() + .getValue(KernelConfig.getConfig().getDefaultLocale()); + + final boolean valid; + if (newName.equalsIgnoreCase(oldName)) { + valid = true; + } else { + final Folder parent = getParentFolder(article); + valid = validateNameUniqueness(parent, event); + } + + if (!valid) { + throw new FormProcessException( + "An item with name already exists", + new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.an_item_with_name_already_exists", + CmsConstants.CMS_BUNDLE)); + } + } + + private Folder getParentFolder(final MultiPartArticle article) { + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final FolderRepository folderRepo = cdiUtil + .findBean(FolderRepository.class); + final FolderManager folderManager = cdiUtil + .findBean(FolderManager.class); + + final ContentItemManager itemManager = cdiUtil + .findBean(ContentItemManager.class); + + final Optional folder = itemManager.getItemFolder(article); + + if (folder.isPresent()) { + return folder.get(); + } else { + return null; + } + } + +}