Skip to content

Commit

Permalink
more date/time format refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 25, 2019
1 parent 779e8bd commit b73271b
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 100 deletions.
Expand Up @@ -49,7 +49,6 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.gui.api.SubscriptionType;
import com.evolveum.midpoint.gui.api.model.ReadOnlyValueModel;
import com.evolveum.midpoint.model.api.AssignmentCandidatesSpecification;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.RoleSelectionSpecification;
Expand All @@ -73,7 +72,6 @@
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
Expand Down Expand Up @@ -1539,35 +1537,45 @@ public static String getLocalizedDate(Date date, String style) {
return converter.convertToString(date, WebComponentUtil.getCurrentLocale());
}

public static String getShortDateTimeFormatValue(XMLGregorianCalendar date, PageBase pageBase) {
return getShortDateTimeFormatValue(XmlTypeConverter.toDate(date), pageBase);
public static String getShortDateTimeFormattedValue(XMLGregorianCalendar date, PageBase pageBase) {
return getShortDateTimeFormattedValue(XmlTypeConverter.toDate(date), pageBase);
}

public static String getShortDateTimeFormatValue(Date date, PageBase pageBase) {
public static String getShortDateTimeFormattedValue(Date date, PageBase pageBase) {
if (date == null) {
return "";
}
AdminGuiConfigurationDisplayFormatsType displayFormats = pageBase.getCompiledUserProfile().getDisplayFormats();
if (displayFormats == null || StringUtils.isEmpty(displayFormats.getShortDateTimeFormat())){
return getLocalizedDate(date, DateLabelComponent.SHORT_MEDIUM_STYLE);
} else {
return getLocalizedDate(date, displayFormats.getShortDateTimeFormat());
}
String shortDateTimeFortam = getShortDateTimeFormat(pageBase);
return getLocalizedDate(date, shortDateTimeFortam);
}

public static String getLongDateTimeFormatValue(XMLGregorianCalendar date, PageBase pageBase) {
return getLongDateTimeFormatValue(XmlTypeConverter.toDate(date), pageBase);
public static String getLongDateTimeFormattedValue(XMLGregorianCalendar date, PageBase pageBase) {
return getLongDateTimeFormattedValue(XmlTypeConverter.toDate(date), pageBase);
}

public static String getLongDateTimeFormatValue(Date date, PageBase pageBase) {
public static String getLongDateTimeFormattedValue(Date date, PageBase pageBase) {
if (date == null) {
return "";
}
String longDateTimeFormat = getLongDateTimeFormat(pageBase);
return getLocalizedDate(date, longDateTimeFormat);
}

public static String getShortDateTimeFormat(PageBase pageBase){
AdminGuiConfigurationDisplayFormatsType displayFormats = pageBase.getCompiledUserProfile().getDisplayFormats();
if (displayFormats == null || StringUtils.isEmpty(displayFormats.getShortDateTimeFormat())){
return DateLabelComponent.SHORT_MEDIUM_STYLE;
} else {
return displayFormats.getShortDateTimeFormat();
}
}

public static String getLongDateTimeFormat(PageBase pageBase){
AdminGuiConfigurationDisplayFormatsType displayFormats = pageBase.getCompiledUserProfile().getDisplayFormats();
if (displayFormats == null || StringUtils.isEmpty(displayFormats.getLongDateTimeFormat())){
return getLocalizedDate(date, DateLabelComponent.LONG_MEDIUM_STYLE);
return DateLabelComponent.LONG_MEDIUM_STYLE;
} else {
return getLocalizedDate(date, displayFormats.getLongDateTimeFormat());
return displayFormats.getLongDateTimeFormat();
}
}

Expand Down
Expand Up @@ -46,7 +46,8 @@ public class DateLabelComponent extends DateLabel {
public static final String MEDIUM_FULL_STYLE = "MF"; //medium style for date, full style for time
public static final String MEDIUM_NOTIME_STYLE = "M-"; //medium style for date, no time
public static final String LONG_SHORT_STYLE = "LS"; //long style for date, short style for time
public static final String LONG_MEDIUM_STYLE = "LM"; //long style for date, medium style for time
public static final String LONG_MEDIUM_STYLE = "LM"; //long style for date, medium style for time TODO ? let it be default style
//if no other is specified
public static final String LONG_FULL_STYLE = "LF"; //long style for date, full style for time
public static final String LONG_NOTIME_STYLE = "L-"; //long style for date, no time
public static final String FULL_SHORT_STYLE = "FS"; //full style for date, short style for time
Expand All @@ -58,31 +59,25 @@ public class DateLabelComponent extends DateLabel {
public static final String NODATE_LONG_STYLE = "-L"; //no date, long style for time
public static final String NODATE_FULL_STYLE = "-F"; //no date, full style for time

public DateLabelComponent(String id, IModel<Date> model){
this(id, model, (DateConverter) null);
}

public DateLabelComponent(String id, IModel<Date> model, DateConverter converter){
this(id, model, converter, null, "", "");
}

public DateLabelComponent(String id, IModel<Date> model, String style){
this(id, model, null, style, "", "");
}
public DateLabelComponent(String id, IModel<Date> model, String style){
super(id, model, new PatternDateConverter(WebComponentUtil.getLocalizedDatePattern(style == null ? LONG_MEDIUM_STYLE : style), true ));

public DateLabelComponent(String id, IModel<Date> model, DateConverter converter, String style,
String beforeDateText, String afterDateText){
super(id, model, converter == null ?
new PatternDateConverter(WebComponentUtil.getLocalizedDatePattern(style == null ? LONG_LONG_STYLE : style), true ) : converter);

setBefore(beforeDateText);
setAfter(afterDateText);
setBefore(getBeforeDateText());
setAfter(getAfterDateText());
}

public void setBeforeTextOnDateNull(String nullDateText){
if (getModel().getObject() == null){
setBefore(nullDateText);
}
}

protected String getBeforeDateText(){
return "";
}

protected String getAfterDateText(){
return "";
}
}

Expand Up @@ -18,7 +18,6 @@

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
Expand Down Expand Up @@ -103,7 +102,7 @@ public String getObject() {
PropertyModel<Object> tempModel = new PropertyModel<>(getModel(),
qname.getLocalPart());
if (tempModel.getObject() instanceof XMLGregorianCalendar){
return WebComponentUtil.getLongDateTimeFormatValue((XMLGregorianCalendar)tempModel.getObject(), getPageBase());
return WebComponentUtil.getLongDateTimeFormattedValue((XMLGregorianCalendar)tempModel.getObject(), getPageBase());
} else if (tempModel.getObject() instanceof ObjectReferenceType){
ObjectReferenceType ref = (ObjectReferenceType) tempModel.getObject();
return WebComponentUtil.getName(ref, getPageBase(), OPERATION_LOAD_USER);
Expand Down
Expand Up @@ -114,7 +114,7 @@ public void populateItem(Item<ICellPopulator<WorkItemDto>> cellItem, String comp
public Date getObject() {
return rowModel.getObject().getStartedDate();
}
}, DateLabelComponent.LONG_MEDIUM_STYLE));
}, WebComponentUtil.getShortDateTimeFormat(WorkItemsPanel.this.getPageBase())));
}
});
}
Expand All @@ -130,7 +130,7 @@ public void populateItem(Item<ICellPopulator<WorkItemDto>> cellItem, String comp
public Date getObject() {
return rowModel.getObject().getCreatedDate();
}
}, DateLabelComponent.LONG_MEDIUM_STYLE));
}, WebComponentUtil.getShortDateTimeFormat(WorkItemsPanel.this.getPageBase())));
}
});
columns.add(new AbstractColumn<WorkItemDto, String>(createStringResource("WorkItemsPanel.deadline")){
Expand All @@ -145,7 +145,7 @@ public void populateItem(Item<ICellPopulator<WorkItemDto>> cellItem, String comp
public Date getObject() {
return rowModel.getObject().getDeadlineDate();
}
}, DateLabelComponent.LONG_MEDIUM_STYLE));
}, WebComponentUtil.getShortDateTimeFormat(WorkItemsPanel.this.getPageBase())));
}
});
columns.add(new PropertyColumn<>(createStringResource("WorkItemsPanel.escalationLevel"),
Expand Down
Expand Up @@ -24,7 +24,6 @@

import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.web.page.admin.workflow.PageWorkItems;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -62,7 +61,6 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.Table;
import com.evolveum.midpoint.web.component.data.column.IsolatedCheckBoxPanel;
Expand Down Expand Up @@ -251,15 +249,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date created;
if (createdCal != null) {
created = createdCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(created, PageCaseWorkItems.this)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormattedValue(created, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
created = null;
}
item.add(new Label(componentId, new IModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getShortDateTimeFormatValue(created, PageCaseWorkItems.this);
return WebComponentUtil.getShortDateTimeFormattedValue(created, PageCaseWorkItems.this);
}
}));
}
Expand All @@ -276,15 +274,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date deadline;
if (deadlineCal != null) {
deadline = deadlineCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(deadline, PageCaseWorkItems.this)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormattedValue(deadline, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
deadline = null;
}
item.add(new Label(componentId, new IModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getShortDateTimeFormatValue(deadline, PageCaseWorkItems.this);
return WebComponentUtil.getShortDateTimeFormattedValue(deadline, PageCaseWorkItems.this);
}
}));
}
Expand All @@ -301,15 +299,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date closed;
if (closedCal != null) {
closed = closedCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(closed, PageCaseWorkItems.this)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormattedValue(closed, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
closed = null;
}
item.add(new Label(componentId, new IModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getShortDateTimeFormatValue(closed, PageCaseWorkItems.this);
return WebComponentUtil.getShortDateTimeFormattedValue(closed, PageCaseWorkItems.this);
}
}));
}
Expand Down
Expand Up @@ -5,7 +5,6 @@
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.util.SelectableBean;
Expand All @@ -27,7 +26,6 @@
import org.apache.wicket.request.mapper.parameter.PageParameters;

