Home | History | Annotate | Download | only in pages
      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.editors.manifest.pages;
     18 
     19 import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
     20 import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper.ManifestSectionPart;
     21 import com.android.ide.eclipse.adt.internal.project.ExportHelper;
     22 import com.android.ide.eclipse.adt.internal.sdk.ProjectState;
     23 import com.android.ide.eclipse.adt.internal.sdk.Sdk;
     24 import com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard;
     25 
     26 import org.eclipse.core.resources.IFile;
     27 import org.eclipse.core.resources.IProject;
     28 import org.eclipse.jface.viewers.StructuredSelection;
     29 import org.eclipse.jface.wizard.WizardDialog;
     30 import org.eclipse.swt.widgets.Composite;
     31 import org.eclipse.ui.IEditorInput;
     32 import org.eclipse.ui.PlatformUI;
     33 import org.eclipse.ui.forms.events.HyperlinkAdapter;
     34 import org.eclipse.ui.forms.events.HyperlinkEvent;
     35 import org.eclipse.ui.forms.widgets.FormText;
     36 import org.eclipse.ui.forms.widgets.FormToolkit;
     37 import org.eclipse.ui.forms.widgets.Section;
     38 import org.eclipse.ui.part.FileEditorInput;
     39 
     40 /**
     41  * Export section part for overview page.
     42  */
     43 final class OverviewExportPart extends ManifestSectionPart {
     44 
     45     private final OverviewPage mOverviewPage;
     46 
     47     public OverviewExportPart(OverviewPage overviewPage, final Composite body, FormToolkit toolkit,
     48             ManifestEditor editor) {
     49         super(body, toolkit, Section.TWISTIE | Section.EXPANDED, true /* description */);
     50         mOverviewPage = overviewPage;
     51         Section section = getSection();
     52         section.setText("Exporting");
     53 
     54         final IProject project = getProject();
     55         boolean isLibrary = false;
     56         if (project != null) {
     57             ProjectState state = Sdk.getProjectState(project);
     58             if (state != null) {
     59                 isLibrary = state.isLibrary();
     60             }
     61         }
     62 
     63         if (isLibrary) {
     64             section.setDescription("Library project cannot be exported.");
     65             Composite table = createTableLayout(toolkit, 2 /* numColumns */);
     66             createFormText(table, toolkit, true, "<form></form>", false /* setupLayoutData */);
     67         } else {
     68             section.setDescription("To export the application for distribution, you have the following options:");
     69 
     70             Composite table = createTableLayout(toolkit, 2 /* numColumns */);
     71 
     72             StringBuffer buf = new StringBuffer();
     73             buf.append("<form><li><a href=\"wizard\">"); //$NON-NLS-1$
     74             buf.append("Use the Export Wizard");
     75             buf.append("</a>"); //$NON-NLS-1$
     76             buf.append(" to export and sign an APK");
     77             buf.append("</li>"); //$NON-NLS-1$
     78             buf.append("<li><a href=\"manual\">"); //$NON-NLS-1$
     79             buf.append("Export an unsigned APK");
     80             buf.append("</a>"); //$NON-NLS-1$
     81             buf.append(" and sign it manually");
     82             buf.append("</li></form>"); //$NON-NLS-1$
     83 
     84             FormText text = createFormText(table, toolkit, true, buf.toString(),
     85                     false /* setupLayoutData */);
     86             text.addHyperlinkListener(new HyperlinkAdapter() {
     87                 @Override
     88                 public void linkActivated(HyperlinkEvent e) {
     89                     if (project != null) {
     90                         if ("manual".equals(e.data)) { //$NON-NLS-1$
     91                             // now we can export an unsigned apk for the project.
     92                             ExportHelper.exportUnsignedReleaseApk(project);
     93                         } else {
     94                             // call the export wizard
     95                             StructuredSelection selection = new StructuredSelection(project);
     96 
     97                             ExportWizard wizard = new ExportWizard();
     98                             wizard.init(PlatformUI.getWorkbench(), selection);
     99                             WizardDialog dialog = new WizardDialog(body.getShell(), wizard);
    100                             dialog.open();
    101                         }
    102                     }
    103                 }
    104             });
    105         }
    106 
    107         layoutChanged();
    108     }
    109 
    110     /**
    111      * Returns the project of the edited file.
    112      */
    113     private IProject getProject() {
    114         IEditorInput input = mOverviewPage.mEditor.getEditorInput();
    115         if (input instanceof FileEditorInput) {
    116             FileEditorInput fileInput = (FileEditorInput)input;
    117             IFile file = fileInput.getFile();
    118             return file.getProject();
    119         }
    120 
    121         return null;
    122     }
    123 }
    124