Skip to content

Commit

Permalink
Merge pull request #43 from itsallcode/focus-loss-activities-table
Browse files Browse the repository at this point in the history
#42 Focus loss activities table
  • Loading branch information
kaklakariada authored Nov 19, 2020
2 parents aa3c315 + 984179e commit a990645
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 60 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ This is generated automatically. The Java FX user interface allows you to edit i

## <a name="changes"></a>Recent changes

### Version 1.0.1 (unreleased)

See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.1) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/3?closed=1)

* [#42](https://github.com/itsallcode/white-rabbit/pull/42): Bugfix: Keep edit focus for activities when table is updated every minute

### Version 1.0.0

See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.0) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/1?closed=1)

* [#40](https://github.com/itsallcode/white-rabbit/pull/40): Bugfix: Keep edit focus when table is updated every minute
* [#39](https://github.com/itsallcode/white-rabbit/pull/39): Publish WhiteRabbit using WebStart
* [#5](https://github.com/itsallcode/white-rabbit/issues/5): Add presets for adding interruptions
Expand All @@ -124,7 +134,7 @@ This is generated automatically. The Java FX user interface allows you to edit i
* [#29](https://github.com/itsallcode/white-rabbit/issues/29): Relaxed parsing of time and duration
* [#27](https://github.com/itsallcode/white-rabbit/issues/27): Delete begin, end and interruption when changing day type to "not working"
* [#26](https://github.com/itsallcode/white-rabbit/issues/26): Omit "activities" from json when list is empty
* [#10](https://github.com/itsallcode/white-rabbit/issues/10): Facelift: Improved menu. Turned buttons an drop-down into toolbar. Turned OT (thanks to [redcatbear](https://github.com/redcatbear))
* [#10](https://github.com/itsallcode/white-rabbit/issues/10): Facelift: Improved menu. Turned buttons and drop-down into toolbar. Turned OT (thanks to [redcatbear](https://github.com/redcatbear))
* [#6](https://github.com/itsallcode/white-rabbit/issues/6): Persist cell changes on focus loss
* Text UI is now deprecated, please use the new Java FX UI.
* Keep track of activities for time booking on multiple projects, See [project configuration](#project_config)
Expand Down
3 changes: 3 additions & 0 deletions jfxui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ task uiTest(type: Test) {

useJUnitPlatform()

forkEvery 5
jvmArgs '-XX:+HeapDumpOnOutOfMemoryError'

if(!project.hasProperty("uiTestsHeadless") || project.property("uiTestsHeadless") != "false") {
systemProperty 'java.awt.headless', 'true'
systemProperty 'testfx.headless', 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,9 @@ private void openHomepage(ButtonType ignored)
private void createUi()
{
LOG.debug("Creating user interface");
dayRecordTable = new DayRecordTable(locale, currentMonth, record -> {
appService.store(record);
appService.updateNow();
}, appService.formatter());
dayRecordTable = new DayRecordTable(locale, currentMonth,
record -> appService.store(record),
appService.formatter());

activitiesTable = new ActivitiesTable(dayRecordTable.selectedDay(), record -> {
appService.store(record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,43 @@ public ActivitiesTable(ReadOnlyProperty<DayRecord> selectedDay, EditListener<Day
public void updateTableValues(DayRecord day)
{
JavaFxUtil.runOnFxApplicationThread(() -> {
activities.clear();
if (day != null)
if (day == null || day.activities().isEmpty())
{
final List<Activity> selectedDayActivities = day.activities().getAll();
LOG.trace("Day {} selected with {} activities", day.getDate(), selectedDayActivities.size());
activities.addAll(ActivityPropertyAdapter.wrap(editListener, selectedDayActivities));
LOG.trace("No day selected or no activities: clear list of activities");
activities.clear();
return;
}
final List<Activity> selectedDayActivities = day.activities().getAll();
LOG.trace("Day {} selected with {} activities", day.getDate(), selectedDayActivities.size());

removeSurplusRows(selectedDayActivities);
for (int i = 0; i < selectedDayActivities.size(); i++)
{
final Activity activity = selectedDayActivities.get(i);
if (activities.size() <= i)
{
LOG.trace("Add activity #{}: {}", i, activity);
activities.add(ActivityPropertyAdapter.wrap(editListener, activity));
}
else
{
LOG.trace("Update activity #{}: {}", i, activity);
activities.get(i).setActivity(activity);
}
}
});
}

private void removeSurplusRows(final List<Activity> selectedDayActivities)
{
final int activitiesToRemove = Math.max(0, activities.size() - selectedDayActivities.size());
LOG.trace("Removing {} surplus rows of {}", activitiesToRemove, activities.size());
for (int i = 0; i < activitiesToRemove; i++)
{
activities.remove(activities.size() - 1);
}
}

public TableView<ActivityPropertyAdapter> initTable()
{
final TableView<ActivityPropertyAdapter> table = new TableView<>(activities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ private ActivityPropertyAdapter(EditListener<DayRecord> editListener, Activity a
update();
}

public void setActivity(Activity activity)
{
super.setRecord(activity);
update();
}

public void update()
{
runUpdate(() -> {
Expand All @@ -44,10 +50,15 @@ public void update()
});
}

public static ActivityPropertyAdapter wrap(EditListener<DayRecord> editListener, Activity activity)
{
return new ActivityPropertyAdapter(editListener, activity);
}

static List<@NonNull ActivityPropertyAdapter> wrap(EditListener<DayRecord> editListener, List<Activity> activities)
{
return activities.stream()
.map(a -> new ActivityPropertyAdapter(editListener, a))
.map(a -> wrap(editListener, a))
.collect(toList());
}
}
2 changes: 1 addition & 1 deletion jfxui/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
size="10 MB" />
</Policies>
</RollingFile>

</Appenders>

<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
Expand Down
Loading

0 comments on commit a990645

Please sign in to comment.