Bug #1533: Avoid hard-coding date formats

* Create new methods in Util class that use DateFormat depending on localte to
  convert a date to string.
* Review all the parts of the code where the date format is hard-coded and call
  to the new methods.

FEA: ItEr77S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2012-09-13 13:12:41 +02:00
parent a60939af9e
commit 5279bb5c35
16 changed files with 123 additions and 119 deletions

View file

@ -20,7 +20,6 @@
package org.libreplan.business.planner.entities; package org.libreplan.business.planner.entities;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.hibernate.validator.AssertTrue; import org.hibernate.validator.AssertTrue;
@ -98,9 +97,8 @@ public class SubcontractorCommunicationValue implements INewObject {
@Override @Override
public String toString() { public String toString() {
String datetime = (date == null) ? "" : new SimpleDateFormat( String progress_reported = progress != null ? progress.toString()
"dd/MM/yyyy").format(date); + "% - " : "";
String progress_reported = progress != null ? progress.toString() + "% - " : ""; return progress_reported + date;
return progress_reported + datetime;
} }
} }

View file

@ -25,7 +25,6 @@ import static org.libreplan.web.I18nHelper._;
import static org.libreplan.web.common.Util.findOrCreate; import static org.libreplan.web.common.Util.findOrCreate;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -311,7 +310,7 @@ public abstract class BaseCalendarEditionController extends
Date date = baseCalendarModel.getCurrentExpiringDate(); Date date = baseCalendarModel.getCurrentExpiringDate();
String label = ""; String label = "";
if (date != null) { if (date != null) {
label = " " + _("to {0}", new SimpleDateFormat("dd/MM/yyyy").format(date)); label = " " + _("to {0}", Util.formatDate(date));
} }
return label; return label;
} }
@ -320,7 +319,7 @@ public abstract class BaseCalendarEditionController extends
Date date = baseCalendarModel.getCurrentStartDate(); Date date = baseCalendarModel.getCurrentStartDate();
String label = ""; String label = "";
if (date != null) { if (date != null) {
label = " " + _("from {0}", new SimpleDateFormat("dd/MM/yyyy").format(date)); label = " " + _("from {0}", Util.formatDate(date));
} }
return label; return label;
} }

View file

@ -25,6 +25,7 @@ import static org.libreplan.web.I18nHelper._;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -35,11 +36,15 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.libreplan.business.common.BaseEntity; import org.libreplan.business.common.BaseEntity;
import org.libreplan.business.common.Configuration; import org.libreplan.business.common.Configuration;
import org.libreplan.business.common.IOnTransaction; import org.libreplan.business.common.IOnTransaction;
import org.libreplan.business.common.Registry; import org.libreplan.business.common.Registry;
import org.zkoss.ganttz.util.ComponentsFinder; import org.zkoss.ganttz.util.ComponentsFinder;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
@ -773,4 +778,73 @@ public class Util {
} }
} }
/**
* Format specific <code>date</code> using the {@link DateFormat#DEFAULT}
* format and showing only date without time.
*/
public static String formatDate(Date date) {
if (date == null) {
return "";
}
return DateFormat.getDateInstance(DateFormat.DEFAULT,
Locales.getCurrent()).format(date);
}
/**
* Format specific <code>date</code> using the {@link DateFormat#DEFAULT}
* format and showing both date and time.
*/
public static String formatDateTime(Date dateTime) {
if (dateTime == null) {
return "";
}
return DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
DateFormat.DEFAULT, Locales.getCurrent()).format(dateTime);
}
/**
* Format specific <code>date</code> using the {@link DateFormat#DEFAULT}
* format and showing only date without time.
*/
public static String formatDate(DateTime dateTime) {
if (dateTime == null) {
return "";
}
return formatDate(dateTime.toDate());
}
/**
* Format specific <code>date</code> using the {@link DateFormat#DEFAULT}
* format and showing only date without time.
*/
public static String formatDate(LocalDate date) {
if (date == null) {
return "";
}
return formatDate(date.toDateTimeAtStartOfDay());
}
/**
* Format specific <code>time</code> using the {@link DateFormat#SHORT}
* format and showing only the time.
*/
public static String formatTime(Date time) {
if (time == null) {
return "";
}
return DateFormat.getTimeInstance(DateFormat.SHORT,
Locales.getCurrent()).format(time);
}
/**
* Format specific <code>time</code> using the {@link DateFormat#SHORT}
* format and showing only the time.
*/
public static String formatTime(LocalTime time) {
if (time == null) {
return "";
}
return formatTime(time.toDateTimeToday().toDate());
}
} }

