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