Search in sources :

Example 1 with S3Tree

use of org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree in project airavata by apache.

the class AmazonS3UtilsWindow method initGUI.

@SuppressWarnings("serial")
protected void initGUI() {
    /* Upload Panel */
    this.fileTextField = new XBayaTextField();
    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.getGUI().getErrorWindow().error(e1);
                }
                return;
            }
            AmazonS3UtilsWindow.this.s3Tree.clean();
            BucketsLoader bucketsLoader = new BucketsLoader(xBayaEngine.getGUI(), 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.getGUI().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.getGUI().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();
            if (node == null)
                return;
            Object nodeInfo = node.getUserObject();
            String bucketName;
            String downloadPanelBucketName = "";
            if (node.isLeaf() && node.getParent() != null) {
                // Node is probably a key
                DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                bucketName = (String) parentNode.getUserObject();
                if (!bucketName.equals("S3 Contents")) {
                    // Node is indeed a key
                    downloadPanelBucketName = (String) parentNode.getUserObject();
                    String currentNodeName = (String) node.getUserObject();
                    int index = currentNodeName.lastIndexOf('/');
                    index = index >= 0 ? index : 0;
                    if (index > 0) {
                        bucketName = bucketName + "/" + currentNodeName.substring(0, index);
                    }
                    String keyName = (String) nodeInfo;
                    window.keyTextField.setText(keyName);
                } else // Node is a bucket
                {
                    bucketName = (String) nodeInfo;
                    window.keyTextField.setText("");
                }
            } else {
                // Node is a bucket
                bucketName = (String) nodeInfo;
                window.keyTextField.setText("");
            }
            window.uploadBucketTextField.setText(bucketName);
            window.downloadBucketTextField.setText(downloadPanelBucketName);
        }
    });
    this.dialog = new XBayaDialog(xBayaEngine.getGUI(), "Amazon S3 Upload/Download Tool", mainPanel, buttonPanel);
}
Also used : XBayaDialog(org.apache.airavata.xbaya.ui.dialogs.XBayaDialog) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) S3Tree(org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree) TreeSelectionListener(javax.swing.event.TreeSelectionListener) S3ServiceException(org.jets3t.service.S3ServiceException) GridPanel(org.apache.airavata.xbaya.ui.widgets.GridPanel) XBayaTextField(org.apache.airavata.xbaya.ui.widgets.XBayaTextField) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) File(java.io.File) XBayaLabel(org.apache.airavata.xbaya.ui.widgets.XBayaLabel)

Example 2 with S3Tree

use of org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree in project airavata by apache.

the class S3FileChooser method initGUI.

private void initGUI() {
    /*
         * ScrollPane for S3 Tree
         */
    // add tree listener to this
    this.s3Tree = new S3Tree();
    this.s3Tree.addTreeSelectionListener(this);
    JScrollPane scrollPane = new JScrollPane(this.s3Tree);
    /*
         * 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()) {
                S3FileChooser.this.xbayaGUI.getErrorWindow().warning(S3FileChooser.this.dialog.getDialog(), "Error", "Aws Access Key not set!");
                if (this.credentialWindow == null) {
                    this.credentialWindow = new ChangeCredentialWindow(S3FileChooser.this.dialog.getDialog());
                }
                try {
                    this.credentialWindow.show();
                } catch (Exception e1) {
                    S3FileChooser.this.xbayaGUI.getErrorWindow().error(e1);
                }
                return;
            }
            S3FileChooser.this.s3Tree.clean();
            try {
                // create S3Service
                S3Service s3Service = new RestS3Service(new AWSCredentials(AmazonCredential.getInstance().getAwsAccessKeyId(), AmazonCredential.getInstance().getAwsSecretAccessKey()));
                BucketsLoader bucketsLoader = new BucketsLoader(S3FileChooser.this.xbayaGUI, S3FileChooser.this.dialog.getDialog());
                bucketsLoader.load(s3Service, S3FileChooser.this.s3Tree);
            } catch (S3ServiceException s3ex) {
                S3FileChooser.this.xbayaGUI.getErrorWindow().error(s3ex);
            }
        }
    });
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (S3FileChooser.this.chosenFile != null) {
                S3FileChooser.this.inputNode.setDefaultValue(new String(S3FileChooser.this.chosenFile));
            }
            hide();
        }
    });
    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(okButton);
    buttonPanel.add(cancelButton);
    this.dialog = new XBayaDialog(this.xbayaGUI, "Amazon S3 Input Chooser", scrollPane, buttonPanel);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) XBayaDialog(org.apache.airavata.xbaya.ui.dialogs.XBayaDialog) S3Tree(org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) S3ServiceException(org.jets3t.service.S3ServiceException) AWSCredentials(org.jets3t.service.security.AWSCredentials) S3ServiceException(org.jets3t.service.S3ServiceException) BucketsLoader(org.apache.airavata.xbaya.ui.dialogs.amazon.BucketsLoader) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) ChangeCredentialWindow(org.apache.airavata.xbaya.ui.dialogs.amazon.ChangeCredentialWindow) AbstractAction(javax.swing.AbstractAction) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Service(org.jets3t.service.S3Service)

Aggregations

ActionEvent (java.awt.event.ActionEvent)2 XBayaDialog (org.apache.airavata.xbaya.ui.dialogs.XBayaDialog)2 S3Tree (org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree)2 S3ServiceException (org.jets3t.service.S3ServiceException)2 File (java.io.File)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 BucketsLoader (org.apache.airavata.xbaya.ui.dialogs.amazon.BucketsLoader)1 ChangeCredentialWindow (org.apache.airavata.xbaya.ui.dialogs.amazon.ChangeCredentialWindow)1 GridPanel (org.apache.airavata.xbaya.ui.widgets.GridPanel)1 XBayaLabel (org.apache.airavata.xbaya.ui.widgets.XBayaLabel)1 XBayaTextField (org.apache.airavata.xbaya.ui.widgets.XBayaTextField)1 S3Service (org.jets3t.service.S3Service)1 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)1 AWSCredentials (org.jets3t.service.security.AWSCredentials)1