View file

@ -21,9 +21,9 @@
package org.libreplan.web.common.typeconverters; package org.libreplan.web.common.typeconverters;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.libreplan.web.common.Util;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.TypeConverter; import org.zkoss.zkplus.databind.TypeConverter;
@ -42,7 +42,6 @@ public class DateConverter implements TypeConverter {
@Override @Override
public Object coerceToUi(Object object, Component component) { public Object coerceToUi(Object object, Component component) {
return object != null ? (new SimpleDateFormat("dd/MM/yyyy")) return Util.formatDate((Date) object);
.format((Date) object) : new String("");
} }
} }

View file

@ -19,9 +19,9 @@
package org.libreplan.web.common.typeconverters; package org.libreplan.web.common.typeconverters;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.libreplan.web.common.Util;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.TypeConverter; import org.zkoss.zkplus.databind.TypeConverter;
@ -40,8 +40,7 @@ public class DateTimeConverter implements TypeConverter {
@Override @Override
public Object coerceToUi(Object object, Component component) { public Object coerceToUi(Object object, Component component) {
return object != null ? (new SimpleDateFormat("dd/MM/yyyy HH:mm")) return Util.formatDateTime((Date) object);
.format((Date) object) : new String("");
} }
} }

View file

@ -19,10 +19,8 @@
package org.libreplan.web.common.typeconverters; package org.libreplan.web.common.typeconverters;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.libreplan.web.common.Util;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.TypeConverter; import org.zkoss.zkplus.databind.TypeConverter;
@ -41,9 +39,6 @@ public class LocalDateConverter implements TypeConverter {
@Override @Override
public Object coerceToUi(Object object, Component component) { public Object coerceToUi(Object object, Component component) {
LocalDate localDate = (LocalDate) object; return Util.formatDate((LocalDate) object);
Date date = localDate != null ? localDate.toDateTimeAtStartOfDay().toDate() : null;
return date != null ? (new SimpleDateFormat("dd/MM/yyyy")).format(date)
: new String("");
} }
} }

View file

@ -22,8 +22,7 @@
package org.libreplan.web.common.typeconverters; package org.libreplan.web.common.typeconverters;
import org.joda.time.LocalTime; import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormat; import org.libreplan.web.common.Util;
import org.joda.time.format.DateTimeFormatter;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.TypeConverter; import org.zkoss.zkplus.databind.TypeConverter;
@ -42,7 +41,6 @@ public class TimeConverter implements TypeConverter {
@Override @Override
public Object coerceToUi(Object object, Component component) { public Object coerceToUi(Object object, Component component) {
DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm a"); return Util.formatTime((LocalTime) object);
return object != null ? fmt.print((LocalTime) object) : new String("");
} }
} }

View file

