1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.ide.eclipse.adt.internal.wizards.newproject; 17 18 import static com.android.SdkConstants.FN_PROJECT_PROGUARD_FILE; 19 import static com.android.SdkConstants.OS_SDK_TOOLS_LIB_FOLDER; 20 21 import com.android.ide.eclipse.adt.AdtPlugin; 22 import com.android.ide.eclipse.adt.AdtUtils; 23 import com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectWizardState.Mode; 24 25 import org.eclipse.jdt.ui.actions.OpenJavaPerspectiveAction; 26 import org.eclipse.jface.resource.ImageDescriptor; 27 import org.eclipse.jface.viewers.IStructuredSelection; 28 import org.eclipse.jface.wizard.Wizard; 29 import org.eclipse.ui.INewWizard; 30 import org.eclipse.ui.IWorkbench; 31 32 import java.io.File; 33 34 35 /** 36 * An "Import Android Project" wizard. 37 */ 38 public class ImportProjectWizard extends Wizard implements INewWizard { 39 private static final String PROJECT_LOGO_LARGE = "icons/android-64.png"; //$NON-NLS-1$ 40 41 private NewProjectWizardState mValues; 42 private ImportPage mImportPage; 43 private IStructuredSelection mSelection; 44 45 /** Constructs a new wizard default project wizard */ 46 public ImportProjectWizard() { 47 } 48 49 @Override 50 public void addPages() { 51 mValues = new NewProjectWizardState(Mode.ANY); 52 mImportPage = new ImportPage(mValues); 53 if (mSelection != null) { 54 mImportPage.init(mSelection, AdtUtils.getActivePart()); 55 } 56 addPage(mImportPage); 57 } 58 59 @Override 60 public void init(IWorkbench workbench, IStructuredSelection selection) { 61 mSelection = selection; 62 63 setHelpAvailable(false); // TODO have help 64 ImageDescriptor desc = AdtPlugin.getImageDescriptor(PROJECT_LOGO_LARGE); 65 setDefaultPageImageDescriptor(desc); 66 67 // Trigger a check to see if the SDK needs to be reloaded (which will 68 // invoke onSdkLoaded asynchronously as needed). 69 AdtPlugin.getDefault().refreshSdk(); 70 } 71 72 @Override 73 public boolean performFinish() { 74 File file = new File(AdtPlugin.getOsSdkFolder(), OS_SDK_TOOLS_LIB_FOLDER + File.separator 75 + FN_PROJECT_PROGUARD_FILE); 76 if (!file.exists()) { 77 AdtPlugin.displayError("Tools Out of Date?", 78 String.format("It looks like you do not have the latest version of the " 79 + "SDK Tools installed. Make sure you update via the SDK Manager " 80 + "first. (Could not find %1$s)", file.getPath())); 81 return false; 82 } 83 84 NewProjectCreator creator = new NewProjectCreator(mValues, getContainer()); 85 if (!(creator.createAndroidProjects())) { 86 return false; 87 } 88 89 // Open the default Java Perspective 90 OpenJavaPerspectiveAction action = new OpenJavaPerspectiveAction(); 91 action.run(); 92 return true; 93 } 94 } 95