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.resources; 18 19 import com.android.ide.common.resources.ResourceFolder; 20 import com.android.ide.eclipse.adt.AdtPlugin; 21 import com.android.ide.eclipse.adt.internal.editors.IPageImageProvider; 22 import com.android.ide.eclipse.adt.internal.editors.IconFactory; 23 import com.android.ide.eclipse.adt.internal.editors.ui.tree.UiTreeBlock; 24 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 25 import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager; 26 27 import org.eclipse.core.resources.IFile; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.ui.IEditorInput; 30 import org.eclipse.ui.forms.IManagedForm; 31 import org.eclipse.ui.forms.editor.FormPage; 32 import org.eclipse.ui.forms.widgets.ScrolledForm; 33 import org.eclipse.ui.part.FileEditorInput; 34 35 /** 36 * Page for instrumentation settings, part of the AndroidManifest form editor. 37 */ 38 public final class ResourcesTreePage extends FormPage implements IPageImageProvider { 39 /** Page id used for switching tabs programmatically */ 40 public final static String PAGE_ID = "res_tree_page"; //$NON-NLS-1$ 41 42 /** Container editor */ 43 ResourcesEditor mEditor; 44 45 public ResourcesTreePage(ResourcesEditor editor) { 46 super(editor, PAGE_ID, "Resources"); // tab's label, keep it short 47 mEditor = editor; 48 } 49 50 public Image getPageImage() { 51 return IconFactory.getInstance().getIcon("editor_page_design"); //$NON-NLS-1$ 52 } 53 54 /** 55 * Creates the content in the form hosted in this page. 56 * 57 * @param managedForm the form hosted in this page. 58 */ 59 @Override 60 protected void createFormContent(IManagedForm managedForm) { 61 super.createFormContent(managedForm); 62 ScrolledForm form = managedForm.getForm(); 63 64 String configText = null; 65 IEditorInput input = mEditor.getEditorInput(); 66 if (input instanceof FileEditorInput) { 67 FileEditorInput fileInput = (FileEditorInput)input; 68 IFile iFile = fileInput.getFile(); 69 70 ResourceFolder resFolder = ResourceManager.getInstance().getResourceFolder(iFile); 71 if (resFolder != null) { 72 configText = resFolder.getConfiguration().toDisplayString(); 73 } 74 } 75 76 if (configText != null) { 77 form.setText(String.format("Android Resources (%1$s)", configText)); 78 } else { 79 form.setText("Android Resources"); 80 } 81 82 form.setImage(AdtPlugin.getAndroidLogo()); 83 84 UiElementNode resources = mEditor.getUiRootNode(); 85 UiTreeBlock block = new UiTreeBlock(mEditor, resources, 86 true /* autoCreateRoot */, 87 null /* no element filters */, 88 "Resources Elements", 89 "List of all resources elements in this XML file."); 90 block.createContent(managedForm); 91 } 92 } 93