@ -23,7 +23,6 @@ package org.libreplan.web.limitingresources;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -47,6 +46,7 @@ import org.libreplan.business.planner.limiting.entities.LimitingResourceQueueEle
import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.resources.entities.Criterion;
import org.libreplan.business.resources.entities.LimitingResourceQueue; import org.libreplan.business.resources.entities.LimitingResourceQueue;
import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.Resource;
import org.libreplan.web.common.Util;
import org.libreplan.web.limitingresources.LimitingResourcesPanel.IToolbarCommand; import org.libreplan.web.limitingresources.LimitingResourcesPanel.IToolbarCommand;
import org.libreplan.web.planner.order.BankHolidaysMarker; import org.libreplan.web.planner.order.BankHolidaysMarker;
import org.libreplan.web.planner.taskedition.EditTaskController; import org.libreplan.web.planner.taskedition.EditTaskController;
@ -266,8 +266,6 @@ public class LimitingResourcesController extends GenericForwardComposer {
public static class LimitingResourceQueueElementDTO implements public static class LimitingResourceQueueElementDTO implements
Comparable<LimitingResourceQueueElementDTO> { Comparable<LimitingResourceQueueElementDTO> {
private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
private LimitingResourceQueueElement original; private LimitingResourceQueueElement original;
private String orderName; private String orderName;
@ -286,7 +284,7 @@ public class LimitingResourcesController extends GenericForwardComposer {
this.original = element; this.original = element;
this.orderName = orderName; this.orderName = orderName;
this.taskName = taskName; this.taskName = taskName;
this.date = DATE_FORMAT.format(date); this.date = Util.formatDate(date);
this.hoursToAllocate = element.getIntentedTotalHours(); this.hoursToAllocate = element.getIntentedTotalHours();
this.resourceOrCriteria = LimitingResourcesController this.resourceOrCriteria = LimitingResourcesController
.getResourceOrCriteria(element.getResourceAllocation()); .getResourceOrCriteria(element.getResourceAllocation());

View file

@ -31,10 +31,9 @@ import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.Period; import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.libreplan.business.planner.limiting.entities.LimitingResourceQueueElement; import org.libreplan.business.planner.limiting.entities.LimitingResourceQueueElement;
import org.libreplan.business.resources.entities.LimitingResourceQueue; import org.libreplan.business.resources.entities.LimitingResourceQueue;
import org.libreplan.web.common.Util;
import org.zkoss.ganttz.DependencyList; import org.zkoss.ganttz.DependencyList;
import org.zkoss.ganttz.timetracker.TimeTracker; import org.zkoss.ganttz.timetracker.TimeTracker;
import org.zkoss.ganttz.timetracker.TimeTracker.IDetailItemFilter; import org.zkoss.ganttz.timetracker.TimeTracker.IDetailItemFilter;
@ -618,7 +617,6 @@ public class LimitingResourcesPanel extends HtmlMacroComponent {
public void populateHorizontalListbox() { public void populateHorizontalListbox() {
horizontalPagination.getItems().clear(); horizontalPagination.getItems().clear();
DateTimeFormatter df = DateTimeFormat.forPattern("dd/MMM/yyyy");
DateTime intervalStart = timeTracker.getRealInterval().getStart() DateTime intervalStart = timeTracker.getRealInterval().getStart()
.toDateTimeAtStartOfDay(); .toDateTimeAtStartOfDay();
if (intervalStart != null) { if (intervalStart != null) {
@ -630,8 +628,8 @@ public class LimitingResourcesPanel extends HtmlMacroComponent {
.plus(intervalIncrease()))) { .plus(intervalIncrease()))) {
itemEnd = intervalEnd; itemEnd = intervalEnd;
} }
Listitem item = new Listitem(df.print(itemStart) + " - " Listitem item = new Listitem(Util.formatDate(itemStart)
+ df.print(itemEnd.minusDays(1))); + " - " + Util.formatDate(itemEnd.minusDays(1)));
horizontalPagination.appendChild(item); horizontalPagination.appendChild(item);
itemStart = itemEnd; itemStart = itemEnd;
itemEnd = itemEnd.plus(intervalIncrease()); itemEnd = itemEnd.plus(intervalIncrease());

View file

@ -489,7 +489,8 @@ public class ManualAllocationController extends GenericForwardComposer {
} }
private String formatTime(DateAndHour time) { private String formatTime(DateAndHour time) {
return time == null ? _("END") : time.getDate().toString("dd/MM/yyyy") + " - " + time.getHour(); return time == null ? _("END") : Util.formatDate(time.getDate())
+ " - " + time.getHour();
} }
} }

View file

@ -23,7 +23,6 @@ package org.libreplan.web.orders;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.text.SimpleDateFormat;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -73,7 +72,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
@ -1209,7 +1207,7 @@ public class OrderCRUDController extends GenericForwardComposer {
private void appendDate(final Row row, Date date) { private void appendDate(final Row row, Date date) {
String labelDate = new String(""); String labelDate = new String("");
if (date != null) { if (date != null) {
labelDate = new SimpleDateFormat("dd/MM/yyyy").format(date); labelDate = Util.formatDate(date);
} }
appendLabel(row, labelDate); appendLabel(row, labelDate);
} }
@ -1617,19 +1615,13 @@ public class OrderCRUDController extends GenericForwardComposer {
EndDateCommunication endDate = (EndDateCommunication) data; EndDateCommunication endDate = (EndDateCommunication) data;
row.setValue(endDate); row.setValue(endDate);
appendLabel(row, toString(endDate.getSaveDate(), "dd/MM/yyyy HH:mm")); appendLabel(row, Util.formatDateTime(endDate.getSaveDate()));
appendLabel(row, toString(endDate.getEndDate(), "dd/MM/yyyy")); appendLabel(row, Util.formatDate(endDate.getEndDate()));
appendLabel(row, toString(endDate.getCommunicationDate(), "dd/MM/yyyy HH:mm")); appendLabel(row,
Util.formatDateTime(endDate.getCommunicationDate()));
appendOperations(row, endDate); appendOperations(row, endDate);
} }
private String toString(Date date, String precision) {
if (date == null) {
return "";
}
return new SimpleDateFormat(precision, Locales.getCurrent()).format(date);
}
private void appendLabel(Row row, String label) { private void appendLabel(Row row, String label) {
row.appendChild(new Label(label)); row.appendChild(new Label(label));
} }

View file

@ -41,8 +41,6 @@ import org.apache.commons.lang.Validate;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.Period; import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.libreplan.business.planner.entities.AggregateOfResourceAllocations; import org.libreplan.business.planner.entities.AggregateOfResourceAllocations;
import org.libreplan.business.planner.entities.AssignmentFunction; import org.libreplan.business.planner.entities.AssignmentFunction;
import org.libreplan.business.planner.entities.AssignmentFunction.AssignmentFunctionName; import org.libreplan.business.planner.entities.AssignmentFunction.AssignmentFunctionName;
@ -459,7 +457,6 @@ public class AdvancedAllocationController extends GenericForwardComposer {
public void populateHorizontalListbox() { public void populateHorizontalListbox() {
advancedAllocationHorizontalPagination.getItems().clear(); advancedAllocationHorizontalPagination.getItems().clear();
DateTimeFormatter df = DateTimeFormat.forPattern("dd/MMM/yyyy");
if (intervalStart != null) { if (intervalStart != null) {
DateTime itemStart = intervalStart; DateTime itemStart = intervalStart;
DateTime itemEnd = intervalStart.plus(intervalIncrease()); DateTime itemEnd = intervalStart.plus(intervalIncrease());
@ -469,8 +466,8 @@ public class AdvancedAllocationController extends GenericForwardComposer {
.plus(intervalIncrease()))) { .plus(intervalIncrease()))) {
itemEnd = intervalEnd; itemEnd = intervalEnd;
} }
Listitem item = new Listitem(df.print(itemStart) + " - " Listitem item = new Listitem(Util.formatDate(itemStart)
+ df.print(itemEnd.minusDays(1))); + " - " + Util.formatDate(itemEnd.minusDays(1)));
advancedAllocationHorizontalPagination.appendChild(item); advancedAllocationHorizontalPagination.appendChild(item);
itemStart = itemEnd; itemStart = itemEnd;
itemEnd = itemEnd.plus(intervalIncrease()); itemEnd = itemEnd.plus(intervalIncrease());

View file

@ -23,7 +23,6 @@ package org.libreplan.web.planner.order;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
@ -180,16 +179,12 @@ public class SubcontractController extends GenericForwardComposer {
SubcontractorDeliverDate subcontractorDeliverDate = (SubcontractorDeliverDate) data; SubcontractorDeliverDate subcontractorDeliverDate = (SubcontractorDeliverDate) data;
row.setValue(subcontractorDeliverDate); row.setValue(subcontractorDeliverDate);
appendLabel(row, SubcontractController.this.toString( appendLabel(row,
subcontractorDeliverDate.getSaveDate(), "dd/MM/yyyy HH:mm")); Util.formatDateTime(subcontractorDeliverDate.getSaveDate()));
appendLabel( appendLabel(row, Util.formatDate(subcontractorDeliverDate
row, .getSubcontractorDeliverDate()));
SubcontractController.this.toString( appendLabel(row, Util.formatDateTime(subcontractorDeliverDate
subcontractorDeliverDate.getSubcontractorDeliverDate(), "dd/MM/yyyy")); .getCommunicationDate()));
appendLabel(
row,
SubcontractController.this.toString(
subcontractorDeliverDate.getCommunicationDate(), "dd/MM/yyyy HH:mm"));
appendOperations(row, subcontractorDeliverDate); appendOperations(row, subcontractorDeliverDate);
} }
@ -252,13 +247,6 @@ public class SubcontractController extends GenericForwardComposer {
return false; return false;
} }
public String toString(Date date, String precision) {
if (date == null) {
return "";
}
return new SimpleDateFormat(precision).format(date);
}
public SortedSet<EndDateCommunication> getAskedEndDates() { public SortedSet<EndDateCommunication> getAskedEndDates() {
return subcontractModel.getAskedEndDates(); return subcontractModel.getAskedEndDates();
} }
@ -274,11 +262,10 @@ public class SubcontractController extends GenericForwardComposer {
EndDateCommunication endDateFromSubcontractor = (EndDateCommunication) data; EndDateCommunication endDateFromSubcontractor = (EndDateCommunication) data;
row.setValue(endDateFromSubcontractor); row.setValue(endDateFromSubcontractor);
appendLabel(row, SubcontractController.this.toString(
endDateFromSubcontractor.getEndDate(), "dd/MM/yyyy"));
appendLabel(row, appendLabel(row,
SubcontractController.this.toString( Util.formatDate(endDateFromSubcontractor.getEndDate()));
endDateFromSubcontractor.getCommunicationDate(), "dd/MM/yyyy HH:mm")); appendLabel(row, Util.formatDateTime(endDateFromSubcontractor
.getCommunicationDate()));
appendOperations(row, endDateFromSubcontractor); appendOperations(row, endDateFromSubcontractor);
} }

View file

@ -21,8 +21,6 @@ package org.libreplan.web.subcontract;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -34,8 +32,8 @@ import org.libreplan.business.externalcompanies.entities.CustomerCommunication;
import org.libreplan.business.orders.entities.Order; import org.libreplan.business.orders.entities.Order;
import org.libreplan.web.common.IMessagesForUser; import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.MessagesForUser; import org.libreplan.web.common.MessagesForUser;
import org.libreplan.web.common.Util;
import org.libreplan.web.planner.tabs.IGlobalViewEntryPoints; import org.libreplan.web.planner.tabs.IGlobalViewEntryPoints;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
@ -141,25 +139,16 @@ public class CustomerCommunicationCRUDController extends GenericForwardComposer
appendLabel(row, toString(type)); appendLabel(row, toString(type));
appendLabel(row, customerCommunication.getOrder().getName()); appendLabel(row, customerCommunication.getOrder().getName());
appendLabel(row, appendLabel(row,
toString(customerCommunication.getDeadline(), "dd/MM/yyyy")); Util.formatDate(customerCommunication.getDeadline()));
appendLabel(row, customerCommunication.getOrder().getCode()); appendLabel(row, customerCommunication.getOrder().getCode());
appendLabel(row, customerCommunication.getOrder() appendLabel(row, customerCommunication.getOrder()
.getCustomerReference()); .getCustomerReference());
appendLabel(row, appendLabel(row, Util.formatDateTime(customerCommunication
toString(customerCommunication.getCommunicationDate(), .getCommunicationDate()));
"dd/MM/yyyy HH:mm"));
appendCheckbox(row, customerCommunication); appendCheckbox(row, customerCommunication);
appendOperations(row, customerCommunication); appendOperations(row, customerCommunication);
} }
private String toString(Date date, String precision) {
if (date == null) {
return "";
}
return new SimpleDateFormat(precision, Locales.getCurrent())
.format(date);
}
private String toString(Object object) { private String toString(Object object) {
if (object == null) { if (object == null) {
return ""; return "";

View file

@ -25,8 +25,6 @@ package org.libreplan.web.subcontract;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -57,7 +55,6 @@ import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button; import org.zkoss.zul.Button;
import org.zkoss.zul.Column; import org.zkoss.zul.Column;
import org.zkoss.zul.Grid; import org.zkoss.zul.Grid;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Label; import org.zkoss.zul.Label;
import org.zkoss.zul.ListModelExt; import org.zkoss.zul.ListModelExt;
import org.zkoss.zul.Row; import org.zkoss.zul.Row;
@ -113,12 +110,10 @@ public class SubcontractedTasksController extends GenericForwardComposer {
Order order = getOrder(subcontractedTaskData); Order order = getOrder(subcontractedTaskData);
appendLabel(row, appendLabel(row, Util.formatDateTime(subcontractedTaskData
toString(subcontractedTaskData.getSubcontratationDate(), "dd/MM/yyyy HH:mm")); .getSubcontratationDate()));
appendLabel( appendLabel(row, Util.formatDateTime(subcontractedTaskData
row, .getSubcontractCommunicationDate()));
toString(subcontractedTaskData.getSubcontractCommunicationDate(),
"dd/MM/yyyy HH:mm"));
appendLabel(row, getExternalCompany(subcontractedTaskData)); appendLabel(row, getExternalCompany(subcontractedTaskData));
appendLabel(row, getOrderCode(order)); appendLabel(row, getOrderCode(order));
appendLabel(row, getOrderName(order)); appendLabel(row, getOrderName(order));
@ -126,8 +121,8 @@ public class SubcontractedTasksController extends GenericForwardComposer {
appendLabel(row, getTaskName(subcontractedTaskData)); appendLabel(row, getTaskName(subcontractedTaskData));
row.setTooltiptext(subcontractedTaskData.getWorkDescription()); row.setTooltiptext(subcontractedTaskData.getWorkDescription());
appendLabel(row, Util.addCurrencySymbol(subcontractedTaskData.getSubcontractPrice())); appendLabel(row, Util.addCurrencySymbol(subcontractedTaskData.getSubcontractPrice()));
appendLabel(row, appendLabel(row, Util.formatDate(subcontractedTaskData
toString(subcontractedTaskData.getLastRequiredDeliverDate(), "dd/MM/yyyy")); .getLastRequiredDeliverDate()));
appendLabel(row, _(toString(subcontractedTaskData.getState()))); appendLabel(row, _(toString(subcontractedTaskData.getState())));
appendOperations(row, subcontractedTaskData); appendOperations(row, subcontractedTaskData);
} }
@ -152,13 +147,6 @@ public class SubcontractedTasksController extends GenericForwardComposer {
return object.toString(); return object.toString();
} }
private String toString(Date date, String precision) {
if (date == null) {
return "";
}
return new SimpleDateFormat(precision).format(date);
}
private void appendLabel(Row row, String label) { private void appendLabel(Row row, String label) {
row.appendChild(new Label(label)); row.appendChild(new Label(label));
} }

View file

@ -21,8 +21,6 @@ package org.libreplan.web.subcontract;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -38,6 +36,7 @@ import org.libreplan.business.planner.entities.SubcontractorCommunicationValue;
import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.planner.entities.TaskElement;
import org.libreplan.web.common.IMessagesForUser; import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.MessagesForUser; import org.libreplan.web.common.MessagesForUser;
import org.libreplan.web.common.Util;
import org.libreplan.web.planner.tabs.IGlobalViewEntryPoints; import org.libreplan.web.planner.tabs.IGlobalViewEntryPoints;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
@ -158,20 +157,13 @@ public class SubcontractorCommunicationCRUDController extends GenericForwardComp
appendLabel(row, getOrderName(subcontractorCommunication.getSubcontractedTaskData())); appendLabel(row, getOrderName(subcontractorCommunication.getSubcontractedTaskData()));
appendLabel(row, getOrderCode(subcontractorCommunication.getSubcontractedTaskData())); appendLabel(row, getOrderCode(subcontractorCommunication.getSubcontractedTaskData()));
appendLabel(row, subcontractorCommunication.getSubcontractedTaskData().getExternalCompany().getName()); appendLabel(row, subcontractorCommunication.getSubcontractedTaskData().getExternalCompany().getName());
appendLabel(row, toString(subcontractorCommunication.getCommunicationDate())); appendLabel(row, Util.formatDateTime(subcontractorCommunication
.getCommunicationDate()));
appendLabelWithTooltip(row, subcontractorCommunication); appendLabelWithTooltip(row, subcontractorCommunication);
appendCheckbox(row, subcontractorCommunication); appendCheckbox(row, subcontractorCommunication);
appendOperations(row, subcontractorCommunication); appendOperations(row, subcontractorCommunication);
} }
private String toString(Date date) {
if (date == null) {
return "";
}
return new SimpleDateFormat("dd/MM/yyyy HH:mm").format(date);
}
private String getOrderCode(SubcontractedTaskData subcontractedTaskData) { private String getOrderCode(SubcontractedTaskData subcontractedTaskData) {
return subcontractorCommunicationModel.getOrderCode(subcontractedTaskData); return subcontractorCommunicationModel.getOrderCode(subcontractedTaskData);
} }