root / src / gr / grnet / pithos / web / client / VersionsList.java @ a33428e4
History | View | Annotate | Download (9.7 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | 63366925 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.FilePropertiesDialog.Images; |
38 | a57faaf0 | Christos Stathis | |
39 | a57faaf0 | Christos Stathis | import java.util.ArrayList; |
40 | a57faaf0 | Christos Stathis | import java.util.Collections; |
41 | a57faaf0 | Christos Stathis | import java.util.Comparator; |
42 | a57faaf0 | Christos Stathis | import java.util.Date; |
43 | a57faaf0 | Christos Stathis | import java.util.List; |
44 | a57faaf0 | Christos Stathis | |
45 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
46 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.i18n.client.DateTimeFormat; |
48 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Window; |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
50 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
55 | a57faaf0 | Christos Stathis | |
56 | a57faaf0 | Christos Stathis | public class VersionsList extends Composite { |
57 | a57faaf0 | Christos Stathis | |
58 | f6445935 | Christos Stathis | // private Pithos app;
|
59 | f6445935 | Christos Stathis | //
|
60 | f6445935 | Christos Stathis | // int selectedRow = -1;
|
61 | f6445935 | Christos Stathis | //
|
62 | f6445935 | Christos Stathis | // int permissionCount = -1;
|
63 | f6445935 | Christos Stathis | //
|
64 | f6445935 | Christos Stathis | // List<FileResource> versions = null;
|
65 | f6445935 | Christos Stathis | //
|
66 | f6445935 | Christos Stathis | // final Images images;
|
67 | f6445935 | Christos Stathis | //
|
68 | f6445935 | Christos Stathis | // final VerticalPanel permPanel = new VerticalPanel();
|
69 | f6445935 | Christos Stathis | //
|
70 | f6445935 | Christos Stathis | // final FlexTable permTable = new FlexTable();
|
71 | f6445935 | Christos Stathis | //
|
72 | f6445935 | Christos Stathis | // FileResource toRemove = null;
|
73 | f6445935 | Christos Stathis | //
|
74 | f6445935 | Christos Stathis | // FilePropertiesDialog container;
|
75 | f6445935 | Christos Stathis | //
|
76 | f6445935 | Christos Stathis | // public VersionsList(Pithos _app, FilePropertiesDialog aContainer, final Images theImages, List<FileResource> theVersions) {
|
77 | f6445935 | Christos Stathis | // app = _app;
|
78 | f6445935 | Christos Stathis | // images = theImages;
|
79 | f6445935 | Christos Stathis | // container = aContainer;
|
80 | f6445935 | Christos Stathis | // versions = theVersions;
|
81 | f6445935 | Christos Stathis | // Collections.sort(theVersions, new Comparator<FileResource>(){
|
82 | f6445935 | Christos Stathis | //
|
83 | f6445935 | Christos Stathis | // @Override
|
84 | f6445935 | Christos Stathis | // public int compare(FileResource o1, FileResource o2) {
|
85 | f6445935 | Christos Stathis | // return o1.getVersion().compareTo(o2.getVersion());
|
86 | f6445935 | Christos Stathis | // }
|
87 | f6445935 | Christos Stathis | //
|
88 | f6445935 | Christos Stathis | // });
|
89 | f6445935 | Christos Stathis | // permTable.setText(0, 0, "Version");
|
90 | f6445935 | Christos Stathis | // permTable.setText(0, 1, "Created");
|
91 | f6445935 | Christos Stathis | // permTable.setText(0, 2, "Modified");
|
92 | f6445935 | Christos Stathis | // permTable.setText(0, 3, "Size");
|
93 | f6445935 | Christos Stathis | // permTable.setText(0, 4, "");
|
94 | f6445935 | Christos Stathis | // permTable.setText(0, 5, "");
|
95 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
|
96 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
|
97 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
|
98 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
|
99 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setColSpan(0, 1, 2);
|
100 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
|
101 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
102 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
103 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
104 | f6445935 | Christos Stathis | // permPanel.add(permTable);
|
105 | f6445935 | Christos Stathis | // permPanel.addStyleName("pithos-TabPanelBottom");
|
106 | f6445935 | Christos Stathis | // permTable.addStyleName("pithos-permList");
|
107 | f6445935 | Christos Stathis | // initWidget(permPanel);
|
108 | f6445935 | Christos Stathis | // updateTable();
|
109 | f6445935 | Christos Stathis | // }
|
110 | f6445935 | Christos Stathis | //
|
111 | f6445935 | Christos Stathis | // public void updateTable() {
|
112 | f6445935 | Christos Stathis | // copyListAndContinue(versions);
|
113 | f6445935 | Christos Stathis | // }
|
114 | f6445935 | Christos Stathis | //
|
115 | f6445935 | Christos Stathis | // public void showVersionsTable(){
|
116 | f6445935 | Christos Stathis | // int i = 1;
|
117 | f6445935 | Christos Stathis | // if (toRemove != null) {
|
118 | f6445935 | Christos Stathis | // versions.remove(toRemove);
|
119 | f6445935 | Christos Stathis | // toRemove = null;
|
120 | f6445935 | Christos Stathis | // }
|
121 | f6445935 | Christos Stathis | // for (final FileResource dto : versions) {
|
122 | f6445935 | Christos Stathis | // HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>"+AbstractImagePrototype.create(images.restore()).getHTML()+"</span><div>Restore this Version</div></a>");
|
123 | f6445935 | Christos Stathis | // restoreVersion.addClickHandler(new ClickHandler() {
|
124 | f6445935 | Christos Stathis | // @Override
|
125 | f6445935 | Christos Stathis | // public void onClick(ClickEvent event) {
|
126 | f6445935 | Christos Stathis | // restoreVersion(dto);
|
127 | f6445935 | Christos Stathis | // }
|
128 | f6445935 | Christos Stathis | // });
|
129 | f6445935 | Christos Stathis | //
|
130 | f6445935 | Christos Stathis | // permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>");
|
131 | f6445935 | Christos Stathis | // permTable.setHTML(i, 1, "<span>" + formatDate(dto.getCreationDate()) + " by " + app.findUserFullName(dto.getCreatedBy()) + "</span>");
|
132 | f6445935 | Christos Stathis | // permTable.setHTML(i, 2, "<span>" + formatDate(dto.getModificationDate()) + " by " + app.findUserFullName(dto.getModifiedBy()) + "</span>");
|
133 | f6445935 | Christos Stathis | // permTable.setHTML(i, 3, "<span>" + dto.getFileSizeAsString() + "</span>");
|
134 | f6445935 | Christos Stathis | // HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>");
|
135 | f6445935 | Christos Stathis | // downloadHtml.addClickHandler(new ClickHandler() {
|
136 | f6445935 | Christos Stathis | // @Override
|
137 | f6445935 | Christos Stathis | // public void onClick(ClickEvent event) {
|
138 | f6445935 | Christos Stathis | // String fileUrl = dto.getUri() + "?version=" + dto.getVersion();
|
139 | f6445935 | Christos Stathis | // Window.open(fileUrl, "_BLANK", "");
|
140 | f6445935 | Christos Stathis | // }
|
141 | f6445935 | Christos Stathis | // });
|
142 | f6445935 | Christos Stathis | // permTable.setWidget(i, 4, downloadHtml);
|
143 | f6445935 | Christos Stathis | // permTable.setWidget(i, 5, restoreVersion);
|
144 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
|
145 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER);
|
146 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
147 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setColSpan(i, 1, 2);
|
148 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
149 | f6445935 | Christos Stathis | // permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
150 | f6445935 | Christos Stathis | // i++;
|
151 | f6445935 | Christos Stathis | // }
|
152 | f6445935 | Christos Stathis | // for (; i < permTable.getRowCount(); i++)
|
153 | f6445935 | Christos Stathis | // permTable.removeRow(i);
|
154 | f6445935 | Christos Stathis | // }
|
155 | f6445935 | Christos Stathis | //
|
156 | f6445935 | Christos Stathis | // void restoreVersion(final FileResource version) {
|
157 | f6445935 | Christos Stathis | //// FileResource selectedFile = (FileResource) app.getCurrentSelection();
|
158 | f6445935 | Christos Stathis | //// PostCommand ep = new PostCommand(app, selectedFile.getUri()+"?restoreVersion="+version.getVersion(),"",200){
|
159 | f6445935 | Christos Stathis | ////
|
160 | f6445935 | Christos Stathis | ////
|
161 | f6445935 | Christos Stathis | //// @Override
|
162 | f6445935 | Christos Stathis | //// public void onComplete() {
|
163 | f6445935 | Christos Stathis | //// container.hide();
|
164 | f6445935 | Christos Stathis | //// app.getTreeView().refreshCurrentNode(false);
|
165 | f6445935 | Christos Stathis | //// }
|
166 | f6445935 | Christos Stathis | ////
|
167 | f6445935 | Christos Stathis | //// @Override
|
168 | f6445935 | Christos Stathis | //// public void onError(Throwable t) {
|
169 | f6445935 | Christos Stathis | //// GWT.log("", t);
|
170 | f6445935 | Christos Stathis | //// if(t instanceof RestException)
|
171 | f6445935 | Christos Stathis | //// app.displayError("Unable to restore version:"+((RestException)t).getHttpStatusText());
|
172 | f6445935 | Christos Stathis | //// else
|
173 | f6445935 | Christos Stathis | //// app.displayError("System error restoring version:"+t.getMessage());
|
174 | f6445935 | Christos Stathis | //// }
|
175 | f6445935 | Christos Stathis | ////
|
176 | f6445935 | Christos Stathis | //// };
|
177 | f6445935 | Christos Stathis | //// DeferredCommand.addCommand(ep);
|
178 | f6445935 | Christos Stathis | // }
|
179 | f6445935 | Christos Stathis | //
|
180 | f6445935 | Christos Stathis | // private String formatDate(Date date){
|
181 | f6445935 | Christos Stathis | // DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy : HH:mm");
|
182 | f6445935 | Christos Stathis | // return format.format(date);
|
183 | f6445935 | Christos Stathis | // }
|
184 | f6445935 | Christos Stathis | //
|
185 | f6445935 | Christos Stathis | // /**
|
186 | f6445935 | Christos Stathis | // * Copies the input List to a new List
|
187 | f6445935 | Christos Stathis | // * @param input
|
188 | f6445935 | Christos Stathis | // */
|
189 | f6445935 | Christos Stathis | // private void copyListAndContinue(List<FileResource> input){
|
190 | f6445935 | Christos Stathis | // List<FileResource> copiedInput = new ArrayList<FileResource>();
|
191 | f6445935 | Christos Stathis | // for(FileResource dto : input) {
|
192 | f6445935 | Christos Stathis | // copiedInput.add(dto);
|
193 | f6445935 | Christos Stathis | // }
|
194 | f6445935 | Christos Stathis | // handleFullNames(copiedInput);
|
195 | f6445935 | Christos Stathis | // }
|
196 | f6445935 | Christos Stathis | //
|
197 | f6445935 | Christos Stathis | // /**
|
198 | f6445935 | Christos Stathis | // * Examines whether or not the user's full name exists in the
|
199 | f6445935 | Christos Stathis | // * userFullNameMap in the Pithos.java for every element of the input list.
|
200 | f6445935 | Christos Stathis | // * If the user's full name does not exist in the map then a request is being made
|
201 | f6445935 | Christos Stathis | // * for the specific username.
|
202 | f6445935 | Christos Stathis | // *
|
203 | f6445935 | Christos Stathis | // * @param input
|
204 | f6445935 | Christos Stathis | // */
|
205 | f6445935 | Christos Stathis | // private void handleFullNames(List<FileResource> input){
|
206 | f6445935 | Christos Stathis | // if(input.isEmpty()){
|
207 | f6445935 | Christos Stathis | // showVersionsTable();
|
208 | f6445935 | Christos Stathis | // return;
|
209 | f6445935 | Christos Stathis | // }
|
210 | f6445935 | Christos Stathis | //
|
211 | f6445935 | Christos Stathis | // if(app.findUserFullName(input.get(0).getOwner()) == null){
|
212 | f6445935 | Christos Stathis | // findFullNameAndUpdate(input);
|
213 | f6445935 | Christos Stathis | // return;
|
214 | f6445935 | Christos Stathis | // }
|
215 | f6445935 | Christos Stathis | //
|
216 | f6445935 | Christos Stathis | // if(input.size() >= 1){
|
217 | f6445935 | Christos Stathis | // input.remove(input.get(0));
|
218 | f6445935 | Christos Stathis | // if(input.isEmpty()){
|
219 | f6445935 | Christos Stathis | // showVersionsTable();
|
220 | f6445935 | Christos Stathis | // }else{
|
221 | f6445935 | Christos Stathis | // handleFullNames(input);
|
222 | f6445935 | Christos Stathis | // }
|
223 | f6445935 | Christos Stathis | // }
|
224 | f6445935 | Christos Stathis | // }
|
225 | f6445935 | Christos Stathis | //
|
226 | f6445935 | Christos Stathis | // /**
|
227 | f6445935 | Christos Stathis | // * Makes a request to search for full name from a given username
|
228 | f6445935 | Christos Stathis | // * and continues checking the next element of the List.
|
229 | f6445935 | Christos Stathis | // *
|
230 | f6445935 | Christos Stathis | // * @param input
|
231 | f6445935 | Christos Stathis | // */
|
232 | f6445935 | Christos Stathis | //
|
233 | f6445935 | Christos Stathis | // private void findFullNameAndUpdate(final List<FileResource> input){
|
234 | f6445935 | Christos Stathis | //// final String aUserName = input.get(0).getOwner();
|
235 | f6445935 | Christos Stathis | //// String path = app.getApiPath() + "users/" + aUserName;
|
236 | f6445935 | Christos Stathis | ////
|
237 | f6445935 | Christos Stathis | //// GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(app, UserSearchResource.class, path, false,null) {
|
238 | f6445935 | Christos Stathis | //// @Override
|
239 | f6445935 | Christos Stathis | //// public void onComplete() {
|
240 | f6445935 | Christos Stathis | //// final UserSearchResource result = getResult();
|
241 | f6445935 | Christos Stathis | //// for (UserResource user : result.getUsers()){
|
242 | f6445935 | Christos Stathis | //// String username = user.getUsername();
|
243 | f6445935 | Christos Stathis | //// String userFullName = user.getName();
|
244 | f6445935 | Christos Stathis | //// app.putUserToMap(username, userFullName);
|
245 | f6445935 | Christos Stathis | //// if(input.size() >= 1){
|
246 | f6445935 | Christos Stathis | //// input.remove(input.get(0));
|
247 | f6445935 | Christos Stathis | //// if(input.isEmpty()){
|
248 | f6445935 | Christos Stathis | //// showVersionsTable();
|
249 | f6445935 | Christos Stathis | //// return;
|
250 | f6445935 | Christos Stathis | //// }
|
251 | f6445935 | Christos Stathis | //// handleFullNames(input);
|
252 | f6445935 | Christos Stathis | //// }
|
253 | f6445935 | Christos Stathis | //// }
|
254 | f6445935 | Christos Stathis | //// }
|
255 | f6445935 | Christos Stathis | //// @Override
|
256 | f6445935 | Christos Stathis | //// public void onError(Throwable t) {
|
257 | f6445935 | Christos Stathis | //// app.displayError("Unable to fetch user's full name from the given username " + aUserName);
|
258 | f6445935 | Christos Stathis | //// if(input.size() >= 1){
|
259 | f6445935 | Christos Stathis | //// input.remove(input.get(0));
|
260 | f6445935 | Christos Stathis | //// handleFullNames(input);
|
261 | f6445935 | Christos Stathis | //// }
|
262 | f6445935 | Christos Stathis | //// }
|
263 | f6445935 | Christos Stathis | //// };
|
264 | f6445935 | Christos Stathis | //// DeferredCommand.addCommand(gg);
|
265 | f6445935 | Christos Stathis | //
|
266 | f6445935 | Christos Stathis | // }
|
267 | f6445935 | Christos Stathis | //
|
268 | a57faaf0 | Christos Stathis | } |