Search in sources :

Example 1 with XbayaEnhancedList

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

the class EC2InstancesManagementWindow method initGUI.

private void initGUI() {
    this.list = new XbayaEnhancedList<EC2InstanceResult>();
    GridPanel mainPanel = new GridPanel();
    TitledBorder border = new TitledBorder(new EtchedBorder(), "My Instances");
    mainPanel.getSwingComponent().setBorder(border);
    mainPanel.add(this.list);
    mainPanel.layout(1, 1, 0, 0);
    /* Connect/Refresh Button */
    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            /* Check if Credential is already set or not */
            if (credentialSet()) {
                InstancesLoader instancesLoader = new InstancesLoader(EC2InstancesManagementWindow.this.engine, EC2InstancesManagementWindow.this.dialog.getDialog());
                instancesLoader.load(EC2InstancesManagementWindow.this.list);
            }
        }
    });
    /* Launch Instance Button */
    JButton launchButton = new JButton("Launch");
    launchButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (credentialSet()) {
                EC2LaunchWindow ec2LaunchWindow = new EC2LaunchWindow(EC2InstancesManagementWindow.this.engine);
                ec2LaunchWindow.show();
            }
        }
    });
    /* Terminate Instance */
    JButton terminateButton = new JButton("Terminate");
    terminateButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<EC2InstanceResult> selected = EC2InstancesManagementWindow.this.list.getSelectedValues();
            if (selected.size() == 0) {
                EC2InstancesManagementWindow.this.engine.getGUI().getErrorWindow().info(EC2InstancesManagementWindow.this.dialog.getDialog(), "Warning", "No instances selected");
                return;
            }
            String text = "";
            List<String> requestIds = new ArrayList<String>();
            for (EC2InstanceResult ec2InstancesResult : selected) {
                requestIds.add(ec2InstancesResult.getInstance().getInstanceId());
                text += ec2InstancesResult.getInstance().getInstanceId() + ",";
            }
            // confirm from user
            int n = JOptionPane.showConfirmDialog(EC2InstancesManagementWindow.this.dialog.getDialog(), "Are you want to terminate instances:\n" + text, "Terminate Instances", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (n == JOptionPane.YES_OPTION) {
                // terminate
                AmazonUtil.terminateInstances(requestIds);
                // reload
                InstancesLoader instancesLoader = new InstancesLoader(EC2InstancesManagementWindow.this.engine, EC2InstancesManagementWindow.this.dialog.getDialog());
                instancesLoader.load(EC2InstancesManagementWindow.this.list);
            }
        }
    });
    /* Close Button */
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            EC2InstancesManagementWindow.this.hide();
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(refreshButton);
    buttonPanel.add(launchButton);
    buttonPanel.add(terminateButton);
    buttonPanel.add(closeButton);
    this.dialog = new XBayaDialog(this.engine.getGUI(), "Amazon EC2 Management Console", mainPanel, buttonPanel);
    int width = 800;
    int height = 500;
    this.dialog.getDialog().setPreferredSize(new Dimension(width, height));
    this.dialog.setDefaultButton(closeButton);
}
Also used : XBayaDialog(org.apache.airavata.xbaya.ui.dialogs.XBayaDialog) EC2InstanceResult(org.apache.airavata.xbaya.core.amazon.EC2InstanceResult) ActionEvent(java.awt.event.ActionEvent) TitledBorder(javax.swing.border.TitledBorder) EtchedBorder(javax.swing.border.EtchedBorder) GridPanel(org.apache.airavata.xbaya.ui.widgets.GridPanel) XbayaEnhancedList(org.apache.airavata.xbaya.ui.widgets.XbayaEnhancedList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EtchedBorder (javax.swing.border.EtchedBorder)1 TitledBorder (javax.swing.border.TitledBorder)1 EC2InstanceResult (org.apache.airavata.xbaya.core.amazon.EC2InstanceResult)1 XBayaDialog (org.apache.airavata.xbaya.ui.dialogs.XBayaDialog)1 GridPanel (org.apache.airavata.xbaya.ui.widgets.GridPanel)1 XbayaEnhancedList (org.apache.airavata.xbaya.ui.widgets.XbayaEnhancedList)1