FileDocCategorySizeDatePackage
ProjectCheckPage.javaAPI DocAndroid 1.5 API11954Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt.project.export

ProjectCheckPage

public final class ProjectCheckPage extends com.android.ide.eclipse.adt.project.export.ExportWizard.ExportWizardPage
First Export Wizard Page. Display warning/errors.

Fields Summary
private static final String
IMG_ERROR
private static final String
IMG_WARNING
private final ExportWizard
mWizard
private org.eclipse.swt.widgets.Display
mDisplay
private org.eclipse.swt.graphics.Image
mError
private org.eclipse.swt.graphics.Image
mWarning
private boolean
mHasMessage
private org.eclipse.swt.widgets.Composite
mTopComposite
private org.eclipse.swt.widgets.Composite
mErrorComposite
private org.eclipse.swt.widgets.Text
mProjectText
private com.android.ide.eclipse.common.project.ProjectChooserHelper
mProjectChooserHelper
private boolean
mFirstOnShow
Constructors Summary
protected ProjectCheckPage(ExportWizard wizard, String pageName)


         
        super(pageName);
        mWizard = wizard;

        setTitle("Project Checks");
        setDescription("Performs a set of checks to make sure the application can be exported.");
    
Methods Summary
private voidaddError(org.eclipse.swt.widgets.Composite parent, java.lang.String message)
Adds an error label to a {@link Composite} object.

param
parent the Composite parent.
param
message the error message.

        if (mError == null) {
            mError = AdtPlugin.getImageLoader().loadImage(IMG_ERROR, mDisplay);
        }
        
        new Label(parent, SWT.NONE).setImage(mError);
        Label label = new Label(parent, SWT.NONE);
        label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        label.setText(message);
        
        setErrorMessage("Application cannot be exported due to the error(s) below.");
        setPageComplete(false);
        mHasMessage = true;
    
private voidaddWarning(org.eclipse.swt.widgets.Composite parent, java.lang.String message)
Adds a warning label to a {@link Composite} object.

param
parent the Composite parent.
param
message the warning message.

        if (mWarning == null) {
            mWarning = AdtPlugin.getImageLoader().loadImage(IMG_WARNING, mDisplay);
        }
        
        new Label(parent, SWT.NONE).setImage(mWarning);
        Label label = new Label(parent, SWT.NONE);
        label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        label.setText(message);
        
        mHasMessage = true;
    
private voidbuildErrorUi(org.eclipse.core.resources.IProject project)

        // Show description the first time
        setErrorMessage(null);
        setMessage(null);
        setPageComplete(true);
        mHasMessage = false;

        // composite parent for the warning/error
        GridLayout gl = null;
        mErrorComposite = new Composite(mTopComposite, SWT.NONE);
        mErrorComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        gl = new GridLayout(2, false);
        gl.marginHeight = gl.marginWidth = 0;
        gl.verticalSpacing *= 3; // more spacing than normal.
        mErrorComposite.setLayout(gl);

        if (project == null) {
            setErrorMessage("Select project to export.");
            mHasMessage = true;
        } else {
            try {
                if (project.hasNature(AndroidConstants.NATURE) == false) {
                    addError(mErrorComposite, "Project is not an Android project.");
                } else {
                    // check for errors
                    if (ProjectHelper.hasError(project, true))  {
                        addError(mErrorComposite, "Project has compilation error(s)");
                    }
                    
                    // check the project output
                    IFolder outputIFolder = BaseProjectHelper.getOutputFolder(project);
                    if (outputIFolder != null) {
                        String outputOsPath =  outputIFolder.getLocation().toOSString();
                        String apkFilePath =  outputOsPath + File.separator + project.getName() +
                                AndroidConstants.DOT_ANDROID_PACKAGE;
                        
                        File f = new File(apkFilePath);
                        if (f.isFile() == false) {
                            addError(mErrorComposite,
                                    String.format("%1$s/%2$s/%1$s%3$s does not exists!",
                                            project.getName(),
                                            outputIFolder.getName(),
                                            AndroidConstants.DOT_ANDROID_PACKAGE));
                        }
                    } else {
                        addError(mErrorComposite,
                                "Unable to get the output folder of the project!");
                    }


                    // project is an android project, we check the debuggable attribute.
                    AndroidManifestParser manifestParser = AndroidManifestParser.parse(
                            BaseProjectHelper.getJavaProject(project), null /* errorListener */,
                            true /* gatherData */, false /* markErrors */);

                    Boolean debuggable = manifestParser.getDebuggable();
                    
                    if (debuggable != null && debuggable == Boolean.TRUE) {
                        addWarning(mErrorComposite,
                                "The manifest 'debuggable' attribute is set to true.\nYou should set it to false for applications that you release to the public."); 
                    }
                    
                    // check for mapview stuff
                }
            } catch (CoreException e) {
                // unable to access nature
                addError(mErrorComposite, "Unable to get project nature");
            }
        }
        
        if (mHasMessage == false) {
            Label label = new Label(mErrorComposite, SWT.NONE);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.horizontalSpan = 2;
            label.setLayoutData(gd);
            label.setText("No errors found. Click Next.");
        }
        
        mTopComposite.layout();
    
public voidcreateControl(org.eclipse.swt.widgets.Composite parent)

        mProjectChooserHelper = new ProjectChooserHelper(parent.getShell());
        mDisplay = parent.getDisplay();

        GridLayout gl = null;
        GridData gd = null;

        mTopComposite = new Composite(parent, SWT.NONE);
        mTopComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        mTopComposite.setLayout(new GridLayout(1, false));
        
        // composite for the project selection.
        Composite projectComposite = new Composite(mTopComposite, SWT.NONE);
        projectComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        projectComposite.setLayout(gl = new GridLayout(3, false));
        gl.marginHeight = gl.marginWidth = 0;

        Label label = new Label(projectComposite, SWT.NONE);
        label.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
        gd.horizontalSpan = 3;
        label.setText("Select the project to export:");

        new Label(projectComposite, SWT.NONE).setText("Project:");
        mProjectText = new Text(projectComposite, SWT.BORDER);
        mProjectText.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
        mProjectText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                handleProjectNameChange();
            }
        });

        Button browseButton = new Button(projectComposite, SWT.PUSH);
        browseButton.setText("Browse...");
        browseButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                IJavaProject javaProject = mProjectChooserHelper.chooseJavaProject(
                        mProjectText.getText().trim());

                if (javaProject != null) {
                    IProject project = javaProject.getProject();

                    // set the new name in the text field. The modify listener will take
                    // care of updating the status and the ExportWizard object.
                    mProjectText.setText(project.getName());
                }
            }
        });

        setControl(mTopComposite);
    
private voidhandleProjectNameChange()
Checks the parameters for correctness, and update the error message and buttons.

        setPageComplete(false);
        
        if (mErrorComposite != null) {
            mErrorComposite.dispose();
            mErrorComposite = null;
        }
        
        // update the wizard with the new project
        mWizard.setProject(null);

        //test the project name first!
        String text = mProjectText.getText().trim();
        if (text.length() == 0) {
            setErrorMessage("Select project to export.");
        } else if (text.matches("[a-zA-Z0-9_ \\.-]+") == false) {
            setErrorMessage("Project name contains unsupported characters!");
        } else {
            IJavaProject[] projects = mProjectChooserHelper.getAndroidProjects(null);
            IProject found = null;
            for (IJavaProject javaProject : projects) {
                if (javaProject.getProject().getName().equals(text)) {
                    found = javaProject.getProject();
                    break;
                }
                
            }
            
            if (found != null) {
                setErrorMessage(null);
                
                // update the wizard with the new project
                mWizard.setProject(found);

                // now rebuild the error ui.
                buildErrorUi(found);
            } else {
                setErrorMessage(String.format("There is no android project named '%1$s'",
                        text));
            }
        }
    
voidonShow()

        if (mFirstOnShow) {
            // get the project and init the ui
            IProject project = mWizard.getProject();
            if (project != null) {
                mProjectText.setText(project.getName());
            }
            
            mFirstOnShow = false;
        }