CCM NG/ccm-cms: ArticlePropertiesStep and dependencies
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4743 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
f68565569c
commit
5ad4ca2ab6
|
|
@ -20,65 +20,72 @@ package com.arsdigita.cms.contenttypes.ui;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
import com.arsdigita.bebop.Component;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
|
||||||
import org.librecms.contenttypes.Article;
|
import org.librecms.contenttypes.Article;
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||||
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||||
|
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authoring step to edit the simple attributes of the Article content
|
* Authoring step to edit the simple attributes of the Article content type (and
|
||||||
* type (and its subclasses). The attributes edited are 'name', 'title',
|
* its subclasses). The attributes edited are 'name', 'title', 'article date',
|
||||||
* 'article date', 'location', 'lead', and 'article type'.
|
* 'location', 'lead', and 'article type'. This authoring step replaces the
|
||||||
* This authoring step replaces
|
* {@code com.arsdigita.ui.authoring.PageEdit} step for this type.
|
||||||
* the <code>com.arsdigita.ui.authoring.PageEdit</code> step for this type.
|
|
||||||
*/
|
*/
|
||||||
public class ArticlePropertiesStep extends GenericArticlePropertiesStep {
|
public class ArticlePropertiesStep extends GenericArticlePropertiesStep {
|
||||||
|
|
||||||
/** The name of the editing sheet added to this step */
|
|
||||||
public static String EDIT_SHEET_NAME = "edit";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* The name of the editing sheet added to this step
|
||||||
*
|
|
||||||
* @param itemModel
|
|
||||||
* @param parent
|
|
||||||
*/
|
*/
|
||||||
|
public final static String EDIT_SHEET_NAME = "edit";
|
||||||
|
|
||||||
public ArticlePropertiesStep(ItemSelectionModel itemModel,
|
public ArticlePropertiesStep(ItemSelectionModel itemModel,
|
||||||
AuthoringKitWizard parent) {
|
AuthoringKitWizard parent) {
|
||||||
super(itemModel, parent);
|
super(itemModel, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createEditSheet(ItemSelectionModel itemModel) {
|
protected void createEditSheet(final ItemSelectionModel itemModel) {
|
||||||
BasicPageForm editSheet;
|
BasicPageForm editSheet;
|
||||||
editSheet = new ArticlePropertyForm(itemModel, this);
|
editSheet = new ArticlePropertyForm(itemModel, this);
|
||||||
add(EDIT_SHEET_NAME,
|
add(EDIT_SHEET_NAME,
|
||||||
GlobalizationUtil.globalize("cms.ui.edit"),
|
new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE),
|
||||||
new WorkflowLockedComponentAccess(editSheet, itemModel),
|
new WorkflowLockedComponentAccess(editSheet, itemModel),
|
||||||
editSheet.getSaveCancelSection().getCancelButton());
|
editSheet.getSaveCancelSection().getCancelButton());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setDisplayComponent(ItemSelectionModel itemModel) {
|
protected void setDisplayComponent(final ItemSelectionModel itemModel) {
|
||||||
setDisplayComponent(getArticlePropertySheet(itemModel));
|
setDisplayComponent(getArticlePropertySheet(itemModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a component that displays the properties of the
|
* Returns a component that displays the properties of the Article specified
|
||||||
* Article specified by the ItemSelectionModel passed in.
|
* by the ItemSelectionModel passed in.
|
||||||
|
*
|
||||||
* @param itemModel The ItemSelectionModel to use
|
* @param itemModel The ItemSelectionModel to use
|
||||||
|
*
|
||||||
* @pre itemModel != null
|
* @pre itemModel != null
|
||||||
* @return A component to display the state of the basic properties
|
* @return A component to display the state of the basic properties of the
|
||||||
* of the release
|
* release
|
||||||
*/
|
*/
|
||||||
public static Component getArticlePropertySheet(ItemSelectionModel itemModel) {
|
public static Component getArticlePropertySheet(
|
||||||
DomainObjectPropertySheet sheet = (DomainObjectPropertySheet)
|
final ItemSelectionModel itemModel) {
|
||||||
getGenericArticlePropertySheet(itemModel);
|
|
||||||
|
|
||||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.lead"),
|
final DomainObjectPropertySheet sheet
|
||||||
Article.LEAD);
|
= (DomainObjectPropertySheet) getGenericArticlePropertySheet(
|
||||||
|
itemModel);
|
||||||
|
|
||||||
|
sheet.add(new GlobalizedMessage("cms.contenttypes.ui.lead",
|
||||||
|
CmsConstants.CMS_BUNDLE),
|
||||||
|
"lead");
|
||||||
|
|
||||||
return sheet;
|
return sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
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.form.TextArea;
|
||||||
|
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
||||||
|
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||||
|
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
import org.librecms.contenttypes.Article;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form to edit the basic properties of an article. This form can be extended to
|
||||||
|
* create forms for Article subclasses.
|
||||||
|
*/
|
||||||
|
public class ArticlePropertyForm extends GenericArticlePropertyForm
|
||||||
|
implements FormProcessListener, FormInitListener, FormSubmissionListener {
|
||||||
|
|
||||||
|
public static final String LEAD = "lead";
|
||||||
|
|
||||||
|
private ArticlePropertiesStep propertyStep;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public ArticlePropertyForm(final ItemSelectionModel itemModel) {
|
||||||
|
this(itemModel, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public ArticlePropertyForm(final ItemSelectionModel itemModel,
|
||||||
|
final ArticlePropertiesStep step) {
|
||||||
|
super(itemModel, step);
|
||||||
|
propertyStep = step;
|
||||||
|
addSubmissionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds widgets to the form.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
super.addWidgets();
|
||||||
|
|
||||||
|
ParameterModel leadParam = new StringParameter(LEAD);
|
||||||
|
if (CMSConfig.getConfig().isMandatoryDescriptions()) {
|
||||||
|
leadParam.addParameterListener(
|
||||||
|
new NotEmptyValidationListener(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.description_missing",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
}
|
||||||
|
leadParam
|
||||||
|
.addParameterListener(new StringInRangeValidationListener(0,
|
||||||
|
1000));
|
||||||
|
TextArea lead = new TextArea(leadParam);
|
||||||
|
lead.setLabel(new GlobalizedMessage("cms.contenttypes.ui.lead",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
lead.setHint(new GlobalizedMessage("cms.contenttypes.ui.lead_hint",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
lead.setCols(40);
|
||||||
|
lead.setRows(5);
|
||||||
|
add(lead);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event) throws
|
||||||
|
FormProcessException {
|
||||||
|
super.validate(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form initialisation hook. Fills widgets with data.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) {
|
||||||
|
// Do some initialization hook stuff
|
||||||
|
FormData data = event.getFormData();
|
||||||
|
final Article article = (Article) super.initBasicWidgets(event);
|
||||||
|
|
||||||
|
data.put(LEAD, article.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels streamlined editing.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void submitted(final FormSectionEvent event) {
|
||||||
|
if (propertyStep != null && getSaveCancelSection().getCancelButton()
|
||||||
|
.isSelected(event.getPageState())) {
|
||||||
|
propertyStep.cancelStreamlinedCreation(event.getPageState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form processing hook. Saves Event object.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event) {
|
||||||
|
FormData data = event.getFormData();
|
||||||
|
|
||||||
|
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 ContentItemRepository itemRepo = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(ContentItemRepository.class);
|
||||||
|
itemRepo.save(article);
|
||||||
|
}
|
||||||
|
if (propertyStep != null) {
|
||||||
|
propertyStep.maybeForwardToNextStep(event.getPageState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
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.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authoring step to edit the simple attributes of the GenericArticle content
|
||||||
|
* type (and its subclasses). The attributes edited are 'name', 'title',
|
||||||
|
* 'article date', 'location', and 'article type'. This authoring step replaces
|
||||||
|
* the {@code com.arsdigita.ui.authoring.PageEdit} step for this type.
|
||||||
|
*/
|
||||||
|
public class GenericArticlePropertiesStep extends SimpleEditStep {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the editing sheet added to this step
|
||||||
|
*/
|
||||||
|
public static final String EDIT_SHEET_NAME = "edit";
|
||||||
|
|
||||||
|
private DomainObjectPropertySheet domainObjectPropertySheet;
|
||||||
|
|
||||||
|
public GenericArticlePropertiesStep(final ItemSelectionModel itemModel,
|
||||||
|
final AuthoringKitWizard parent) {
|
||||||
|
|
||||||
|
super(itemModel, parent);
|
||||||
|
|
||||||
|
setDefaultEditKey(EDIT_SHEET_NAME);
|
||||||
|
createEditSheet(itemModel);
|
||||||
|
|
||||||
|
setDisplayComponent(itemModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createEditSheet(final ItemSelectionModel itemModel) {
|
||||||
|
BasicPageForm editSheet;
|
||||||
|
editSheet = new GenericArticlePropertyForm(itemModel, this);
|
||||||
|
add(EDIT_SHEET_NAME,
|
||||||
|
new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE),
|
||||||
|
new WorkflowLockedComponentAccess(editSheet, itemModel),
|
||||||
|
editSheet.getSaveCancelSection().getCancelButton());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDisplayComponent(ItemSelectionModel itemModel) {
|
||||||
|
setDisplayComponent(getGenericArticlePropertySheet(itemModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a component that displays the properties of the Article specified
|
||||||
|
* by the ItemSelectionModel passed in.
|
||||||
|
*
|
||||||
|
* @param itemModel The ItemSelectionModel to use
|
||||||
|
*
|
||||||
|
* @pre itemModel != null
|
||||||
|
* @return A component to display the state of the basic properties of the
|
||||||
|
* release
|
||||||
|
*/
|
||||||
|
public static Component getGenericArticlePropertySheet(
|
||||||
|
ItemSelectionModel itemModel) {
|
||||||
|
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
|
||||||
|
itemModel);
|
||||||
|
|
||||||
|
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.getConfig().isHideLaunchDate()) {
|
||||||
|
sheet.add(new GlobalizedMessage("cms.contenttypes.ui.launch_date",
|
||||||
|
CmsConstants.CMS_BUNDLE),
|
||||||
|
"launchDate",
|
||||||
|
new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(final Object item,
|
||||||
|
final String attribute,
|
||||||
|
final PageState state) {
|
||||||
|
final ContentItem page = (ContentItem) item;
|
||||||
|
if (page.getLaunchDate() != null) {
|
||||||
|
return DateFormat
|
||||||
|
.getDateInstance(DateFormat.LONG)
|
||||||
|
.format(page.getLaunchDate());
|
||||||
|
} else {
|
||||||
|
return (String) new GlobalizedMessage(
|
||||||
|
"cms.ui.unknown",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
.localize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
|
||||||
import com.arsdigita.cms.ContentSection;
|
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
|
||||||
import com.arsdigita.cms.contenttypes.GenericArticle;
|
|
||||||
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.util.GlobalizationUtil;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Authoring step to edit the simple attributes of the GenericArticle content
|
|
||||||
* type (and its subclasses). The attributes edited are 'name', 'title',
|
|
||||||
* 'article date', 'location', and 'article type'.
|
|
||||||
* This authoring step replaces
|
|
||||||
* the <code>com.arsdigita.ui.authoring.PageEdit</code> step for this type.
|
|
||||||
*/
|
|
||||||
public class GenericArticlePropertiesStep extends SimpleEditStep {
|
|
||||||
|
|
||||||
/** The name of the editing sheet added to this step */
|
|
||||||
public static String EDIT_SHEET_NAME = "edit";
|
|
||||||
DomainObjectPropertySheet get;
|
|
||||||
|
|
||||||
public GenericArticlePropertiesStep(ItemSelectionModel itemModel,
|
|
||||||
AuthoringKitWizard parent) {
|
|
||||||
super(itemModel, parent);
|
|
||||||
|
|
||||||
setDefaultEditKey(EDIT_SHEET_NAME);
|
|
||||||
createEditSheet(itemModel);
|
|
||||||
|
|
||||||
setDisplayComponent(itemModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createEditSheet(ItemSelectionModel itemModel) {
|
|
||||||
BasicPageForm editSheet;
|
|
||||||
editSheet = new GenericArticlePropertyForm(itemModel, this);
|
|
||||||
add(EDIT_SHEET_NAME,
|
|
||||||
GlobalizationUtil.globalize("cms.ui.edit"),
|
|
||||||
new WorkflowLockedComponentAccess(editSheet, itemModel),
|
|
||||||
editSheet.getSaveCancelSection().getCancelButton());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setDisplayComponent(ItemSelectionModel itemModel) {
|
|
||||||
setDisplayComponent(getGenericArticlePropertySheet(itemModel));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a component that displays the properties of the
|
|
||||||
* Article specified by the ItemSelectionModel passed in.
|
|
||||||
* @param itemModel The ItemSelectionModel to use
|
|
||||||
* @pre itemModel != null
|
|
||||||
* @return A component to display the state of the basic properties
|
|
||||||
* of the release
|
|
||||||
*/
|
|
||||||
public static Component getGenericArticlePropertySheet(ItemSelectionModel itemModel) {
|
|
||||||
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
|
|
||||||
|
|
||||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.title"),
|
|
||||||
GenericArticle.TITLE);
|
|
||||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.name"),
|
|
||||||
GenericArticle.NAME);
|
|
||||||
if (!ContentSection.getConfig().getHideLaunchDate()) {
|
|
||||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"),
|
|
||||||
ContentPage.LAUNCH_DATE,
|
|
||||||
new DomainObjectPropertySheet.AttributeFormatter() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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) GlobalizationUtil.globalize(
|
|
||||||
"cms.ui.unknown").localize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return sheet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
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.cms.ItemSelectionModel;
|
||||||
|
|
||||||
|
import org.librecms.contenttypes.Article;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
|
||||||
|
import javax.enterprise.inject.spi.CDI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form to edit the basic properties of an article. This form can be extended to
|
||||||
|
* create forms for Article subclasses.
|
||||||
|
*/
|
||||||
|
public class GenericArticlePropertyForm extends BasicPageForm
|
||||||
|
implements FormProcessListener, FormInitListener, FormSubmissionListener {
|
||||||
|
|
||||||
|
private GenericArticlePropertiesStep propertiesStep;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public GenericArticlePropertyForm(final ItemSelectionModel itemModel) {
|
||||||
|
this(itemModel, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new form to edit the GenericArticle object specified by the
|
||||||
|
* item selection model passed in.
|
||||||
|
*
|
||||||
|
* @param itemModel The ItemSelectionModel to use to obtain the
|
||||||
|
* GenericArticle to work on
|
||||||
|
* @param step The GenericArticlePropertiesStep which controls this
|
||||||
|
* form.
|
||||||
|
*/
|
||||||
|
public GenericArticlePropertyForm(final ItemSelectionModel itemModel,
|
||||||
|
final GenericArticlePropertiesStep step) {
|
||||||
|
super(ID, itemModel);
|
||||||
|
propertiesStep = step;
|
||||||
|
addSubmissionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds widgets to the form.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
super.addWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
super.validate(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form initialisation hook. Fills widgets with data.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) {
|
||||||
|
// Do some initialization hook stuff
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final Article article = (Article) super.initBasicWidgets(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels streamlined editing.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void submitted(final FormSectionEvent event) {
|
||||||
|
if (propertiesStep != null
|
||||||
|
&& getSaveCancelSection().getCancelButton().isSelected(event
|
||||||
|
.getPageState())) {
|
||||||
|
propertiesStep.cancelStreamlinedCreation(event.getPageState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form processing hook. Saves Event object.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event) {
|
||||||
|
|
||||||
|
final Article article = (Article) super.processBasicWidgets(event);
|
||||||
|
|
||||||
|
// save only if save button was pressed
|
||||||
|
if (article != null
|
||||||
|
&& getSaveCancelSection().getSaveButton().isSelected(event
|
||||||
|
.getPageState())) {
|
||||||
|
|
||||||
|
final ContentItemRepository itemRepo = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(ContentItemRepository.class);
|
||||||
|
|
||||||
|
itemRepo.save(article);
|
||||||
|
}
|
||||||
|
if (propertiesStep != null) {
|
||||||
|
propertiesStep.maybeForwardToNextStep(event.getPageState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -28,7 +28,6 @@ import com.arsdigita.bebop.PropertyEditorModel;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
import com.arsdigita.bebop.form.Submit;
|
import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.ComponentAccess;
|
import com.arsdigita.toolbox.ui.ComponentAccess;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
|
|
@ -36,8 +35,7 @@ import com.arsdigita.util.Assert;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ package com.arsdigita.cms.ui.authoring;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.event.RequestEvent;
|
import com.arsdigita.bebop.event.RequestEvent;
|
||||||
import com.arsdigita.bebop.event.RequestListener;
|
import com.arsdigita.bebop.event.RequestListener;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
|
@ -29,22 +27,30 @@ import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
import com.arsdigita.cms.ui.ContentItemPage;
|
||||||
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.ComponentAccess;
|
import com.arsdigita.toolbox.ui.ComponentAccess;
|
||||||
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
|
import java.beans.BeanInfo;
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.Introspector;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple implementation of an Authoring Kit editing step. Extends
|
* A simple implementation of an Authoring Kit editing step. Extends
|
||||||
|
|
@ -130,16 +136,9 @@ public class SimpleEditStep extends SecurityPropertyEditor
|
||||||
authoringKitWizard.getContentType().getContentItemClass().getName()
|
authoringKitWizard.getContentType().getContentItemClass().getName()
|
||||||
+ "_properties_done" + parameterSuffix);
|
+ "_properties_done" + parameterSuffix);
|
||||||
|
|
||||||
authoringKitWizard.getList().addActionListener(new ActionListener() {
|
authoringKitWizard
|
||||||
|
.getList()
|
||||||
@Override
|
.addActionListener(event -> showDisplayPane(event.getPageState()));
|
||||||
public void actionPerformed(final ActionEvent event) {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
showDisplayPane(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
additionalDisplayComponents
|
additionalDisplayComponents
|
||||||
.stream()
|
.stream()
|
||||||
|
|
@ -151,6 +150,8 @@ public class SimpleEditStep extends SecurityPropertyEditor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers global state parameter for cancelling streamlined creation
|
* Registers global state parameter for cancelling streamlined creation
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void register(final Page page) {
|
public void register(final Page page) {
|
||||||
|
|
@ -277,34 +278,62 @@ public class SimpleEditStep extends SecurityPropertyEditor
|
||||||
* the domain object.
|
* the domain object.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String format(final CcmObject object,
|
public String format(final Object object,
|
||||||
final String attribute,
|
final String attribute,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
|
|
||||||
if (object != null && object instanceof ContentItem) {
|
if (object != null && object instanceof ContentItem) {
|
||||||
|
|
||||||
final ContentItem page = (ContentItem) object;
|
final ContentItem page = (ContentItem) object;
|
||||||
final Object field = page.get(attribute);
|
final BeanInfo beanInfo;
|
||||||
|
try {
|
||||||
|
beanInfo = Introspector
|
||||||
|
.getBeanInfo(page.getClass());
|
||||||
|
} catch (IntrospectionException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
final Optional<PropertyDescriptor> propertyDescriptor = Arrays
|
||||||
|
.stream(beanInfo.getPropertyDescriptors())
|
||||||
|
.filter(propDesc -> attribute.equals(propDesc.getName()))
|
||||||
|
.findAny();
|
||||||
|
if (propertyDescriptor.isPresent()) {
|
||||||
|
final Method readMethod = propertyDescriptor
|
||||||
|
.get()
|
||||||
|
.getReadMethod();
|
||||||
|
final Object value;
|
||||||
|
try {
|
||||||
|
value = readMethod.invoke(object);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
if (value == null) {
|
||||||
|
return (String) new GlobalizedMessage("cms.ui.unknown",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
.localize();
|
||||||
|
} else {
|
||||||
|
final GlobalizationHelper globalizationHelper = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
|
||||||
if (field != null) {
|
|
||||||
// Note: No type safety here! We relay that it is
|
// Note: No type safety here! We relay that it is
|
||||||
// attached to a date property!
|
// attached to a date property!
|
||||||
return DateFormat.getDateInstance(
|
return DateFormat.getDateInstance(
|
||||||
DateFormat.LONG,
|
DateFormat.LONG,
|
||||||
GlobalizationHelper.getNegotiatedLocale()
|
globalizationHelper.getNegotiatedLocale())
|
||||||
)
|
.format(value);
|
||||||
.format(field);
|
|
||||||
} else {
|
|
||||||
return (String) GlobalizationUtil
|
|
||||||
.globalize("cms.ui.unknown")
|
|
||||||
.localize();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return (String) new GlobalizedMessage("cms.ui.unknown",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
.localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (String) GlobalizationUtil
|
} else {
|
||||||
.globalize("cms.ui.unknown")
|
return (String) new GlobalizedMessage("cms.ui.unknown",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
.localize();
|
.localize();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,197 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2001-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.domain;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
|
|
||||||
|
import java.beans.BeanInfo;
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.Introspector;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This class should be extended by domain object services that need privileged
|
||||||
|
* access to the DataObject encapsulated by a DomainObject or the DataCollection
|
||||||
|
* encapsulated by a DomainCollection.
|
||||||
|
*
|
||||||
|
* Note: This class was tightly coupled with the old PDL based persistence
|
||||||
|
* system. The class has been adapted to use standard Bean/Reflection methods
|
||||||
|
* instead, but some the results may differ.
|
||||||
|
*
|
||||||
|
* @author Oumi Mehrotra
|
||||||
|
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public abstract class DomainService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get a property of the specified domain object.
|
||||||
|
*
|
||||||
|
* @param domainObject
|
||||||
|
* @param attr
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected static Object get(final Object domainObject,
|
||||||
|
final String attr) {
|
||||||
|
|
||||||
|
final BeanInfo beanInfo;
|
||||||
|
try {
|
||||||
|
beanInfo = Introspector.getBeanInfo(domainObject.getClass());
|
||||||
|
} catch (IntrospectionException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Optional<PropertyDescriptor> property = Arrays
|
||||||
|
.stream(beanInfo.getPropertyDescriptors())
|
||||||
|
.filter(current -> attr.equals(current.getName()))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (property.isPresent()) {
|
||||||
|
|
||||||
|
final Method readMethod = property.get().getReadMethod();
|
||||||
|
|
||||||
|
final Object result;
|
||||||
|
try {
|
||||||
|
result = readMethod.invoke(domainObject);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// These methods modify domain objects and should be used cautiously.
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Set a property of the DomainObjects DataObject.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param domainObject
|
||||||
|
* @param attr
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected static void set(final Object domainObject,
|
||||||
|
final String attr,
|
||||||
|
final Object value) {
|
||||||
|
|
||||||
|
final BeanInfo beanInfo;
|
||||||
|
try {
|
||||||
|
beanInfo = Introspector.getBeanInfo(domainObject.getClass());
|
||||||
|
} catch (IntrospectionException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Optional<PropertyDescriptor> property = Arrays
|
||||||
|
.stream(beanInfo.getPropertyDescriptors())
|
||||||
|
.filter(current -> attr.equals(current.getName()))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (property.isPresent()) {
|
||||||
|
|
||||||
|
final Method writeMethod = property.get().getWriteMethod();
|
||||||
|
|
||||||
|
try {
|
||||||
|
writeMethod.invoke(domainObject, value);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Set an association DomainObjects DataObject.
|
||||||
|
*
|
||||||
|
* @see DomainObject#set(String, Object)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// protected static void setAssociation(DomainObject domainObject,
|
||||||
|
// String attr, DomainObject dobj) {
|
||||||
|
// domainObject.set(attr, dobj);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds data object specified by <i>value</i> to the specified role (with
|
||||||
|
* multiplicity>1) of the specified domain object.
|
||||||
|
*
|
||||||
|
* @see DomainObject#add(String, DataObject)
|
||||||
|
*/
|
||||||
|
// protected static DataObject add(DomainObject domainObject,
|
||||||
|
// String roleName, DataObject value) {
|
||||||
|
// return domainObject.add(roleName, value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds domain object specified by <i>value</i> to the specified role (with
|
||||||
|
* multiplicity>1) of the specified domain object.
|
||||||
|
*
|
||||||
|
* @see DomainObject#add(String, DomainObject)
|
||||||
|
*/
|
||||||
|
// protected static DataObject add(DomainObject domainObject,
|
||||||
|
// String roleName, DomainObject value) {
|
||||||
|
// return domainObject.add(roleName, value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Removes data object specified by <i>value</i> from the specified role
|
||||||
|
* (with multiplicity>1) of the specified domain object.
|
||||||
|
*
|
||||||
|
* @see DomainObject#remove(String, DataObject)
|
||||||
|
*/
|
||||||
|
// protected static void remove(DomainObject domainObject,
|
||||||
|
// String roleName, DataObject value) {
|
||||||
|
// domainObject.remove(roleName, value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Removes domain object specified by <i>value</i> from the specified role
|
||||||
|
* (with multiplicity>1) of the specified domain object.
|
||||||
|
*
|
||||||
|
* @see DomainObject#remove(String, DomainObject)
|
||||||
|
*/
|
||||||
|
// protected static void remove(DomainObject domainObject,
|
||||||
|
// String roleName, DomainObject value) {
|
||||||
|
// domainObject.remove(roleName, value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Clears specified role (with multiplicity > 1) of specified domain object.
|
||||||
|
*
|
||||||
|
* @see DomainObject#clear(String)
|
||||||
|
*/
|
||||||
|
// protected static void clear(DomainObject domainObject, String roleName) {
|
||||||
|
// domainObject.clear(roleName);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -28,10 +28,19 @@ import com.arsdigita.ui.CcmObjectSelectionModel;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
|
|
||||||
|
import java.beans.BeanInfo;
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.Introspector;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -232,7 +241,7 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
* @return A String representation of the retrieved attribute of the
|
* @return A String representation of the retrieved attribute of the
|
||||||
* domain object.
|
* domain object.
|
||||||
*/
|
*/
|
||||||
String format(CcmObject obj, String attribute, PageState state);
|
String format(Object obj, String attribute, PageState state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -397,7 +406,6 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
* formatted to a String by the default format method.
|
* formatted to a String by the default format method.
|
||||||
*/
|
*/
|
||||||
private static abstract class DefaultAttributeFormatter
|
private static abstract class DefaultAttributeFormatter
|
||||||
extends DomainService
|
|
||||||
implements AttributeFormatter {
|
implements AttributeFormatter {
|
||||||
|
|
||||||
private GlobalizedMessage m_default;
|
private GlobalizedMessage m_default;
|
||||||
|
|
@ -431,7 +439,7 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
* A simple attribute formatter that calls get on the object with the
|
* A simple attribute formatter that calls get on the object with the
|
||||||
* specified attribute.
|
* specified attribute.
|
||||||
*/
|
*/
|
||||||
private static class SimpleAttributeFormatter
|
private class SimpleAttributeFormatter
|
||||||
extends DefaultAttributeFormatter {
|
extends DefaultAttributeFormatter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -461,7 +469,8 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String format(final CcmObject obj,
|
@Override
|
||||||
|
public String format(final Object obj,
|
||||||
final String attribute,
|
final String attribute,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
|
|
||||||
|
|
@ -471,12 +480,13 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return (String) defaultMsg.localize();
|
return (String) defaultMsg.localize();
|
||||||
}
|
}
|
||||||
Object value = get(obj, attribute);
|
|
||||||
|
|
||||||
if (value == null) {
|
final Optional<Object> value = getPropertyValue(obj, attribute);
|
||||||
return (String) defaultMsg.localize();
|
|
||||||
|
if (value.isPresent()) {
|
||||||
|
return value.get().toString();
|
||||||
} else {
|
} else {
|
||||||
return value.toString();
|
return (String) defaultMsg.localize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -488,8 +498,7 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
* says "foo.bar.baz", the formatter will attempt to call
|
* says "foo.bar.baz", the formatter will attempt to call
|
||||||
* obj.get("foo").get("bar").get("baz");
|
* obj.get("foo").get("bar").get("baz");
|
||||||
*/
|
*/
|
||||||
private static class RecursiveAttributeFormatter
|
private class RecursiveAttributeFormatter extends DefaultAttributeFormatter {
|
||||||
extends DefaultAttributeFormatter {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor, simply calls the super class. Uses a default value for
|
* Constructor, simply calls the super class. Uses a default value for
|
||||||
|
|
@ -518,33 +527,71 @@ public class DomainObjectPropertySheet extends PropertySheet {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String format(DomainObject obj, String attribute, PageState state) {
|
@Override
|
||||||
|
public String format(final Object obj,
|
||||||
|
final String attribute,
|
||||||
|
final PageState state) {
|
||||||
|
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return (String) getDefaultValue().localize();
|
return (String) getDefaultValue().localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer(attribute, ".");
|
final StringTokenizer tokenizer
|
||||||
|
= new StringTokenizer(attribute, ".");
|
||||||
String token = null;
|
String token = null;
|
||||||
Object value = getDataObject(obj);
|
Object currentObject = obj;
|
||||||
|
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
token = tokenizer.nextToken();
|
token = tokenizer.nextToken();
|
||||||
// Null check
|
// Null check
|
||||||
value = ((DataObject) value).get(token);
|
currentObject = getPropertyValue(currentObject, token);
|
||||||
if (value == null) {
|
if (currentObject == null) {
|
||||||
return (String) getDefaultValue().localize();
|
return (String) getDefaultValue().localize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract leaf value
|
// Extract leaf value
|
||||||
if (token == null || value == null) {
|
if (token == null) {
|
||||||
return (String) getDefaultValue().localize();
|
return (String) getDefaultValue().localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.toString();
|
return currentObject.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<Object> getPropertyValue(final Object obj,
|
||||||
|
final String property) {
|
||||||
|
|
||||||
|
final BeanInfo beanInfo;
|
||||||
|
try {
|
||||||
|
beanInfo = Introspector.getBeanInfo(obj.getClass());
|
||||||
|
} catch (IntrospectionException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Optional<PropertyDescriptor> propertyDescriptor = Arrays
|
||||||
|
.stream(beanInfo.getPropertyDescriptors())
|
||||||
|
.filter(current -> property.equals(current.getName()))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (propertyDescriptor.isPresent()) {
|
||||||
|
|
||||||
|
final Method readMethod = propertyDescriptor
|
||||||
|
.get()
|
||||||
|
.getReadMethod();
|
||||||
|
|
||||||
|
final Object value;
|
||||||
|
try {
|
||||||
|
value = readMethod.invoke(obj);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
return Optional.of(value);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue