CCM NG/ccm-cms: Some improvments for EventPropertiesStep and EventPropertyForm

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4839 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 783e25eaa7
pull/2/head
jensp 2017-07-04 18:19:52 +00:00
parent 9dfd155bea
commit dccdacf8fd
7 changed files with 113 additions and 46 deletions

View File

@ -31,6 +31,7 @@ import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ToolboxConstants;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
@ -48,6 +49,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.Optional; import java.util.Optional;
/** /**
@ -101,7 +103,8 @@ public class EventPropertiesStep extends SimpleEditStep {
* Returns a component that displays the properties of the Event specified * Returns a component that displays the properties of the Event specified
* by the ItemSelectionModel passed in. * by the ItemSelectionModel passed in.
* *
* @param itemSelectionModel The ItemSelectionModel to use * @param itemSelectionModel The ItemSelectionModel to use
* @param selectedLanguageParam
* *
* @return A component to display the state of the basic properties of the * @return A component to display the state of the basic properties of the
* release * release
@ -210,13 +213,13 @@ public class EventPropertiesStep extends SimpleEditStep {
* @return A String representation of the retrieved boolean attribute of * @return A String representation of the retrieved boolean attribute of
* the domain object. * the domain object.
*/ */
@Override
public String format(final Object obj, public String format(final Object obj,
final String attribute, final String attribute,
final PageState state) { final PageState state) {
if (obj != null && obj instanceof Event) { if (obj != null && obj instanceof Event) {
final Event event = (Event) obj;
final BeanInfo beanInfo; final BeanInfo beanInfo;
try { try {
beanInfo = Introspector.getBeanInfo(Event.class); beanInfo = Introspector.getBeanInfo(Event.class);
@ -246,24 +249,38 @@ public class EventPropertiesStep extends SimpleEditStep {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
return DateFormat if (result == null) {
.getDateTimeInstance( return (String) new GlobalizedMessage(
DateFormat.LONG, "toolbox.ui.na", ToolboxConstants.TOOLBOX_BUNDLE)
DateFormat.SHORT, .localize();
globalizationHelper.getNegotiatedLocale()) } else if (result instanceof Date) {
.format(result); return DateFormat
.getDateTimeInstance(
DateFormat.LONG,
DateFormat.SHORT,
globalizationHelper.getNegotiatedLocale())
.format((Date) result);
} else {
throw new IllegalArgumentException(String
.format(
"Value is not an instance of \"%s\" but is an "
+ "instance of \"%s\".",
Date.class.getName(),
result.getClass().getName()));
}
} else { } else {
return (String) new GlobalizedMessage( return (String) new GlobalizedMessage(
"cms.ui.unknown", "toolbox.ui.na",
CmsConstants.CMS_BUNDLE) ToolboxConstants.TOOLBOX_BUNDLE)
.localize(); .localize();
} }
} else { } else {
return (String) new GlobalizedMessage("cms.ui.unknown", return (String) new GlobalizedMessage(
CmsConstants.CMS_BUNDLE) "toolbox.ui.na",
ToolboxConstants.TOOLBOX_BUNDLE)
.localize(); .localize();
} }
} }

View File

@ -442,14 +442,14 @@ public class EventPropertyForm
data.put(LEAD, item.getDescription().getValue(selectedLocale)); data.put(LEAD, item.getDescription().getValue(selectedLocale));
data.put(START_DATE, startDate); data.put(START_DATE, startDate);
data.put(START_TIME, startDate.getTime()); data.put(START_TIME, startDate);
data.put(END_DATE, endDate); data.put(END_DATE, endDate);
data.put(END_TIME, endDate.getTime()); data.put(END_TIME, endDate);
if (!eventConfig.isHideDateDescription()) { if (!eventConfig.isHideDateDescription()) {
data.put(EVENT_DATE, data.put(EVENT_DATE,
item.getEventDate().getValue(selectedLocale)); item.getEventDate().getValue(selectedLocale));
} }
data.put(LOCATION, item.getLocation()); data.put(LOCATION, item.getLocation().getValue(selectedLocale));
if (!eventConfig.isHideMainContributor()) { if (!eventConfig.isHideMainContributor()) {
data.put(MAIN_CONTRIBUTOR, data.put(MAIN_CONTRIBUTOR,
item.getMainContributor().getValue(selectedLocale)); item.getMainContributor().getValue(selectedLocale));
@ -489,7 +489,8 @@ public class EventPropertyForm
*/ */
@Override @Override
public void process(final FormSectionEvent event) { public void process(final FormSectionEvent event) {
FormData data = event.getFormData();
final FormData data = event.getFormData();
final Event item = (Event) super.processBasicWidgets(event); final Event item = (Event) super.processBasicWidgets(event);
@ -498,12 +499,20 @@ public class EventPropertyForm
.findBean(ConfigurationManager.class); .findBean(ConfigurationManager.class);
final EventConfig eventConfig = confManager final EventConfig eventConfig = confManager
.findConfiguration(EventConfig.class); .findConfiguration(EventConfig.class);
final PageState state = event.getPageState();
// save only if save button was pressed // save only if save button was pressed
if (item != null if (item != null
&& getSaveCancelSection() && getSaveCancelSection().getSaveButton().isSelected(state)) {
.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);
}
final java.util.Date startDate = (java.util.Date) data final java.util.Date startDate = (java.util.Date) data
.get(START_DATE); .get(START_DATE);
@ -516,39 +525,34 @@ public class EventPropertyForm
item.setEndDate((java.util.Date) data.get(END_DATE)); item.setEndDate((java.util.Date) data.get(END_DATE));
//date_description //date_description
if (!eventConfig.isHideDateDescription()) { if (!eventConfig.isHideDateDescription()) {
item.getEventDate().addValue( item.getEventDate().addValue(selectedLocale,
KernelConfig.getConfig().getDefaultLocale(), (String) data.get(EVENT_DATE));
(String) data.get(EVENT_DATE));
} }
if (!eventConfig.isHideMainContributor()) { if (!eventConfig.isHideMainContributor()) {
item item
.getMainContributor() .getMainContributor()
.addValue(KernelConfig.getConfig().getDefaultLocale(), .addValue(selectedLocale,
(String) data.get(MAIN_CONTRIBUTOR)); (String) data.get(MAIN_CONTRIBUTOR));
} }
if (!eventConfig.isHideEventType()) { if (!eventConfig.isHideEventType()) {
item item
.getEventType() .getEventType()
.addValue(KernelConfig.getConfig().getDefaultLocale(), .addValue(selectedLocale,
(String) data.get(EVENT_TYPE)); (String) data.get(EVENT_TYPE));
} }
if (!eventConfig.isHideLinkToMap()) { if (!eventConfig.isHideLinkToMap()) {
item.setMapLink((String) data.get(MAP_LINK)); item.setMapLink((String) data.get(MAP_LINK));
} }
item item
.getLocation() .getLocation().addValue(selectedLocale,
.addValue(KernelConfig.getConfig().getDefaultLocale(), (String) data.get(LOCATION));
(String) data.get(LOCATION));
item item
.getDescription() .getDescription().addValue(selectedLocale,
.addValue(KernelConfig.getConfig().getDefaultLocale(), (String) data.get(LEAD));
(String) data.get(LEAD));
if (!eventConfig.isHideCost()) { if (!eventConfig.isHideCost()) {
item item.getCost().addValue(selectedLocale,
.getCost() (String) data.get(COST));
.addValue(KernelConfig.getConfig().getDefaultLocale(),
(String) data.get(COST));
} }
final ContentItemRepository itemRepo = cdiUtil final ContentItemRepository itemRepo = cdiUtil

View File

@ -167,19 +167,35 @@ public class Event extends ContentItem implements Serializable {
} }
public Date getStartDate() { public Date getStartDate() {
return new Date(startDate.getTime()); if (startDate == null) {
return null;
} else {
return new Date(startDate.getTime());
}
} }
public void setStartDate(final Date startDate) { public void setStartDate(final Date startDate) {
this.startDate = new Date(startDate.getTime()); if (startDate == null) {
this.startDate = null;
} else {
this.startDate = new Date(startDate.getTime());
}
} }
public Date getEndDate() { public Date getEndDate() {
return new Date(endDate.getTime()); if (endDate == null) {
return null;
} else {
return new Date(endDate.getTime());
}
} }
public void setEndDate(final Date endDate) { public void setEndDate(final Date endDate) {
this.endDate = new Date(endDate.getTime()); if (endDate == null) {
this.endDate = null;
} else {
this.endDate = new Date(endDate.getTime());
}
} }
public LocalizedString getEventDate() { public LocalizedString getEventDate() {

View File

@ -336,3 +336,13 @@ cms.ui.action=Action
cms.ui.item.language.add=Add language cms.ui.item.language.add=Add language
cms.contenttypes.ui.newsitem.date=News date cms.contenttypes.ui.newsitem.date=News date
cms.contenttypes.ui.newsitem.lead=Description cms.contenttypes.ui.newsitem.lead=Description
cms.contenttypes.ui.event.lead=Description
cms.contenttypes.ui.event.start_time=Starts at
cms.contenttypes.ui.event.end_date=End date
cms.contenttypes.ui.event.end_time=Ends at
cms.contenttypes.ui.event.date_description=More information
cms.contenttypes.ui.event.location=Location
cms.contenttypes.ui.event.main_contributor=Main contributor
cms.contenttypes.ui.event.event_type=Event type
cms.contenttypes.ui.event.link_to_map=Link to map
cms.contenttypes.ui.event.cost=Cost

View File

@ -333,3 +333,13 @@ cms.ui.action=Aktion
cms.ui.item.language.add=Sprache hinzuf\u00fcgen cms.ui.item.language.add=Sprache hinzuf\u00fcgen
cms.contenttypes.ui.newsitem.date=Datum cms.contenttypes.ui.newsitem.date=Datum
cms.contenttypes.ui.newsitem.lead=Zusammenfassung cms.contenttypes.ui.newsitem.lead=Zusammenfassung
cms.contenttypes.ui.event.lead=Zusammenfassung
cms.contenttypes.ui.event.start_time=Beginnt um
cms.contenttypes.ui.event.end_date=Enddatum
cms.contenttypes.ui.event.end_time=Endet um
cms.contenttypes.ui.event.date_description=Weitere Informationen
cms.contenttypes.ui.event.location=Ort
cms.contenttypes.ui.event.main_contributor=Ansprechpartner
cms.contenttypes.ui.event.event_type=Art der Veranstaltung
cms.contenttypes.ui.event.link_to_map=Link zur Karte
cms.contenttypes.ui.event.cost=Kosten

View File

@ -292,3 +292,13 @@ cms.ui.action=Action
cms.ui.item.language.add=Add language cms.ui.item.language.add=Add language
cms.contenttypes.ui.newsitem.date=News date cms.contenttypes.ui.newsitem.date=News date
cms.contenttypes.ui.newsitem.lead=Description cms.contenttypes.ui.newsitem.lead=Description
cms.contenttypes.ui.event.lead=Description
cms.contenttypes.ui.event.start_time=Starts at
cms.contenttypes.ui.event.end_date=End date
cms.contenttypes.ui.event.end_time=Ends at
cms.contenttypes.ui.event.date_description=More information
cms.contenttypes.ui.event.location=Location
cms.contenttypes.ui.event.main_contributor=Main contributor
cms.contenttypes.ui.event.event_type=Event type
cms.contenttypes.ui.event.link_to_map=Link to map
cms.contenttypes.ui.event.cost=Cost

View File

@ -630,7 +630,7 @@ public class DomainObjectPropertySheet extends PropertySheet {
} catch (IllegalAccessException | InvocationTargetException ex) { } catch (IllegalAccessException | InvocationTargetException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
return Optional.of(value); return Optional.ofNullable(value);
} else { } else {
return Optional.empty(); return Optional.empty();