diff --git a/aws-toolkit-eclipse-master/bundles/com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/server/ui/ImportEnvironmentsWizard.java b/aws-toolkit-eclipse-master/bundles/com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/server/ui/ImportEnvironmentsWizard.java index 654f5579b..14a270ab4 100644 --- a/aws-toolkit-eclipse-master/bundles/com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/server/ui/ImportEnvironmentsWizard.java +++ b/aws-toolkit-eclipse-master/bundles/com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/server/ui/ImportEnvironmentsWizard.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2010-2012 Amazon Technologies, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,49 +14,49 @@ */ package com.amazonaws.eclipse.elasticbeanstalk.server.ui; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.layout.TreeColumnLayout; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.wst.server.core.IServer; - -import com.amazonaws.AmazonClientException; -import com.amazonaws.AmazonServiceException; -import com.amazonaws.eclipse.core.AwsToolkitCore; -import com.amazonaws.eclipse.core.regions.Region; -import com.amazonaws.eclipse.core.regions.RegionUtils; -import com.amazonaws.eclipse.core.regions.ServiceAbbreviations; -import com.amazonaws.eclipse.elasticbeanstalk.ElasticBeanstalkPlugin; -import com.amazonaws.eclipse.elasticbeanstalk.NoCredentialsDialog; -import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalk; -import com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription; -import com.amazonaws.services.elasticbeanstalk.model.EnvironmentStatus; - +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.layout.TreeColumnLayout; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.wst.server.core.IServer; + +import com.amazonaws.AmazonClientException; +import com.amazonaws.AmazonServiceException; +import com.amazonaws.eclipse.core.AwsToolkitCore; +import com.amazonaws.eclipse.core.regions.Region; +import com.amazonaws.eclipse.core.regions.RegionUtils; +import com.amazonaws.eclipse.core.regions.ServiceAbbreviations; +import com.amazonaws.eclipse.elasticbeanstalk.ElasticBeanstalkPlugin; +import com.amazonaws.eclipse.elasticbeanstalk.NoCredentialsDialog; +import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalk; +import com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription; +import com.amazonaws.services.elasticbeanstalk.model.EnvironmentStatus; + /** * Wizard that allows the user to select running AWS Elastic Beanstalk environments to import into @@ -83,19 +83,19 @@ public ImportEnvironmentsWizard() { setWindowTitle("Import environments into the Servers view"); setHelpAvailable(false); } - - private static final class RegionEnvironmentDescription { - private final Region region; - private final EnvironmentDescription environmentDescription; - - public RegionEnvironmentDescription(Region region, EnvironmentDescription environmentDescription) { - this.region = region; - this.environmentDescription = environmentDescription; - } - } + + private static final class RegionEnvironmentDescription { + private final Region region; + private final EnvironmentDescription environmentDescription; + + public RegionEnvironmentDescription(Region region, EnvironmentDescription environmentDescription) { + this.region = region; + this.environmentDescription = environmentDescription; + } + } /** - * Our single page is responsible for creating the controls. + * Our single page is responsible for creating the controls. */ private class ImportPage extends WizardPage { @@ -106,46 +106,46 @@ protected ImportPage() { .getDefault().getImageRegistry().getDescriptor(AwsToolkitCore.IMAGE_AWS_LOGO)); } - @Override + @Override public void createControl(Composite container) { - - if ( !AwsToolkitCore.getDefault().getAccountInfo().isValid() ) { - setControl(NoCredentialsDialog.createComposite(container)); - return; - } - - IStatus status = testConnection(); - if ( !status.isOK() ) { - setControl(new ErrorComposite(container, SWT.None, status)); - return; - } - + + if ( !AwsToolkitCore.getDefault().getAccountInfo().isValid() ) { + setControl(NoCredentialsDialog.createComposite(container)); + return; + } + + IStatus status = testConnection(); + if ( !status.isOK() ) { + setControl(new ErrorComposite(container, SWT.None, status)); + return; + } + Composite parent = new Composite(container, SWT.None); FillLayout layout = new FillLayout(SWT.VERTICAL); - parent.setLayout(layout); - - /* - * Determine which elastic beanstalk environments aren't already imported as servers - */ - List environmentsToImport = new LinkedList<>(); - for ( Region region : RegionUtils.getRegionsForService(ServiceAbbreviations.BEANSTALK) ) { - List elasticBeanstalkEnvs = getExistingEnvironments(region); - Collection elasticBeanstalkServers = ElasticBeanstalkPlugin - .getExistingElasticBeanstalkServers(); - - for ( EnvironmentDescription env : elasticBeanstalkEnvs ) { - boolean alreadyExists = false; - for ( IServer server : elasticBeanstalkServers ) { - if ( ElasticBeanstalkPlugin.environmentsSame(env, region, server) ) { - alreadyExists = true; - break; - } - } - if ( !alreadyExists ) { - environmentsToImport.add(new RegionEnvironmentDescription(region, env)); - } - } - } + parent.setLayout(layout); + + /* + * Determine which elastic beanstalk environments aren't already imported as servers + */ + List environmentsToImport = new LinkedList<>(); + for ( Region region : RegionUtils.getRegionsForService(ServiceAbbreviations.BEANSTALK) ) { + List elasticBeanstalkEnvs = getExistingEnvironments(region); + Collection elasticBeanstalkServers = ElasticBeanstalkPlugin + .getExistingElasticBeanstalkServers(); + + for ( EnvironmentDescription env : elasticBeanstalkEnvs ) { + boolean alreadyExists = false; + for ( IServer server : elasticBeanstalkServers ) { + if ( ElasticBeanstalkPlugin.environmentsSame(env, region, server) ) { + alreadyExists = true; + break; + } + } + if ( !alreadyExists ) { + environmentsToImport.add(new RegionEnvironmentDescription(region, env)); + } + } + } if ( environmentsToImport.isEmpty() ) { new Label(parent, SWT.None).setText("There are no running environments to import."); @@ -185,7 +185,7 @@ public void createControl(Composite container) { viewer.setInput(environmentsToImport.toArray(new RegionEnvironmentDescription[environmentsToImport.size()])); viewer.getTree().addSelectionListener(new SelectionListener() { - @Override + @Override public void widgetSelected(SelectionEvent e) { if ( viewer.getCheckedElements().length > 0 ) { setErrorMessage(null); @@ -198,7 +198,7 @@ public void widgetSelected(SelectionEvent e) { ImportEnvironmentsWizard.this.getContainer().updateButtons(); } - @Override + @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @@ -206,35 +206,35 @@ public void widgetDefaultSelected(SelectionEvent e) { } setControl(container); - } - - private IStatus testConnection() { - try { - this.getWizard() - .getContainer() - .run(true, - false, - new CheckAccountRunnable(AwsToolkitCore.getClientFactory() - .getElasticBeanstalkClientByEndpoint( - RegionUtils.getRegion(ElasticBeanstalkPlugin.DEFAULT_REGION) - .getServiceEndpoints().get(ServiceAbbreviations.BEANSTALK)))); - return Status.OK_STATUS; - } catch ( InvocationTargetException ite ) { - String errorMessage = "Unable to connect to AWS Elastic Beanstalk. "; - try { - throw ite.getCause(); - } catch ( AmazonServiceException ase ) { - errorMessage += "Make sure you've registered your AWS account for the AWS Elastic Beanstalk service."; - } catch ( AmazonClientException ace ) { - errorMessage += "Make sure your computer is connected to the internet, and any network firewalls or proxys are configured appropriately."; - } catch ( Throwable t ) { - } - - return new Status(IStatus.ERROR, ElasticBeanstalkPlugin.PLUGIN_ID, errorMessage, ite.getCause()); - } catch ( InterruptedException e ) { - return Status.CANCEL_STATUS; - } - } + } + + private IStatus testConnection() { + try { + this.getWizard() + .getContainer() + .run(true, + false, + new CheckAccountRunnable(AwsToolkitCore.getClientFactory() + .getElasticBeanstalkClientByEndpoint( + RegionUtils.getRegion(ElasticBeanstalkPlugin.DEFAULT_REGION) + .getServiceEndpoints().get(ServiceAbbreviations.BEANSTALK)))); + return Status.OK_STATUS; + } catch ( InvocationTargetException ite ) { + String errorMessage = "Unable to connect to AWS Elastic Beanstalk. "; + try { + throw ite.getCause(); + } catch ( AmazonServiceException ase ) { + errorMessage += "Make sure you've registered your AWS account for the AWS Elastic Beanstalk service."; + } catch ( AmazonClientException ace ) { + errorMessage += "Make sure your computer is connected to the internet, and any network firewalls or proxys are configured appropriately."; + } catch ( Throwable t ) { + } + + return new Status(IStatus.ERROR, ElasticBeanstalkPlugin.PLUGIN_ID, errorMessage, ite.getCause()); + } catch ( InterruptedException e ) { + return Status.CANCEL_STATUS; + } + } } @Override @@ -243,23 +243,12 @@ public void addPages() { } /** - * Returns all AWS Elastic Beanstalk environments in the region given. + * Returns all AWS Elastic Beanstalk environments in the region given. */ - private List getExistingEnvironments(Region region) { - List filtered = new ArrayList<>(); - - AWSElasticBeanstalk client = AwsToolkitCore.getClientFactory().getElasticBeanstalkClientByEndpoint( - region.getServiceEndpoints().get(ServiceAbbreviations.BEANSTALK)); - List environments = client.describeEnvironments().getEnvironments(); - - // Only list the active environments - for ( EnvironmentDescription env : environments ) { - if ( !(env.getStatus().equals(EnvironmentStatus.Terminated.toString()) || env.getStatus().equals( - EnvironmentStatus.Terminating.toString())) ) - filtered.add(env); - } - return filtered; - } + private List getExistingEnvironments(Region region) { + List filtered = new ArrayList<>(); + return filtered; + } /* * (non-Javadoc) @@ -272,16 +261,16 @@ public boolean performFinish() { try { getContainer().run(true, false, new IRunnableWithProgress() { - @Override + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Importing servers", toImport.length * 3); try { for ( Object elasticBeanstalkEnv : toImport ) { - try { - RegionEnvironmentDescription regionEnvironmentDescription = (RegionEnvironmentDescription) elasticBeanstalkEnv; - ElasticBeanstalkPlugin.importEnvironment( - regionEnvironmentDescription.environmentDescription, - regionEnvironmentDescription.region, monitor); + try { + RegionEnvironmentDescription regionEnvironmentDescription = (RegionEnvironmentDescription) elasticBeanstalkEnv; + ElasticBeanstalkPlugin.importEnvironment( + regionEnvironmentDescription.environmentDescription, + regionEnvironmentDescription.region, monitor); } catch ( CoreException e ) { throw new RuntimeException(e); } @@ -325,24 +314,24 @@ protected TreeColumn newColumn(String columnText, int weight) { private class EnvironmentSelectionTreeProvider implements ITableLabelProvider, ITreeContentProvider { - @Override + @Override public void removeListener(ILabelProviderListener listener) { } - @Override + @Override public boolean isLabelProperty(Object element, String property) { return false; } - @Override + @Override public void dispose() { } - @Override + @Override public void addListener(ILabelProviderListener listener) { } - @Override + @Override public String getColumnText(Object element, int columnIndex) { RegionEnvironmentDescription env = (RegionEnvironmentDescription) element; @@ -361,33 +350,33 @@ public String getColumnText(Object element, int columnIndex) { return ""; } - @Override + @Override public Image getColumnImage(Object element, int columnIndex) { if ( columnIndex == 0 ) return ElasticBeanstalkPlugin.getDefault().getImageRegistry().get(ElasticBeanstalkPlugin.IMG_SERVER); return null; } - @Override + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } - @Override + @Override public boolean hasChildren(Object element) { return false; } - @Override + @Override public Object getParent(Object element) { return null; } - @Override + @Override public Object[] getElements(Object inputElement) { return (Object[]) inputElement; } - @Override + @Override public Object[] getChildren(Object parentElement) { return new Object[0]; }