Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Messages
public static String removeComponentFailed;
public static String renameItemFailed;
public static String timer;
public static String timers;
public static String unacknowledgeFailed;
public static String withEnableDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.*;

/** TreeCell for AlarmTreeItem
* @author Kay Kasemir
Expand Down Expand Up @@ -127,22 +125,27 @@ protected void updateItem(final AlarmTreeItem<?> item, final boolean empty)
else
{
final AlarmClientNode node = (AlarmClientNode) item;

Optional<Pair<LeavesDisabledStatus, Boolean>> maybeLeavesDisabledStatusBooleanPair = leavesDisabledStatus(node);
if (maybeLeavesDisabledStatusBooleanPair.isPresent() && !maybeLeavesDisabledStatusBooleanPair.get().getKey().equals(LeavesDisabledStatus.AllEnabled)) {
Pair<LeavesDisabledStatus, Boolean> leavesDisabledStatusBooleanPair = maybeLeavesDisabledStatusBooleanPair.get();

if (leavesDisabledStatusBooleanPair.getKey().equals(LeavesDisabledStatus.AllDisabled)) {
if (leavesDisabledStatusBooleanPair.getValue()) {
disabledTimerIndicator.setText("(" + Messages.disabled + "; " + Messages.timer + ")");
}
else {
Set<AlarmClientLeaf> withEnableDate = new HashSet<>();
boolean test = DisableAction.checkEnableDates(node.getChildren(), new HashSet<>(), withEnableDate);
if (test){
disabledTimerIndicator.setText("(" + Messages.disabled + "; " + Messages.timer + ": " + withEnableDate.iterator().next().getEnabledDate() + ")");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment describing DisableAction.checkEnableDates() states:

Returns true when all leaf items of the same structure either have no enable dates or all the same

Therefore, withEnableDate.iterator().next().getEnabledDate() not throwing an exception here (in the case that there are no enable dates) implicitly depends on leavesDisabledStatusBooleanPair.getValue() being true meaning that there is at least one timer in the sub-tree.

In practice, it seems that DisableAction.checkEnableDates() is used to determine whether there exists one shared enable date for a sub-tree: I suggest to consider changing the signature of DisableAction.checkEnableDates() to something like the following to reflect this:

Optional<LocalDateTime> checkEnableDates(AlarmTreeItem<?>) 

Returning:

  1. Optional.empty() if there is no shared enabled date.
  2. Optional.of(sharedEnabledDate) if there is a shared enabled date.

This would remove the implicit dependency, also.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisableAction.checkEnableDates() is actually used also for another purpose, which has been a bit lost in the refactoring done in this commit.
I will update to split the required business logic a bit to improve readability.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to format the enabled date with second-precision only, i.e., to remove the milliseconds, etc.

I don't know whether it would be a good idea to also implement logic to simplify the date depending on the current date: e.g., if the current date is 2026-07-15 and the enable date is 2026-07-15T10:00:00, perhaps it would simplify the display to only display 10:00:00, or similar.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, second precision is sufficient. But I prefer to always use the same format for the sake of consistency.

} else {
disabledTimerIndicator.setText("(" + Messages.disabled + "; " + Messages.timers + ")");
}

} else {
disabledTimerIndicator.setText("(" + Messages.disabled + ")");
}
}
else if (leavesDisabledStatusBooleanPair.getKey().equals(LeavesDisabledStatus.SomeEnabledSomeDisabled)) {
if (leavesDisabledStatusBooleanPair.getValue()) {
disabledTimerIndicator.setText("(" + Messages.partlyDisabled + "; " + Messages.timer + ")");
disabledTimerIndicator.setText("(" + Messages.partlyDisabled + "; " + Messages.timers + ")");
}
else {
disabledTimerIndicator.setText("(" + Messages.partlyDisabled + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ relativeDateTooltip=Select a predefined duration for disabling the alarm
removeComponentFailed=Failed to remove component
renameItemFailed=Failed to rename item
timer=Timer
timers=Timers
title=Title
tooltipAddTableItem=Add a new table item
tooltipDeleteSelectedItems=Delete selected table items
Expand Down
Loading