XBayaLabel fileLabel = new XBayaLabel("Upload File Path", this.fileTextField);
this.uploadBucketTextField = new XBayaTextField();
XBayaLabel uploadBucketLabel = new XBayaLabel("Bucket Name", this.uploadBucketTextField);
GridPanel uploadPanel = new GridPanel();
uploadPanel.getSwingComponent().setBorder(BorderFactory.createTitledBorder("Upload"));
uploadPanel.add(fileLabel);
uploadPanel.add(this.fileTextField);
uploadPanel.add(uploadBucketLabel);
uploadPanel.add(this.uploadBucketTextField);
uploadPanel.layout(2, 2, GridPanel.WEIGHT_NONE, 1);
/*
* Download Panel
*/if (AmazonCredential.getInstance().getAwsAccessKeyId().equals("AKIAI3GNMQVYA5LSQNEQ")) { // Avoid to use
// default Aws
// Access Key
JOptionPane.showMessageDialog(AmazonS3UtilsWindow.this.dialog.getDialog(), "Aws Access Key not set!",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
this.downloadBucketTextField = new XBayaTextField();
XBayaLabel downloadBucketLabel = new XBayaLabel("Bucket Name", this.downloadBucketTextField);
this.keyTextField = new XBayaTextField();
XBayaLabel keyLabel = new XBayaLabel("Key Name", this.keyTextField);
this.folderTextField = new XBayaTextField();
XBayaLabel folderLabel = new XBayaLabel("Download Location", this.folderTextField);
GridPanel downloadPanel = new GridPanel();
downloadPanel.getSwingComponent().setBorder(BorderFactory.createTitledBorder("Download"));
downloadPanel.add(downloadBucketLabel);
downloadPanel.add(this.downloadBucketTextField);
downloadPanel.add(keyLabel);
downloadPanel.add(this.keyTextField);
downloadPanel.add(folderLabel);
downloadPanel.add(this.folderTextField);
downloadPanel.layout(3, 2, GridPanel.WEIGHT_NONE, 1);
/*
* Button Panel
*/
JButton refreshButton = new JButton("Connect/Refresh");
refreshButton.addActionListener(new AbstractAction() {
private ChangeCredentialWindow credentialWindow;
@Override
public void actionPerformed(ActionEvent e) {
if (AmazonCredential.getInstance().getAwsAccessKeyId().isEmpty()
|| AmazonCredential.getInstance().getAwsSecretAccessKey().isEmpty()) {
JOptionPane.showMessageDialog(AmazonS3UtilsWindow.this.dialog.getDialog(),
"Aws Access Key not set!", "Error", JOptionPane.ERROR_MESSAGE);
if (this.credentialWindow == null) {
this.credentialWindow = new ChangeCredentialWindow(AmazonS3UtilsWindow.this.dialog.getDialog());
}
try {
this.credentialWindow.show();
} catch (Exception e1) {
xBayaEngine.getErrorWindow().error(e1);
}
return;
}
AmazonS3UtilsWindow.this.s3Tree.clean();
BucketsLoader bucketsLoader = new BucketsLoader(xBayaEngine, window.dialog.getDialog());
bucketsLoader.load(getS3Service(), AmazonS3UtilsWindow.this.s3Tree);
}
});
JButton uploadButton = new JButton("Upload");
uploadButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ((window.fileTextField.getText().length() != 0)
&& (window.uploadBucketTextField.getText().length() != 0)) {
S3Uploader s3Uploader = new S3Uploader(xBayaEngine, window.dialog.getDialog());
s3Uploader.upload(getS3Service(), AmazonS3UtilsWindow.this.s3Tree,
window.uploadBucketTextField.getText(), window.fileTextField.getText());
window.fileTextField.setText("");
window.folderTextField.setText("");
} else {
xBayaEngine.getErrorWindow().error(window.dialog.getDialog(),
"Please give input to every upload fields");
}
}
});
JButton downloadButton = new JButton("Download");
downloadButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ((window.downloadBucketTextField.getText().length() != 0)
&& (window.keyTextField.getText().length() != 0)
&& (window.folderTextField.getText().length() != 0)) {
S3Downloader s3Downloader = new S3Downloader(xBayaEngine, window.dialog.getDialog());
s3Downloader.download(getS3Service(), window.downloadBucketTextField.getText(),
window.keyTextField.getText(), window.folderTextField.getText());
window.downloadBucketTextField.setText("");
window.keyTextField.setText("");
window.folderTextField.setText("");
} else {
xBayaEngine.getErrorWindow().error(window.dialog.getDialog(),
"Please give input to every download fields");
}
}
});
JButton fileButton = new JButton("Choose File & Flolder");
fileButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = fc.showOpenDialog(AmazonS3UtilsWindow.this.dialog.getDialog());
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filePath = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
if (file.isFile()) {
window.fileTextField.setText(filePath);
window.folderTextField.setText("");
} else if (file.isDirectory()) {
window.folderTextField.setText(filePath);
window.fileTextField.setText("");
}
}
}
});
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
hide();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(refreshButton);
buttonPanel.add(uploadButton);
buttonPanel.add(downloadButton);
buttonPanel.add(fileButton);
buttonPanel.add(cancelButton);
/*
* Main Panel
*/
GridPanel mainPanel = new GridPanel(true);
this.s3Tree = new S3Tree();
mainPanel.add(new JScrollPane(this.s3Tree));
mainPanel.add(uploadPanel);
mainPanel.add(downloadPanel);
mainPanel.layout(3, 1, 0, GridPanel.WEIGHT_EQUALLY);
this.s3Tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = AmazonS3UtilsWindow.this.s3Tree.getSelectedNode();