Skip to content

Commit

Permalink
Merge pull request #67 from itsallcode/#13-store-restore-widgets
Browse files Browse the repository at this point in the history
#13 store restore widgets
  • Loading branch information
kaklakariada authored Jan 9, 2021
2 parents fa50e7f + 32ddb06 commit 9aa7e58
Show file tree
Hide file tree
Showing 39 changed files with 1,076 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.3.0) /

### Added

* [#13](https://github.com/itsallcode/white-rabbit/issues/13): Persist window position and column width.
* [#49](https://github.com/itsallcode/white-rabbit/issues/49): Added monthly project report.
* [#59](https://github.com/itsallcode/white-rabbit/issues/59): Log to data directory.
* [#9](https://github.com/itsallcode/white-rabbit/issues/9): Add vacation and project report.
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ext {
log4jVersion = '2.14.0'
mockitoVersion = '3.6.28'
yassonVersion = '1.0.8'
jsonBindApiVersion = '1.0'
}

def getProjectVersion() {
Expand Down
4 changes: 3 additions & 1 deletion jfxui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ dependencies {

implementation "org.eclipse.jdt:org.eclipse.jdt.annotation:2.2.600"
implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
implementation "javax.json.bind:javax.json.bind-api:${jsonBindApiVersion}"

runtimeOnly "org.fusesource.jansi:jansi:2.1.1"

testImplementation "javax.json.bind:javax.json.bind-api:1.0"
testImplementation "javax.json.bind:javax.json.bind-api:${jsonBindApiVersion}"
testRuntimeOnly "org.eclipse:yasson:${yassonVersion}"

testImplementation "org.testfx:testfx-junit5:4.0.16-alpha"
Expand Down
13 changes: 10 additions & 3 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.itsallcode.whiterabbit.jfxui.property.ClockPropertyFactory;
import org.itsallcode.whiterabbit.jfxui.property.ScheduledProperty;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
import org.itsallcode.whiterabbit.logic.model.Activity;
import org.itsallcode.whiterabbit.logic.model.DayRecord;
import org.itsallcode.whiterabbit.logic.model.MonthIndex;
Expand All @@ -31,20 +32,25 @@ public final class AppState
public final SimpleObjectProperty<DayRecord> selectedDay = new SimpleObjectProperty<>(null);
public final SimpleObjectProperty<Activity> selectedActivity = new SimpleObjectProperty<>(null);

public final UiStateService uiState;

public final ScheduledProperty<LocalDate> currentDateProperty;
public final ScheduledProperty<Instant> currentTimeProperty;
private Stage primaryStage;

private AppState(ScheduledProperty<LocalDate> currentDateProperty, ScheduledProperty<Instant> currentTimeProperty)
private AppState(ScheduledProperty<LocalDate> currentDateProperty, ScheduledProperty<Instant> currentTimeProperty,
UiStateService uiState)
{
this.currentDateProperty = currentDateProperty;
this.currentTimeProperty = currentTimeProperty;
this.uiState = uiState;
}

static AppState create(AppService appService)
static AppState create(AppService appService, UiStateService uiState)
{
final ClockPropertyFactory clockPropertyFactory = new ClockPropertyFactory(appService);
return new AppState(clockPropertyFactory.currentDateProperty(), clockPropertyFactory.currentTimeProperty());
return new AppState(clockPropertyFactory.currentDateProperty(), clockPropertyFactory.currentTimeProperty(),
uiState);
}

public Optional<DayRecord> getSelectedDay()
Expand All @@ -71,5 +77,6 @@ void shutdown()
{
currentDateProperty.cancel();
currentTimeProperty.cancel();
uiState.persistState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.itsallcode.whiterabbit.jfxui.log.LoggingConfigurator;
import org.itsallcode.whiterabbit.jfxui.property.DelayedPropertyListener;
import org.itsallcode.whiterabbit.jfxui.splashscreen.ProgressPreloaderNotification;
import org.itsallcode.whiterabbit.jfxui.splashscreen.ProgressPreloaderNotification.Type;
import org.itsallcode.whiterabbit.jfxui.ui.AppUi;
import org.itsallcode.whiterabbit.jfxui.ui.InterruptionDialog;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
import org.itsallcode.whiterabbit.logic.Config;
import org.itsallcode.whiterabbit.logic.ConfigLoader;
import org.itsallcode.whiterabbit.logic.DefaultWorkingDirProvider;
Expand Down Expand Up @@ -111,7 +113,8 @@ private void doInitialize()
throw new OtherInstanceAlreadyRunningException(response);
}

state = AppState.create(appService);
state = AppState.create(appService,
UiStateService.loadState(config, new DelayedPropertyListener(appService.scheduler())));
actions = UiActions.create(config, state, appService, getHostServices());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void openFileWithDefaultProgram(Path file)
public void showVacationReport()
{
final VacationReport vacationReport = appService.getVacationReport();
new VacationReportViewer(getPrimaryStage(), vacationReport).show();
new VacationReportViewer(getPrimaryStage(), state.uiState, vacationReport).show();
}

public void showProjectReport()
Expand All @@ -77,7 +77,7 @@ public void showProjectReport()
return;
}
final ProjectReport report = appService.generateProjectReport(monthIndex.getYearMonth());
new ProjectReportViewer(getPrimaryStage(), appService.formatter(), report).show();
new ProjectReportViewer(getPrimaryStage(), state.uiState, appService.formatter(), report).show();
}

private Stage getPrimaryStage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public <T> ScheduledProperty<T> updatingProperty(Trigger trigger, Supplier<T> su
LOG.debug("Setting initial property value {} from supplier", initialValue);
property.set(initialValue);
final Runnable runnable = new ClockPropertyFactoryRunnable<T>(supplier, trigger, property);
final ScheduledTaskFuture scheduledTaskFuture = appService.schedule(trigger, runnable);
final ScheduledTaskFuture scheduledTaskFuture = appService.scheduler().schedule(trigger, runnable);
return new ScheduledProperty<>(property, scheduledTaskFuture);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.itsallcode.whiterabbit.jfxui.property;

import java.time.Duration;
import java.util.function.Consumer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.itsallcode.whiterabbit.logic.service.scheduling.SchedulingService;

import javafx.beans.value.ObservableValue;

public class DelayedPropertyListener
{
private static final Logger LOG = LogManager.getLogger(DelayedPropertyListener.class);
public static final Duration DELAY = Duration.ofMillis(500);

private final SchedulingService schedulingService;

public DelayedPropertyListener(SchedulingService schedulingService)
{
this.schedulingService = schedulingService;
}

public <T> void register(ObservableValue<T> property, Consumer<T> delegate)
{
delegate.accept(property.getValue());
property.addListener(observable -> {
LOG.trace("Schedule with {} delay", DELAY);
schedulingService.schedule(DELAY, () -> {
final T newValue = property.getValue();
LOG.trace("Property {} changed to {}", property, newValue);
delegate.accept(newValue);
});
});
}
}

This file was deleted.

13 changes: 11 additions & 2 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.itsallcode.whiterabbit.jfxui.UiActions;
import org.itsallcode.whiterabbit.jfxui.feature.InterruptionPresetFeature;
import org.itsallcode.whiterabbit.jfxui.table.activities.ActivitiesTable;
import org.itsallcode.whiterabbit.jfxui.table.activities.ActivityPropertyAdapter;
import org.itsallcode.whiterabbit.jfxui.table.days.DayRecordPropertyAdapter;
import org.itsallcode.whiterabbit.jfxui.table.days.DayRecordTable;
import org.itsallcode.whiterabbit.jfxui.tray.Tray;
import org.itsallcode.whiterabbit.jfxui.tray.TrayCallback;
Expand All @@ -34,6 +36,7 @@
import javafx.scene.control.MenuBar;
import javafx.scene.control.Separator;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableView;
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToolBar;
import javafx.scene.input.KeyCode;
Expand Down Expand Up @@ -137,6 +140,8 @@ public AppUi build()
primaryStage.hide();
}
});

state.uiState.register("main-window", primaryStage);
LOG.debug("User interface finished");
return new AppUi(this);
}
Expand Down Expand Up @@ -189,9 +194,9 @@ public void exit()

private BorderPane createMainPane()
{
final Node daysTable = dayRecordTable.initTable();
final TableView<DayRecordPropertyAdapter> daysTable = dayRecordTable.initTable();
state.currentDateProperty.property().addListener(this::dateChanged);
final Node activitiesTab = activitiesTable.initTable();
final TableView<ActivityPropertyAdapter> activitiesTab = activitiesTable.initTable();
final Button addActivityButton = UiWidget.button("add-activity-button", "+", "Add activity",
e -> app.addActivity());
final Button removeActivityButton = UiWidget.button("remove-activity-button", "-", "Remove activity",
Expand All @@ -202,6 +207,7 @@ private BorderPane createMainPane()
final SplitPane mainPane = new SplitPane(daysTable,
new TitledPane("Activities", new HBox(UiResources.GAP_PIXEL, activitiesButtonPane, activitiesTab)));
HBox.setHgrow(activitiesTab, Priority.ALWAYS);
mainPane.setId("mainSplitPane");
mainPane.setOrientation(Orientation.VERTICAL);
mainPane.setDividerPositions(0.8);

Expand All @@ -213,6 +219,9 @@ private BorderPane createMainPane()
BorderPane.setMargin(createStatusBar(), new Insets(0, UiResources.GAP_PIXEL, 0, UiResources.GAP_PIXEL));
pane.setBottom(createStatusBar());

state.uiState.register(daysTable);
state.uiState.register(activitiesTab);
state.uiState.register(mainPane);
return pane;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.itsallcode.whiterabbit.jfxui.table.converter.DurationStringConverter;
import org.itsallcode.whiterabbit.jfxui.table.converter.ProjectStringConverter;
import org.itsallcode.whiterabbit.jfxui.ui.widget.ReportWindow;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
import org.itsallcode.whiterabbit.logic.model.json.DayType;
import org.itsallcode.whiterabbit.logic.report.project.ProjectReport;
import org.itsallcode.whiterabbit.logic.report.project.ProjectReport.Day;
Expand All @@ -28,17 +29,22 @@ public class ProjectReportViewer
private final ProjectReport report;
private final FormatterService formatterService;
private final ReportWindow reportWindow;
private final UiStateService uiState;

public ProjectReportViewer(Stage primaryStage, FormatterService formatterService, ProjectReport report)
public ProjectReportViewer(Stage primaryStage, UiStateService uiState, FormatterService formatterService,
ProjectReport report)
{
this.reportWindow = new ReportWindow(primaryStage, "Project Report");
this.uiState = uiState;
this.reportWindow = new ReportWindow(primaryStage, uiState, "project-report", "Project Report");
this.formatterService = formatterService;
this.report = report;
}

public void show()
{
reportWindow.show(createTreeTable());
final TreeTableView<ReportRow> treeTable = createTreeTable();
reportWindow.show(treeTable);
uiState.register(treeTable);
}

private TreeTableView<ReportRow> createTreeTable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.itsallcode.whiterabbit.jfxui.table.converter.YearMonthStringConverter;
import org.itsallcode.whiterabbit.jfxui.table.converter.YearStringConverter;
import org.itsallcode.whiterabbit.jfxui.ui.widget.ReportWindow;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
import org.itsallcode.whiterabbit.logic.report.vacation.VacationReport;
import org.itsallcode.whiterabbit.logic.report.vacation.VacationReport.VacationMonth;
import org.itsallcode.whiterabbit.logic.report.vacation.VacationReport.VacationYear;
Expand All @@ -35,35 +36,39 @@ public class VacationReportViewer
private final VacationReport report;

private final ReportWindow reportWindow;
private final UiStateService uiState;

public VacationReportViewer(Stage primaryStage, VacationReport report)
public VacationReportViewer(Stage primaryStage, UiStateService uiState, VacationReport report)
{
this.reportWindow = new ReportWindow(primaryStage, "Vacation Report");
this.uiState = uiState;
this.reportWindow = new ReportWindow(primaryStage, uiState, "vacation-report", "Vacation Report");
this.report = report;
}

public void show()
{
reportWindow.show(createReportView());
}

private Node createReportView()
{
final TableView<VacationYear> yearsTable = createYearsTable();
final TableView<VacationMonth> monthsTable = createMonthsTable();

final SplitPane mainPane = new SplitPane(yearsTable, monthsTable);
mainPane.setId("vacationReportMainPane");
mainPane.setOrientation(Orientation.VERTICAL);
mainPane.setDividerPositions(0.2);
return mainPane;
final Node reportView = mainPane;

reportWindow.show(reportView);

uiState.register(mainPane);
uiState.register(yearsTable);
uiState.register(monthsTable);
}

private TableView<VacationMonth> createMonthsTable()
{
final TableView<VacationMonth> table = new TableView<>(FXCollections.observableArrayList(report.months));
table.setEditable(false);
table.getColumns().addAll(createMonthTableColumns());
table.setId("month-table");
table.setId("vacation-report-month-table");
return table;
}

Expand All @@ -85,7 +90,7 @@ private TableView<VacationYear> createYearsTable()
final TableView<VacationYear> table = new TableView<>(FXCollections.observableArrayList(report.years));
table.setEditable(false);
table.getColumns().addAll(createYearTableColumns());
table.setId("year-table");
table.setId("vacation-report-year-table");
table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
table.getSelectionModel().selectedItemProperty()
.addListener((observable, oldValue, newValue) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.itsallcode.whiterabbit.jfxui.ui.UiResources;
import org.itsallcode.whiterabbit.jfxui.ui.UiWidget;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;

import javafx.scene.Node;
import javafx.scene.Parent;
Expand All @@ -17,11 +18,15 @@ public class ReportWindow
{
private final Stage primaryStage;
private final String windowTitle;
private final UiStateService uiState;
private final String id;
private Stage stage;

public ReportWindow(Stage primaryStage, String windowTitle)
public ReportWindow(Stage primaryStage, UiStateService uiState, String id, String windowTitle)
{
this.primaryStage = primaryStage;
this.uiState = uiState;
this.id = id;
this.windowTitle = windowTitle;
}

Expand Down Expand Up @@ -59,6 +64,7 @@ private Stage createStage(final Parent root)
});
newStage.initOwner(primaryStage);
newStage.getIcons().add(UiResources.APP_ICON);
uiState.register(id, newStage);
return newStage;
}

Expand Down
Loading

0 comments on commit 9aa7e58

Please sign in to comment.