import javax.xml.datatype.XMLGregorianCalendar;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -177,7 +175,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<CaseType>>> cellItem
cellItem.add(new Label(componentId, new IModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getShortDateTimeFormatValue(created, PageCases.this);
return WebComponentUtil.getShortDateTimeFormattedValue(created, PageCases.this);
}
}));
}
Expand All @@ -201,7 +199,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<CaseType>>> cellItem
cellItem.add(new Label(componentId, new IModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getShortDateTimeFormatValue(closed, PageCases.this);
return WebComponentUtil.getShortDateTimeFormattedValue(closed, PageCases.this);
}
}));
}
Expand Down
Expand Up @@ -28,7 +28,6 @@
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.MultiButtonPanel;
import com.evolveum.midpoint.web.component.data.Table;
Expand Down Expand Up @@ -321,7 +320,7 @@ public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String comp
CertWorkItemDto dto = rowModel.getObject();
Date started = dto.getStageStarted();
if (started != null) {
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(started, PageCertDecisions.this)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormattedValue(started, PageCertDecisions.this)));
item.add(new TooltipBehavior());
}
}
Expand Down
Expand Up @@ -95,7 +95,7 @@ public Date getObject() {
PersonalInfoDto dto = getModel().getObject();
return dto == null ? null : dto.getLastLoginDate();
}
}, DateLabelComponent.LONG_MEDIUM_STYLE);
}, WebComponentUtil.getLongDateTimeFormat(parentPage));
lastLoginDate.setBeforeTextOnDateNull(parentPage.getString("PersonalInfoPanel.never"));
add(lastLoginDate);

