root / src / gr / ebs / gss / admin / client / ui / FilesPanel.java @ 0a37ac21
History | View | Annotate | Download (6.9 kB)
1 |
package gr.ebs.gss.admin.client.ui; |
---|---|
2 |
|
3 |
import gr.ebs.gss.admin.client.TwoAdmin; |
4 |
import gr.ebs.gss.server.domain.dto.FileBodyDTO; |
5 |
import gr.ebs.gss.server.domain.dto.FileHeaderDTO; |
6 |
import gr.ebs.gss.server.domain.dto.PermissionDTO; |
7 |
|
8 |
import java.util.ArrayList; |
9 |
import java.util.HashSet; |
10 |
import java.util.List; |
11 |
|
12 |
import com.google.gwt.core.client.GWT; |
13 |
import com.google.gwt.event.dom.client.ClickEvent; |
14 |
import com.google.gwt.event.dom.client.ClickHandler; |
15 |
import com.google.gwt.event.dom.client.KeyPressEvent; |
16 |
import com.google.gwt.event.dom.client.KeyPressHandler; |
17 |
import com.google.gwt.gen2.table.event.client.RowSelectionEvent; |
18 |
import com.google.gwt.gen2.table.event.client.RowSelectionHandler; |
19 |
import com.google.gwt.uibinder.client.UiBinder; |
20 |
import com.google.gwt.uibinder.client.UiField; |
21 |
import com.google.gwt.uibinder.client.UiHandler; |
22 |
import com.google.gwt.user.client.Command; |
23 |
import com.google.gwt.user.client.DeferredCommand; |
24 |
import com.google.gwt.user.client.rpc.AsyncCallback; |
25 |
import com.google.gwt.user.client.ui.Button; |
26 |
import com.google.gwt.user.client.ui.Composite; |
27 |
import com.google.gwt.user.client.ui.Grid; |
28 |
import com.google.gwt.user.client.ui.HTML; |
29 |
import com.google.gwt.user.client.ui.TextBox; |
30 |
import com.google.gwt.user.client.ui.Widget; |
31 |
|
32 |
public class FilesPanel extends Composite { |
33 |
|
34 |
private static UserPanelUiBinder uiBinder = GWT |
35 |
.create(UserPanelUiBinder.class); |
36 |
|
37 |
interface UserPanelUiBinder extends UiBinder<Widget, FilesPanel> { |
38 |
} |
39 |
|
40 |
|
41 |
|
42 |
@UiField TextBox searchBox;
|
43 |
@UiField Button searchButton; |
44 |
@UiField(provided=true) final FilesTable filesTable = new FilesTable(); |
45 |
@UiField(provided=true) Grid g =new Grid(9,6); |
46 |
@UiField(provided=true) PermissionsList permissionsGrid = new PermissionsList(new HashSet<PermissionDTO>(),"",true); |
47 |
@UiField(provided=true) VersionsList versionsList = new VersionsList(new ArrayList<FileBodyDTO>()); |
48 |
private Object lastQuery; |
49 |
|
50 |
public FilesPanel() {
|
51 |
g.setCellPadding(5);
|
52 |
g.setCellSpacing(5);
|
53 |
|
54 |
initWidget(uiBinder.createAndBindUi(this));
|
55 |
searchBox.addKeyPressHandler(new KeyPressHandler() {
|
56 |
|
57 |
@Override
|
58 |
public void onKeyPress(KeyPressEvent event) { |
59 |
char keyCode = event.getCharCode();
|
60 |
if (keyCode == '\r') |
61 |
handleClick(null);
|
62 |
} |
63 |
}); |
64 |
filesTable.addRowSelectionHandler(new RowSelectionHandler() {
|
65 |
|
66 |
@Override
|
67 |
public void onRowSelection(RowSelectionEvent event) { |
68 |
final FileHeaderDTO user = filesTable.getSelectedRowObject(event);
|
69 |
|
70 |
TwoAdmin.get().showLoadingBox(); |
71 |
if(user!=null) |
72 |
DeferredCommand.addCommand(new Command() {
|
73 |
|
74 |
@Override
|
75 |
public void execute() { |
76 |
TwoAdmin.get().showLoadingBox(); |
77 |
TwoAdmin.get().getAdminService().getFile(user.getId(), new AsyncCallback<FileHeaderDTO>() {
|
78 |
|
79 |
@Override
|
80 |
public void onSuccess(final FileHeaderDTO result) { |
81 |
TwoAdmin.get().getAdminService().getVersions(result.getOwner().getId(), result.getId(), new AsyncCallback<List<FileBodyDTO>>() { |
82 |
|
83 |
@Override
|
84 |
public void onFailure(Throwable caught) { |
85 |
GWT.log("Error requesting file details", caught);
|
86 |
TwoAdmin.get().hideLoadingBox(); |
87 |
TwoAdmin.get().showErrorBox("Error requesting file details");
|
88 |
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void onSuccess(List<FileBodyDTO> versions) { |
93 |
clearFileDetails(); |
94 |
displayFileDetails(result, versions); |
95 |
TwoAdmin.get().hideLoadingBox(); |
96 |
|
97 |
|
98 |
} |
99 |
|
100 |
}); |
101 |
|
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void onFailure(Throwable caught) { |
106 |
GWT.log("Error requesting user statistics file", caught);
|
107 |
TwoAdmin.get().hideLoadingBox(); |
108 |
TwoAdmin.get().showErrorBox("Error requesting user statistics");
|
109 |
|
110 |
} |
111 |
}); |
112 |
|
113 |
} |
114 |
}); |
115 |
|
116 |
} |
117 |
}); |
118 |
|
119 |
|
120 |
clearFileDetails(); |
121 |
|
122 |
} |
123 |
|
124 |
@UiHandler("searchButton") |
125 |
void handleClick(@SuppressWarnings("unused") ClickEvent e){ |
126 |
final String toSearch = searchBox.getText(); |
127 |
if(toSearch == null || "".equals(toSearch.trim())){ |
128 |
TwoAdmin.get().showErrorBox("You must enter a query");
|
129 |
return;
|
130 |
} |
131 |
lastQuery = toSearch; |
132 |
populateTable(toSearch); |
133 |
} |
134 |
|
135 |
|
136 |
|
137 |
public void populateTable(String query){ |
138 |
TwoAdmin.get().showLoadingBox(); |
139 |
TwoAdmin.get().getAdminService().searchFiles(query,new AsyncCallback<List<FileHeaderDTO>>() { |
140 |
|
141 |
@Override
|
142 |
public void onFailure(Throwable caught) { |
143 |
TwoAdmin.get().hideLoadingBox(); |
144 |
GWT.log("Error fetching files", caught);
|
145 |
TwoAdmin.get().showErrorBox("Unable to Find any Files");
|
146 |
} |
147 |
|
148 |
@Override
|
149 |
public void onSuccess(List<FileHeaderDTO> result) { |
150 |
filesTable.showUsers(result); |
151 |
clearFileDetails(); |
152 |
TwoAdmin.get().hideLoadingBox(); |
153 |
|
154 |
} |
155 |
|
156 |
}); |
157 |
} |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
public void displayFileDetails(final FileHeaderDTO file, List<FileBodyDTO> versions){ |
163 |
clearFileDetails(); |
164 |
versionsList.updateTable(versions); |
165 |
g.setHTML(0, 0, "<span>" + "Name:"); |
166 |
g.setHTML(0, 1, file.getName()+"</span>"); |
167 |
g.setHTML(1, 0, "<span>" + "URI:"); |
168 |
g.setHTML(1, 1, file.getURI()+"</span>"); |
169 |
g.setHTML(2, 0, "<span>" + "Owner:"); |
170 |
HTML userLabel =new HTML("<a href='#'>"+file.getOwner().getUsername()+"</a></span>"); |
171 |
g.setWidget(2, 1, userLabel ); |
172 |
|
173 |
userLabel.addClickHandler(new ClickHandler() {
|
174 |
|
175 |
@Override
|
176 |
public void onClick(ClickEvent event) { |
177 |
TwoAdmin.get().searchUsers("username:"+file.getOwner().getUsername());
|
178 |
|
179 |
} |
180 |
}); |
181 |
g.setHTML(3, 0, "<span>" + "Size:"); |
182 |
g.setHTML(3, 1, file.getFileSizeAsString()+"</span>"); |
183 |
g.setHTML(4, 0, "<span>" + "Content Type:"); |
184 |
g.setHTML(4, 1, file.getMimeType()+"</span>"); |
185 |
|
186 |
g.setHTML(5, 0, "<span>" + "Creation Date:"); |
187 |
g.setHTML(5, 1, file.getAuditInfo().getCreationDate()+"</span>"); |
188 |
|
189 |
g.setHTML(6, 0, "<span>" + "Modification Date:"); |
190 |
g.setHTML(6, 1, file.getAuditInfo().getModificationDate()+"</span>"); |
191 |
if(file.isVersioned())
|
192 |
g.setHTML(7, 0, "<span>" + "File is Versioned:</span>"); |
193 |
else
|
194 |
g.setHTML(7, 0, "<span>" + "File is NOT Versioned:</span>"); |
195 |
if(file.isReadForAll()){
|
196 |
g.setHTML(8, 0, "<span>" + "Read For All:"); |
197 |
g.setHTML(8, 1, file.getURI()+"</span>"); |
198 |
} |
199 |
permissionsGrid.update(file.getPermissions(), file.getURI()); |
200 |
} |
201 |
|
202 |
public void clearFileDetails(){ |
203 |
g.setHTML(0, 0, "<span>" + "Name:"); |
204 |
g.setHTML(0, 1, ""+"</span>"); |
205 |
g.setHTML(1, 0, "<span>" + "URI:"); |
206 |
g.setHTML(1, 1, ""+"</span>"); |
207 |
g.setHTML(2, 0, "<span>" + "Owner:"); |
208 |
g.setHTML(2, 1, ""+"</span>"); |
209 |
g.setHTML(3, 0, "<span>" + "Size:"); |
210 |
g.setHTML(3, 1, ""+"</span>"); |
211 |
g.setHTML(4, 0, "<span>" + "Content Type:"); |
212 |
g.setHTML(4, 1, ""+"</span>"); |
213 |
g.setHTML(5, 0, "<span>" + "Creation Date:"); |
214 |
g.setHTML(5, 1, "</span>"); |
215 |
|
216 |
g.setHTML(6, 0, "<span>" + "Modification Date:"); |
217 |
g.setHTML(6, 1, "</span>"); |
218 |
g.setHTML(7, 0, "<span>" + "File is Versioned:</span>"); |
219 |
g.setHTML(8, 0, "<span>" + "Read For All:"); |
220 |
g.setHTML(8, 1, "</span>"); |
221 |
permissionsGrid.clear(); |
222 |
versionsList.updateTable(new ArrayList<FileBodyDTO>()); |
223 |
|
224 |
|
225 |
} |
226 |
|
227 |
|
228 |
/**
|
229 |
* Retrieve the lastQuery.
|
230 |
*
|
231 |
* @return the lastQuery
|
232 |
*/
|
233 |
public Object getLastQuery() { |
234 |
return lastQuery;
|
235 |
} |
236 |
} |