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