OSDN Git Service

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