Expand All @@ -118,7 +118,7 @@ public Date getObject() {
PersonalInfoDto dto = getModel().getObject();
return dto == null ? null : dto.getLastFailDate();
}
}, DateLabelComponent.LONG_MEDIUM_STYLE);
}, WebComponentUtil.getLongDateTimeFormat(parentPage));
lastFailDate.setBeforeTextOnDateNull(parentPage.getString("PersonalInfoPanel.never"));
add(lastFailDate);

Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.evolveum.midpoint.web.page.admin.home.component;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -44,7 +45,7 @@
/**
* @author Viliam Repan (lazyman)
*/
public class SystemInfoPanel extends SimplePanel<SystemInfoPanel.SystemInfoDto> {
public class SystemInfoPanel extends BasePanel<SystemInfoPanel.SystemInfoDto> {

private static final Trace LOGGER = TraceManager.getTrace(SystemInfoPanel.class);

Expand All @@ -60,6 +61,12 @@ public SystemInfoPanel(String id) {
super(id);
}

@Override
protected void onInitialize(){
super.onInitialize();
initLayout();
}

@Override
public IModel<SystemInfoDto> createModel() {
return new LoadableModel<SystemInfoDto>() {
Expand Down Expand Up @@ -135,8 +142,7 @@ private void fillThreads(SystemInfoDto dto) throws Exception {
dto.threads[2] = (Number) mbs.getAttribute(name, "TotalStartedThreadCount");
}

@Override
protected void initLayout() {
private void initLayout() {
final WebMarkupContainer table = new WebMarkupContainer(ID_TABLE);
table.setOutputMarkupId(true);
add(table);
Expand All @@ -154,7 +160,8 @@ protected void initLayout() {
Label threads = new Label(ID_THREADS, createThreadModel());
table.add(threads);

DateLabelComponent startTime = new DateLabelComponent(ID_START_TIME, createStartTimeModel(), DateLabelComponent.MEDIUM_MEDIUM_STYLE);
DateLabelComponent startTime = new DateLabelComponent(ID_START_TIME, createStartTimeModel(),
WebComponentUtil.getLongDateTimeFormat(SystemInfoPanel.this.getPageBase()));
table.add(startTime);

Label uptime = new Label(ID_UPTIME, createUptimeModel());
Expand Down
Expand Up @@ -19,7 +19,6 @@

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.page.admin.reports.dto.AuditEventRecordItemValueDto;
Expand Down Expand Up @@ -226,7 +225,7 @@ private List<IColumn<AuditEventRecordType, String>> initColumns() {
public void populateItem(Item<ICellPopulator<AuditEventRecordType>> item, String componentId,
IModel<AuditEventRecordType> rowModel) {
XMLGregorianCalendar time = rowModel.getObject().getTimestamp();
item.add(new Label(componentId, WebComponentUtil.getShortDateTimeFormatValue(time, PageAuditLogDetails.this)));
item.add(new Label(componentId, WebComponentUtil.getShortDateTimeFormattedValue(time, PageAuditLogDetails.this)));
}
};
columns.add(timeColumn);
Expand Down

0 comments on commit b73271b

Please sign in to comment.