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.SWT; 29 import org.eclipse.swt.graphics.Image; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.ui.forms.IManagedForm; 33 import org.eclipse.ui.forms.editor.FormPage; 34 import org.eclipse.ui.forms.widgets.FormToolkit; 35 import org.eclipse.ui.forms.widgets.ScrolledForm; 36 37 import java.util.ArrayList; 38 import java.util.HashSet; 39 40 41 /** 42 * Page for overview settings, part of the AndroidManifest form editor. 43 * <p/> 44 * Useful reference: 45 * <a href="http://www.eclipse.org/articles/Article-Forms/article.html"> 46 * http://www.eclipse.org/articles/Article-Forms/article.html</a> 47 */ 48 public final class OverviewPage extends FormPage implements IPageImageProvider { 49 50 /** Page id used for switching tabs programmatically */ 51 final static String PAGE_ID = "overview_page"; //$NON-NLS-1$ 52 53 /** Container editor */ 54 ManifestEditor mEditor; 55 /** Overview part (attributes for manifest) */ 56 private OverviewInfoPart mOverviewPart; 57 /** Overview link part */ 58 private OverviewLinksPart mOverviewLinkPart; 59 60 private UiTreeBlock mTreeBlock; 61 62 public OverviewPage(ManifestEditor editor) { 63 super(editor, PAGE_ID, "Manifest"); // tab's label, user visible, keep it short 64 mEditor = editor; 65 } 66 67 public Image getPageImage() { 68 return IconFactory.getInstance().getIcon("editor_page_design"); //$NON-NLS-1$ 69 } 70 71 /** 72 * Creates the content in the form hosted in this page. 73 * 74 * @param managedForm the form hosted in this page. 75 */ 76 @Override 77 protected void createFormContent(IManagedForm managedForm) { 78 super.createFormContent(managedForm); 79 ScrolledForm form = managedForm.getForm(); 80 form.setText("Android Manifest"); 81 form.setImage(AdtPlugin.getAndroidLogo()); 82 83 Composite body = form.getBody(); 84 FormToolkit toolkit = managedForm.getToolkit(); 85 86 // Usually we would set a ColumnLayout on body here. However the presence of the 87 // UiTreeBlock forces a GridLayout with one column so we comply with it. 88 89 mOverviewPart = new OverviewInfoPart(body, toolkit, mEditor); 90 mOverviewPart.getSection().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 91 managedForm.addPart(mOverviewPart); 92 93 newManifestExtrasPart(managedForm); 94 95 OverviewExportPart exportPart = new OverviewExportPart(this, body, toolkit, mEditor); 96 exportPart.getSection().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 97 managedForm.addPart(exportPart); 98 99 mOverviewLinkPart = new OverviewLinksPart(body, toolkit, mEditor); 100 mOverviewLinkPart.getSection().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 101 managedForm.addPart(mOverviewLinkPart); 102 } 103 104 private void newManifestExtrasPart(IManagedForm managedForm) { 105 UiElementNode manifest = mEditor.getUiRootNode(); 106 mTreeBlock = new UiTreeBlock(mEditor, manifest, 107 true /* autoCreateRoot */, 108 computeManifestExtraFilters(), 109 "Manifest Extras", 110 "Extra manifest elements"); 111 mTreeBlock.createContent(managedForm); 112 } 113 114 /** 115 * Changes and refreshes the Application UI node handled by the sub parts. 116 */ 117 public void refreshUiApplicationNode() { 118 if (mOverviewPart != null) { 119 mOverviewPart.onSdkChanged(); 120 } 121 122 if (mOverviewLinkPart != null) { 123 mOverviewLinkPart.onSdkChanged(); 124 } 125 126 if (mTreeBlock != null) { 127 UiElementNode manifest = mEditor.getUiRootNode(); 128 mTreeBlock.changeRootAndDescriptors(manifest, 129 computeManifestExtraFilters(), 130 true /* refresh */); 131 } 132 } 133 134 private ElementDescriptor[] computeManifestExtraFilters() { 135 UiElementNode manifest = mEditor.getUiRootNode(); 136 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 137 138 if (manifestDescriptor == null) { 139 return null; 140 } 141 142 // get the elements we want to exclude 143 HashSet<ElementDescriptor> excludes = new HashSet<ElementDescriptor>(); 144 excludes.add(manifestDescriptor.getApplicationElement()); 145 excludes.add(manifestDescriptor.getInstrumentationElement()); 146 excludes.add(manifestDescriptor.getPermissionElement()); 147 excludes.add(manifestDescriptor.getPermissionGroupElement()); 148 excludes.add(manifestDescriptor.getPermissionTreeElement()); 149 excludes.add(manifestDescriptor.getUsesPermissionElement()); 150 151 // walk through the known children of the manifest descriptor and keep what's not excluded 152 ArrayList<ElementDescriptor> descriptorFilters = new ArrayList<ElementDescriptor>(); 153 for (ElementDescriptor child : manifest.getDescriptor().getChildren()) { 154 if (!excludes.contains(child)) { 155 descriptorFilters.add(child); 156 } 157 } 158 159 if (descriptorFilters.size() == 0) { 160 return null; 161 } 162 return descriptorFilters.toArray(new ElementDescriptor[descriptorFilters.size()]); 163 } 164 } 165