OSDN Git Service

AI 145419: am: CL 145402 am: CL 145004 ADT #1761064: Properly refresh manifest activi...
authorRaphael Moll <>
Thu, 9 Apr 2009 20:09:46 +0000 (13:09 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Thu, 9 Apr 2009 20:09:46 +0000 (13:09 -0700)
  Issue: when the SDK gets (re)loaded, the uiRootNode changes
  in the UiTreeBlock. However the TreeViewer is using a
  content provider which root node was not updated. The fix is
  to make the content provider dynamically ask for the root
  node to the tree block. Instead of depending on the class
  directly, a new interface is passed for this.
  Original author: raphael
  Merged from: //branches/cupcake/...
  Original author: android-build

Automated import of CL 145419

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/manifest/ManifestEditor.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/NewItemSelectionDialog.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/UiModelTreeContentProvider.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/UiRootNodeProvider.java [new file with mode: 0644]
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/UiTreeBlock.java

index d0f8d7b..dc32383 100644 (file)
@@ -159,9 +159,9 @@ public final class ManifestEditor extends AndroidEditor {
     protected void xmlModelChanged(Document xml_doc) {
         // create the ui root node on demand.
         initUiRootNode(false /*force*/);
-        
+
         loadFromXml(xml_doc);
-        
+
         super.xmlModelChanged(xml_doc);
     }
     
@@ -184,7 +184,7 @@ public final class ManifestEditor extends AndroidEditor {
             }
         }
     }
-    
+
     private void onDescriptorsChanged(UiElementNode oldManifestNode) {
         mUiManifestNode.reloadFromXmlNode(oldManifestNode.getXmlNode());
 
@@ -321,7 +321,6 @@ public final class ManifestEditor extends AndroidEditor {
         if (mUiManifestNode != null && force == false) {
             return;
         }
-
         
         AndroidManifestDescriptors manifestDescriptor = getManifestDescriptors();
         
index 0729881..72fe060 100644 (file)
@@ -38,7 +38,7 @@ import java.util.Arrays;
 
 /**
  * A selection dialog to select the type of the new element node to
- * created, either in the application node or the selected sub node.
+ * create, either in the application node or the selected sub node.
  */
 public class NewItemSelectionDialog extends AbstractElementListSelectionDialog {
 
index 9f34d9e..3091992 100644 (file)
@@ -30,16 +30,15 @@ import java.util.ArrayList;
  */
 class UiModelTreeContentProvider implements ITreeContentProvider {
     
-    /** The root {@link UiElementNode} which contains all the elements that are to be 
-     *  manipulated by this tree view. In general this is the manifest UI node. */
-    private UiElementNode mUiRootNode;
     /** The descriptor of the elements to be displayed as root in this tree view. All elements
      *  of the same type in the root will be displayed. */
     private ElementDescriptor[] mDescriptorFilters;
+    /** Object which provides the uiRootNode */
+    private final UiRootNodeProvider mUiRootNodeProvider;
 
-    public UiModelTreeContentProvider(UiElementNode uiRootNode,
+    public UiModelTreeContentProvider(UiRootNodeProvider rootNodeProvider,
             ElementDescriptor[] descriptorFilters) {
-        mUiRootNode = uiRootNode;
+        mUiRootNodeProvider = rootNodeProvider;
         mDescriptorFilters = descriptorFilters;
     }
     
@@ -87,8 +86,9 @@ class UiModelTreeContentProvider implements ITreeContentProvider {
      */
     public Object[] getElements(Object inputElement) {
         ArrayList<UiElementNode> roots = new ArrayList<UiElementNode>();
-        if (mUiRootNode != null) {
-            for (UiElementNode ui_node : mUiRootNode.getUiChildren()) {
+        UiElementNode uiRootNode = mUiRootNodeProvider.getRootNode();
+        if (uiRootNode != null) {
+            for (UiElementNode ui_node : uiRootNode.getUiChildren()) {
                 if (mDescriptorFilters == null || mDescriptorFilters.length == 0) {
                     roots.add(ui_node);
                 } else {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/UiRootNodeProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/ui/tree/UiRootNodeProvider.java
new file mode 100644 (file)
index 0000000..5121e35
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.editors.ui.tree;
+
+import com.android.ide.eclipse.editors.uimodel.UiElementNode;
+
+/**
+ * An object that can provide a uiRootNode.
+ */
+public interface UiRootNodeProvider {
+    /** Returns the UiDocumentNode for the current model. */
+    public abstract UiElementNode getRootNode();
+}
index fc384e8..8038a47 100644 (file)
@@ -83,7 +83,8 @@ import java.util.LinkedList;
  * On the left is a details part that displays all the visible UI attributes for a given
  * selected UI element node.
  */
-public final class UiTreeBlock extends MasterDetailsBlock implements ICommitXml {
+public final class UiTreeBlock extends MasterDetailsBlock
+    implements ICommitXml, UiRootNodeProvider {
 
     /** Height hint for the tree view. Helps the grid layout resize properly on smaller screens. */
     private static final int TREE_HEIGHT_HINT = 50;
@@ -181,6 +182,17 @@ public final class UiTreeBlock extends MasterDetailsBlock implements ICommitXml
         return mMasterPart;
     }
 
+    /**
+     * Returns the {@link UiElementNode} for the current model.
+     * <p/>
+     * This is used by the content provider attached to {@link #mTreeViewer} since
+     * the uiRootNode changes after each call to
+     * {@link #changeRootAndDescriptors(UiElementNode, ElementDescriptor[], boolean)}. 
+     */
+    public UiElementNode getRootNode() {
+        return mUiRootNode;
+    }
+
     @Override
     protected void createMasterPart(final IManagedForm managedForm, Composite parent) {
         FormToolkit toolkit = managedForm.getToolkit();
@@ -239,8 +251,7 @@ public final class UiTreeBlock extends MasterDetailsBlock implements ICommitXml
         tree.setLayoutData(gd);
 
         mTreeViewer = new TreeViewer(tree);
-        mTreeViewer.setContentProvider(new UiModelTreeContentProvider(
-                mUiRootNode, mDescriptorFilters));
+        mTreeViewer.setContentProvider(new UiModelTreeContentProvider(this, mDescriptorFilters));
         mTreeViewer.setLabelProvider(new UiModelTreeLabelProvider());
         mTreeViewer.setInput("unused"); //$NON-NLS-1$