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