This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
DocumentListView.java
423 lines (356 loc) · 10.8 KB
/
DocumentListView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.webtrans.client.view;
import java.util.HashMap;
import java.util.List;
import org.zanata.common.TranslationStats;
import org.zanata.webtrans.client.Application;
import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.DocumentListTable;
import org.zanata.webtrans.client.ui.DocumentListTable.DocValidationStatus;
import org.zanata.webtrans.client.ui.DocumentNode;
import org.zanata.webtrans.client.ui.DownloadFilesConfirmationBox;
import org.zanata.webtrans.client.ui.FileUploadDialog;
import org.zanata.webtrans.client.ui.HasPager;
import org.zanata.webtrans.client.ui.InlineLink;
import org.zanata.webtrans.client.ui.LoadingPanel;
import org.zanata.webtrans.client.ui.Pager;
import org.zanata.webtrans.client.ui.SearchField;
import org.zanata.webtrans.shared.model.AuditInfo;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.model.WorkspaceId;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
public class DocumentListView extends Composite implements DocumentListDisplay
{
interface DocumentListViewUiBinder extends UiBinder<LayoutPanel, DocumentListView>
{
}
private static DocumentListViewUiBinder uiBinder = GWT.create(DocumentListViewUiBinder.class);
private DocumentListDisplay.Listener listener;
@UiField(provided = true)
SearchField searchField;
@UiField
FlowPanel documentListContainer;
@UiField
CheckBox exactSearchCheckBox, caseSensitiveCheckBox;
@UiField
RadioButton statsByMsg, statsByWord;
@UiField
PushButton downloadAllFiles;
@UiField(provided = true)
Pager pager;
private DocumentListTable documentListTable;
private final DownloadFilesConfirmationBox confirmationBox;
private final FileUploadDialog fileUploadDialog;
private final LoadingPanel loadingPanel;
private Timer timer = new Timer()
{
public void run()
{
getDownloadStatus();
}
};
@Inject
public DocumentListView(Resources resources, WebTransMessages messages, UserWorkspaceContext userworkspaceContext, LoadingPanel loadingPanel)
{
this.loadingPanel = loadingPanel;
confirmationBox = new DownloadFilesConfirmationBox(false, messages, resources);
fileUploadDialog = new FileUploadDialog(resources);
pager = new Pager(messages, resources);
searchField = new SearchField(this);
searchField.setTextBoxTitle(messages.docListFilterDescription());
initWidget(uiBinder.createAndBindUi(this));
caseSensitiveCheckBox.setTitle(messages.docListFilterCaseSensitiveDescription());
exactSearchCheckBox.setTitle(messages.docListFilterExactMatchDescription());
statsByMsg.setText(messages.byMessage());
statsByWord.setText(messages.byWords());
documentListTable = new DocumentListTable(userworkspaceContext, messages,resources);
documentListContainer.add(documentListTable);
}
@Override
public Widget asWidget()
{
return this;
}
@Override
public String getSelectedStatsOption()
{
if (statsByMsg.getValue())
{
return STATS_OPTION_MESSAGE;
}
else
{
return STATS_OPTION_WORDS;
}
}
@UiHandler("exactSearchCheckBox")
public void onExactSearchCheckboxChange(ValueChangeEvent<Boolean> event)
{
listener.fireExactSearchToken(event.getValue());
}
@UiHandler("caseSensitiveCheckBox")
public void onCaseSensitiveCheckboxValueChange(ValueChangeEvent<Boolean> event)
{
listener.fireCaseSensitiveToken(event.getValue());
}
@UiHandler("statsByMsg")
public void onStatsByMsgChange(ValueChangeEvent<Boolean> event)
{
if (event.getValue())
{
listener.statsOptionChange();
}
}
@UiHandler("statsByWord")
public void onStatsByWordChange(ValueChangeEvent<Boolean> event)
{
if (event.getValue())
{
listener.statsOptionChange();
}
}
@UiHandler("downloadAllFiles")
public void onDownloadAllFilesClick(ClickEvent event)
{
confirmationBox.center();
}
@UiHandler("pager")
public void onPagerValueChanged(ValueChangeEvent<Integer> event)
{
listener.pagerValueChanged(event.getValue());
}
@Override
public void setLayout(String layout)
{
documentListContainer.setStyleName(layout);
}
@Override
public void updateFilter(boolean docFilterCaseSensitive, boolean docFilterExact, String docFilterText)
{
caseSensitiveCheckBox.setValue(docFilterCaseSensitive, false);
exactSearchCheckBox.setValue(docFilterExact, false);
searchField.setText(docFilterText);
}
@Override
public void setListener(Listener documentListPresenter)
{
this.listener = documentListPresenter;
confirmationBox.registerHandler(listener);
fileUploadDialog.registerHandler(listener, Application.getUploadFileUrl());
documentListTable.setListener(listener);
}
@Override
public void onSearchFieldValueChange(String value)
{
listener.fireFilterToken(value);
}
@Override
public void onSearchFieldCancel()
{
searchField.setValue("");
}
@Override
public void onSearchFieldBlur()
{
}
@Override
public void onSearchFieldFocus()
{
}
@Override
public void onSearchFieldClick()
{
}
@Override
public void hideConfirmation()
{
confirmationBox.hide();
}
@Override
public void updateFileDownloadProgress(int currentProgress, int maxProgress)
{
confirmationBox.setProgressMessage(currentProgress + " of " + maxProgress);
}
@Override
public void setDownloadInProgress(boolean inProgress)
{
confirmationBox.setInProgress(inProgress);
}
@Override
public void setAndShowFilesDownloadLink(String url)
{
confirmationBox.setDownloadLink(url);
confirmationBox.showDownloadLink(true);
}
@Override
public InlineLink getDownloadAllFilesInlineLink(final String url)
{
return new InlineLink()
{
@Override
public Widget asWidget()
{
Anchor anchor = new Anchor();
anchor.setStyleName("icon-download");
anchor.addStyleName("downloadLink");
anchor.setHref(url);
anchor.setTarget("_blank");
return anchor;
}
@Override
public void setLinkStyle(String styleName)
{
}
@Override
public void setDisabledStyle(String styleName)
{
}
};
}
@Override
public void showUploadDialog(DocumentInfo info, WorkspaceId workspaceId)
{
fileUploadDialog.setDocumentInfo(info, workspaceId);
fileUploadDialog.center();
}
@Override
public void closeFileUpload()
{
fileUploadDialog.hide();
}
@Override
public String getSelectedUploadFileName()
{
return fileUploadDialog.getUploadFileName();
}
@Override
public void submitUploadForm()
{
fileUploadDialog.submitForm();
}
@Override
public void startGetDownloadStatus(int periodMillis)
{
timer.scheduleRepeating(periodMillis);
}
public void getDownloadStatus()
{
listener.updateDownloadFileProgress();
}
@Override
public void stopGetDownloadStatus()
{
timer.cancel();
}
@Override
public void setEnableDownloadZip(boolean enabled)
{
downloadAllFiles.setEnabled(enabled);
}
@Override
public void setDownloadZipButtonText(String text)
{
downloadAllFiles.setText(text);
}
@Override
public void setDownloadZipButtonTitle(String title)
{
downloadAllFiles.setTitle(title);
}
@Override
public void showLoading(boolean showLoading)
{
if (showLoading)
{
loadingPanel.center();
}
else
{
loadingPanel.hide();
}
}
@Override
public HashMap<DocumentId, Integer> buildContent(List<DocumentNode> nodes)
{
return documentListTable.buildContent(nodes, statsByWord.getValue().booleanValue());
}
@Override
public void updateRowHasError(int row, DocValidationStatus status)
{
documentListTable.updateRowHasError(row, status);
}
@Override
public void updateLastTranslated(int row, AuditInfo lastTranslated)
{
documentListTable.updateLastTranslatedInfo(row, lastTranslated);
}
@Override
public void updateStats(int row, TranslationStats stats)
{
documentListTable.updateStats(row, stats, statsByWord.getValue().booleanValue());
}
@Override
public void setStatsFilters(Integer row)
{
documentListTable.setStatsFilter(statsByWord.getValue().booleanValue(), row);
}
@Override
public void setStatsFilters(String option)
{
if (option.equals(STATS_OPTION_MESSAGE))
{
statsByMsg.setValue(true);
}
else
{
statsByWord.setValue(true);
}
}
@Override
public HasPager getPageNavigation()
{
return pager;
}
@Override
public void showRowLoading(int row)
{
documentListTable.showRowLoading(row);
}
}