Skip to content

Commit

Permalink
Merge pull request #2406 from bardsoftware/tkt-2402-earliest-start
Browse files Browse the repository at this point in the history
Make earliest start field working in the task properties dialog
  • Loading branch information
dbarashev authored Feb 5, 2024
2 parents 2bd33b1 + 4628db4 commit c47b316
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private int getLength() {
}

private GanttCalendar getThird() {
return myThird;
return getThirdDateConstraint() == 1 ? myThird : null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public interface MutableTask {

void setCompletionPercentage(int percentage);

// void setStartFixed(boolean isFixed);

// void setFinishFixed(boolean isFixed);

void setShape(ShapePaint shape);

void setColor(Color color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,15 @@ public void setEnd(GanttCalendar end) {

@Override
public void setThirdDate(GanttCalendar third) {
Date closestWorkingStart = myManager.findClosestWorkingTime(third.getTime());
third.setTime(closestWorkingStart);
myThird = third;
if (third == null) {
myThird = null;
myThirdDateConstraint = 0;
} else {
Date closestWorkingStart = myManager.findClosestWorkingTime(third.getTime());
third.setTime(closestWorkingStart);
myThird = third;
myThirdDateConstraint = 1;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ internal class MutatorReentered(taskImpl: TaskImpl, private val delegate: Mutato
}
}

data class EarliestStartValue(val startDate: GanttCalendar?, val isEnabled: Boolean)

internal open class MutatorImpl(
private val myManager: TaskManagerImpl,
taskImpl: TaskImpl,
Expand All @@ -173,7 +175,7 @@ internal open class MutatorImpl(

private val myStartChange = FieldChange(myPropertiesEventSender, taskImpl.start)
private val myEndChange: FieldChange<GanttCalendar?> = FieldChange(myPropertiesEventSender, taskImpl.myEnd)
private val myThirdChange: FieldChange<GanttCalendar?> = FieldChange(myPropertiesEventSender, taskImpl.myThird)
private val myThirdChange: FieldChange<EarliestStartValue> = FieldChange(myPropertiesEventSender, EarliestStartValue(taskImpl.myThird, taskImpl.thirdDateConstraint == 1))
private val myDurationChange = FieldChange(myPropertiesEventSender, taskImpl.duration)

private val hasDateFieldsChange: Boolean get() = myStartChange.hasChange() || myDurationChange.hasChange() || myEndChange.hasChange() || myThirdChange.hasChange() || milestoneChange.hasChange()
Expand All @@ -200,7 +202,13 @@ internal open class MutatorImpl(
}
}
myThirdChange.ifChanged {
taskImpl.setThirdDate(it)
if (it.isEnabled) {
taskImpl.setThirdDate(it.startDate)
taskImpl.thirdDateConstraint = 1
} else {
taskImpl.setThirdDate(null)
taskImpl.thirdDateConstraint = 0
}
}
milestoneChange.ifChanged {
taskImpl.isMilestone = it
Expand Down Expand Up @@ -290,7 +298,9 @@ internal open class MutatorImpl(
}
}

override fun getThird(): GanttCalendar? = myThirdChange.newValueOrElse { taskImpl.myThird }
override fun getThird(): GanttCalendar? = myThirdChange.newValueOrElse {
EarliestStartValue(taskImpl.myThird, taskImpl.thirdDateConstraint == 1)
}.startDate

override fun getActivities(): List<TaskActivity>? {
return if (myStartChange.hasChange() || myDurationChange.hasChange()) {
Expand All @@ -313,7 +323,9 @@ internal open class MutatorImpl(

override fun setEnd(end: GanttCalendar) { myEndChange.setValue(end) }

override fun setThird(third: GanttCalendar, thirdDateConstraint: Int) { myThirdChange.setValue(third) }
override fun setThird(third: GanttCalendar?, thirdDateConstraint: Int) {
myThirdChange.setValue(if (thirdDateConstraint == 1) EarliestStartValue(third!!, true) else EarliestStartValue(null, false))
}

override fun setDuration(length: TimeDuration) {
// If duration of task was set to 0 or less do not change it
Expand Down

0 comments on commit c47b316

Please sign in to comment.