aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/pages/OverviewExportPart.java
blob: b0eb75a2d71bc9f3fb2642ff76177eac71255a39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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.sdk.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.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.FileEditorInput;

/**
 * Export section part for overview page.
 */
final class OverviewExportPart extends ManifestSectionPart {

    private final OverviewPage mOverviewPage;

    public OverviewExportPart(OverviewPage overviewPage, final Composite body, FormToolkit toolkit,
            ManifestEditor editor) {
        super(body, toolkit, Section.TWISTIE | Section.EXPANDED, true /* description */);
        mOverviewPage = overviewPage;
        Section section = getSection();
        section.setText("Exporting");

        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) {
                    if (project != null) {
                        if ("manual".equals(e.data)) { //$NON-NLS-1$
                            // now we can export an unsigned apk for the project.
                            ExportHelper.exportUnsignedReleaseApk(project);
                        } else {
                            // call the export wizard
                            StructuredSelection selection = new StructuredSelection(project);

                            ExportWizard wizard = new ExportWizard();
                            wizard.init(PlatformUI.getWorkbench(), selection);
                            WizardDialog dialog = new WizardDialog(body.getShell(), wizard);
                            dialog.open();
                        }
                    }
                }
            });
        }

        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;
    }
}