summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/fbin/java2fx/tables/LocalDateTimeTableCellFactory.java
blob: 0c5c41d32cb37aab27b8ebbe9a61bf107c3ad035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package de.fhswf.fbin.java2fx.tables;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;

public class LocalDateTimeTableCellFactory<S> implements
      Callback<TableColumn<S, LocalDateTime>, TableCell<S, LocalDateTime>>
{
   @Override
   public TableCell<S, LocalDateTime> call(TableColumn<S, LocalDateTime> param)
   {
      return new TableCell<S, LocalDateTime>()
      {
         @Override
         protected void updateItem(LocalDateTime item, boolean empty)
         {
            super.updateItem(item, empty);

            if (!empty)
            {
               ZonedDateTime zdt = ZonedDateTime.of(item, ZoneId.systemDefault());
               setText(zdt.format(DateTimeFormatter.RFC_1123_DATE_TIME));
            }
            else
            {
               setText(null);
            }
         }
      };
   }
}