2 * Copyright 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.admin.client.ui;
21 import gr.ebs.gss.admin.client.TwoAdmin;
22 import gr.ebs.gss.server.domain.dto.FileBodyDTO;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.Date;
27 import java.util.List;
29 import com.google.gwt.event.dom.client.ClickEvent;
30 import com.google.gwt.event.dom.client.ClickHandler;
31 import com.google.gwt.i18n.client.DateTimeFormat;
32 import com.google.gwt.user.client.ui.Composite;
33 import com.google.gwt.user.client.ui.FlexTable;
34 import com.google.gwt.user.client.ui.HTML;
35 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
36 import com.google.gwt.user.client.ui.VerticalPanel;
43 public class VersionsList extends Composite{
46 final FlexTable permTable = new FlexTable();
47 final VerticalPanel permPanel = new VerticalPanel();
52 public VersionsList(List<FileBodyDTO> versions) {
54 permTable.setText(0, 0, "Version");
55 permTable.setText(0, 1, "Created By");
56 permTable.setText(0, 2, "Created");
57 permTable.setText(0, 3, "Modified By");
58 permTable.setText(0, 4, "Modified");
59 permTable.setText(0, 5, "Size");
60 permTable.setText(0, 6, "");
61 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
62 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
63 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
64 permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
65 permTable.getFlexCellFormatter().setStyleName(0, 4, "props-toplabels");
66 permTable.getFlexCellFormatter().setStyleName(0, 5, "props-toplabels");
67 permTable.getFlexCellFormatter().setStyleName(0, 6, "props-toplabels");
68 permTable.getFlexCellFormatter().setColSpan(0, 1, 2);
69 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
70 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
71 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
72 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
73 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
74 permTable.getFlexCellFormatter().setHorizontalAlignment(0, 5, HasHorizontalAlignment.ALIGN_CENTER);
75 permPanel.add(permTable);
76 permPanel.addStyleName("gss-TabPanelBottom");
77 permTable.addStyleName("gss-permList");
78 initWidget(permPanel);
79 updateTable(versions);
82 public void updateTable(List<FileBodyDTO> versions) {
83 Collections.sort(versions, new Comparator<FileBodyDTO>(){
86 public int compare(FileBodyDTO o1, FileBodyDTO o2) {
87 return new Integer(o1.getVersion()).compareTo(new Integer(o2.getVersion()));
92 for (final FileBodyDTO dto : versions) {
94 permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>");
95 HTML createdByLabel = new HTML("<a href='#'>"+dto.getAuditInfo().getCreatedBy().getUsername()+"</a></span>");
96 permTable.setWidget(i, 1, createdByLabel);
97 createdByLabel.addClickHandler(new ClickHandler() {
100 public void onClick(ClickEvent event) {
101 TwoAdmin.get().searchUsers("username:"+dto.getAuditInfo().getCreatedBy().getUsername());
105 permTable.setHTML(i, 2, "<span>" + formatLocalDateTime(dto.getAuditInfo().getCreationDate()) + "</span>");
106 HTML modifiedByLabel = new HTML("<a href='#'>"+dto.getAuditInfo().getModifiedBy().getUsername()+"</a></span>");
107 permTable.setWidget(i, 3, modifiedByLabel);
108 modifiedByLabel.addClickHandler(new ClickHandler() {
111 public void onClick(ClickEvent event) {
112 TwoAdmin.get().searchUsers("username:"+dto.getAuditInfo().getModifiedBy().getUsername());
117 permTable.setHTML(i, 4, "<span>" + formatLocalDateTime(dto.getAuditInfo().getModificationDate()) + "</span>");
118 permTable.setHTML(i, 5, "<span>" + dto.getFileSizeAsString() + "</span>");
119 HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+"</span><div>View this Version</div></a>");
120 downloadHtml.addClickHandler( new ClickHandler() {
122 public void onClick(ClickEvent event) {
127 permTable.setWidget(i, 6, downloadHtml);
129 permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
130 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER);
131 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
132 permTable.getFlexCellFormatter().setColSpan(i, 1, 2);
133 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
134 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
137 for (; i < permTable.getRowCount(); i++)
138 permTable.removeRow(i);
141 public static String formatLocalDateTime(Date date) {
142 Date convertedDate = new Date(date.getTime() - date.getTimezoneOffset());
143 final DateTimeFormat dateFormatter = DateTimeFormat.getShortDateFormat();
144 final DateTimeFormat timeFormatter = DateTimeFormat.getFormat("HH:mm");
145 String datePart = dateFormatter.format(convertedDate);
146 String timePart = timeFormatter.format(convertedDate);
147 return datePart + " " + timePart;