-
Notifications
You must be signed in to change notification settings - Fork 6
/
Cockpit.java
3052 lines (2680 loc) · 139 KB
/
Cockpit.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
/*
* jets3t : Java Extra-Tasty S3 Toolkit (for Amazon S3 online storage service)
* This is a java.net project, see https://jets3t.dev.java.net/
*
* Copyright 2008 James Murty
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jets3t.apps.cockpit;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.httpclient.auth.NTLMScheme;
import org.apache.commons.httpclient.auth.RFC2617Scheme;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jets3t.apps.cockpit.gui.AccessControlDialog;
import org.jets3t.apps.cockpit.gui.BucketLoggingDialog;
import org.jets3t.apps.cockpit.gui.BucketTableModel;
import org.jets3t.apps.cockpit.gui.CreateBucketDialog;
import org.jets3t.apps.cockpit.gui.ObjectTableModel;
import org.jets3t.apps.cockpit.gui.PreferencesDialog;
import org.jets3t.apps.cockpit.gui.RequesterPaysDialog;
import org.jets3t.apps.cockpit.gui.SignedGetUrlDialog;
import org.jets3t.apps.cockpit.gui.StartupDialog;
import org.jets3t.gui.AuthenticationDialog;
import org.jets3t.gui.CopyObjectsDialog;
import org.jets3t.gui.ErrorDialog;
import org.jets3t.gui.GuiUtils;
import org.jets3t.gui.HyperlinkActivatedListener;
import org.jets3t.gui.ItemPropertiesDialog;
import org.jets3t.gui.JHtmlLabel;
import org.jets3t.gui.ManageDistributionsDialog;
import org.jets3t.gui.ObjectsAttributesDialog;
import org.jets3t.gui.ProgressDialog;
import org.jets3t.gui.TableSorter;
import org.jets3t.gui.skins.SkinsFactory;
import org.jets3t.service.CloudFrontService;
import org.jets3t.service.CloudFrontServiceException;
import org.jets3t.service.Constants;
import org.jets3t.service.Jets3tProperties;
import org.jets3t.service.S3ObjectsChunk;
import org.jets3t.service.S3Service;
import org.jets3t.service.S3ServiceException;
import org.jets3t.service.acl.AccessControlList;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.io.BytesProgressWatcher;
import org.jets3t.service.model.S3Bucket;
import org.jets3t.service.model.S3Object;
import org.jets3t.service.model.cloudfront.Distribution;
import org.jets3t.service.multithread.CancelEventTrigger;
import org.jets3t.service.multithread.CopyObjectsEvent;
import org.jets3t.service.multithread.CreateBucketsEvent;
import org.jets3t.service.multithread.CreateObjectsEvent;
import org.jets3t.service.multithread.DeleteObjectsEvent;
import org.jets3t.service.multithread.DownloadObjectsEvent;
import org.jets3t.service.multithread.DownloadPackage;
import org.jets3t.service.multithread.GetObjectHeadsEvent;
import org.jets3t.service.multithread.GetObjectsEvent;
import org.jets3t.service.multithread.ListObjectsEvent;
import org.jets3t.service.multithread.LookupACLEvent;
import org.jets3t.service.multithread.S3ServiceEventListener;
import org.jets3t.service.multithread.S3ServiceMulti;
import org.jets3t.service.multithread.ServiceEvent;
import org.jets3t.service.multithread.ThreadWatcher;
import org.jets3t.service.multithread.UpdateACLEvent;
import org.jets3t.service.security.AWSCredentials;
import org.jets3t.service.security.EncryptionUtil;
import org.jets3t.service.utils.ByteFormatter;
import org.jets3t.service.utils.FileComparer;
import org.jets3t.service.utils.FileComparerResults;
import org.jets3t.service.utils.Mimetypes;
import org.jets3t.service.utils.ObjectUtils;
import org.jets3t.service.utils.TimeFormatter;
import com.centerkey.utils.BareBonesBrowserLaunch;
/**
* Cockpit is a graphical Java application for viewing and managing the contents of an Amazon S3 account.
* For more information and help please see the
* <a href="http://jets3t.s3.amazonaws.com/applications/cockpit.html">Cockpit Guide</a>.
* <p>
* This is the Cockpit application class; it may be run as a stand-alone application or as an Applet.
*
* @author jmurty
*/
public class Cockpit extends JApplet implements S3ServiceEventListener, ActionListener,
ListSelectionListener, HyperlinkActivatedListener, CredentialsProvider
{
private static final long serialVersionUID = -3982368878320163058L;
private static final Log log = LogFactory.getLog(Cockpit.class);
public static final String JETS3T_COCKPIT_HELP_PAGE = "http://jets3t.s3.amazonaws.com/applications/cockpit.html";
public static final String AMAZON_S3_PAGE = "http://www.amazon.com/s3";
public static final String OS_NAME_MAC = "Mac OS X";
public static final String APPLICATION_DESCRIPTION = "Cockpit/0.7.0";
public static final String APPLICATION_TITLE = "JetS3t Cockpit";
private static final int BUCKET_LIST_CHUNKING_SIZE = 1000;
private File cockpitHomeDirectory = Constants.DEFAULT_PREFERENCES_DIRECTORY;
private CockpitPreferences cockpitPreferences = null;
private final Insets insetsZero = new Insets(0, 0, 0, 0);
private final Insets insetsDefault = new Insets(5, 7, 5, 7);
private final ByteFormatter byteFormatter = new ByteFormatter();
private final TimeFormatter timeFormatter = new TimeFormatter();
private final SimpleDateFormat yearAndTimeSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final SimpleDateFormat timeSDF = new SimpleDateFormat("HH:mm:ss");
private final GuiUtils guiUtils = new GuiUtils();
/**
* Multi-threaded S3 service used by the application.
*/
private S3ServiceMulti s3ServiceMulti = null;
private CloudFrontService cloudFrontService = null;
private boolean cloudFrontMembershipChecked = false;
private JFrame ownerFrame = null;
private boolean isStandAloneApplication = false;
// Service main menu items
private JMenuItem loginMenuItem = null;
private JMenuItem logoutMenuItem = null;
// Bucket main menu items
private JPopupMenu bucketActionMenu = null;
private JMenuItem viewBucketPropertiesMenuItem = null;
private JMenuItem refreshBucketMenuItem = null;
private JMenuItem createBucketMenuItem = null;
private JMenuItem manageDistributionsMenuItem = null;
private JMenuItem updateBucketACLMenuItem = null;
private JMenuItem updateBucketRequesterPaysStatusMenuItem = null;
private JMenuItem deleteBucketMenuItem = null;
// Object main menu items
private JPopupMenu objectActionMenu = null;
private JMenuItem refreshObjectMenuItem = null;
private JMenuItem viewOrModifyObjectAttributesMenuItem = null;
private JMenuItem copyObjectsMenuItem = null;
private JMenuItem updateObjectACLMenuItem = null;
private JMenuItem downloadObjectMenuItem = null;
private JMenuItem uploadFilesMenuItem = null;
private JMenuItem generatePublicGetUrls = null;
private JMenuItem generateTorrentUrl = null;
private JMenuItem deleteObjectMenuItem = null;
// Tools menu items.
private JMenuItem bucketLoggingMenuItem = null;
// Preference menu items.
private JMenuItem preferencesDialogMenuItem = null;
// Help menu items.
private JMenuItem cockpitHelpMenuItem = null;
private JMenuItem amazonS3HelpMenuItem = null;
// Tables
private JTable bucketsTable = null;
private JTable objectsTable = null;
private JScrollPane objectsTableSP = null;
private BucketTableModel bucketTableModel = null;
private TableSorter bucketTableModelSorter = null;
private ObjectTableModel objectTableModel = null;
private TableSorter objectTableModelSorter = null;
private JLabel objectsSummaryLabel = null;
private HashMap cachedBuckets = new HashMap();
private ProgressDialog progressDialog = null;
private ObjectsAttributesDialog objectsAttributesDialog = null;
private File downloadDirectory = null;
private File fileChoosersLastUploadDirectory = null;
private JPanel filterObjectsPanel = null;
private JCheckBox filterObjectsCheckBox = null;
private JTextField filterObjectsPrefix = null;
private JComboBox filterObjectsDelimiter = null;
// File comparison options
private static final String UPLOAD_NEW_FILES_ONLY = "Only upload new files";
private static final String UPLOAD_NEW_AND_CHANGED_FILES = "Upload new and changed files";
private static final String UPLOAD_ALL_FILES = "Upload all files";
private static final String DOWNLOAD_NEW_FILES_ONLY = "Only download new files";
private static final String DOWNLOAD_NEW_AND_CHANGED_FILES = "Download new and changed files";
private static final String DOWNLOAD_ALL_FILES = "Download all files";
private EncryptionUtil encryptionUtil = null;
private Jets3tProperties cockpitProperties = null;
private SkinsFactory skinsFactory = null;
private S3Bucket currentSelectedBucket = null;
/**
* Constructor to run this application as an Applet.
*/
public Cockpit() {
}
/**
* Constructor to run this application in a stand-alone window.
*
* @param ownerFrame the frame the application will be displayed in
* @throws S3ServiceException
*/
public Cockpit(JFrame ownerFrame) throws S3ServiceException {
this.ownerFrame = ownerFrame;
isStandAloneApplication = true;
init();
ownerFrame.getContentPane().add(this);
ownerFrame.setBounds(this.getBounds());
ownerFrame.setVisible(true);
}
/**
* Prepares application to run as a GUI by finding/creating a root owner JFrame, creating an
* un-authenticated {@link RestS3Service} and loading properties files.
*/
public void init() {
super.init();
// Find or create a Frame to own modal dialog boxes.
if (this.ownerFrame == null) {
Component c = this;
while (!(c instanceof Frame) && c.getParent() != null) {
c = c.getParent();
}
if (!(c instanceof JFrame)) {
this.ownerFrame = new JFrame();
} else {
this.ownerFrame = (JFrame) c;
}
}
// Initialise the GUI.
initGui();
// Initialise a non-authenticated service.
try {
// Revert to anonymous service.
s3ServiceMulti = new S3ServiceMulti(
new RestS3Service(null, APPLICATION_DESCRIPTION, this), this);
cloudFrontService = null;
} catch (S3ServiceException e) {
String message = "Unable to start anonymous service";
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, message, e);
}
// Load Cockpit configuration files from cockpit's home directory.
File mimeTypesFile = new File(cockpitHomeDirectory, "mime.types");
if (mimeTypesFile.exists()) {
try {
Mimetypes.getInstance().loadAndReplaceMimetypes(
new FileInputStream(mimeTypesFile));
} catch (IOException e) {
String message = "Unable to load mime.types file: " + mimeTypesFile;
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, message, e);
}
}
File jets3tPropertiesFile = new File(cockpitHomeDirectory, "jets3t.properties");
if (jets3tPropertiesFile.exists()) {
try {
Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME)
.loadAndReplaceProperties(new FileInputStream(jets3tPropertiesFile),
"jets3t.properties in Cockpit's home folder " + cockpitHomeDirectory);
} catch (IOException e) {
String message = "Unable to load jets3t.properties file: " + jets3tPropertiesFile;
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, message, e);
}
}
// Initialise the user's preferences.
this.cockpitPreferences = new CockpitPreferences();
File cockpitPreferencesPropertiesFile = new File(cockpitHomeDirectory, Constants.COCKPIT_PROPERTIES_FILENAME);
if (cockpitPreferencesPropertiesFile.exists()) {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(cockpitPreferencesPropertiesFile));
this.cockpitPreferences.fromProperties(properties);
} catch (IOException e) {
String message = "Unable to load your preferences";
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, message, e);
}
}
cockpitProperties = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);
skinsFactory = SkinsFactory.getInstance(cockpitProperties.getProperties());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loginEvent();
}
});
}
/**
* Initialises the application's GUI elements.
*/
private void initGui() {
initMenus();
JPanel appContent = new JPanel(new GridBagLayout());
this.getContentPane().add(appContent);
// Buckets panel.
JPanel bucketsPanel = new JPanel(new GridBagLayout());
JButton bucketActionButton = new JButton();
bucketActionButton.setToolTipText("Bucket actions menu");
guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png");
bucketActionButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton sourceButton = (JButton) e.getSource();
bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight());
}
});
bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this),
new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
bucketsPanel.add(bucketActionButton,
new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
bucketTableModel = new BucketTableModel(false);
bucketTableModelSorter = new TableSorter(bucketTableModel);
bucketsTable = new JTable(bucketTableModelSorter);
bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());
bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bucketsTable.getSelectionModel().addListSelectionListener(this);
bucketsTable.setShowHorizontalLines(true);
bucketsTable.setShowVerticalLines(false);
bucketsTable.addMouseListener(new ContextMenuListener());
bucketsPanel.add(new JScrollPane(bucketsTable),
new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
bucketsPanel.add(new JLabel(" "),
new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
// Filter panel.
filterObjectsPanel = new JPanel(new GridBagLayout());
filterObjectsPrefix = new JTextField();
filterObjectsPrefix.setToolTipText("Only show objects with this prefix");
filterObjectsPrefix.addActionListener(this);
filterObjectsPrefix.setActionCommand("RefreshObjects");
filterObjectsDelimiter = new JComboBox(new String[] {"", "/", "?", "\\"});
filterObjectsDelimiter.setEditable(true);
filterObjectsDelimiter.setToolTipText("Object name delimiter");
filterObjectsDelimiter.addActionListener(this);
filterObjectsDelimiter.setActionCommand("RefreshObjects");
filterObjectsPanel.add(new JHtmlLabel("Prefix:", this),
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
filterObjectsPanel.add(filterObjectsPrefix,
new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this),
new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
filterObjectsPanel.add(filterObjectsDelimiter,
new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
filterObjectsPanel.setVisible(false);
// Objects panel.
JPanel objectsPanel = new JPanel(new GridBagLayout());
int row = 0;
filterObjectsCheckBox = new JCheckBox("Filter objects");
filterObjectsCheckBox.addActionListener(this);
filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed");
objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this),
new GridBagConstraints(0, row, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
objectsPanel.add(filterObjectsCheckBox,
new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
JButton objectActionButton = new JButton();
objectActionButton.setToolTipText("Object actions menu");
guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
objectActionButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton sourceButton = (JButton) e.getSource();
objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
}
});
objectsPanel.add(objectActionButton,
new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
objectsPanel.add(filterObjectsPanel,
new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
objectsTable = new JTable();
objectTableModel = new ObjectTableModel();
objectTableModelSorter = new TableSorter(objectTableModel);
objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
objectsTable.setModel(objectTableModelSorter);
objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
private static final long serialVersionUID = 301092191828910402L;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String formattedSize = byteFormatter.formatByteSize(((Long)value).longValue());
return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
}
});
objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
private static final long serialVersionUID = 7285511556343895652L;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Date date = (Date) value;
return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus, row, column);
}
});
objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
objectsTable.getSelectionModel().addListSelectionListener(this);
objectsTable.setShowHorizontalLines(true);
objectsTable.setShowVerticalLines(true);
objectsTable.addMouseListener(new ContextMenuListener());
objectsTableSP = new JScrollPane(objectsTable);
objectsPanel.add(objectsTableSP,
new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this);
objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
objectsSummaryLabel.setFocusable(false);
objectsPanel.add(objectsSummaryLabel,
new GridBagConstraints(0, ++row, 3, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
// Combine sections.
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
bucketsPanel, objectsPanel);
splitPane.setOneTouchExpandable(true);
splitPane.setContinuousLayout(true);
appContent.add(splitPane,
new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsDefault, 0, 0));
// Set preferred sizes
int preferredWidth = 800;
int preferredHeight = 600;
this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));
splitPane.setResizeWeight(0.30);
// Initialize drop target.
initDropTarget(new JComponent[] {objectsTableSP, objectsTable} );
objectsTable.getDropTarget().setActive(false);
objectsTableSP.getDropTarget().setActive(false);
}
/**
* Initialise the application's menu bar.
*/
private void initMenus() {
JMenuBar appMenuBar = new JMenuBar();
if (this.isStandAloneApplication && OS_NAME_MAC.equals(System.getProperty("os.name"))) {
/*
* We need to check we're running on a Mac before adding the menu to the
* owner frame, otherwise the menus will be displayed *behind* the main
* GUI panel on Windows Vista and later [sigh]
*/
ownerFrame.setJMenuBar(appMenuBar);
} else {
this.setJMenuBar(appMenuBar);
}
// Service menu
JMenu serviceMenu = new JMenu("Service");
loginMenuItem = new JMenuItem("Log in...");
loginMenuItem.setActionCommand("LoginEvent");
loginMenuItem.addActionListener(this);
guiUtils.applyIcon(loginMenuItem, "/images/nuvola/16x16/actions/connect_creating.png");
serviceMenu.add(loginMenuItem);
logoutMenuItem = new JMenuItem("Log out");
logoutMenuItem.setActionCommand("LogoutEvent");
logoutMenuItem.addActionListener(this);
guiUtils.applyIcon(logoutMenuItem, "/images/nuvola/16x16/actions/connect_no.png");
serviceMenu.add(logoutMenuItem);
if (isStandAloneApplication) {
serviceMenu.add(new JSeparator());
JMenuItem quitMenuItem = new JMenuItem("Quit");
quitMenuItem.setActionCommand("QuitEvent");
quitMenuItem.addActionListener(this);
guiUtils.applyIcon(quitMenuItem, "/images/nuvola/16x16/actions/exit.png");
serviceMenu.add(quitMenuItem);
}
loginMenuItem.setEnabled(true);
logoutMenuItem.setEnabled(false);
// Bucket action menu.
bucketActionMenu = new JPopupMenu();
refreshBucketMenuItem = new JMenuItem("Refresh bucket listing");
refreshBucketMenuItem.setActionCommand("RefreshBuckets");
refreshBucketMenuItem.addActionListener(this);
guiUtils.applyIcon(refreshBucketMenuItem, "/images/nuvola/16x16/actions/reload.png");
bucketActionMenu.add(refreshBucketMenuItem);
viewBucketPropertiesMenuItem = new JMenuItem("View bucket properties...");
viewBucketPropertiesMenuItem.setActionCommand("ViewBucketProperties");
viewBucketPropertiesMenuItem.addActionListener(this);
guiUtils.applyIcon(viewBucketPropertiesMenuItem, "/images/nuvola/16x16/actions/viewmag.png");
bucketActionMenu.add(viewBucketPropertiesMenuItem);
updateBucketACLMenuItem = new JMenuItem("Update bucket's Access Control List...");
updateBucketACLMenuItem.setActionCommand("UpdateBucketACL");
updateBucketACLMenuItem.addActionListener(this);
guiUtils.applyIcon(updateBucketACLMenuItem, "/images/nuvola/16x16/actions/encrypted.png");
bucketActionMenu.add(updateBucketACLMenuItem);
updateBucketRequesterPaysStatusMenuItem = new JMenuItem("Update bucket's Requester Pays status...");
updateBucketRequesterPaysStatusMenuItem.setActionCommand("UpdateBucketRequesterPaysStatus");
updateBucketRequesterPaysStatusMenuItem.addActionListener(this);
guiUtils.applyIcon(updateBucketRequesterPaysStatusMenuItem, "/images/nuvola/16x16/actions/identity.png");
bucketActionMenu.add(updateBucketRequesterPaysStatusMenuItem);
bucketActionMenu.add(new JSeparator());
createBucketMenuItem = new JMenuItem("Create new bucket...");
createBucketMenuItem.setActionCommand("CreateBucket");
createBucketMenuItem.addActionListener(this);
guiUtils.applyIcon(createBucketMenuItem, "/images/nuvola/16x16/actions/viewmag+.png");
bucketActionMenu.add(createBucketMenuItem);
JMenuItem thirdPartyBucketMenuItem = new JMenuItem("Add third-party bucket...");
thirdPartyBucketMenuItem.setActionCommand("AddThirdPartyBucket");
thirdPartyBucketMenuItem.addActionListener(this);
guiUtils.applyIcon(thirdPartyBucketMenuItem, "/images/nuvola/16x16/actions/viewmagfit.png");
bucketActionMenu.add(thirdPartyBucketMenuItem);
bucketActionMenu.add(new JSeparator());
deleteBucketMenuItem = new JMenuItem("Delete bucket...");
deleteBucketMenuItem.setActionCommand("DeleteBucket");
deleteBucketMenuItem.addActionListener(this);
guiUtils.applyIcon(deleteBucketMenuItem, "/images/nuvola/16x16/actions/cancel.png");
bucketActionMenu.add(deleteBucketMenuItem);
viewBucketPropertiesMenuItem.setEnabled(false);
refreshBucketMenuItem.setEnabled(false);
createBucketMenuItem.setEnabled(false);
updateBucketACLMenuItem.setEnabled(false);
updateBucketRequesterPaysStatusMenuItem.setEnabled(false);
deleteBucketMenuItem.setEnabled(false);
// Object action menu.
objectActionMenu = new JPopupMenu();
refreshObjectMenuItem = new JMenuItem("Refresh object listing");
refreshObjectMenuItem.setActionCommand("RefreshObjects");
refreshObjectMenuItem.addActionListener(this);
guiUtils.applyIcon(refreshObjectMenuItem, "/images/nuvola/16x16/actions/reload.png");
objectActionMenu.add(refreshObjectMenuItem);
viewOrModifyObjectAttributesMenuItem = new JMenuItem("View or Modify object attributes...");
viewOrModifyObjectAttributesMenuItem.setActionCommand("ViewOrModifyObjectAttributes");
viewOrModifyObjectAttributesMenuItem.addActionListener(this);
guiUtils.applyIcon(viewOrModifyObjectAttributesMenuItem, "/images/nuvola/16x16/actions/viewmag.png");
objectActionMenu.add(viewOrModifyObjectAttributesMenuItem);
copyObjectsMenuItem = new JMenuItem("Copy or Move objects...");
copyObjectsMenuItem.setActionCommand("CopyObjects");
copyObjectsMenuItem.addActionListener(this);
guiUtils.applyIcon(copyObjectsMenuItem, "/images/nuvola/16x16/actions/filenew.png");
objectActionMenu.add(copyObjectsMenuItem);
updateObjectACLMenuItem = new JMenuItem("View or Modify Access Control Lists...");
updateObjectACLMenuItem.setActionCommand("UpdateObjectACL");
updateObjectACLMenuItem.addActionListener(this);
guiUtils.applyIcon(updateObjectACLMenuItem, "/images/nuvola/16x16/actions/encrypted.png");
objectActionMenu.add(updateObjectACLMenuItem);
downloadObjectMenuItem = new JMenuItem("Download objects...");
downloadObjectMenuItem.setActionCommand("DownloadObjects");
downloadObjectMenuItem.addActionListener(this);
guiUtils.applyIcon(downloadObjectMenuItem, "/images/nuvola/16x16/actions/1downarrow.png");
objectActionMenu.add(downloadObjectMenuItem);
uploadFilesMenuItem = new JMenuItem("Upload files...");
uploadFilesMenuItem.setActionCommand("UploadFiles");
uploadFilesMenuItem.addActionListener(this);
guiUtils.applyIcon(uploadFilesMenuItem, "/images/nuvola/16x16/actions/1uparrow.png");
objectActionMenu.add(uploadFilesMenuItem);
objectActionMenu.add(new JSeparator());
generatePublicGetUrls = new JMenuItem("Generate Public GET URLs...");
generatePublicGetUrls.setActionCommand("GeneratePublicGetURLs");
generatePublicGetUrls.addActionListener(this);
guiUtils.applyIcon(generatePublicGetUrls, "/images/nuvola/16x16/actions/wizard.png");
objectActionMenu.add(generatePublicGetUrls);
generateTorrentUrl = new JMenuItem("Generate Torrent URL...");
generateTorrentUrl.setActionCommand("GenerateTorrentURL");
generateTorrentUrl.addActionListener(this);
guiUtils.applyIcon(generateTorrentUrl, "/images/nuvola/16x16/actions/wizard.png");
objectActionMenu.add(generateTorrentUrl);
objectActionMenu.add(new JSeparator());
deleteObjectMenuItem = new JMenuItem("Delete objects...");
deleteObjectMenuItem.setActionCommand("DeleteObjects");
deleteObjectMenuItem.addActionListener(this);
guiUtils.applyIcon(deleteObjectMenuItem, "/images/nuvola/16x16/actions/cancel.png");
objectActionMenu.add(deleteObjectMenuItem);
viewOrModifyObjectAttributesMenuItem.setEnabled(false);
copyObjectsMenuItem.setEnabled(false);
refreshObjectMenuItem.setEnabled(false);
updateObjectACLMenuItem.setEnabled(false);
downloadObjectMenuItem.setEnabled(false);
uploadFilesMenuItem.setEnabled(false);
generatePublicGetUrls.setEnabled(false);
generateTorrentUrl.setEnabled(false);
deleteObjectMenuItem.setEnabled(false);
// Tools menu.
JMenu toolsMenu = new JMenu("Tools");
bucketLoggingMenuItem = new JMenuItem("Configure Bucket logging...");
bucketLoggingMenuItem.setActionCommand("BucketLogging");
bucketLoggingMenuItem.addActionListener(this);
bucketLoggingMenuItem.setEnabled(false);
guiUtils.applyIcon(bucketLoggingMenuItem, "/images/nuvola/16x16/actions/toggle_log.png");
toolsMenu.add(bucketLoggingMenuItem);
manageDistributionsMenuItem = new JMenuItem("Manage CloudFront Distributions...");
manageDistributionsMenuItem.setActionCommand("ManageDistributions");
manageDistributionsMenuItem.addActionListener(this);
guiUtils.applyIcon(manageDistributionsMenuItem, "/images/nuvola/16x16/actions/irkick.png");
manageDistributionsMenuItem.setEnabled(false);
toolsMenu.add(manageDistributionsMenuItem);
toolsMenu.add(new JSeparator());
preferencesDialogMenuItem = new JMenuItem("Preferences...");
preferencesDialogMenuItem.setActionCommand("PreferencesDialog");
preferencesDialogMenuItem.addActionListener(this);
guiUtils.applyIcon(preferencesDialogMenuItem, "/images/nuvola/16x16/actions/configure.png");
toolsMenu.add(preferencesDialogMenuItem);
// Help menu.
JMenu helpMenu = new JMenu("Help");
cockpitHelpMenuItem = new JMenuItem("Cockpit Guide");
guiUtils.applyIcon(cockpitHelpMenuItem, "/images/nuvola/16x16/actions/help.png");
cockpitHelpMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
followHyperlink(new URL(JETS3T_COCKPIT_HELP_PAGE), "_blank");
} catch (MalformedURLException ex) {
throw new IllegalStateException("Invalid URL embedded in program: "
+ JETS3T_COCKPIT_HELP_PAGE);
}
}
});
helpMenu.add(cockpitHelpMenuItem);
amazonS3HelpMenuItem = new JMenuItem("Amazon S3");
guiUtils.applyIcon(amazonS3HelpMenuItem, "/images/nuvola/16x16/actions/gohome.png");
amazonS3HelpMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
followHyperlink(new URL(AMAZON_S3_PAGE), "_blank");
} catch (MalformedURLException ex) {
throw new IllegalStateException("Invalid URL embedded in program: "
+ AMAZON_S3_PAGE);
}
}
});
helpMenu.add(amazonS3HelpMenuItem);
// Build application menu bar.
appMenuBar.add(serviceMenu);
appMenuBar.add(toolsMenu);
appMenuBar.add(helpMenu);
}
/**
* Initialise the application's File drop targets for drag and drop copying of local files
* to S3.
*
* @param dropTargetComponents
* the components files can be dropped on to transfer them to S3
*/
private void initDropTarget(JComponent[] dropTargetComponents) {
DropTargetListener dropTargetListener = new DropTargetListener() {
private boolean checkValidDrag(DropTargetDragEvent dtde) {
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
&& (DnDConstants.ACTION_COPY == dtde.getDropAction()
|| DnDConstants.ACTION_MOVE == dtde.getDropAction()))
{
dtde.acceptDrag(dtde.getDropAction());
return true;
} else {
dtde.rejectDrag();
return false;
}
}
public void dragEnter(DropTargetDragEvent dtde) {
if (checkValidDrag(dtde)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
objectsTable.requestFocusInWindow();
};
});
}
}
public void dragOver(DropTargetDragEvent dtde) {
checkValidDrag(dtde);
}
public void dropActionChanged(DropTargetDragEvent dtde) {
if (checkValidDrag(dtde)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
objectsTable.requestFocusInWindow();
};
});
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ownerFrame.requestFocusInWindow();
};
});
}
}
public void dragExit(DropTargetEvent dte) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ownerFrame.requestFocusInWindow();
};
});
}
public void drop(DropTargetDropEvent dtde) {
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
&& (DnDConstants.ACTION_COPY == dtde.getDropAction()
|| DnDConstants.ACTION_MOVE == dtde.getDropAction()))
{
dtde.acceptDrop(dtde.getDropAction());
try {
final List fileList = (List) dtde.getTransferable().getTransferData(
DataFlavor.javaFileListFlavor);
if (fileList != null && fileList.size() > 0) {
uploadFiles((File[]) fileList.toArray(new File[fileList.size()]));
}
} catch (Exception e) {
String message = "Unable to start accept dropped items";
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, null, message, e);
}
} else {
dtde.rejectDrop();
}
}
};
// Attach drop target listener to each target component.
for (int i = 0; i < dropTargetComponents.length; i++) {
new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
}
}
/**
* Run the provided Runnable object in a background thread. This method will
* return as soon as the background thread is started, it does not wait for
* the thread to complete.
*/
private synchronized void runInBackgroundThread(Runnable runnable) {
Thread t = new Thread(runnable);
t.start();
}
/**
* Run the provided runnable in the application's event dispatcher thread,
* and wait for the action to complete before returning.
*
* @param runnable
* @return
*/
private synchronized boolean runInDispatcherThreadImmediately(Runnable runnable) {
try {
SwingUtilities.invokeAndWait(runnable);
return true;
} catch (Exception e) {
log.error("Error displaying graphical elements", e);
return false;
}
}
/**
* Starts a progress display dialog that cannot be cancelled. While the dialog is running the user
* cannot interact with the application.
*
* @param statusText
* describes the status of a task in text meaningful to the user
*/
private void startProgressDialog(String statusText) {
startProgressDialog(statusText, null, 0, 0, null, null);
}
/**
* Starts a progress display dialog. While the dialog is running the user cannot interact
* with the application, except to cancel the task.
*
* @param statusMessage
* describes the status of a task text meaningful to the user, such as "3 files of 7 uploaded"
* @param detailsText
* describes the status of a task in more detail, such as the current transfer rate and Time remaining.
* @param minTaskValue the minimum progress value for a task, generally 0
* @param maxTaskValue
* the maximum progress value for a task, such as the total number of threads or 100 if
* using percentage-complete as a metric.
* @param cancelEventListener
* listener that is responsible for cancelling a long-lived task when the user clicks
* the cancel button. If a task cannot be cancelled this must be null.
* @param cancelButtonText
* text displayed in the cancel button if a task can be cancelled. This is only used if
* a cancel event listener is provided.
*/
private void startProgressDialog(final String statusMessage, final String detailsText,
final int minTaskValue, final int maxTaskValue, final String cancelButtonText,
final CancelEventTrigger cancelEventListener)
{
if (this.progressDialog == null) {
this.progressDialog = new ProgressDialog(this.ownerFrame, "Please wait...", null);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressDialog.startDialog(statusMessage, detailsText, minTaskValue, maxTaskValue,
cancelEventListener, cancelButtonText);
}
});
}
/**
* Updates the status text and value of the progress display dialog.
* @param statusMessage
* describes the status of a task text meaningful to the user, such as "3 files of 7 uploaded"
* @param detailsText
* describes the status of a task in more detail, such as the current transfer rate and time remaining.
* @param progressValue
* value representing how far through the task we are (relative to min and max values)
*/
private void updateProgressDialog(final String statusMessage, final String detailsText, final int progressValue) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressDialog.updateDialog(statusMessage, detailsText, progressValue);
}
});
}
/**
* Stops/halts the progress display dialog and allows the user to interact with the application.
*/
private void stopProgressDialog() {
runInDispatcherThreadImmediately(new Runnable() {
public void run() {
progressDialog.stopDialog();
}
});
}
/**
* Event handler for this application, handles all menu items.
*/
public void actionPerformed(ActionEvent event) {
// Service Menu Events
if ("LoginEvent".equals(event.getActionCommand())) {
loginEvent();
} else if ("LogoutEvent".equals(event.getActionCommand())) {
logoutEvent();
} else if ("QuitEvent".equals(event.getActionCommand())) {
System.exit(0);
}
// Bucket Events.
else if ("ViewBucketProperties".equals(event.getActionCommand())) {
listBucketProperties();
} else if ("RefreshBuckets".equals(event.getActionCommand())) {
listAllBuckets();
} else if ("CreateBucket".equals(event.getActionCommand())) {
createBucketAction();
} else if ("DeleteBucket".equals(event.getActionCommand())) {
deleteSelectedBucket();
} else if ("ManageDistributions".equals(event.getActionCommand())) {
S3Bucket[] buckets = bucketTableModel.getBuckets();
String[] bucketNames = new String[buckets.length];
for (int i = 0; i < buckets.length; i++) {
bucketNames[i] = buckets[i].getName();
}
ManageDistributionsDialog.showDialog(ownerFrame, cloudFrontService, bucketNames, this);
} else if ("AddThirdPartyBucket".equals(event.getActionCommand())) {
addThirdPartyBucket();
} else if ("UpdateBucketACL".equals(event.getActionCommand())) {
updateBucketAccessControlList();
} else if ("UpdateBucketRequesterPaysStatus".equals(event.getActionCommand())) {
updateBucketRequesterPaysSetting();
}
// Object Events
else if ("ViewOrModifyObjectAttributes".equals(event.getActionCommand())) {
displayObjectsAttributesDialog();
} else if ("CopyObjects".equals(event.getActionCommand())) {
copyObjects();
} else if ("RefreshObjects".equals(event.getActionCommand())) {
listObjects();
} else if ("UpdateObjectACL".equals(event.getActionCommand())) {
displayAclModificationDialog();
} else if ("GeneratePublicGetURLs".equals(event.getActionCommand())) {
generatePublicGetUrls();
} else if ("GenerateTorrentURL".equals(event.getActionCommand())) {
generateTorrentUrl();
} else if ("DeleteObjects".equals(event.getActionCommand())) {
deleteSelectedObjects();
} else if ("DownloadObjects".equals(event.getActionCommand())) {