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.IPageImageProvider;
     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.tree.UiTreeBlock;
     26 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
     27 
     28 import org.eclipse.swt.graphics.Image;
     29 import org.eclipse.ui.forms.IManagedForm;
     30 import org.eclipse.ui.forms.editor.FormPage;
     31 import org.eclipse.ui.forms.widgets.ScrolledForm;
     32 
     33 /**
     34  * Page for permissions settings, part of the AndroidManifest form editor.
     35  * <p/>
     36  * Useful reference:
     37  * <a href="http://www.eclipse.org/articles/Article-Forms/article.html">
     38  *   http://www.eclipse.org/articles/Article-Forms/article.html</a>
     39  */
     40 public final class PermissionPage extends FormPage implements IPageImageProvider {
     41     /** Page id used for switching tabs programmatically */
     42     public final static String PAGE_ID = "permission_page"; //$NON-NLS-1$
     43 
     44     /** Container editor */
     45     ManifestEditor mEditor;
     46 
     47     private UiTreeBlock mTreeBlock;
     48 
     49     public PermissionPage(ManifestEditor editor) {
     50         super(editor, PAGE_ID, "Permissions");  // tab label, keep it short
     51         mEditor = editor;
     52     }
     53 
     54     public Image getPageImage() {
     55         return IconFactory.getInstance().getIcon(getTitle(),
     56                                                  IconFactory.COLOR_RED,
     57                                                  IconFactory.SHAPE_RECT);
     58     }
     59 
     60     /**
     61      * Creates the content in the form hosted in this page.
     62      *
     63      * @param managedForm the form hosted in this page.
     64      */
     65     @Override
     66     protected void createFormContent(IManagedForm managedForm) {
     67         super.createFormContent(managedForm);
     68         ScrolledForm form = managedForm.getForm();
     69         form.setText("Android Manifest Permissions");
     70         form.setImage(AdtPlugin.getAndroidLogo());
     71 
     72         UiElementNode manifest = mEditor.getUiRootNode();
     73         AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors();
     74 
     75         ElementDescriptor[] descriptorFilters = null;
     76         if (manifestDescriptor != null) {
     77             descriptorFilters = new ElementDescriptor[] {
     78                     manifestDescriptor.getPermissionElement(),
     79                     manifestDescriptor.getUsesPermissionElement(),
     80                     manifestDescriptor.getPermissionGroupElement(),
     81                     manifestDescriptor.getPermissionTreeElement()
     82             };
     83         }
     84         mTreeBlock = new UiTreeBlock(mEditor, manifest,
     85                 true /* autoCreateRoot */,
     86                 descriptorFilters,
     87                 "Permissions",
     88                 "List of permissions defined and used by the manifest");
     89         mTreeBlock.createContent(managedForm);
     90     }
     91 
     92     /**
     93      * Changes and refreshes the Application UI node handled by the sub parts.
     94      */
     95     public void refreshUiNode() {
     96         if (mTreeBlock != null) {
     97             UiElementNode manifest = mEditor.getUiRootNode();
     98             AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors();
     99 
    100             mTreeBlock.changeRootAndDescriptors(manifest,
    101                     new ElementDescriptor[] {
    102                         manifestDescriptor.getPermissionElement(),
    103                         manifestDescriptor.getUsesPermissionElement(),
    104                         manifestDescriptor.getPermissionGroupElement(),
    105                         manifestDescriptor.getPermissionTreeElement()
    106                     },
    107                     true /* refresh */);
    108         }
    109     }
    110 }
    111