1 /* 2 * Copyright (C) 2007 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 17 package com.android.ide.eclipse.adt.internal.wizards.actions; 18 19 import com.android.ide.eclipse.adt.internal.lint.EclipseLintRunner; 20 import com.android.ide.eclipse.adt.internal.project.ExportHelper; 21 import com.android.ide.eclipse.adt.internal.sdk.ProjectState; 22 import com.android.ide.eclipse.adt.internal.sdk.Sdk; 23 24 import org.eclipse.core.resources.IProject; 25 import org.eclipse.core.runtime.IAdaptable; 26 import org.eclipse.jface.action.IAction; 27 import org.eclipse.jface.dialogs.MessageDialog; 28 import org.eclipse.jface.viewers.ISelection; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.ui.IObjectActionDelegate; 32 import org.eclipse.ui.IWorkbenchPart; 33 34 public class ExportAction implements IObjectActionDelegate { 35 36 private ISelection mSelection; 37 private Shell mShell; 38 39 /** 40 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) 41 */ 42 @Override 43 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 44 mShell = targetPart.getSite().getShell(); 45 } 46 47 @Override 48 public void run(IAction action) { 49 if (mSelection instanceof IStructuredSelection) { 50 IStructuredSelection selection = (IStructuredSelection)mSelection; 51 // get the unique selected item. 52 if (selection.size() == 1) { 53 Object element = selection.getFirstElement(); 54 55 // get the project object from it. 56 IProject project = null; 57 if (element instanceof IProject) { 58 project = (IProject) element; 59 } else if (element instanceof IAdaptable) { 60 project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); 61 } 62 63 // and finally do the action 64 if (project != null) { 65 if (!EclipseLintRunner.runLintOnExport(mShell, project)) { 66 return; 67 } 68 69 ProjectState state = Sdk.getProjectState(project); 70 if (state.isLibrary()) { 71 MessageDialog.openError(mShell, "Android Export", 72 "Android library projects cannot be exported."); 73 } else { 74 ExportHelper.exportUnsignedReleaseApk(project); 75 } 76 } 77 } 78 } 79 } 80 81 @Override 82 public void selectionChanged(IAction action, ISelection selection) { 83 mSelection = selection; 84 } 85 } 86