Home | History | Annotate | Download | only in pages
      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.internal.editors.descriptors.ElementDescriptor;
     20 import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
     21 import com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.AndroidManifestDescriptors;
     22 import com.android.ide.eclipse.adt.internal.editors.ui.UiElementPart;
     23 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
     24 
     25 import org.eclipse.swt.widgets.Composite;
     26 import org.eclipse.ui.forms.IManagedForm;
     27 import org.eclipse.ui.forms.widgets.FormToolkit;
     28 import org.eclipse.ui.forms.widgets.Section;
     29 
     30 /**
     31  * Generic info section part for overview page: it displays all the attributes from
     32  * the manifest element.
     33  */
     34 final class OverviewInfoPart extends UiElementPart {
     35 
     36     private IManagedForm mManagedForm;
     37 
     38     public OverviewInfoPart(Composite body, FormToolkit toolkit, ManifestEditor editor) {
     39         super(body, toolkit, editor,
     40                 getManifestUiNode(editor),  // uiElementNode
     41                 "Manifest General Attributes", // section title
     42                 "Defines general information about the AndroidManifest.xml", // section description
     43                 Section.TWISTIE | Section.EXPANDED);
     44     }
     45 
     46     /**
     47      * Retrieves the UiElementNode that this part will edit. The node must exist
     48      * and can't be null, by design, because it's a mandatory node.
     49      */
     50     private static UiElementNode getManifestUiNode(ManifestEditor editor) {
     51         AndroidManifestDescriptors manifestDescriptors = editor.getManifestDescriptors();
     52         if (manifestDescriptors != null) {
     53             ElementDescriptor desc = manifestDescriptors.getManifestElement();
     54             if (editor.getUiRootNode().getDescriptor() == desc) {
     55                 return editor.getUiRootNode();
     56             } else {
     57                 return editor.getUiRootNode().findUiChildNode(desc.getXmlName());
     58             }
     59         }
     60 
     61         // No manifest descriptor: we have a dummy UiRootNode, so we return that.
     62         // The editor will be reloaded once we have the proper descriptors anyway.
     63         return editor.getUiRootNode();
     64     }
     65 
     66     /**
     67      * Overridden in order to capture the current managed form.
     68      *
     69      * {@inheritDoc}
     70      */
     71     @Override
     72     protected void createFormControls(final IManagedForm managedForm) {
     73         mManagedForm = managedForm;
     74         super.createFormControls(managedForm);
     75     }
     76 
     77     /**
     78      * Removes any existing Attribute UI widgets and recreate them if the SDK has changed.
     79      * <p/>
     80      * This is called by {@link OverviewPage#refreshUiApplicationNode()} when the
     81      * SDK has changed.
     82      */
     83     public void onSdkChanged() {
     84         setUiElementNode(getManifestUiNode(getEditor()));
     85         createUiAttributes(mManagedForm);
     86     }
     87 }
     88