Switch IDatesMapper to use types based on joda time instead of dates
FEA: ItEr61S08TimeUnitConfigurablePlanning
This commit is contained in:
parent
369dd74e41
commit
0bea855f98
7 changed files with 91 additions and 72 deletions
|
|
@ -23,10 +23,11 @@
|
|||
*/
|
||||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.math.Fraction;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.ReadableDuration;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
public class DatesMapperOnInterval implements IDatesMapper {
|
||||
|
|
@ -45,38 +46,46 @@ public class DatesMapperOnInterval implements IDatesMapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date toDate(int pixels) {
|
||||
public LocalDate toDate(int pixels) {
|
||||
int daysInto = Fraction.getFraction(pixels, 1).divideBy(pixelsPerDay)
|
||||
.intValue();
|
||||
return interval.getStart().plusDays(daysInto).toDateTimeAtStartOfDay()
|
||||
.toDate();
|
||||
return interval.getStart().plusDays(daysInto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toPixels(Date date) {
|
||||
Fraction proportion = interval.getProportion(new DateTime(date
|
||||
.getTime()));
|
||||
public int toPixels(LocalDate date) {
|
||||
return toPixels(getProportion(date));
|
||||
}
|
||||
|
||||
private Fraction getProportion(LocalDate date) {
|
||||
return getProportion(date.toDateTimeAtStartOfDay());
|
||||
}
|
||||
|
||||
private Fraction getProportion(DateTime dateTime) {
|
||||
return interval.getProportion(dateTime);
|
||||
}
|
||||
|
||||
private int toPixels(Fraction proportion) {
|
||||
return proportion.multiplyBy(Fraction.getFraction(horizontalSize, 1))
|
||||
.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toPixels(long milliseconds) {
|
||||
Date date = new Date(interval.getStart().toDateTimeAtStartOfDay()
|
||||
.getMillis()
|
||||
+ milliseconds);
|
||||
return this.toPixels(date);
|
||||
public int toPixels(ReadableDuration duration) {
|
||||
DateTime end = interval.getStart().toDateTimeAtStartOfDay()
|
||||
.plus(duration);
|
||||
return toPixels(getProportion(end));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toPixelsAbsolute(long milliseconds) {
|
||||
Date date = new Date(milliseconds);
|
||||
return this.toPixels(date);
|
||||
DateTime date = new DateTime(milliseconds);
|
||||
return this.toPixels(getProportion(date));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long toMilliseconds(int pixels) {
|
||||
return millisecondsPerPixel * pixels;
|
||||
public ReadableDuration toDuration(int pixels) {
|
||||
return new Duration(millisecondsPerPixel * pixels);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -20,19 +20,20 @@
|
|||
|
||||
package org.zkoss.ganttz;
|
||||
|
||||
import java.util.Date;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.ReadableDuration;
|
||||
|
||||
public interface IDatesMapper {
|
||||
|
||||
final long MILISECONDS_PER_HOUR = 3600000;
|
||||
|
||||
int toPixels(Date date);
|
||||
int toPixels(LocalDate date);
|
||||
|
||||
Date toDate(int pixel);
|
||||
LocalDate toDate(int pixel);
|
||||
|
||||
int toPixels(long milliseconds);
|
||||
int toPixels(ReadableDuration duration);
|
||||
|
||||
long toMilliseconds(int pixels);
|
||||
ReadableDuration toDuration(int pixels);
|
||||
|
||||
int toPixelsAbsolute(long milliseconds);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ import java.util.regex.Pattern;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
|
||||
import org.zkoss.ganttz.data.Milestone;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
|
|
@ -338,7 +341,8 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
|
||||
void doUpdatePosition(String leftX, String topY) {
|
||||
Date startBeforeMoving = this.task.getBeginDate();
|
||||
this.task.moveTo(getMapper().toDate(stripPx(leftX)));
|
||||
LocalDate newPosition = getMapper().toDate(stripPx(leftX));
|
||||
this.task.moveTo(newPosition.toDateTimeAtStartOfDay().toDate());
|
||||
boolean remainsInOriginalPosition = this.task.getBeginDate().equals(
|
||||
startBeforeMoving);
|
||||
if (remainsInOriginalPosition) {
|
||||
|
|
@ -348,8 +352,9 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
|
||||
void doUpdateSize(String size) {
|
||||
int pixels = stripPx(size);
|
||||
this.task.setEndDate(new Date(this.task.getBeginDate().getTime()
|
||||
+ getMapper().toMilliseconds(pixels)));
|
||||
DateTime end = new DateTime(this.task.getBeginDate().getTime())
|
||||
.plus(getMapper().toDuration(pixels));
|
||||
this.task.setEndDate(end.toDate());
|
||||
updateWidth();
|
||||
}
|
||||
|
||||
|
|
@ -422,7 +427,8 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
return;
|
||||
}
|
||||
setLeft("0");
|
||||
setLeft(getMapper().toPixels(this.task.getBeginDate()) + "px");
|
||||
setLeft(getMapper().toPixels(this.task.getBeginDateAsLocalDate())
|
||||
+ "px");
|
||||
updateWidth();
|
||||
smartUpdate("name", this.task.getName());
|
||||
DependencyList dependencyList = getDependencyList();
|
||||
|
|
@ -436,13 +442,14 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
|
||||
private void updateWidth() {
|
||||
setWidth("0");
|
||||
setWidth(getMapper().toPixels(this.task.getLengthMilliseconds())
|
||||
+ "px");
|
||||
setWidth(getMapper().toPixels(this.task.getLength()) + "px");
|
||||
}
|
||||
|
||||
private void updateDeadline() {
|
||||
if (task.getDeadline() != null) {
|
||||
String position = getMapper().toPixels(task.getDeadline()) + "px";
|
||||
String position = getMapper().toPixels(
|
||||
LocalDate.fromDateFields(task.getDeadline()))
|
||||
+ "px";
|
||||
response(null, new AuInvoke(this, "moveDeadline", position));
|
||||
} else {
|
||||
// Move deadline out of visible area
|
||||
|
|
@ -450,8 +457,10 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
}
|
||||
|
||||
if (task.getConsolidatedline() != null) {
|
||||
String position = (getMapper().toPixels(task.getConsolidatedline()) - CONSOLIDATED_MARK_HALF_WIDTH)
|
||||
+ "px";
|
||||
int pixels = getMapper().toPixels(
|
||||
LocalDate.fromDateFields(task.getConsolidatedline()))
|
||||
- CONSOLIDATED_MARK_HALF_WIDTH;
|
||||
String position = pixels + "px";
|
||||
response(null, new AuInvoke(this, "moveConsolidatedline", position));
|
||||
} else {
|
||||
// Move consolidated line out of visible area
|
||||
|
|
@ -471,33 +480,27 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
}
|
||||
|
||||
private void updateCompletion() {
|
||||
long beginMilliseconds = this.task.getBeginDate().getTime();
|
||||
|
||||
long hoursAdvanceEndMilliseconds = this.task.getHoursAdvanceEndDate()
|
||||
.getTime()
|
||||
- beginMilliseconds;
|
||||
if (hoursAdvanceEndMilliseconds < 0) {
|
||||
hoursAdvanceEndMilliseconds = 0;
|
||||
}
|
||||
String widthHoursAdvancePercentage = getMapper().toPixels(
|
||||
hoursAdvanceEndMilliseconds)
|
||||
fromStartUntil(this.task.getHoursAdvanceEndDate()))
|
||||
+ "px";
|
||||
response(null, new AuInvoke(this, "resizeCompletionAdvance",
|
||||
widthHoursAdvancePercentage));
|
||||
|
||||
long advanceEndMilliseconds = this.task.getAdvanceEndDate()
|
||||
.getTime()
|
||||
- beginMilliseconds;
|
||||
if (advanceEndMilliseconds < 0) {
|
||||
advanceEndMilliseconds = 0;
|
||||
}
|
||||
String widthAdvancePercentage = getMapper().toPixels(
|
||||
advanceEndMilliseconds)
|
||||
fromStartUntil(this.task.getHoursAdvanceEndDate()))
|
||||
+ "px";
|
||||
response(null, new AuInvoke(this, "resizeCompletion2Advance",
|
||||
widthAdvancePercentage));
|
||||
}
|
||||
|
||||
private Duration fromStartUntil(Date until) {
|
||||
DateTime start = new DateTime(this.task.getBeginDate().getTime());
|
||||
DateTime end = new DateTime(until.getTime());
|
||||
Duration duration = end.isAfter(start) ? new Duration(start, end)
|
||||
: Duration.ZERO;
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void updateTooltipText() {
|
||||
smartUpdate("taskTooltipText", task.updateTooltipText());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.ReadableDuration;
|
||||
import org.zkoss.ganttz.data.GanttDiagramGraph.IDependenciesEnforcerHook;
|
||||
import org.zkoss.ganttz.data.GanttDiagramGraph.IDependenciesEnforcerHookFactory;
|
||||
import org.zkoss.ganttz.data.GanttDiagramGraph.INotificationAfterDependenciesEnforcement;
|
||||
|
|
@ -185,6 +188,10 @@ public abstract class Task implements ITaskFundamentalProperties {
|
|||
return getEndDate().getTime() - getBeginDate().getTime();
|
||||
}
|
||||
|
||||
public ReadableDuration getLength() {
|
||||
return new Duration(getBeginDate().getTime(), getEndDate().getTime());
|
||||
}
|
||||
|
||||
public void addVisibilityPropertiesChangeListener(
|
||||
PropertyChangeListener listener) {
|
||||
this.visibilityProperties.addPropertyChangeListener(listener);
|
||||
|
|
@ -371,4 +378,8 @@ public abstract class Task implements ITaskFundamentalProperties {
|
|||
return fundamentalProperties.isFixed();
|
||||
}
|
||||
|
||||
public LocalDate getBeginDateAsLocalDate() {
|
||||
return LocalDate.fromDateFields(getBeginDate());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.zkoss.ganttz.IDatesMapper;
|
||||
import org.zkoss.ganttz.data.resourceload.LoadPeriod;
|
||||
|
|
@ -35,8 +36,8 @@ import org.zkoss.ganttz.timetracker.TimeTracker;
|
|||
import org.zkoss.ganttz.timetracker.zoom.IZoomLevelChangedListener;
|
||||
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
|
||||
import org.zkoss.ganttz.util.MenuBuilder;
|
||||
import org.zkoss.ganttz.util.WeakReferencedListeners;
|
||||
import org.zkoss.ganttz.util.MenuBuilder.ItemAction;
|
||||
import org.zkoss.ganttz.util.WeakReferencedListeners;
|
||||
import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
|
@ -197,12 +198,8 @@ public class ResourceLoadComponent extends XulElement {
|
|||
LoadPeriod loadPeriod) {
|
||||
LocalDate start = loadPeriod.getStart();
|
||||
LocalDate end = loadPeriod.getEnd();
|
||||
return datesMapper
|
||||
.toPixels(toMilliseconds(end) - toMilliseconds(start));
|
||||
}
|
||||
|
||||
private static long toMilliseconds(LocalDate localDate) {
|
||||
return localDate.toDateMidnight().getMillis();
|
||||
return datesMapper.toPixels(new Duration(
|
||||
start.toDateTimeAtStartOfDay(), end.toDateTimeAtStartOfDay()));
|
||||
}
|
||||
|
||||
private static String forCSS(int pixels) {
|
||||
|
|
@ -211,8 +208,7 @@ public class ResourceLoadComponent extends XulElement {
|
|||
|
||||
private static int getStartPixels(IDatesMapper datesMapper,
|
||||
LoadPeriod loadPeriod) {
|
||||
return datesMapper.toPixels(loadPeriod.getStart().toDateMidnight()
|
||||
.toDate());
|
||||
return datesMapper.toPixels(loadPeriod.getStart());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,8 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
|
|
@ -150,6 +152,14 @@ public class LimitingResourceQueueElement extends BaseEntity {
|
|||
notifyQueueElementIsMoved();
|
||||
}
|
||||
|
||||
public Duration getLengthBetween() {
|
||||
DateTime start = getStartDate().toDateTimeAtStartOfDay().plusHours(
|
||||
getStartHour());
|
||||
DateTime end = getEndDate().toDateTimeAtStartOfDay().plusHours(
|
||||
getEndHour());
|
||||
return new Duration(start, end);
|
||||
}
|
||||
|
||||
public Date getEarlierStartDateBecauseOfGantt() {
|
||||
return earlierStartDateBecauseOfGantt;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.Set;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
|
@ -321,11 +322,11 @@ public class QueueComponent extends XulElement implements
|
|||
if (advancementEndDate == null) {
|
||||
return null;
|
||||
}
|
||||
long millis = (advancementEndDate.toDateTime().getMillis() - queueElement
|
||||
.getStartTime().toDateTime().getMillis());
|
||||
Duration durationBetween = new Duration(queueElement.getStartTime()
|
||||
.toDateTime().getMillis(), advancementEndDate.toDateTime().getMillis());
|
||||
Div progressBar = new Div();
|
||||
if (!queueElement.getStartDate().isEqual(advancementEndDate.getDate())) {
|
||||
progressBar.setWidth(datesMapper.toPixels(millis) + "px");
|
||||
progressBar.setWidth(datesMapper.toPixels(durationBetween) + "px");
|
||||
progressBar.setSclass("queue-progress-bar");
|
||||
}
|
||||
return progressBar;
|
||||
|
|
@ -390,13 +391,7 @@ public class QueueComponent extends XulElement implements
|
|||
|
||||
private static int getWidthPixels(IDatesMapper datesMapper,
|
||||
LimitingResourceQueueElement queueElement) {
|
||||
return datesMapper.toPixels(getEndMillis(queueElement)
|
||||
- getStartMillis(queueElement));
|
||||
}
|
||||
|
||||
private static long getStartMillis(LimitingResourceQueueElement queueElement) {
|
||||
return queueElement.getStartDate().toDateMidnight().getMillis()
|
||||
+ (queueElement.getStartHour() * DatesMapperOnInterval.MILISECONDS_PER_HOUR);
|
||||
return datesMapper.toPixels(queueElement.getLengthBetween());
|
||||
}
|
||||
|
||||
private static int getDeadlinePixels(IDatesMapper datesMapper,
|
||||
|
|
@ -406,12 +401,6 @@ public class QueueComponent extends XulElement implements
|
|||
.toDateMidnight().getMillis());
|
||||
}
|
||||
|
||||
|
||||
private static long getEndMillis(LimitingResourceQueueElement queueElement) {
|
||||
return queueElement.getEndDate().toDateMidnight().getMillis()
|
||||
+ (queueElement.getEndHour() * DatesMapperOnInterval.MILISECONDS_PER_HOUR);
|
||||
}
|
||||
|
||||
private static String forCSS(int pixels) {
|
||||
return String.format("%dpx", pixels);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue