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 instrumentation settings, part of the AndroidManifest form editor. 35 */ 36 public final class InstrumentationPage extends FormPage implements IPageImageProvider { 37 /** Page id used for switching tabs programmatically */ 38 public final static String PAGE_ID = "instrumentation_page"; //$NON-NLS-1$ 39 40 /** Container editor */ 41 ManifestEditor mEditor; 42 43 private UiTreeBlock mTreeBlock; 44 45 public InstrumentationPage(ManifestEditor editor) { 46 super(editor, PAGE_ID, "Instrumentation"); // tab's label, keep it short 47 mEditor = editor; 48 } 49 50 public Image getPageImage() { 51 return IconFactory.getInstance().getIcon(getTitle(), 52 IconFactory.COLOR_GREEN, 53 IconFactory.SHAPE_RECT); 54 } 55 56 /** 57 * Creates the content in the form hosted in this page. 58 * 59 * @param managedForm the form hosted in this page. 60 */ 61 @Override 62 protected void createFormContent(IManagedForm managedForm) { 63 super.createFormContent(managedForm); 64 ScrolledForm form = managedForm.getForm(); 65 form.setText("Android Manifest Instrumentation"); 66 form.setImage(AdtPlugin.getAndroidLogo()); 67 68 UiElementNode manifest = mEditor.getUiRootNode(); 69 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 70 71 ElementDescriptor[] descriptorFilters = null; 72 if (manifestDescriptor != null) { 73 descriptorFilters = new ElementDescriptor[] { 74 manifestDescriptor.getInstrumentationElement(), 75 }; 76 } 77 78 mTreeBlock = new UiTreeBlock(mEditor, manifest, 79 true /* autoCreateRoot */, 80 descriptorFilters, 81 "Instrumentation", 82 "List of instrumentations defined in the manifest"); 83 mTreeBlock.createContent(managedForm); 84 } 85 86 /** 87 * Changes and refreshes the Application UI node handled by the sub parts. 88 */ 89 public void refreshUiNode() { 90 if (mTreeBlock != null) { 91 UiElementNode manifest = mEditor.getUiRootNode(); 92 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 93 94 mTreeBlock.changeRootAndDescriptors(manifest, 95 new ElementDescriptor[] { 96 manifestDescriptor.getInstrumentationElement() 97 }, 98 true /* refresh */); 99 } 100 } 101 } 102