getAdvance methods on ITaskFundamentalProperties return GanttDates instead of dates
This is needed to allow more precision when showing advance dates. FEA: ItEr62S05BugFixing
This commit is contained in:
parent
637a6a8bda
commit
a6712ebcf7
5 changed files with 39 additions and 43 deletions
|
|
@ -22,7 +22,6 @@ package org.zkoss.ganttz;
|
|||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
@ -32,7 +31,6 @@ 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.GanttDate;
|
||||
|
|
@ -485,26 +483,23 @@ public class TaskComponent extends Div implements AfterCompose {
|
|||
}
|
||||
|
||||
private void updateCompletion() {
|
||||
String widthHoursAdvancePercentage = getMapper().toPixels(
|
||||
fromStartUntil(this.task.getHoursAdvanceEndDate()))
|
||||
+ "px";
|
||||
int startPixels = this.task.getBeginDate().toPixels(getMapper());
|
||||
|
||||
String widthHoursAdvancePercentage = pixelsFromStartUntil(startPixels,
|
||||
this.task.getHoursAdvanceEndDate()) + "px";
|
||||
response(null, new AuInvoke(this, "resizeCompletionAdvance",
|
||||
widthHoursAdvancePercentage));
|
||||
|
||||
String widthAdvancePercentage = getMapper().toPixels(
|
||||
fromStartUntil(this.task.getAdvanceEndDate()))
|
||||
+ "px";
|
||||
String widthAdvancePercentage = pixelsFromStartUntil(startPixels,
|
||||
this.task.getAdvanceEndDate()) + "px";
|
||||
response(null, new AuInvoke(this, "resizeCompletion2Advance",
|
||||
widthAdvancePercentage));
|
||||
}
|
||||
|
||||
private Duration fromStartUntil(Date until) {
|
||||
DateTime start = new DateTime(this.task.getBeginDate()
|
||||
.toDayRoundedDate().getTime());
|
||||
DateTime end = new DateTime(until.getTime());
|
||||
Duration duration = end.isAfter(start) ? new Duration(start, end)
|
||||
: Duration.ZERO;
|
||||
return duration;
|
||||
private int pixelsFromStartUntil(int startPixels, GanttDate until) {
|
||||
int endPixels = until.toPixels(getMapper());
|
||||
assert endPixels >= startPixels;
|
||||
return endPixels - startPixels;
|
||||
}
|
||||
|
||||
public void updateTooltipText() {
|
||||
|
|
|
|||
|
|
@ -142,13 +142,14 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date getHoursAdvanceEndDate() {
|
||||
return new Date(hoursAdvanceEndDate);
|
||||
public GanttDate getHoursAdvanceEndDate() {
|
||||
return GanttDate.createFrom(new Date(hoursAdvanceEndDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getAdvanceEndDate() {
|
||||
return advanceEndDate != null ? new Date(advanceEndDate.getTime())
|
||||
public GanttDate getAdvanceEndDate() {
|
||||
return advanceEndDate != null ? GanttDate.createFrom(new Date(
|
||||
advanceEndDate.getTime()))
|
||||
: null;
|
||||
}
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ public interface ITaskFundamentalProperties {
|
|||
|
||||
public void setNotes(String notes);
|
||||
|
||||
public Date getHoursAdvanceEndDate();
|
||||
public GanttDate getHoursAdvanceEndDate();
|
||||
|
||||
public Date getAdvanceEndDate();
|
||||
public GanttDate getAdvanceEndDate();
|
||||
|
||||
public BigDecimal getHoursAdvancePercentage();
|
||||
|
||||
|
|
|
|||
|
|
@ -275,12 +275,12 @@ public abstract class Task implements ITaskFundamentalProperties {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date getHoursAdvanceEndDate() {
|
||||
public GanttDate getHoursAdvanceEndDate() {
|
||||
return fundamentalProperties.getHoursAdvanceEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getAdvanceEndDate() {
|
||||
public GanttDate getAdvanceEndDate() {
|
||||
return fundamentalProperties.getAdvanceEndDate();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date getHoursAdvanceEndDate() {
|
||||
public GanttDate getHoursAdvanceEndDate() {
|
||||
OrderElement orderElement = taskElement.getOrderElement();
|
||||
|
||||
Integer assignedHours = 0;
|
||||
|
|
@ -382,24 +382,24 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
.getTotalChargedHours();
|
||||
}
|
||||
|
||||
LocalDate date = null;
|
||||
GanttDate result = null;
|
||||
if(!(taskElement instanceof TaskGroup)) {
|
||||
date = calculateLimitDate(assignedHours);
|
||||
result = calculateLimitDate(assignedHours);
|
||||
}
|
||||
if (date == null) {
|
||||
if (result == null) {
|
||||
Integer hours = taskElement.getSumOfHoursAllocated();
|
||||
|
||||
if (hours == 0) {
|
||||
return getBeginDate().toDayRoundedDate();
|
||||
return getBeginDate();
|
||||
} else {
|
||||
BigDecimal percentage = new BigDecimal(assignedHours)
|
||||
.setScale(2).divide(new BigDecimal(hours),
|
||||
RoundingMode.DOWN);
|
||||
date = calculateLimitDate(percentage);
|
||||
result = calculateLimitDate(percentage);
|
||||
}
|
||||
}
|
||||
|
||||
return date.toDateTimeAtStartOfDay().toDate();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -423,7 +423,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Date getAdvanceEndDate() {
|
||||
public GanttDate getAdvanceEndDate() {
|
||||
OrderElement orderElement = taskElement.getOrderElement();
|
||||
|
||||
BigDecimal advancePercentage;
|
||||
|
|
@ -439,29 +439,29 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
Integer advanceHours = advancePercentage.multiply(
|
||||
new BigDecimal(hours)).intValue();
|
||||
|
||||
LocalDate date;
|
||||
GanttDate result;
|
||||
if(taskElement instanceof TaskGroup) {
|
||||
date = calculateLimitDate(advancePercentage);
|
||||
result = calculateLimitDate(advancePercentage);
|
||||
}
|
||||
else {
|
||||
date = calculateLimitDate(advanceHours);
|
||||
if (date == null) {
|
||||
date = calculateLimitDate(advancePercentage);
|
||||
result = calculateLimitDate(advanceHours);
|
||||
if (result == null) {
|
||||
result = calculateLimitDate(advancePercentage);
|
||||
}
|
||||
}
|
||||
|
||||
return date.toDateTimeAtStartOfDay().toDate();
|
||||
return result;
|
||||
}
|
||||
|
||||
private LocalDate calculateLimitDate(BigDecimal advancePercentage) {
|
||||
private GanttDate calculateLimitDate(BigDecimal advancePercentage) {
|
||||
if (advancePercentage.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return new LocalDate(getBeginDate().toDayRoundedDate());
|
||||
return getBeginDate();
|
||||
}
|
||||
Long totalMillis = taskElement.getLengthMilliseconds();
|
||||
Long advanceMillis = advancePercentage.multiply(
|
||||
new BigDecimal(totalMillis)).longValue();
|
||||
return new LocalDate(getBeginDate().toDayRoundedDate().getTime()
|
||||
+ advanceMillis).plusDays(1);
|
||||
return GanttDate.createFrom(new LocalDate(getBeginDate()
|
||||
.toDayRoundedDate().getTime() + advanceMillis).plusDays(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -472,7 +472,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
return new BigDecimal(0);
|
||||
}
|
||||
|
||||
private LocalDate calculateLimitDate(Integer hours) {
|
||||
private GanttDate calculateLimitDate(Integer hours) {
|
||||
if (hours == null || hours == 0) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -508,7 +508,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
return lastDay.plusDays(1);
|
||||
return GanttDate.createFrom(lastDay.plusDays(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue