OSDN Git Service

Disable export for library projects.
authorXavier Ducrohet <xav@android.com>
Tue, 30 Mar 2010 01:03:17 +0000 (18:03 -0700)
committerXavier Ducrohet <xav@android.com>
Tue, 30 Mar 2010 17:24:22 +0000 (10:24 -0700)
Change-Id: I050e5b39027b960e28e6e463dc6048c02848d091

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/OverviewExportPart.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/actions/ExportAction.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/actions/ExportWizardAction.java

index ec947c5..4c75a86 100644 (file)
@@ -19,6 +19,8 @@ package com.android.ide.eclipse.adt.internal.editors.manifest.pages;
 import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
 import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper.ManifestSectionPart;
 import com.android.ide.eclipse.adt.internal.project.ExportHelper;
+import com.android.ide.eclipse.adt.internal.project.ProjectState;
+import com.android.ide.eclipse.adt.internal.sdk.Sdk;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
@@ -43,45 +45,69 @@ final class OverviewExportPart extends ManifestSectionPart {
         mOverviewPage = overviewPage;
         Section section = getSection();
         section.setText("Exporting");
-        section.setDescription("To export the application for distribution, you have the following options:");
 
-        Composite table = createTableLayout(toolkit, 2 /* numColumns */);
-        
-        StringBuffer buf = new StringBuffer();
-        buf.append("<form><li><a href=\"wizard\">"); //$NON-NLS-1$
-        buf.append("Use the Export Wizard");
-        buf.append("</a>"); //$NON-NLS-1$
-        buf.append(" to export and sign an APK");
-        buf.append("</li>"); //$NON-NLS-1$
-        buf.append("<li><a href=\"manual\">"); //$NON-NLS-1$
-        buf.append("Export an unsigned APK");
-        buf.append("</a>"); //$NON-NLS-1$
-        buf.append(" and sign it manually");
-        buf.append("</li></form>"); //$NON-NLS-1$
+        final IProject project = getProject();
+        boolean isLibrary = false;
+        if (project != null) {
+            ProjectState state = Sdk.getProjectState(project);
+            if (state != null) {
+                isLibrary = state.isLibrary();
+            }
+        }
+
+        if (isLibrary) {
+            section.setDescription("Library project cannot be exported.");
+            Composite table = createTableLayout(toolkit, 2 /* numColumns */);
+            createFormText(table, toolkit, true, "<form></form>", false /* setupLayoutData */);
+        } else {
+            section.setDescription("To export the application for distribution, you have the following options:");
+
+            Composite table = createTableLayout(toolkit, 2 /* numColumns */);
+
+            StringBuffer buf = new StringBuffer();
+            buf.append("<form><li><a href=\"wizard\">"); //$NON-NLS-1$
+            buf.append("Use the Export Wizard");
+            buf.append("</a>"); //$NON-NLS-1$
+            buf.append(" to export and sign an APK");
+            buf.append("</li>"); //$NON-NLS-1$
+            buf.append("<li><a href=\"manual\">"); //$NON-NLS-1$
+            buf.append("Export an unsigned APK");
+            buf.append("</a>"); //$NON-NLS-1$
+            buf.append(" and sign it manually");
+            buf.append("</li></form>"); //$NON-NLS-1$
 
-        FormText text = createFormText(table, toolkit, true, buf.toString(),
-                false /* setupLayoutData */);
-        text.addHyperlinkListener(new HyperlinkAdapter() {
-            @Override
-            public void linkActivated(HyperlinkEvent e) {
-                // get the project from the editor
-                IEditorInput input = mOverviewPage.mEditor.getEditorInput();
-                if (input instanceof FileEditorInput) {
-                    FileEditorInput fileInput = (FileEditorInput)input;
-                    IFile file = fileInput.getFile();
-                    IProject project = file.getProject();
-                    
-                    if ("manual".equals(e.data)) { //$NON-NLS-1$
-                        // now we can export an unsigned apk for the project.
-                        ExportHelper.exportProject(project);
-                    } else {
-                        // call the export wizard
-                        ExportHelper.startExportWizard(project);
+            FormText text = createFormText(table, toolkit, true, buf.toString(),
+                    false /* setupLayoutData */);
+            text.addHyperlinkListener(new HyperlinkAdapter() {
+                @Override
+                public void linkActivated(HyperlinkEvent e) {
+                    if (project != null) {
+                        if ("manual".equals(e.data)) { //$NON-NLS-1$
+                            // now we can export an unsigned apk for the project.
+                            ExportHelper.exportProject(project);
+                        } else {
+                            // call the export wizard
+                            ExportHelper.startExportWizard(project);
+                        }
                     }
                 }
-            }
-        });
-        
+            });
+        }
+
         layoutChanged();
-    }        
+    }
+
+    /**
+     * Returns the project of the edited file.
+     */
+    private IProject getProject() {
+        IEditorInput input = mOverviewPage.mEditor.getEditorInput();
+        if (input instanceof FileEditorInput) {
+            FileEditorInput fileInput = (FileEditorInput)input;
+            IFile file = fileInput.getFile();
+            return file.getProject();
+        }
+
+        return null;
+    }
 }
index 9093470..c331680 100644 (file)
 package com.android.ide.eclipse.adt.internal.wizards.actions;
 
 import com.android.ide.eclipse.adt.internal.project.ExportHelper;
+import com.android.ide.eclipse.adt.internal.project.ProjectState;
+import com.android.ide.eclipse.adt.internal.sdk.Sdk;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 
 public class ExportAction implements IObjectActionDelegate {
 
     private ISelection mSelection;
+    private Shell mShell;
 
     /**
      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
      */
     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+        mShell = targetPart.getSite().getShell();
     }
 
     public void run(IAction action) {
@@ -53,13 +59,19 @@ public class ExportAction implements IObjectActionDelegate {
 
                 // and finally do the action
                 if (project != null) {
-                    ExportHelper.exportProject(project);
+                    ProjectState state = Sdk.getProjectState(project);
+                    if (state.isLibrary()) {
+                        MessageDialog.openError(mShell, "Android Export",
+                                "Android library projects cannot be exported.");
+                    } else {
+                        ExportHelper.exportProject(project);
+                    }
                 }
             }
         }
     }
 
     public void selectionChanged(IAction action, ISelection selection) {
-        this.mSelection = selection;
+        mSelection = selection;
     }
 }
index 8165f97..cfdab0f 100644 (file)
 
 package com.android.ide.eclipse.adt.internal.wizards.actions;
 
+import com.android.ide.eclipse.adt.internal.project.ProjectState;
+import com.android.ide.eclipse.adt.internal.sdk.Sdk;
 import com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard;
 
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
@@ -42,16 +47,39 @@ public class ExportWizardAction implements IObjectActionDelegate {
         if (mSelection instanceof IStructuredSelection) {
             IStructuredSelection selection = (IStructuredSelection)mSelection;
 
-            // call the export wizard on the current selection.
-            ExportWizard wizard = new ExportWizard();
-            wizard.init(mWorkbench, selection);
-            WizardDialog dialog = new WizardDialog(mWorkbench.getDisplay().getActiveShell(),
-                    wizard);
-            dialog.open();
+            // get the unique selected item.
+            if (selection.size() == 1) {
+                Object element = selection.getFirstElement();
+
+                // get the project object from it.
+                IProject project = null;
+                if (element instanceof IProject) {
+                    project = (IProject) element;
+                } else if (element instanceof IAdaptable) {
+                    project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
+                }
+
+                // and finally do the action
+                if (project != null) {
+                    ProjectState state = Sdk.getProjectState(project);
+                    if (state.isLibrary()) {
+                        MessageDialog.openError(mWorkbench.getDisplay().getActiveShell(),
+                                "Android Export",
+                                "Android library projects cannot be exported.");
+                    } else {
+                        // call the export wizard on the current selection.
+                        ExportWizard wizard = new ExportWizard();
+                        wizard.init(mWorkbench, selection);
+                        WizardDialog dialog = new WizardDialog(
+                                mWorkbench.getDisplay().getActiveShell(), wizard);
+                        dialog.open();
+                    }
+                }
+            }
         }
     }
 
     public void selectionChanged(IAction action, ISelection selection) {
-        this.mSelection = selection;
+        mSelection = selection;
     }
 }