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