OverviewLinksPart.java revision 23da069e4f407df1b06e7db2324e3247496abe3d
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
17package com.android.ide.eclipse.adt.internal.editors.manifest.pages;
18
19import com.android.ide.eclipse.adt.AdtPlugin;
20import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
21import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
22import com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.AndroidManifestDescriptors;
23import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper.ManifestSectionPart;
24
25import org.eclipse.swt.graphics.Image;
26import org.eclipse.swt.widgets.Composite;
27import org.eclipse.ui.forms.widgets.FormText;
28import org.eclipse.ui.forms.widgets.FormToolkit;
29import org.eclipse.ui.forms.widgets.Section;
30
31/**
32 * Links section part for overview page.
33 */
34final class OverviewLinksPart extends ManifestSectionPart {
35
36    private final ManifestEditor mEditor;
37    private FormText mFormText;
38
39    public OverviewLinksPart(Composite body, FormToolkit toolkit, ManifestEditor editor) {
40        super(body, toolkit, Section.TWISTIE | Section.EXPANDED, true /* description */);
41        mEditor = editor;
42        Section section = getSection();
43        section.setText("Links");
44        section.setDescription("The content of the Android Manifest is made up of three sections. You can also edit the XML directly.");
45
46        Composite table = createTableLayout(toolkit, 2 /* numColumns */);
47
48        StringBuffer buf = new StringBuffer();
49        buf.append(String.format("<form><li style=\"image\" value=\"app_img\"><a href=\"page:%1$s\">", //$NON-NLS-1$
50                ApplicationPage.PAGE_ID));
51        buf.append("Application");
52        buf.append("</a>");  //$NON-NLS-1$
53        buf.append(": Activities, intent filters, providers, services and receivers.");
54        buf.append("</li>"); //$NON-NLS-1$
55
56        buf.append(String.format("<li style=\"image\" value=\"perm_img\"><a href=\"page:%1$s\">", //$NON-NLS-1$
57                PermissionPage.PAGE_ID));
58        buf.append("Permission");
59        buf.append("</a>"); //$NON-NLS-1$
60        buf.append(": Permissions defined and permissions used.");
61        buf.append("</li>"); //$NON-NLS-1$
62
63        buf.append(String.format("<li style=\"image\" value=\"inst_img\"><a href=\"page:%1$s\">", //$NON-NLS-1$
64                InstrumentationPage.PAGE_ID));
65        buf.append("Instrumentation");
66        buf.append("</a>"); //$NON-NLS-1$
67        buf.append(": Instrumentation defined.");
68        buf.append("</li>"); //$NON-NLS-1$
69
70        buf.append(String.format("<li style=\"image\" value=\"android_img\"><a href=\"page:%1$s\">", //$NON-NLS-1$
71                ManifestEditor.TEXT_EDITOR_ID));
72        buf.append("XML Source");
73        buf.append("</a>"); //$NON-NLS-1$
74        buf.append(": Directly edit the AndroidManifest.xml file.");
75        buf.append("</li>"); //$NON-NLS-1$
76
77        buf.append("<li style=\"image\" value=\"android_img\">"); //$NON-NLS-1$
78        buf.append("<a href=\"http://code.google.com/android/devel/bblocks-manifest.html\">Documentation</a>: Documentation from the Android SDK for AndroidManifest.xml."); //$NON-NLS-1$
79        buf.append("</li>"); //$NON-NLS-1$
80        buf.append("</form>"); //$NON-NLS-1$
81
82        mFormText = createFormText(table, toolkit, true, buf.toString(),
83                false /* setupLayoutData */);
84
85        AndroidManifestDescriptors manifestDescriptor = editor.getManifestDescriptors();
86
87        Image androidLogo = AdtPlugin.getAndroidLogo();
88        mFormText.setImage("android_img", androidLogo); //$NON-NLS-1$
89
90        if (manifestDescriptor != null) {
91            mFormText.setImage("app_img", getIcon(manifestDescriptor.getApplicationElement())); //$NON-NLS-1$
92            mFormText.setImage("perm_img", getIcon(manifestDescriptor.getPermissionElement())); //$NON-NLS-1$
93            mFormText.setImage("inst_img", getIcon(manifestDescriptor.getInstrumentationElement())); //$NON-NLS-1$
94        } else {
95            mFormText.setImage("app_img", androidLogo); //$NON-NLS-1$
96            mFormText.setImage("perm_img", androidLogo); //$NON-NLS-1$
97            mFormText.setImage("inst_img", androidLogo); //$NON-NLS-1$
98        }
99        mFormText.addHyperlinkListener(editor.createHyperlinkListener());
100    }
101
102    /**
103     * Update the UI with information from the new descriptors.
104     * <p/>At this point, this only refreshes the icons.
105     * <p/>
106     * This is called by {@link OverviewPage#refreshUiApplicationNode()} when the
107     * SDK has changed.
108     */
109    public void onSdkChanged() {
110        AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors();
111        if (manifestDescriptor != null) {
112            mFormText.setImage("app_img", getIcon(manifestDescriptor.getApplicationElement())); //$NON-NLS-1$
113            mFormText.setImage("perm_img", getIcon(manifestDescriptor.getPermissionElement())); //$NON-NLS-1$
114            mFormText.setImage("inst_img", getIcon(manifestDescriptor.getInstrumentationElement())); //$NON-NLS-1$
115        }
116    }
117
118    private Image getIcon(ElementDescriptor desc) {
119        if (desc != null && desc.getIcon() != null) {
120            return desc.getIcon();
121        }
122
123        return AdtPlugin.getAndroidLogo();
124    }
125}
126