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.SWT; 29 import org.eclipse.swt.graphics.Image; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.ui.forms.IManagedForm; 33 import org.eclipse.ui.forms.editor.FormPage; 34 import org.eclipse.ui.forms.widgets.FormToolkit; 35 import org.eclipse.ui.forms.widgets.ScrolledForm; 36 37 38 /** 39 * Page for "Application" settings, part of the AndroidManifest form editor. 40 * <p/> 41 * Useful reference: 42 * <a href="http://www.eclipse.org/articles/Article-Forms/article.html"> 43 * http://www.eclipse.org/articles/Article-Forms/article.html</a> 44 */ 45 public final class ApplicationPage extends FormPage implements IPageImageProvider { 46 /** Page id used for switching tabs programmatically */ 47 public final static String PAGE_ID = "application_page"; //$NON-NLS-1$ 48 49 /** Container editor */ 50 ManifestEditor mEditor; 51 /** The Application Toogle part */ 52 private ApplicationToggle mTooglePart; 53 /** The Application Attributes part */ 54 private ApplicationAttributesPart mAttrPart; 55 /** The tree view block */ 56 private UiTreeBlock mTreeBlock; 57 58 public ApplicationPage(ManifestEditor editor) { 59 super(editor, PAGE_ID, "Application"); // tab's label, keep it short 60 mEditor = editor; 61 } 62 63 @Override 64 public Image getPageImage() { 65 return IconFactory.getInstance().getIcon(getTitle(), 66 IconFactory.COLOR_BLUE, 67 IconFactory.SHAPE_RECT); 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 form.setText("Android Manifest Application"); 80 form.setImage(AdtPlugin.getAndroidLogo()); 81 82 UiElementNode appUiNode = getUiApplicationNode(); 83 84 Composite body = form.getBody(); 85 FormToolkit toolkit = managedForm.getToolkit(); 86 87 // We usually prefer to have a ColumnLayout here. However 88 // MasterDetailsBlock.createContent() below will reset the body's layout to a grid layout. 89 mTooglePart = new ApplicationToggle(body, toolkit, mEditor, appUiNode); 90 mTooglePart.getSection().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 91 managedForm.addPart(mTooglePart); 92 mAttrPart = new ApplicationAttributesPart(body, toolkit, mEditor, appUiNode); 93 mAttrPart.getSection().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 94 managedForm.addPart(mAttrPart); 95 96 mTreeBlock = new UiTreeBlock(mEditor, appUiNode, 97 false /* autoCreateRoot */, 98 null /* element filters */, 99 "Application Nodes", 100 "List of all elements in the application"); 101 mTreeBlock.createContent(managedForm); 102 } 103 104 /** 105 * Retrieves the application UI node. Since this is a mandatory node, it *always* 106 * exists, even if there is no matching XML node. 107 */ 108 private UiElementNode getUiApplicationNode() { 109 AndroidManifestDescriptors manifestDescriptor = mEditor.getManifestDescriptors(); 110 if (manifestDescriptor != null) { 111 ElementDescriptor desc = manifestDescriptor.getApplicationElement(); 112 return mEditor.getUiRootNode().findUiChildNode(desc.getXmlName()); 113 } else { 114 // return the ui root node, as a dummy application root node. 115 return mEditor.getUiRootNode(); 116 } 117 } 118 119 /** 120 * Changes and refreshes the Application UI node handled by the sub parts. 121 */ 122 public void refreshUiApplicationNode() { 123 UiElementNode appUiNode = getUiApplicationNode(); 124 if (mTooglePart != null) { 125 mTooglePart.setUiElementNode(appUiNode); 126 } 127 if (mAttrPart != null) { 128 mAttrPart.setUiElementNode(appUiNode); 129 } 130 if (mTreeBlock != null) { 131 mTreeBlock.changeRootAndDescriptors(appUiNode, 132 null /* element filters */, 133 true /* refresh */); 134 } 135 } 136 } 137