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 @Override 55 public Image getPageImage() { 56 return IconFactory.getInstance().getIcon(getTitle(), 57 IconFactory.COLOR_RED, 58 IconFactory.SHAPE_RECT); 59 } 60 61 /** 62 * Creates the content in the form hosted in this page. 63 * 64 * @param managedForm the form hosted in this page. 65 */ 66 @Override 67 protected void createFormContent(IManagedForm managedForm) { 68 super.createFormContent(managedForm); 69 ScrolledForm form = managedForm.getForm(); 70 form.setText("Android Manifest Permissions"); 71 form.setImage(AdtPlugin.getAndroidLogo()); 72 73 UiElementNode manifest = mEditor.getUiRootNode(); 74 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 75 76 ElementDescriptor[] descriptorFilters = null; 77 if (manifestDescriptor != null) { 78 descriptorFilters = new ElementDescriptor[] { 79 manifestDescriptor.getPermissionElement(), 80 manifestDescriptor.getUsesPermissionElement(), 81 manifestDescriptor.getPermissionGroupElement(), 82 manifestDescriptor.getPermissionTreeElement() 83 }; 84 } 85 mTreeBlock = new UiTreeBlock(mEditor, manifest, 86 true /* autoCreateRoot */, 87 descriptorFilters, 88 "Permissions", 89 "List of permissions defined and used by the manifest"); 90 mTreeBlock.createContent(managedForm); 91 } 92 93 /** 94 * Changes and refreshes the Application UI node handled by the sub parts. 95 */ 96 public void refreshUiNode() { 97 if (mTreeBlock != null) { 98 UiElementNode manifest = mEditor.getUiRootNode(); 99 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 100 101 mTreeBlock.changeRootAndDescriptors(manifest, 102 new ElementDescriptor[] { 103 manifestDescriptor.getPermissionElement(), 104 manifestDescriptor.getUsesPermissionElement(), 105 manifestDescriptor.getPermissionGroupElement(), 106 manifestDescriptor.getPermissionTreeElement() 107 }, 108 true /* refresh */); 109 } 110 } 111 } 112