package de.kopis.timeclicker.pages;

import de.kopis.timeclicker.ListEntriesCsvProducerResource;
import de.kopis.timeclicker.exceptions.NotAuthenticatedException;
import de.kopis.timeclicker.model.TimeEntry;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ListEntriesPage extends TemplatePage {
    private static final long serialVersionUID = 1L;
    private final DateFormat DF = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy Z");

    public ListEntriesPage(PageParameters parameters) {
        super("Time Entries", parameters);
    }

    @Override
    public void onInitialize() {
        super.onInitialize();
        setStatelessHint(true);
        setVersioned(false);

        add(new ResourceLink("csvLink", new ListEntriesCsvProducerResource()));

        final List<TimeEntry> entries = new ArrayList<>();
        if (getCurrentUser() != null) {
            try {
                entries.addAll(getApi().list(getCurrentUser()));
                Collections.sort(entries, new Comparator<TimeEntry>() {
                    @Override
                    public int compare(TimeEntry o1, TimeEntry o2) {
                        // sort DESC by start date
                        return o2.getStart().compareTo(o1.getStart());
                    }
                });
            } catch (NotAuthenticatedException e) {
                LOGGER.severe("Can not load entries for user " + getCurrentUser() + ": " + e.getMessage());
            }
        }

        final PageableListView<TimeEntry> listView = new PageableListView<TimeEntry>("listView", entries, 10) {
            @Override
            protected void populateItem(final ListItem<TimeEntry> item) {
                item.add(new Label("entryKey", item.getModelObject().getKey()));
                item.add(new Label("entryStart", DF.format(item.getModelObject().getStart())));
                if (item.getModelObject().getStop() != null) {
                    item.add(new Label("entryStop", DF.format(item.getModelObject().getStop())));
                } else {
                    item.add(new Label("entryStop", "-"));
                }
                item.add(new Link("editLink") {
                    @Override
                    public void onClick() {
                        PageParameters parameters = new PageParameters();
                        parameters.add("key", item.getModelObject().getKey());
                        setResponsePage(TimeEntryPage.class, parameters);
                    }
                });
                item.add(new Link("deleteLink") {
                    @Override
                    public void onClick() {
                        try {
                            getApi().delete(item.getModelObject().getKey(), getCurrentUser());
                        } catch (NotAuthenticatedException e) {
                            LOGGER.severe("Can not delete entry " + item.getModelObject().getKey());
                        }
                        setResponsePage(findPage());
                    }
                });
            }
        };
        final PagingNavigator navigator = new PagingNavigator("paginator", listView);
        add(navigator);
		add(listView);
    }
}

@@ -41,125 +41,121 @@
 ort 
-de.kopis.timeclicker.ListEntriesCsvProducerResource;%0Aimport de.kopis.timeclicker.exceptions.NotAuthenticatedExcep
+java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Collec
 tion
+s
 ;%0Aim
@@ -163,45 +163,53 @@
 ort 
-de.kopis.timeclicker.model.TimeEntry;
+java.util.Comparator;%0Aimport java.util.List;%0A
 %0Aimp
@@ -415,60 +415,8 @@
 em;%0A
-import org.apache.wicket.markup.html.list.ListView;%0A
 impo
@@ -621,121 +621,125 @@
 ort 
-java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Collec
+de.kopis.timeclicker.ListEntriesCsvProducerResource;%0Aimport de.kopis.timeclicker.exceptions.NotAuthenticatedExcep
 tion
-s
 ;%0Aim
@@ -747,51 +747,44 @@
 ort 
-java.util.Comparator;%0Aimport java.util.List
+de.kopis.timeclicker.model.TimeEntry
 ;%0A%0Ap
@@ -899,22 +899,16 @@
 private 
-final 
 DateForm
@@ -915,57 +915,18 @@
 at D
-F = new SimpleDateFormat(%22HH:mm:ss dd.MM.yyyy Z%22)
+ATE_FORMAT
 ;%0A%0A 
@@ -1248,16 +1248,153 @@
 rce()));
+%0A        // use the locale to figure out the dateformat%0A        DATE_FORMAT = new SimpleDateFormat(%22HH:mm:ss dd.MM.yyyy Z%22, getLocale());
 %0A%0A      
@@ -2424,25 +2424,34 @@
 tryStart%22, D
-F
+ATE_FORMAT
 .format(item
@@ -2599,17 +2599,26 @@
 Stop%22, D
-F
+ATE_FORMAT
 .format(

Use TimeZone for DateTimeField.