root / src / gr / ebs / gss / admin / client / ui / VersionsList.java @ 0a37ac21
History | View | Annotate | Download (5.9 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2010 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.admin.client.ui; |
20 |
|
21 |
import gr.ebs.gss.admin.client.TwoAdmin; |
22 |
import gr.ebs.gss.server.domain.dto.FileBodyDTO; |
23 |
|
24 |
import java.util.Collections; |
25 |
import java.util.Comparator; |
26 |
import java.util.Date; |
27 |
import java.util.List; |
28 |
|
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; |
37 |
|
38 |
|
39 |
/**
|
40 |
* @author kman
|
41 |
*
|
42 |
*/
|
43 |
public class VersionsList extends Composite{ |
44 |
|
45 |
|
46 |
final FlexTable permTable = new FlexTable(); |
47 |
final VerticalPanel permPanel = new VerticalPanel(); |
48 |
|
49 |
/**
|
50 |
*
|
51 |
*/
|
52 |
public VersionsList(List<FileBodyDTO> versions) { |
53 |
|
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); |
80 |
} |
81 |
|
82 |
public void updateTable(List<FileBodyDTO> versions) { |
83 |
Collections.sort(versions, new Comparator<FileBodyDTO>(){ |
84 |
|
85 |
@Override
|
86 |
public int compare(FileBodyDTO o1, FileBodyDTO o2) { |
87 |
return new Integer(o1.getVersion()).compareTo(new Integer(o2.getVersion())); |
88 |
} |
89 |
|
90 |
}); |
91 |
int i = 1; |
92 |
for (final FileBodyDTO dto : versions) { |
93 |
|
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() {
|
98 |
|
99 |
@Override
|
100 |
public void onClick(ClickEvent event) { |
101 |
TwoAdmin.get().searchUsers("username:"+dto.getAuditInfo().getCreatedBy().getUsername());
|
102 |
|
103 |
} |
104 |
}); |
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() {
|
109 |
|
110 |
@Override
|
111 |
public void onClick(ClickEvent event) { |
112 |
TwoAdmin.get().searchUsers("username:"+dto.getAuditInfo().getModifiedBy().getUsername());
|
113 |
|
114 |
} |
115 |
}); |
116 |
|
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() {
|
121 |
@Override
|
122 |
public void onClick(ClickEvent event) { |
123 |
|
124 |
|
125 |
} |
126 |
}); |
127 |
permTable.setWidget(i, 6, downloadHtml);
|
128 |
|
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);
|
135 |
i++; |
136 |
} |
137 |
for (; i < permTable.getRowCount(); i++)
|
138 |
permTable.removeRow(i); |
139 |
} |
140 |
|
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; |
148 |
} |
149 |
|
150 |
} |