/
InfoController.java
2836 lines (2536 loc) · 117 KB
/
InfoController.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
package ch.cyberduck.ui.cocoa;
/*
* Copyright (c) 2002-2010 David Kocher. All rights reserved.
*
* http://cyberduck.ch/
*
* 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.
*
* 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.
*
* Bug fixes, suggestions and comments should be sent to:
* dkocher@cyberduck.ch
*/
import ch.cyberduck.binding.application.*;
import ch.cyberduck.binding.foundation.NSAttributedString;
import ch.cyberduck.binding.foundation.NSIndexSet;
import ch.cyberduck.binding.foundation.NSMutableAttributedString;
import ch.cyberduck.binding.foundation.NSNotification;
import ch.cyberduck.binding.foundation.NSNotificationCenter;
import ch.cyberduck.binding.foundation.NSObject;
import ch.cyberduck.binding.foundation.NSString;
import ch.cyberduck.core.*;
import ch.cyberduck.core.analytics.AnalyticsProvider;
import ch.cyberduck.core.cdn.Distribution;
import ch.cyberduck.core.cdn.DistributionConfiguration;
import ch.cyberduck.core.cdn.features.Cname;
import ch.cyberduck.core.cdn.features.DistributionLogging;
import ch.cyberduck.core.cdn.features.Index;
import ch.cyberduck.core.cdn.features.Purge;
import ch.cyberduck.core.date.RFC1123DateFormatter;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AclPermission;
import ch.cyberduck.core.features.Encryption;
import ch.cyberduck.core.features.Headers;
import ch.cyberduck.core.features.Lifecycle;
import ch.cyberduck.core.features.Location;
import ch.cyberduck.core.features.Logging;
import ch.cyberduck.core.features.Move;
import ch.cyberduck.core.features.Redundancy;
import ch.cyberduck.core.features.UnixPermission;
import ch.cyberduck.core.features.Versioning;
import ch.cyberduck.core.formatter.SizeFormatterFactory;
import ch.cyberduck.core.identity.IdentityConfiguration;
import ch.cyberduck.core.lifecycle.LifecycleConfiguration;
import ch.cyberduck.core.local.BrowserLauncherFactory;
import ch.cyberduck.core.local.FileDescriptor;
import ch.cyberduck.core.local.FileDescriptorFactory;
import ch.cyberduck.core.logging.LoggingConfiguration;
import ch.cyberduck.core.preferences.Preferences;
import ch.cyberduck.core.preferences.PreferencesFactory;
import ch.cyberduck.core.resources.IconCacheFactory;
import ch.cyberduck.core.s3.VersioningConfiguration;
import ch.cyberduck.core.threading.WorkerBackgroundAction;
import ch.cyberduck.core.worker.CalculateSizeWorker;
import ch.cyberduck.core.worker.ReadAclWorker;
import ch.cyberduck.core.worker.ReadMetadataWorker;
import ch.cyberduck.core.worker.ReadPermissionWorker;
import ch.cyberduck.core.worker.ReadSizeWorker;
import ch.cyberduck.core.worker.WriteAclWorker;
import ch.cyberduck.core.worker.WriteMetadataWorker;
import ch.cyberduck.core.worker.WritePermissionWorker;
import ch.cyberduck.ui.cocoa.threading.BrowserControllerBackgroundAction;
import ch.cyberduck.ui.cocoa.threading.WindowMainAction;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.rococoa.Foundation;
import org.rococoa.ID;
import org.rococoa.Selector;
import org.rococoa.cocoa.foundation.NSInteger;
import org.rococoa.cocoa.foundation.NSPoint;
import org.rococoa.cocoa.foundation.NSSize;
import org.rococoa.cocoa.foundation.NSUInteger;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
/**
* @version $Id$
*/
public class InfoController extends ToolbarWindowController {
private static Logger log = Logger.getLogger(InfoController.class);
/**
* Selected files
*/
private List<Path> files;
private FileDescriptor descriptor = FileDescriptorFactory.get();
private LoginCallback prompt = LoginCallbackFactory.get(this);
private PathContainerService containerService
= new PathContainerService();
private Preferences preferences
= PreferencesFactory.get();
private Path getSelected() {
for(Path file : files) {
return file;
}
return null;
}
@Outlet
private NSTextField filenameField;
public void setFilenameField(NSTextField filenameField) {
this.filenameField = filenameField;
NSNotificationCenter.defaultCenter().addObserver(this.id(),
Foundation.selector("filenameInputDidEndEditing:"),
NSControl.NSControlTextDidEndEditingNotification,
filenameField);
}
@Outlet
private NSTextField groupField;
public void setGroupField(NSTextField t) {
this.groupField = t;
}
@Outlet
private NSTextField kindField;
public void setKindField(NSTextField t) {
this.kindField = t;
}
@Outlet
private NSTextField modifiedField;
public void setModifiedField(NSTextField t) {
this.modifiedField = t;
}
@Outlet
private NSTextField createdField;
public void setCreatedField(NSTextField t) {
this.createdField = t;
}
@Outlet
private NSTextField permissionsField;
public void setPermissionsField(NSTextField permissionsField) {
this.permissionsField = permissionsField;
}
@Outlet
private NSTextField octalField;
public void setOctalField(NSTextField octalField) {
this.octalField = octalField;
NSNotificationCenter.defaultCenter().addObserver(this.id(),
Foundation.selector("octalPermissionsInputDidEndEditing:"),
NSControl.NSControlTextDidEndEditingNotification,
octalField);
}
@Outlet
private NSTextField ownerField;
public void setOwnerField(NSTextField ownerField) {
this.ownerField = ownerField;
}
@Outlet
private NSTextField sizeField;
public void setSizeField(NSTextField sizeField) {
this.sizeField = sizeField;
}
@Outlet
private NSTextField checksumField;
public void setChecksumField(NSTextField checksumField) {
this.checksumField = checksumField;
}
@Outlet
private NSTextField pathField;
public void setPathField(NSTextField pathField) {
this.pathField = pathField;
}
@Outlet
private NSTextField webUrlField;
public void setWebUrlField(NSTextField webUrlField) {
this.webUrlField = webUrlField;
this.webUrlField.setAllowsEditingTextAttributes(true);
this.webUrlField.setSelectable(true);
}
@Outlet
private NSButton recursiveButton;
public void setRecursiveButton(NSButton b) {
this.recursiveButton = b;
this.recursiveButton.setTarget(this.id());
this.recursiveButton.setAction(Foundation.selector("recursiveButtonClicked:"));
}
@Outlet
private NSButton sizeButton;
public void setSizeButton(NSButton b) {
this.sizeButton = b;
this.sizeButton.setTarget(this.id());
this.sizeButton.setAction(Foundation.selector("calculateSizeButtonClicked:"));
}
@Outlet
private NSProgressIndicator sizeProgress;
public void setSizeProgress(final NSProgressIndicator p) {
this.sizeProgress = p;
this.sizeProgress.setDisplayedWhenStopped(false);
this.sizeProgress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSProgressIndicator permissionProgress;
public void setPermissionProgress(final NSProgressIndicator p) {
this.permissionProgress = p;
this.permissionProgress.setDisplayedWhenStopped(false);
this.permissionProgress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSProgressIndicator s3Progress;
public void setS3Progress(final NSProgressIndicator p) {
this.s3Progress = p;
this.s3Progress.setDisplayedWhenStopped(false);
this.s3Progress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSProgressIndicator aclProgress;
public void setAclProgress(final NSProgressIndicator p) {
this.aclProgress = p;
this.aclProgress.setDisplayedWhenStopped(false);
this.aclProgress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSProgressIndicator metadataProgress;
public void setMetadataProgress(final NSProgressIndicator p) {
this.metadataProgress = p;
this.metadataProgress.setDisplayedWhenStopped(false);
this.metadataProgress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSProgressIndicator distributionProgress;
public void setDistributionProgress(final NSProgressIndicator p) {
this.distributionProgress = p;
this.distributionProgress.setDisplayedWhenStopped(false);
this.distributionProgress.setStyle(NSProgressIndicator.NSProgressIndicatorSpinningStyle);
}
@Outlet
private NSButton distributionEnableButton;
public void setDistributionEnableButton(NSButton b) {
this.distributionEnableButton = b;
this.distributionEnableButton.setTarget(this.id());
this.distributionEnableButton.setAction(Foundation.selector("distributionApplyButtonClicked:"));
}
@Outlet
private NSButton distributionLoggingButton;
public void setDistributionLoggingButton(NSButton b) {
this.distributionLoggingButton = b;
this.distributionLoggingButton.setTarget(this.id());
this.distributionLoggingButton.setAction(Foundation.selector("distributionApplyButtonClicked:"));
}
private NSPopUpButton distributionLoggingPopup;
public void setDistributionLoggingPopup(NSPopUpButton b) {
this.distributionLoggingPopup = b;
this.distributionLoggingPopup.setTarget(this.id());
this.distributionLoggingPopup.setAction(Foundation.selector("distributionLoggingPopupClicked:"));
}
@Outlet
private NSButton distributionInvalidateObjectsButton;
public void setDistributionInvalidateObjectsButton(NSButton b) {
this.distributionInvalidateObjectsButton = b;
this.distributionInvalidateObjectsButton.setTarget(this.id());
this.distributionInvalidateObjectsButton.setAction(Foundation.selector("distributionInvalidateObjectsButtonClicked:"));
}
@Outlet
private NSTextField distributionInvalidationStatusField;
public void setDistributionInvalidationStatusField(NSTextField t) {
this.distributionInvalidationStatusField = t;
}
@Outlet
private NSPopUpButton distributionDeliveryPopup;
public void setDistributionDeliveryPopup(NSPopUpButton b) {
this.distributionDeliveryPopup = b;
this.distributionDeliveryPopup.setTarget(this.id());
this.distributionDeliveryPopup.setAction(Foundation.selector("distributionStatusButtonClicked:"));
}
@Outlet
private NSPopUpButton distributionDefaultRootPopup;
public void setDistributionDefaultRootPopup(NSPopUpButton b) {
this.distributionDefaultRootPopup = b;
this.distributionDefaultRootPopup.setTarget(this.id());
this.distributionDefaultRootPopup.setAction(Foundation.selector("distributionApplyButtonClicked:"));
}
@Outlet
private NSTextField bucketLocationField;
public void setBucketLocationField(NSTextField t) {
this.bucketLocationField = t;
}
@Outlet
private NSPopUpButton storageClassPopup;
public void setStorageClassPopup(NSPopUpButton b) {
this.storageClassPopup = b;
this.storageClassPopup.setTarget(this.id());
this.storageClassPopup.setAction(Foundation.selector("storageClassPopupClicked:"));
}
@Action
public void storageClassPopupClicked(final NSPopUpButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction(controller) {
@Override
public Boolean run() throws BackgroundException {
final Redundancy feature = controller.getSession().getFeature(Redundancy.class);
for(Path next : files) {
feature.setClass(next, sender.selectedItem().representedObject());
}
return true;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
@Override
public String getActivity() {
return MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"),
this.toString(files));
}
});
}
}
@Outlet
private NSButton encryptionButton;
public void setEncryptionButton(NSButton b) {
this.encryptionButton = b;
this.encryptionButton.setTarget(this.id());
this.encryptionButton.setAction(Foundation.selector("encryptionButtonClicked:"));
}
@Action
public void encryptionButtonClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction(controller) {
@Override
public Boolean run() throws BackgroundException {
final Encryption feature = controller.getSession().getFeature(Encryption.class);
for(Path next : files) {
if(next.isFile()) {
feature.setEncryption(next, encryptionButton.state() == NSCell.NSOnState ?
feature.getAlgorithms().iterator().next() : null);
}
}
return true;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
@Override
public String getActivity() {
return MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"),
this.toString(files));
}
});
}
}
@Outlet
private NSButton bucketLoggingButton;
public void setBucketLoggingButton(NSButton b) {
this.bucketLoggingButton = b;
this.bucketLoggingButton.setAction(Foundation.selector("bucketLoggingButtonClicked:"));
}
@Action
public void bucketLoggingButtonClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction(controller) {
@Override
public Boolean run() throws BackgroundException {
controller.getSession().getFeature(Logging.class).setConfiguration(containerService.getContainer(getSelected()),
new LoggingConfiguration(
bucketLoggingButton.state() == NSCell.NSOnState,
null == bucketLoggingPopup.selectedItem() ? null : bucketLoggingPopup.selectedItem().representedObject()
)
);
return true;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
@Override
public String getActivity() {
return MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"),
this.toString(files));
}
});
}
}
private NSPopUpButton bucketLoggingPopup;
public void setBucketLoggingPopup(NSPopUpButton b) {
this.bucketLoggingPopup = b;
this.bucketLoggingPopup.setTarget(this.id());
this.bucketLoggingPopup.setAction(Foundation.selector("bucketLoggingPopupClicked:"));
}
@Action
public void bucketLoggingPopupClicked(final NSPopUpButton sender) {
if(bucketLoggingButton.state() == NSCell.NSOnState) {
// Only write change if logging is already enabled
this.bucketLoggingButtonClicked(sender);
}
}
@Outlet
private NSButton bucketAnalyticsButton;
public void setBucketAnalyticsButton(NSButton b) {
this.bucketAnalyticsButton = b;
this.bucketAnalyticsButton.setAction(Foundation.selector("bucketAnalyticsButtonClicked:"));
}
@Action
public void bucketAnalyticsButtonClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction<Void>(controller) {
@Override
public Void run() throws BackgroundException {
final Session<?> session = controller.getSession();
final IdentityConfiguration iam = session.getFeature(IdentityConfiguration.class);
if(bucketAnalyticsButton.state() == NSCell.NSOnState) {
final String document = preferences.getProperty("analytics.provider.qloudstat.iam.policy");
iam.create(controller.getSession().getFeature(AnalyticsProvider.class).getName(), document, prompt);
}
else {
iam.delete(controller.getSession().getFeature(AnalyticsProvider.class).getName(), prompt);
}
return null;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
});
}
}
@Outlet
private NSTextField bucketAnalyticsSetupUrlField;
public void setBucketAnalyticsSetupUrlField(NSTextField f) {
this.bucketAnalyticsSetupUrlField = f;
this.bucketAnalyticsSetupUrlField.setAllowsEditingTextAttributes(true);
this.bucketAnalyticsSetupUrlField.setSelectable(true);
}
@Outlet
private NSButton bucketVersioningButton;
public void setBucketVersioningButton(NSButton b) {
this.bucketVersioningButton = b;
this.bucketVersioningButton.setAction(Foundation.selector("bucketVersioningButtonClicked:"));
}
@Action
public void bucketVersioningButtonClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction<Void>(controller) {
@Override
public Void run() throws BackgroundException {
controller.getSession().getFeature(Versioning.class).setConfiguration(containerService.getContainer(getSelected()), prompt,
new VersioningConfiguration(
bucketVersioningButton.state() == NSCell.NSOnState,
bucketMfaButton.state() == NSCell.NSOnState)
);
return null;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
});
}
}
@Outlet
private NSButton bucketMfaButton;
public void setBucketMfaButton(NSButton b) {
this.bucketMfaButton = b;
this.bucketMfaButton.setAction(Foundation.selector("bucketMfaButtonClicked:"));
}
@Action
public void bucketMfaButtonClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction<Void>(controller) {
@Override
public Void run() throws BackgroundException {
controller.getSession().getFeature(Versioning.class).setConfiguration(containerService.getContainer(getSelected()),
prompt,
new VersioningConfiguration(
bucketVersioningButton.state() == NSCell.NSOnState,
bucketMfaButton.state() == NSCell.NSOnState)
);
return null;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
});
}
}
@Outlet
private NSTextField s3PublicUrlField;
public void setS3PublicUrlField(NSTextField t) {
this.s3PublicUrlField = t;
this.s3PublicUrlField.setAllowsEditingTextAttributes(true);
this.s3PublicUrlField.setSelectable(true);
}
@Outlet
private NSTextField s3PublicUrlValidityField;
public void setS3PublicUrlValidityField(NSTextField s3PublicUrlValidityField) {
this.s3PublicUrlValidityField = s3PublicUrlValidityField;
}
@Outlet
private NSTextField s3torrentUrlField;
public void setS3torrentUrlField(NSTextField t) {
this.s3torrentUrlField = t;
this.s3torrentUrlField.setAllowsEditingTextAttributes(true);
this.s3torrentUrlField.setSelectable(true);
}
@Outlet
private NSButton lifecycleTransitionCheckbox;
public void setLifecycleTransitionCheckbox(final NSButton b) {
this.lifecycleTransitionCheckbox = b;
this.lifecycleTransitionCheckbox.setAction(Foundation.selector("lifecyclePopupClicked:"));
}
@Outlet
private NSPopUpButton lifecycleTransitionPopup;
public void setLifecycleTransitionPopup(final NSPopUpButton b) {
this.lifecycleTransitionPopup = b;
this.lifecycleTransitionPopup.setTarget(this.id());
for(String option : preferences.getList("s3.lifecycle.transition.options")) {
this.lifecycleTransitionPopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), option));
this.lifecycleTransitionPopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
this.lifecycleTransitionPopup.lastItem().setTarget(this.id());
this.lifecycleTransitionPopup.lastItem().setRepresentedObject(option);
}
}
@Outlet
private NSButton lifecycleDeleteCheckbox;
public void setLifecycleDeleteCheckbox(final NSButton b) {
this.lifecycleDeleteCheckbox = b;
this.lifecycleDeleteCheckbox.setAction(Foundation.selector("lifecyclePopupClicked:"));
}
@Outlet
private NSPopUpButton lifecycleDeletePopup;
public void setLifecycleDeletePopup(final NSPopUpButton b) {
this.lifecycleDeletePopup = b;
for(String option : preferences.getList("s3.lifecycle.delete.options")) {
this.lifecycleDeletePopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), option));
this.lifecycleDeletePopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
this.lifecycleDeletePopup.lastItem().setTarget(this.id());
this.lifecycleDeletePopup.lastItem().setRepresentedObject(option);
}
}
@Action
public void lifecyclePopupClicked(final NSButton sender) {
if(this.toggleS3Settings(false)) {
this.background(new BrowserControllerBackgroundAction<Void>(controller) {
@Override
public Void run() throws BackgroundException {
controller.getSession().getFeature(Lifecycle.class).setConfiguration(containerService.getContainer(getSelected()),
new LifecycleConfiguration(
lifecycleTransitionCheckbox.state() == NSCell.NSOnState ? Integer.valueOf(lifecycleTransitionPopup.selectedItem().representedObject()) : null,
lifecycleDeleteCheckbox.state() == NSCell.NSOnState ? Integer.valueOf(lifecycleDeletePopup.selectedItem().representedObject()) : null)
);
return null;
}
@Override
public void cleanup() {
super.cleanup();
toggleS3Settings(true);
initS3();
}
});
}
}
@Outlet
private NSTextField distributionCnameField;
public void setDistributionCnameField(NSTextField t) {
this.distributionCnameField = t;
NSNotificationCenter.defaultCenter().addObserver(this.id(),
Foundation.selector("distributionApplyButtonClicked:"),
NSControl.NSControlTextDidEndEditingNotification,
distributionCnameField);
}
@Outlet
private NSTextField distributionOriginField;
public void setDistributionOriginField(NSTextField t) {
this.distributionOriginField = t;
this.distributionOriginField.setAllowsEditingTextAttributes(true);
this.distributionOriginField.setSelectable(true);
}
@Outlet
private NSTextField distributionStatusField;
public void setDistributionStatusField(NSTextField t) {
this.distributionStatusField = t;
}
@Outlet
private NSTextField distributionUrlField;
public void setDistributionUrlField(NSTextField t) {
this.distributionUrlField = t;
this.distributionUrlField.setAllowsEditingTextAttributes(true);
this.distributionUrlField.setSelectable(true);
}
@Outlet
private NSTextField distributionCnameUrlField;
public void setDistributionCnameUrlField(NSTextField t) {
this.distributionCnameUrlField = t;
this.distributionCnameUrlField.setAllowsEditingTextAttributes(true);
this.distributionCnameUrlField.setSelectable(true);
}
@Outlet
private NSTextField aclUrlField;
public void setAclUrlField(NSTextField t) {
this.aclUrlField = t;
this.aclUrlField.setAllowsEditingTextAttributes(true);
this.aclUrlField.setSelectable(true);
}
/**
* Grant editing model.
*/
private List<Acl.UserAndRole> acl = new ArrayList<Acl.UserAndRole>();
/**
* Replace current metadata model. Will reload the table view.
*
* @param acl The updated access control list
*/
private void setAcl(List<Acl.UserAndRole> acl) {
this.acl.clear();
this.acl.addAll(acl);
this.aclTable.reloadData();
}
@Outlet
private NSTableView aclTable;
private ListDataSource aclTableModel;
private AbstractTableDelegate<Acl.UserAndRole> aclTableDelegate;
private enum AclColumns {
GRANTEE,
PERMISSION,
}
private final NSComboBoxCell aclPermissionCellPrototype = NSComboBoxCell.comboBoxCell();
public void setAclTable(final NSTableView t) {
this.aclTable = t;
this.aclTable.setAllowsMultipleSelection(true);
this.aclPermissionCellPrototype.setFont(NSFont.systemFontOfSize(NSFont.smallSystemFontSize()));
this.aclPermissionCellPrototype.setControlSize(NSCell.NSSmallControlSize);
this.aclPermissionCellPrototype.setCompletes(false);
this.aclPermissionCellPrototype.setBordered(false);
this.aclPermissionCellPrototype.setButtonBordered(false);
this.aclTable.setColumnAutoresizingStyle(NSTableView.NSTableViewUniformColumnAutoresizingStyle);
this.aclTable.tableColumnWithIdentifier(AclColumns.PERMISSION.name()).setDataCell(aclPermissionCellPrototype);
this.aclTable.setDataSource((aclTableModel = new ListDataSource() {
@Override
public NSInteger numberOfRowsInTableView(NSTableView view) {
return new NSInteger(acl.size());
}
public NSObject tableView_objectValueForTableColumn_row(NSTableView view, NSTableColumn tableColumn,
NSInteger row) {
if(row.intValue() < acl.size()) {
final String identifier = tableColumn.identifier();
final Acl.UserAndRole grant = acl.get(row.intValue());
if(identifier.equals(AclColumns.GRANTEE.name())) {
return NSString.stringWithString(grant.getUser().getDisplayName());
}
if(identifier.equals(AclColumns.PERMISSION.name())) {
return NSString.stringWithString(grant.getRole().getName());
}
}
return null;
}
@Override
public void tableView_setObjectValue_forTableColumn_row(NSTableView view, NSObject value,
NSTableColumn c, NSInteger row) {
if(row.intValue() < acl.size()) {
final Acl.UserAndRole grant = acl.get(row.intValue());
if(c.identifier().equals(AclColumns.GRANTEE.name())) {
grant.getUser().setIdentifier(value.toString());
}
if(c.identifier().equals(AclColumns.PERMISSION.name())) {
grant.getRole().setName(value.toString());
}
if(StringUtils.isNotBlank(grant.getUser().getIdentifier())
&& StringUtils.isNotBlank(grant.getRole().getName())) {
InfoController.this.aclInputDidEndEditing();
}
}
}
}).id());
this.aclTable.setDelegate((aclTableDelegate = new AbstractTableDelegate<Acl.UserAndRole>(
aclTable.tableColumnWithIdentifier(AclColumns.GRANTEE.name())
) {
@Override
public boolean isColumnRowEditable(NSTableColumn column, int row) {
if(column.identifier().equals(AclColumns.GRANTEE.name())) {
final Acl.UserAndRole grant = acl.get(row);
if(grant.getUser().isEditable()) {
return true;
}
// Group Grantee identifier is not editable
return false;
}
if(column.identifier().equals(AclColumns.PERMISSION.name())) {
final Acl.UserAndRole grant = acl.get(row);
if(grant.getRole().isEditable()) {
return true;
}
// Static role that cannot be modified
return false;
}
return true;
}
@Override
public void tableRowDoubleClicked(final ID sender) {
this.enterKeyPressed(sender);
}
@Override
public void enterKeyPressed(final ID sender) {
aclTable.editRow(aclTable.columnWithIdentifier(AclColumns.GRANTEE.name()), aclTable.selectedRow(), true);
}
@Override
public void deleteKeyPressed(final ID sender) {
aclRemoveButtonClicked(sender);
}
public String tableView_toolTipForCell_rect_tableColumn_row_mouseLocation(NSTableView t, NSCell cell,
ID rect, NSTableColumn c,
NSInteger row, NSPoint mouseLocation) {
return this.tooltip(acl.get(row.intValue()));
}
@Override
public String tooltip(Acl.UserAndRole c) {
return c.getUser().getIdentifier();
}
@Override
public void tableColumnClicked(NSTableView view, NSTableColumn c) {
//
}
@Override
public void selectionDidChange(NSNotification notification) {
aclRemoveButton.setEnabled(aclTable.numberOfSelectedRows().intValue() > 0);
}
public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSTextFieldCell cell,
NSTableColumn c, NSInteger row) {
if(c.identifier().equals(AclColumns.GRANTEE.name())) {
final Acl.UserAndRole grant = acl.get(row.intValue());
cell.setPlaceholderString(grant.getUser().getPlaceholder());
if(grant.getUser().isEditable()) {
cell.setTextColor(NSColor.controlTextColor());
}
else {
// Group Grantee identifier is not editable
cell.setTextColor(NSColor.disabledControlTextColor());
}
}
}
@Override
protected boolean isTypeSelectSupported() {
return false;
}
}).id());
this.aclTable.sizeToFit();
}
@Outlet
private NSPopUpButton aclAddButton;
public void setAclAddButton(NSPopUpButton b) {
this.aclAddButton = b;
this.aclAddButton.setTarget(this.id());
}
public void aclAddButtonClicked(NSMenuItem sender) {
final AclPermission feature = controller.getSession().getFeature(AclPermission.class);
for(Acl.User grantee : feature.getAvailableAclUsers()) {
if(sender.representedObject().equals(grantee.getPlaceholder())) {
this.addAclItem(new Acl.UserAndRole(grantee, new Acl.Role(StringUtils.EMPTY)));
}
}
}
/**
* Add to the table, reload data and select inserted row.
*
* @param update The acl to insert.
*/
private void addAclItem(Acl.UserAndRole update) {
List<Acl.UserAndRole> updated = new ArrayList<Acl.UserAndRole>(acl);
final int index = updated.size();
updated.add(index, update);
this.setAcl(updated);
aclTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(index)), false);
if(update.getUser().isEditable()) {
aclTable.editRow(aclTable.columnWithIdentifier(AclColumns.GRANTEE.name()), new NSInteger(index), true);
}
else {
aclTable.editRow(aclTable.columnWithIdentifier(AclColumns.PERMISSION.name()), new NSInteger(index), true);
}
}
@Outlet
private NSButton aclRemoveButton;
public void setAclRemoveButton(NSButton b) {
this.aclRemoveButton = b;
// Only enable upon selection change
this.aclRemoveButton.setEnabled(false);
this.aclRemoveButton.setAction(Foundation.selector("aclRemoveButtonClicked:"));
this.aclRemoveButton.setTarget(this.id());
}
@Action
public void aclRemoveButtonClicked(ID sender) {
List<Acl.UserAndRole> updated = new ArrayList<Acl.UserAndRole>(acl);
NSIndexSet iterator = aclTable.selectedRowIndexes();
List<Acl.UserAndRole> remove = new ArrayList<Acl.UserAndRole>();
for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) {
remove.add(updated.get(index.intValue()));
}
updated.removeAll(remove);
this.setAcl(updated);
this.aclInputDidEndEditing();
}
private void aclInputDidEndEditing() {
if(this.toggleAclSettings(false)) {
this.background(new WorkerBackgroundAction<Boolean>(controller, controller.getSession(), controller.getCache(),
new WriteAclWorker(controller.getSession(), controller.getSession().getFeature(AclPermission.class),
files, new Acl(acl.toArray(new Acl.UserAndRole[acl.size()])), true, controller) {
@Override
public void cleanup(final Boolean v) {
toggleAclSettings(true);
initAcl();
}
}
)
);
}
}
@Outlet
private NSTableView metadataTable;
private ListDataSource metadataTableModel;
private AbstractTableDelegate<String> metadataTableDelegate;
private enum MetadataColumns {
NAME,
VALUE
}
/**
* Custom HTTP headers for REST protocols
*/
private List<Header> metadata
= new ArrayList<Header>();
/**
* Replace current metadata model. Will reload the table view.
*
* @param m The new header key and values