/
FileBrowser.java
2574 lines (2247 loc) · 83.6 KB
/
FileBrowser.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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* OpenKM, Open Document Management System (http://www.openkm.com)
* Copyright (c) 2006-2017 Paco Avila & Josep Llort
* <p>
* No bytes were intentionally harmed during the development of this application.
* <p>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* <p>
* This program 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 General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.openkm.frontend.client.widget.filebrowser;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DragEnterEvent;
import com.google.gwt.event.dom.client.DragEnterHandler;
import com.google.gwt.gen2.table.client.AbstractScrollTable.ScrollTableImages;
import com.google.gwt.gen2.table.client.FixedWidthFlexTable;
import com.google.gwt.gen2.table.client.FixedWidthGrid;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.openkm.extension.frontend.client.widget.htmleditor.HTMLEditor;
import com.openkm.frontend.client.Main;
import com.openkm.frontend.client.bean.*;
import com.openkm.frontend.client.constants.ui.UIDesktopConstants;
import com.openkm.frontend.client.constants.ui.UIFileUploadConstants;
import com.openkm.frontend.client.extension.event.HasDocumentEvent;
import com.openkm.frontend.client.extension.event.HasFolderEvent;
import com.openkm.frontend.client.extension.event.HasMailEvent;
import com.openkm.frontend.client.extension.event.handler.DocumentHandlerExtension;
import com.openkm.frontend.client.extension.event.handler.FolderHandlerExtension;
import com.openkm.frontend.client.extension.event.handler.MailHandlerExtension;
import com.openkm.frontend.client.extension.event.hashandler.HasDocumentHandlerExtension;
import com.openkm.frontend.client.extension.event.hashandler.HasFolderHandlerExtension;
import com.openkm.frontend.client.extension.event.hashandler.HasMailHandlerExtension;
import com.openkm.frontend.client.service.*;
import com.openkm.frontend.client.util.OKMBundleResources;
import com.openkm.frontend.client.util.ScrollTableHelper;
import com.openkm.frontend.client.util.Util;
import com.openkm.frontend.client.widget.ConfirmPopup;
import com.openkm.frontend.client.widget.MenuPopup;
import com.openkm.frontend.client.widget.OriginPanel;
import com.openkm.frontend.client.widget.filebrowser.menu.*;
import com.openkm.frontend.client.widget.filebrowser.uploader.DragAndDropUploader;
import com.openkm.frontend.client.widget.foldertree.FolderSelectPopup;
import java.util.*;
/**
* File browser panel
*
* @author jllort
*/
public class FileBrowser extends Composite implements OriginPanel, HasDocumentEvent, HasFolderEvent, HasMailEvent,
HasDocumentHandlerExtension, HasFolderHandlerExtension, HasMailHandlerExtension {
private final OKMPaginationServiceAsync paginationService = GWT.create(OKMPaginationService.class);
private final OKMDocumentServiceAsync documentService = GWT.create(OKMDocumentService.class);
private final OKMMassiveServiceAsync massiveService = GWT.create(OKMMassiveService.class);
private final OKMFolderServiceAsync folderService = GWT.create(OKMFolderService.class);
private final OKMNotifyServiceAsync notifyService = GWT.create(OKMNotifyService.class);
private final OKMMailServiceAsync mailService = GWT.create(OKMMailService.class);
public static final int STATUS_SIZE = 26;
// Refreshing next controler values
private static final int GET_NONE = -1;
private static final int GET_FOLDERS = 0;
private static final int GET_DOCUMENTS = 1;
private static final int GET_MAILS = 2;
private static final int GET_ENDS = 3;
// Definitions of fileBrowser actions
public static final int ACTION_NONE = -1;
public static final int ACTION_SECURITY_REFRESH_FOLDER = 0;
public static final int ACTION_SECURITY_REFRESH_DOCUMENT = 1;
public static final int ACTION_RENAME = 2;
public static final int ACTION_SECURITY_REFRESH_MAIL = 3;
public static final int ACTION_PROPERTY_GROUP_REFRESH_FOLDER = 4;
public static final int ACTION_PROPERTY_GROUP_REFRESH_DOCUMENT = 5;
public static final int ACTION_PROPERTY_GROUP_REFRESH_MAIL = 6;
// Number of columns
private int numberOfColumns = 0;
private HTML separator;
public VerticalPanel panel;
public FocusPanel focusPanel;
public ExtendedScrollTable table;
private FixedWidthFlexTable headerTable;
private FixedWidthGrid dataTable;
private FilePath filePath;
public MenuPopup taxonomyMenuPopup;
public MenuPopup categoriesMenuPopup;
public MenuPopup metadataMenuPopup;
public MenuPopup thesaurusMenuPopup;
public MenuPopup trashMenuPopup;
public MenuPopup templatesMenuPopup;
public MenuPopup personalMenuPopup;
public MenuPopup mailMenuPopup;
public MenuPopup massiveOperationsMenuPopup;
public Status status;
private com.openkm.frontend.client.widget.massive.Status massiveStatus;
private FileTextBox fileTextBox;
private String fldId;
// Indicates if panel is selected
private boolean panelSelected = false;
// Used to continue selecting the same row before resfreshing the same directory
private String selectedRowId = "";
// Used on rename to preserve initial value name
private String initialRowValueName = "";
private GWTFolder tmpFolder;
// To control rename and create folder actions
public int fileBrowserAction = ACTION_NONE;
// Used to indicate the actual view
private int actualView = UIDesktopConstants.NAVIGATOR_TAXONOMY;
private HashMap<String, Controller> viewValues;
private int numberOfFolders = 0;
private int numberOfDocuments = 0;
private int numberOfMails = 0;
private List<DocumentHandlerExtension> docHandlerExtensionList;
private List<FolderHandlerExtension> folderHandlerExtensionList;
private List<MailHandlerExtension> mailHandlerExtensionList;
// columns index
private GWTProfileFileBrowser profileFileBrowser;
private GWTProfilePagination profilePagination;
private int colNameIndex = 0;
private int colSizeIndex = 0;
private int colLastModifiedIndex = 0;
private int colAuthorIndex = 0;
private int colVersionIndex = 0;
// Controller
private FileBrowserController fBController;
private int nextRefresh = GET_NONE;
private Map<String, GWTFilter> mapFilter;
// Drag and drop box
private DragAndDropBox dragAndDropBox;
/**
* FileBrowser
*/
public FileBrowser() {
// Sets the actual view and view values hashMap object
actualView = UIDesktopConstants.NAVIGATOR_TAXONOMY;
viewValues = new HashMap<>();
docHandlerExtensionList = new ArrayList<>();
folderHandlerExtensionList = new ArrayList<>();
mailHandlerExtensionList = new ArrayList<>();
mapFilter = new LinkedHashMap<>();
panel = new VerticalPanel();
filePath = new FilePath();
ScrollTableImages scrollTableImages = new ScrollTableImages() {
/*
* (non-Javadoc)
* @see com.google.gwt.gen2.table.client.AbstractScrollTable.
* ScrollTableImages#scrollTableAscending()
*/
public AbstractImagePrototype scrollTableAscending() {
return new AbstractImagePrototype() {
public void applyTo(Image image) {
image.setUrl("img/sort_asc.gif");
}
public Image createImage() {
return new Image("img/sort_asc.gif");
}
public String getHTML() {
return "<img border=\"0\" src=\"img/sort_asc.gif\"/>";
}
};
}
/*
* (non-Javadoc)
* @see com.google.gwt.gen2.table.client.AbstractScrollTable.
* ScrollTableImages#scrollTableDescending()
*/
public AbstractImagePrototype scrollTableDescending() {
return new AbstractImagePrototype() {
public void applyTo(Image image) {
image.setUrl("img/sort_desc.gif");
}
public Image createImage() {
return new Image("img/sort_desc.gif");
}
public String getHTML() {
return "<img border=\"0\" src=\"img/sort_desc.gif\"/>";
}
};
}
/*
* (non-Javadoc)
* @see com.google.gwt.gen2.table.client.AbstractScrollTable.
* ScrollTableImages#scrollTableFillWidth()
*/
public AbstractImagePrototype scrollTableFillWidth() {
return new AbstractImagePrototype() {
public void applyTo(Image image) {
image.setUrl("img/fill_width.gif");
}
public Image createImage() {
return new Image("img/fill_width.gif");
}
public String getHTML() {
return "<img border=\"0\" src=\"img/fill_width.gif\"/>";
}
};
}
};
headerTable = new FixedWidthFlexTable();
dataTable = new FixedWidthGrid();
table = new ExtendedScrollTable(dataTable, headerTable, scrollTableImages);
table.setSize("100%", "100%");
table.setCellSpacing(0);
table.setCellPadding(0);
headerTable.addStyleName("okm-DisableSelect");
table.addStyleName("okm-Input");
taxonomyMenuPopup = new MenuPopup(new TaxonomyMenu());
taxonomyMenuPopup.setStyleName("okm-MenuPopup");
categoriesMenuPopup = new MenuPopup(new CategoriesMenu());
categoriesMenuPopup.setStyleName("okm-MenuPopup");
metadataMenuPopup = new MenuPopup(new MetadataMenu());
metadataMenuPopup.setStyleName("okm-MenuPopup");
thesaurusMenuPopup = new MenuPopup(new ThesaurusMenu());
thesaurusMenuPopup.setStyleName("okm-MenuPopup");
trashMenuPopup = new MenuPopup(new TrashMenu());
trashMenuPopup.setStyleName("okm-MenuPopup");
templatesMenuPopup = new MenuPopup(new TemplatesMenu());
templatesMenuPopup.setStyleName("okm-MenuPopup");
personalMenuPopup = new MenuPopup(new PersonalMenu());
personalMenuPopup.setStyleName("okm-MenuPopup");
mailMenuPopup = new MenuPopup(new MailMenu());
mailMenuPopup.setStyleName("okm-MenuPopup");
massiveOperationsMenuPopup = new MenuPopup(new MassiveOperationsMenu());
massiveOperationsMenuPopup.setStyleName("okm-MenuPopup");
status = new Status(this);
status.setStyleName("okm-StatusPopup");
massiveStatus = new com.openkm.frontend.client.widget.massive.Status(this);
massiveStatus.setStyleName("okm-StatusPopup");
fileTextBox = new FileTextBox();
separator = Util.vSpace("4px");
separator.setWidth("100%");
separator.setStyleName("okm-FileBrowser-Separator");
panel.add(filePath);
panel.add(separator);
panel.add(table);
panel.setSize("100%", "100%");
panel.setCellHeight(filePath, "22px");
panel.setCellHeight(separator, "4px");
panel.setCellWidth(filePath, "100%");
panel.setCellWidth(separator, "100%");
panel.setCellVerticalAlignment(table, VerticalPanel.ALIGN_TOP);
panel.setVerticalAlignment(VerticalPanel.ALIGN_TOP);
focusPanel = new FocusPanel(panel);
dragAndDropBox = new DragAndDropBox();
dragAndDropBox.setVisible(false);
panel.add(dragAndDropBox);
if (DragAndDropUploader.isHTML5DragAndDropApiSupported()) {
focusPanel.addDragEnterHandler(new DragEnterHandler() {
@Override
public void onDragEnter(DragEnterEvent arg0) {
if (actualView != UIDesktopConstants.NAVIGATOR_TRASH && actualView != UIDesktopConstants.NAVIGATOR_METADATA
&& actualView != UIDesktopConstants.NAVIGATOR_CATEGORIES) {
dragAndDropBox.show(panel.getOffsetWidth(), panel.getOffsetHeight(), panel.getAbsoluteLeft(), panel.getAbsoluteTop());
}
}
});
}
initWidget(focusPanel);
}
/**
* Get actual path from view.
*/
public String getActualPath() {
if (Main.get() != null && Main.get().activeFolderTree != null) {
return Main.get().activeFolderTree.getActualPath();
} else {
return "";
}
}
/**
* Resets the file browser values
*/
public void reset() {
selectedRowId = "";
table.reset();
}
/**
* Refresh languague values
*/
public void langRefresh() {
fBController.clearOrderBy();
fBController.addOrderByItem("", String.valueOf(GWTPaginated.COL_NONE));
int row = 0;
if (profilePagination.isPaginationEnabled() || profilePagination.isTypeFilterEnabled()
|| profilePagination.isMiscFilterEnabled()) {
row++;
}
if (profileFileBrowser.isIconVisible()) {
fBController.addOrderByItem(Main.i18n("filebrowser.type"), String.valueOf(GWTPaginated.COL_TYPE));
}
if (profileFileBrowser.isNameVisible()) {
headerTable.setHTML(row, colNameIndex, Main.i18n("filebrowser.name"));
fBController.addOrderByItem(Main.i18n("filebrowser.name"), String.valueOf(GWTPaginated.COL_NAME));
}
if (profileFileBrowser.isSizeVisible()) {
headerTable.setHTML(row, colSizeIndex, Main.i18n("filebrowser.size"));
fBController.addOrderByItem(Main.i18n("filebrowser.size"), String.valueOf(GWTPaginated.COL_SIZE));
}
if (profileFileBrowser.isLastModifiedVisible()) {
headerTable.setHTML(row, colLastModifiedIndex, Main.i18n("filebrowser.date.update"));
fBController.addOrderByItem(Main.i18n("filebrowser.date.update"), String.valueOf(GWTPaginated.COL_DATE));
}
if (profileFileBrowser.isAuthorVisible()) {
headerTable.setHTML(row, colAuthorIndex, Main.i18n("filebrowser.author"));
fBController.addOrderByItem(Main.i18n("filebrowser.author"), String.valueOf(GWTPaginated.COL_AUTHOR));
}
if (profileFileBrowser.isVersionVisible()) {
headerTable.setHTML(row, colVersionIndex, Main.i18n("filebrowser.version"));
fBController.addOrderByItem(Main.i18n("filebrowser.version"), String.valueOf(GWTPaginated.COL_VERSION));
}
if (profileFileBrowser.getColumn0() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn0().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN0));
}
if (profileFileBrowser.getColumn1() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn1().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN1));
}
if (profileFileBrowser.getColumn2() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn2().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN2));
}
if (profileFileBrowser.getColumn3() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn3().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN3));
}
if (profileFileBrowser.getColumn4() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn4().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN4));
}
if (profileFileBrowser.getColumn5() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn5().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN5));
}
if (profileFileBrowser.getColumn6() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn6().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN6));
}
if (profileFileBrowser.getColumn7() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn7().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN7));
}
if (profileFileBrowser.getColumn8() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn8().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN8));
}
if (profileFileBrowser.getColumn9() != null) {
fBController.addOrderByItem(profileFileBrowser.getColumn9().getFormElement().getLabel(),
String.valueOf(GWTPaginated.COL_COLUMN9));
}
filePath.langRefresh();
taxonomyMenuPopup.langRefresh();
thesaurusMenuPopup.langRefresh();
trashMenuPopup.langRefresh();
personalMenuPopup.langRefresh();
templatesMenuPopup.langRefresh();
mailMenuPopup.langRefresh();
fBController.langRefresh();
dragAndDropBox.langRefresh();
}
/**
* Refresh the panel
*
* @param fldId The path id
*/
public void refresh(String fldId) {
// Try catch to prevent non controled error which stop filebrowser and not send finish signal to folder tree
try {
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.resetNumericFolderValues();
numberOfFolders = 0;
numberOfDocuments = 0;
numberOfMails = 0;
// Because its asyncronous the getFolderChilds when finishes calls the
// getDocumentChilds(flId) to be sure refresh forlder before document files
// and each time refresh file browser content needs to reset values
table.reset();
this.fldId = fldId;
// Preparing for refreshing
removeAllRows();
if (fBController.isPaginated()) {
enableDefaultTableSorter(false);
Main.get().mainPanel.desktop.browser.fileBrowser.status.setFlagGetChilds();
paginationService.getChildrenPaginated(fldId, true, fBController.getOffset(), fBController.getLimit(),
fBController.getSelectedOrderBy(), fBController.isReverse(), fBController.isShowFolder(),
fBController.isShowDocument(), fBController.isShowMail(), selectedRowId, fBController.getFilter(),
new AsyncCallback<GWTPaginated>() {
@Override
public void onSuccess(GWTPaginated result) {
// Try catch to prevent non controled error which stop filebrowser and not send finish signal to folder tree
try {
if (result.isOutOfRange()) {
result.setOutOfRange(false);
fBController.setOffset(result.getNewOffset());
}
numberOfFolders = result.getTotalFolder();
numberOfDocuments = result.getTotalDocuments();
numberOfMails = result.getTotalMails();
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfFolders(numberOfFolders);
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfDocuments(numberOfDocuments);
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfMails(numberOfMails);
for (Object obj : result.getObjects()) {
if (obj instanceof GWTFolder) {
addRow((GWTFolder) obj);
} else if (obj instanceof GWTDocument) {
addRow((GWTDocument) obj);
} else if (obj instanceof GWTMail) {
addRow((GWTMail) obj);
}
}
selectSelectedRowInTable();
fBController.updateTotal(result.getTotal());
fBController.refresh();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagGetChilds();
Main.get().activeFolderTree.fileBrowserRefreshDone();
} catch (Exception e) {
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
}
@Override
public void onFailure(Throwable caught) {
Main.get().showError("getChildrenPaginated", caught);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagGetChilds();
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
});
} else {
enableDefaultTableSorter(true);
nextRefresh = GET_FOLDERS;
nextRefresh();
}
// On initialization fldId==null
if (fldId != null) {
filePath.setPath(fldId);
}
} catch (Exception e) {
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
}
/**
* nextRefresh
*/
private void nextRefresh() {
switch (nextRefresh) {
case GET_NONE:
break;
case GET_FOLDERS:
if (fBController.getController().isShowFolder()) {
getFolderChilds(fldId);
} else {
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfFolders(0);
nextRefresh = GET_DOCUMENTS;
nextRefresh();
}
break;
case GET_DOCUMENTS:
if (fBController.getController().isShowDocuments()) {
getDocumentChilds(fldId);
} else {
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfDocuments(0);
nextRefresh = GET_MAILS;
nextRefresh();
}
break;
case GET_MAILS:
if (fBController.getController().isShowMails()) {
getMailChilds(fldId);
} else {
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfMails(0);
nextRefresh = GET_ENDS;
nextRefresh();
}
break;
case GET_ENDS:
// Selects the selected row in table
fBController.updateTotal((numberOfFolders + numberOfDocuments + numberOfMails));
selectSelectedRowInTable();
if (table.isSorted()) {
table.refreshSort();
}
nextRefresh = GET_NONE;
Main.get().activeFolderTree.fileBrowserRefreshDone();
break;
}
}
/**
* Removes all rows except the first
*/
private void removeAllRows() {
// Purge all rows
while (dataTable.getRowCount() > 0) {
dataTable.removeRow(0);
}
table.getDataTable().resize(0, numberOfColumns);
}
/**
* Adds a folder to the panel
*
* @param folder The folder to add
*/
private void addRow(GWTFolder folder) {
table.addRow(folder);
}
/**
* Adds a new folder Normally executed from directory tree
*
* @param folder The folder
*/
public void addFolder(GWTFolder folder) {
if (fBController.isShowFolder()) {
if (fBController.isPaginated()) {
// Values has been changed is not sure folder will be visible, needed refreshing
refreshOnlyFileBrowser();
} else {
table.addRow(folder);
}
}
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderChilds();
}
/**
* Adds a document to the panel
*
* @param doc The doc to add
*/
private void addRow(GWTDocument doc) {
table.addRow(doc);
}
/**
* Adds a mail to the panel
*
* @param doc The doc to add
*/
private void addRow(GWTMail mail) {
table.addRow(mail);
}
/**
* Refresh the folder childs and call after the documentChilds refresh
*/
final AsyncCallback<List<GWTFolder>> callbackGetFolderChilds = new AsyncCallback<List<GWTFolder>>() {
public void onSuccess(List<GWTFolder> result) {
// Try catch to prevent non controlled error which stop filebrowser and not send finish signal to folder tree
try {
List<GWTFolder> folderList = result;
numberOfFolders = folderList.size();
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfFolders(numberOfFolders);
for (GWTFolder folder : folderList) {
addRow(folder);
}
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderChilds();
nextRefresh = GET_DOCUMENTS;
nextRefresh();
} catch (Exception e) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderChilds();
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderChilds();
Main.get().showError("GetFolderChilds", caught);
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
};
/**
* Refresh the document childs
*/
final AsyncCallback<List<GWTDocument>> callbackGetDocumentChilds = new AsyncCallback<List<GWTDocument>>() {
public void onSuccess(List<GWTDocument> result) {
// Try catch to prevent non controlled error which stop filebrowser and not send finish signal to folder tree
try {
List<GWTDocument> documentList = result;
numberOfDocuments = result.size();
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfDocuments(numberOfDocuments);
for (GWTDocument doc : documentList) {
addRow(doc);
}
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentChilds();
nextRefresh = GET_MAILS;
nextRefresh();
} catch (Exception e) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentChilds();
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentChilds();
Main.get().showError("GetDocumentChilds", caught);
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
};
/**
* Refresh the document childs
*/
final AsyncCallback<List<GWTMail>> callbackGetMailChilds = new AsyncCallback<List<GWTMail>>() {
public void onSuccess(List<GWTMail> result) {
// Try catch to prevent non controlled error which stop filebrowser and not send finish signal to folder tree
try {
List<GWTMail> mailList = result;
numberOfMails = result.size();
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setNumberOfMails(numberOfMails);
for (GWTMail mail : mailList) {
addRow(mail);
}
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailChilds();
nextRefresh = GET_ENDS;
nextRefresh();
} catch (Exception e) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailChilds();
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailChilds();
Main.get().showError("GetMailChilds", caught);
Main.get().activeFolderTree.fileBrowserRefreshDone();
}
};
/**
* selectSelectedRowInTable
*/
private void selectSelectedRowInTable() {
// If selectedRow > 0 must continue selecting the row ( after refreshing )
if (!selectedRowId.equals("")) {
int selectedRow = table.findSelectedRowById(selectedRowId);
if (selectedRow >= 0) {
table.setSelectedRow(selectedRow);
// Ensures selected row is visible before resfreshing
// Must create a tmp widget to ensure row is visible and after
// we restore values
String tmpHTML = dataTable.getHTML(selectedRow, 0);
HTML tmpWidget = new HTML("");
dataTable.setWidget(selectedRow, 0, tmpWidget);
// fileBrowserPanel.ensureVisible(tmpWidget);
// TODO: El ensure visible ha cambiado al ser un ScrollTable !!
dataTable.setHTML(selectedRow, 0, tmpHTML);
setSelectedPanel(true);
GWTDocument doc = table.getDocument();
if (doc != null) {
// Every time refreshing document properties can be changed ( multi user activity for example )
Main.get().mainPanel.desktop.browser.tabMultiple.enableTabDocument();
Main.get().mainPanel.desktop.browser.tabMultiple.tabDocument.setProperties(doc);
Main.get().mainPanel.topPanel.toolBar.checkToolButtonPermissions(doc,
Main.get().activeFolderTree.getFolder());
} else {
GWTMail mail = table.getMail();
if (mail != null) {
// Every time refreshing document properties can be changed ( multi user activity for example )
Main.get().mainPanel.desktop.browser.tabMultiple.enableTabMail();
Main.get().mainPanel.desktop.browser.tabMultiple.tabMail.setProperties(mail);
Main.get().mainPanel.topPanel.toolBar.checkToolButtonPermissions(mail,
Main.get().activeFolderTree.getFolder());
} else {
GWTFolder folder = table.getFolder();
if (folder != null) {
// Every time refreshing folder properties can be changed ( multi user activity for example )
Main.get().mainPanel.desktop.browser.tabMultiple.enableTabFolder();
Main.get().mainPanel.desktop.browser.tabMultiple.tabFolder.setProperties(folder);
Main.get().mainPanel.topPanel.toolBar.checkToolButtonPermissions(folder,
Main.get().activeFolderTree.getFolder(), FILE_BROWSER);
}
}
}
}
}
if (fBController.isPaginated() && !table.isSelectedRow()) {
Main.get().activeFolderTree.showTabFolderProperties();
}
selectedRowId = ""; // Always initializes value
}
/**
* Deletes a document
*/
final AsyncCallback<Object> callbackDeleteDocument = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
Log.debug("FileBroser callbackDeleteDocument:");
fireEvent(HasDocumentEvent.DOCUMENT_DELETED);
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentDelete();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentDelete();
Main.get().showError("DeleteDocument", caught);
}
};
/**
* Deletes a mail
*/
final AsyncCallback<Object> callbackDeleteMail = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
Log.debug("FileBroser callbackDeleteMail:");
fireEvent(HasMailEvent.MAIL_DELETED);
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailDelete();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailDelete();
Main.get().showError("DeleteMail", caught);
}
};
/**
* Purge a document
*/
final AsyncCallback<Object> callbackPurgeDocument = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().workspaceUserProperties.getUserDocumentsSize();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentPurge();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagDocumentPurge();
Main.get().showError("PurgeDocument", caught);
}
};
/**
* Purge a mail
*/
final AsyncCallback<Object> callbackPurgeMail = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().workspaceUserProperties.getUserDocumentsSize();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailPurge();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagMailPurge();
Main.get().showError("PurgeMail", caught);
}
};
/**
* Deletes a folder
*/
final AsyncCallback<Object> callbackDeleteFolder = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
fireEvent(HasFolderEvent.FOLDER_DELETED);
// Deletes folder from tree for consistence view
Main.get().activeFolderTree.removeDeleted(((GWTFolder) table.getFolder()).getPath());
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderDelete();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderDelete();
Main.get().showError("DeleteFolder", caught);
}
};
/**
* Purges a folder
*/
final AsyncCallback<Object> callbackPurgeFolder = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
// Deletes folder from tree for consistence view
Main.get().activeFolderTree.removeDeleted(((GWTFolder) table.getFolder()).getPath());
// int row = table.getSelectedRow();
table.delete();
// table.decrementHiddenIndexValues(row);
mantainSelectedRow();
Main.get().workspaceUserProperties.getUserDocumentsSize();
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderPurge();
refresh(fldId);
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagFolderPurge();
Main.get().showError("PurgeFolder", caught);
}
};
/**
* Document checkout
*/
final AsyncCallback<Object> callbackCheckOut = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
mantainSelectedRow();
// Marks flag to ensure all RPC calls has finished before document download
Main.get().mainPanel.dashboard.userDashboard.setPendingCheckoutDocumentFlag();
Main.get().mainPanel.dashboard.userDashboard.getUserCheckedOutDocuments();
if (HTMLEditor.isRegistered(Main.get().getExtensionUuidList())
&& HTMLEditor.isEditableDocument(table.getDocument()) && HTMLEditor.isEnabled()) {
HTMLEditor.get().edit(table.getDocument());
} else {
table.downloadDocument(true);
}
// Document download is made after finishing refresh although there's RPC call in
// getUserCheckedOutDocuments we suppose refresh it'll be more slower, and download
// must be done after last RPC call is finished
refresh(fldId);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
Main.get().showError("CheckOut", caught);
}
};
/**
* Document cancel checkout
*/
final AsyncCallback<Object> callbackCancelCheckOut = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
mantainSelectedRow();
refresh(fldId);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
Main.get().mainPanel.dashboard.userDashboard.getUserCheckedOutDocuments();
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
Main.get().showError("CancelCheckOut", caught);
}
};
/**
* Document force cancel checkout
*/
final AsyncCallback<Object> callbackForceCancelCheckOut = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
mantainSelectedRow();
refresh(fldId);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
Main.get().mainPanel.dashboard.userDashboard.getUserCheckedOutDocuments();
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagCheckout();
Main.get().showError("Force CancelCheckOut", caught);
}
};
/**
* Document lock
*/
final AsyncCallback<Object> callbackLock = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
mantainSelectedRow();
refresh(fldId);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagLock();
Main.get().mainPanel.dashboard.userDashboard.getUserLockedDocuments();
}
public void onFailure(Throwable caught) {
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagLock();
Main.get().showError("Lock", caught);
}
};
/**
* Document cancel lock
*/
final AsyncCallback<Object> callbackUnLock = new AsyncCallback<Object>() {
public void onSuccess(Object result) {
mantainSelectedRow();
refresh(fldId);
Main.get().mainPanel.desktop.browser.fileBrowser.status.unsetFlagUnLock();
Main.get().mainPanel.dashboard.userDashboard.getUserLockedDocuments();
}