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

Former-commit-id: 2841e29333
pull/2/head
jensp 2017-06-08 12:58:32 +00:00
parent 54069591f9
commit cfafa974cb
2 changed files with 266 additions and 0 deletions

View File

@ -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 <a href="mailto:dturner@arsdigita.com">Dave Turner</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}

View File

@ -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> folder = itemManager.getItemFolder(article);
if (folder.isPresent()) {
return folder.get();
} else {
return null;
}
}
}