FileDocCategorySizeDatePackage
ConvertToAndroidAction.javaAPI DocAndroid 1.5 API5575Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt.project

ConvertToAndroidAction

public class ConvertToAndroidAction extends Object implements org.eclipse.ui.IObjectActionDelegate
Converts a project created with the activity creator into an Android project.

Fields Summary
private org.eclipse.jface.viewers.ISelection
mSelection
Constructors Summary
Methods Summary
private voidconvertProject(org.eclipse.core.resources.IProject project)
Toggles sample nature on a project

param
project to have sample nature added or removed

        new Job("Convert Project") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    if (monitor != null) {
                        monitor.beginTask(String.format(
                                "Convert %1$s to Android", project.getName()), 5);
                    }

                    IProjectDescription description = project.getDescription();
                    String[] natures = description.getNatureIds();

                    // check if the project already has the android nature.
                    for (int i = 0; i < natures.length; ++i) {
                        if (AndroidConstants.NATURE.equals(natures[i])) {
                            // we shouldn't be here as the visibility of the item
                            // is dependent on the project.
                            return new Status(Status.WARNING, AdtPlugin.PLUGIN_ID,
                                    "Project is already an Android project");
                        }
                    }

                    if (monitor != null) {
                        monitor.worked(1);
                    }

                    String[] newNatures = new String[natures.length + 1];
                    System.arraycopy(natures, 0, newNatures, 1, natures.length);
                    newNatures[0] = AndroidConstants.NATURE;

                    // set the new nature list in the project
                    description.setNatureIds(newNatures);
                    project.setDescription(description, null);
                    if (monitor != null) {
                        monitor.worked(1);
                    }

                    // Fix the classpath entries.
                    // get a java project
                    IJavaProject javaProject = JavaCore.create(project);
                    ProjectHelper.fixProjectClasspathEntries(javaProject);
                    if (monitor != null) {
                        monitor.worked(1);
                    }

                    return Status.OK_STATUS;
                } catch (JavaModelException e) {
                    return e.getJavaModelStatus();
                } catch (CoreException e) {
                    return e.getStatus();
                } finally {
                    if (monitor != null) {
                        monitor.done();
                    }
                }
            }
        }.schedule();
    
public voidrun(org.eclipse.jface.action.IAction action)

        if (mSelection instanceof IStructuredSelection) {
            for (Iterator<?> it = ((IStructuredSelection)mSelection).iterator(); it.hasNext();) {
                Object element = it.next();
                IProject project = null;
                if (element instanceof IProject) {
                    project = (IProject)element;
                } else if (element instanceof IAdaptable) {
                    project = (IProject)((IAdaptable)element).getAdapter(IProject.class);
                }
                if (project != null) {
                    convertProject(project);
                }
            }
        }
    
public voidselectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection)

        this.mSelection = selection;
    
public voidsetActivePart(org.eclipse.jface.action.IAction action, org.eclipse.ui.IWorkbenchPart targetPart)

        // pass