Skip to content

Commit

Permalink
Merge branch 'BRANCH_3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashev committed May 21, 2024
2 parents 1370459 + 56aa9a8 commit 55802f5
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
*/
package biz.ganttproject.core.option;

import kotlin.Pair;
import kotlin.jvm.functions.Function1;

import java.util.Date;

public interface DateOption extends GPOption<Date> {
Function1<Date, Pair<Boolean, String>> getValueValidator();
void setValueValidator(Function1<Date, Pair<Boolean, String>> validator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
*/
package biz.ganttproject.core.option;

import kotlin.Pair;
import kotlin.jvm.functions.Function1;
import org.w3c.util.DateParser;
import org.w3c.util.InvalidDateException;

import java.util.Date;

public class DefaultDateOption extends GPAbstractOption<Date> implements DateOption {

private Function1<Date, Pair<Boolean, String>> valueValidator;

public DefaultDateOption(String id) {
super(id);
}
Expand All @@ -48,4 +52,13 @@ public void loadPersistentValue(String value) {
}
}

@Override
public Function1<Date, Pair<Boolean, String>> getValueValidator() {
return valueValidator;
}

@Override
public void setValueValidator(Function1<Date, Pair<Boolean, String>> validator) {
valueValidator = validator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package biz.ganttproject.core.option
import com.google.common.base.Strings
import com.google.common.base.Supplier
import javafx.beans.property.StringProperty
import org.apache.commons.math3.util.Pair
import java.text.DateFormat
import java.text.ParseException
import java.time.Duration
Expand Down Expand Up @@ -89,12 +88,12 @@ object DateValidators {
fun dateInRange(center: Date, yearDiff: Int): DateValidatorType = { value: Date ->
val diff = Duration.between(value.toInstant(), center.toInstant()).abs().dividedBy(Duration.ofDays(365))
if (diff > yearDiff) {
Pair.create(false, String.format(
Pair(false, String.format(
"Date %s is far away (%d years) from expected date %s. Any mistake?", value, diff, center
)
)
} else {
Pair.create<Boolean?, String?>(java.lang.Boolean.TRUE, null)
Pair(java.lang.Boolean.TRUE, null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 BarD Software s.r.o., Dmitry Barashev.
*
* This file is part of GanttProject, an opensource project management tool.
*
* GanttProject is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GanttProject is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sourceforge.ganttproject.test.task

import junit.framework.TestCase
import net.sourceforge.ganttproject.TestSetupHelper
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test


class Test2453: TaskTestCase() {
@BeforeEach
override fun setUp() {
super.setUp()
}

fun `test for issue 2453`() {
val monday = TestSetupHelper.newMonday()

val milestone = createTask(monday)
milestone.isMilestone = true
assertEquals(1, milestone.activities.first().duration.length)

milestone.createMutator().let {
it.setMilestone(false)
it.setDuration(taskManager.createLength(3))
it.commit()
}
assertEquals(3, milestone.duration.length)
assertFalse(milestone.isMilestone)
assertEquals(3, milestone.activities.first().duration.length)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class TaskTable(
treeTable.contextMenuActions = this::contextMenuActions

filterManager.sync = { this.sync() }
minCellHeight.addListener { observable, oldValue, newValue ->
if (oldValue != newValue) {
treeTable.coalescingRefresh()
}
}
}

fun loadDefaultColumns() = Platform.runLater {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ fun initFontProperty(appFontOption: FontOption, rowPaddingOption: DoubleOption)
}
}
}
rowPaddingOption.addChangeValueListener { event ->
cellPadding = rowPaddingOption.value
calculateMinCellHeight(appFontOption.value)
}
}
val applicationBackground = SimpleObjectProperty(Color.BLACK)
val applicationForeground = SimpleObjectProperty<Paint>(Color.BLACK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ of the License, or (at your option) any later version.
*/
package net.sourceforge.ganttproject.export;

import biz.ganttproject.core.option.DefaultDateOption;
import biz.ganttproject.core.option.GPOption;
import biz.ganttproject.core.option.GPOptionGroup;
import biz.ganttproject.core.option.*;
import net.sourceforge.ganttproject.GPLogger;
import net.sourceforge.ganttproject.GanttExportSettings;
import net.sourceforge.ganttproject.IGanttProject;
Expand Down Expand Up @@ -69,9 +67,23 @@ public void setContext(IGanttProject project, UIFacade uiFacade, Preferences pre
myExportRangeStart.addChangeValueListener(event -> {
prefNode.put("export-range-start", myExportRangeStart.getPersistentValue());
});
myExportRangeStart.setValueValidator(date -> {
if (date.after(myExportRangeEnd.getValue())) {
return new kotlin.Pair(false, "Start date > end date");
} else {
return new kotlin.Pair(true, "");
}
});
myExportRangeEnd = new DefaultDateOption("export.range.end", myGanttChart.getEndDate());
myExportRangeEnd.loadPersistentValue(prefNode.get(
"export-range-end", DateParser.getIsoDate(myGanttChart.getEndDate())));
myExportRangeEnd.setValueValidator(date -> {
if (date.before(myExportRangeStart.getValue())) {
return new kotlin.Pair(false, "Start date > end date");
} else {
return new kotlin.Pair(true, "");
}
});
myExportRangeEnd.addChangeValueListener(event -> {
prefNode.put("export-range-end", myExportRangeEnd.getPersistentValue());
});
Expand All @@ -86,7 +98,7 @@ protected DefaultDateOption getExportRangeEndOption() {
}

protected GPOptionGroup createExportRangeOptionGroup() {
return new GPOptionGroup("export.range", new GPOption[] { getExportRangeStartOption(), getExportRangeEndOption() });
return new GPOptionGroup("export.range", getExportRangeStartOption(), getExportRangeEndOption());
}

public UIFacade getUIFacade() {
Expand Down Expand Up @@ -144,6 +156,9 @@ public GanttExportSettings createExportSettings() {
GPLogger.log(e);
}
}
if (result.getStartDate().after(result.getEndDate())) {
GPLogger.log(new ValidationException("In the export range the start date=" + result.getStartDate() + " is after the end date=" + result.getEndDate()));
}
result.setCommandLineMode(myRootPreferences.getBoolean("commandLine", false));
if (myRootPreferences.getBoolean("expandResources", false)) {
result.setExpandedResources("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import com.google.common.collect.Lists;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import kotlin.Pair;
import kotlin.jvm.functions.Function1;
import net.sourceforge.ganttproject.IGanttProject;
import net.sourceforge.ganttproject.action.GPAction;
import net.sourceforge.ganttproject.language.GanttLanguage;
import net.sourceforge.ganttproject.language.GanttLanguage.Event;
import net.sourceforge.ganttproject.util.PropertiesUtil;
import org.apache.commons.math3.util.Pair;
import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.ColorHighlighter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public void propertyChange(PropertyChangeEvent evt) {
}
OptionValueUpdater valueUpdater = new OptionValueUpdater();
final JXDatePicker result = UIUtil.createDatePicker();
UIUtil.setupDatePicker(result, option.getValue(), null, valueUpdater);
UIUtil.setupDatePicker(result, option.getValue(), option.getValueValidator(), valueUpdater);
result.setDate(option.getValue());
result.getEditor().addPropertyChangeListener("value", valueUpdater);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import biz.ganttproject.core.time.GanttCalendar;
import com.google.common.collect.ImmutableList;
import kotlin.jvm.functions.Function1;
import kotlin.Pair;
import net.sourceforge.ganttproject.action.GPAction;
import net.sourceforge.ganttproject.gui.UIFacade;
import net.sourceforge.ganttproject.gui.UIUtil;
import net.sourceforge.ganttproject.language.GanttLanguage;
import net.sourceforge.ganttproject.task.Task;
import org.apache.commons.math3.util.Pair;
import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.JXHyperlink;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ internal open class MutatorImpl(
}
var hasActualDatesChange = false
try {
milestoneChange.ifChanged {
taskImpl.isMilestone = it
taskUpdateBuilder?.setMilestone(milestoneChange.oldValue, it)
}
myStartChange.ifChanged {
taskImpl.start = it
}
Expand All @@ -210,10 +214,6 @@ internal open class MutatorImpl(
taskImpl.thirdDateConstraint = 0
}
}
milestoneChange.ifChanged {
taskImpl.isMilestone = it
taskUpdateBuilder?.setMilestone(milestoneChange.oldValue, it)
}
if (hasDateFieldsChange) {
hasActualDatesChange = taskImpl.start != myStartChange.oldValue || taskImpl.duration != myDurationChange.oldValue || taskImpl.third != myThirdChange.oldValue.startDate
if (hasActualDatesChange && taskUpdateBuilder != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ of the License, or (at your option) any later version.
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class ExporterToHTML extends StylesheetExporterBase {
Expand All @@ -58,7 +59,9 @@ protected void setSelectedStylesheet(Stylesheet stylesheet) {

@Override
public List<GPOptionGroup> getSecondaryOptions() {
return null;
List<GPOptionGroup> result = new ArrayList<>();
result.add(createExportRangeOptionGroup());
return result;
}

@Override
Expand Down

0 comments on commit 55802f5

Please sign in to comment.