소스 검색

add time field to the eventcell

Armin Schrenk 1 개월 전
부모
커밋
341710f724

+ 1 - 1
src/main/java/org/cryptomator/common/vaults/Vault.java

@@ -262,7 +262,7 @@ public class Vault {
 
 	private void consumeVaultEvent(FilesystemEvent e) {
 		//TODO: here we could implement a buffer to prevent event spam (due to many filesystem requests)
-		long timestamp = Instant.now().toEpochMilli();
+		var timestamp = Instant.now();
 		Platform.runLater(() -> eventList.addLast(new VaultEvent(timestamp, this, e)));
 	}
 

+ 7 - 6
src/main/java/org/cryptomator/event/VaultEvent.java

@@ -5,18 +5,19 @@ import org.cryptomator.cryptofs.event.FilesystemEvent;
 
 import java.time.Instant;
 
-public record VaultEvent(long timestamp, Vault v, FilesystemEvent actualEvent) implements Comparable<VaultEvent> {
+public record VaultEvent(Instant timestamp, Vault v, FilesystemEvent actualEvent) implements Comparable<VaultEvent> {
 
 	public VaultEvent(Vault v, FilesystemEvent actualEvent) {
-		this(Instant.now().toEpochMilli(), v, actualEvent);
+		this(Instant.now(), v, actualEvent);
 	}
 
 	@Override
 	public int compareTo(VaultEvent other) {
-		long timeDiff = this.timestamp - other.timestamp;
-		if (timeDiff != 0) {
-			return (int) timeDiff;
+		var timeResult = this.timestamp.compareTo(other.timestamp);
+		if(timeResult != 0) {
+			return timeResult;
+		} else {
+			return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName());
 		}
-		return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName());
 	}
 }

+ 24 - 1
src/main/java/org/cryptomator/ui/eventview/EventListCellController.java

@@ -30,6 +30,9 @@ import javafx.scene.control.ContextMenu;
 import javafx.scene.control.MenuItem;
 import javafx.scene.layout.HBox;
 import java.nio.file.Path;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
 import java.util.Optional;
 import java.util.ResourceBundle;
 import java.util.function.Function;
@@ -37,6 +40,8 @@ import java.util.function.Function;
 public class EventListCellController implements FxController {
 
 	private static final Logger LOG = LoggerFactory.getLogger(EventListCellController.class);
+	private static final DateTimeFormatter LOCAL_DATE_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.systemDefault());
+	private static final DateTimeFormatter LOCAL_TIME_FORMATTER = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withZone(ZoneId.systemDefault());
 
 	private final ObservableList<VaultEvent> events;
 	private final Optional<RevealPathService> revealService;
@@ -46,6 +51,8 @@ public class EventListCellController implements FxController {
 	private final StringProperty eventDescription;
 	private final ObjectProperty<FontAwesome5Icon> eventIcon;
 	private final ObservableValue<Boolean> vaultUnlocked;
+	private final ObservableValue<String> readableTime;
+	private final ObservableValue<String> readableDate;
 	private final ObservableValue<String> message;
 	private final ObservableValue<String> description;
 	private final ObservableValue<FontAwesome5Icon> icon;
@@ -68,6 +75,8 @@ public class EventListCellController implements FxController {
 		this.eventDescription = new SimpleStringProperty();
 		this.eventIcon = new SimpleObjectProperty<>();
 		this.vaultUnlocked = ObservableUtil.mapWithDefault(event.flatMap(e -> e.v().unlockedProperty()), Function.identity(), false);
+		this.readableTime = ObservableUtil.mapWithDefault(event, e -> LOCAL_TIME_FORMATTER.format(e.timestamp()), "");
+		this.readableDate = ObservableUtil.mapWithDefault(event, e -> LOCAL_DATE_FORMATTER.format(e.timestamp()), "");
 		this.message = Bindings.createStringBinding(this::selectMessage, vaultUnlocked, eventMessage);
 		this.description = Bindings.createStringBinding(this::selectDescription, vaultUnlocked, eventDescription);
 		this.icon = Bindings.createObjectBinding(this::selectIcon, vaultUnlocked, eventIcon);
@@ -77,7 +86,7 @@ public class EventListCellController implements FxController {
 	@FXML
 	public void initialize() {
 		actionsButtonVisible.bind(Bindings.createBooleanBinding(this::determineActionsButtonVisibility, root.hoverProperty(), eventActionsMenu.showingProperty(), vaultUnlocked));
-		vaultUnlocked.addListener((_,_,newValue) -> eventActionsMenu.hide());
+		vaultUnlocked.addListener((_, _, newValue) -> eventActionsMenu.hide());
 	}
 
 	private boolean determineActionsButtonVisibility() {
@@ -222,5 +231,19 @@ public class EventListCellController implements FxController {
 		return actionsButtonVisible.getValue();
 	}
 
+	public ObservableValue<String> eventLocalTimeProperty() {
+		return readableTime;
+	}
+
+	public String getEventLocalTime() {
+		return readableTime.getValue();
+	}
 
+	public ObservableValue<String> eventLocalDateProperty() {
+		return readableDate;
+	}
+
+	public String getEventLocalDate() {
+		return readableDate.getValue();
+	}
 }

+ 5 - 1
src/main/resources/fxml/eventview_cell.fxml

@@ -7,7 +7,7 @@
 <?import javafx.geometry.Insets?>
 <?import javafx.scene.control.Button?>
 <?import javafx.scene.control.ContextMenu?>
-<?import javafx.scene.control.MenuItem?>
+<?import org.cryptomator.ui.controls.FormattedLabel?>
 <HBox xmlns:fx="http://javafx.com/fxml"
 	  xmlns="http://javafx.com/javafx"
 	  fx:controller="org.cryptomator.ui.eventview.EventListCellController"
@@ -32,6 +32,10 @@
 			<FontAwesome5IconView glyph="ELLIPSIS_V" glyphSize="16"/>
 		</graphic>
 	</Button>
+	<VBox alignment="CENTER" maxWidth="64" minWidth="64" visible="${!controller.actionsButtonVisible}" managed="${!controller.actionsButtonVisible}">
+		<Label text="${controller.eventLocalTime}" />
+		<Label text="${controller.eventLocalDate}" />
+	</VBox>
 
 	<fx:define>
 		<ContextMenu fx:id="eventActionsMenu"/>