root / client / src / com / gonnatrak / util / SubjectsHelper.java @ 1

View | Annotate | Download

1
/**
2
 * Created by Andrey Khalzov
3
 * 02.08.2008 23:48:34
4
 */
5
package com.gonnatrak.util;
6
7
import com.gonnatrak.middleware.entity.Subject;
8
import org.jetbrains.annotations.NotNull;
9
import org.joda.time.DateTime;
10
11
import java.util.List;
12
import java.text.DateFormat;
13
import java.text.SimpleDateFormat;
14
15
public class SubjectsHelper {
16
17
    public static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
18
19
    public static String createHtmlTable(@NotNull List<Subject> subjects) {
20
        if (subjects.isEmpty()) {
21
            return "У вас нет ни одного объекта.";
22
        }
23
24
        final DateFormat df = new SimpleDateFormat(DATE_FORMAT);
25
        final StringBuilder sb = new StringBuilder("<table cellpadding=\"5\">");
26
        for (Subject subject : subjects) {
27
            sb
28
                    .append("<tr><td><b>")
29
                    .append(subject.getName())
30
31
                    .append("</b></td><td>(<a href=\"/subject?id=")
32
                    .append(subject.getId())
33
                    .append("\">")
34
                    .append("изменить")
35
                    .append("</a>&nbsp;|&nbsp;")
36
37
                    .append("<a href=\"/subject/link?id=")
38
                    .append(subject.getId())
39
                    .append("\">")
40
                    .append("связать")
41
                    .append("</a>&nbsp;|&nbsp;")
42
43
                    .append("<a href=\"/subject/remove?id=")
44
                    .append(subject.getId())
45
                    .append("\">")
46
                    .append("удалить")
47
                    .append("</a>)")
48
                    
49
                    .append("</td></tr><tr><td>")
50
51
                    .append("пробег: ").append(subject.getOdometer() == null ? "0" : subject.getOdometer()).append(" м")
52
53
                    .append("</td><td>")
54
                    .append("обновлено: ").append(getUpdated(df, subject.getLastUpdated()))
55
                    .append("</td></tr>");
56
        }
57
        sb.append("</table>");
58
        return sb.toString();
59
    }
60
61
    private static String getUpdated(DateFormat df, DateTime lastUpdated) {
62
        if (lastUpdated == null) {
63
            return "";
64
        }
65
        return df.format(lastUpdated.toDate());
66
    }
67
}