From 076609b9c96a13f5fb8f37cb91444f7fcbdfe3c5 Mon Sep 17 00:00:00 2001
From: Raphael Moll <>
Date: Tue, 24 Mar 2009 19:14:49 -0700
Subject: [PATCH] Automated import from //branches/cupcake/...@142190,142190
---
.../common/resources/DeclareStyleableInfo.java | 12 +++
.../editors/descriptors/ElementDescriptor.java | 13 +++
.../layout/descriptors/LayoutDescriptors.java | 110 +++++++++++++++++++--
3 files changed, 128 insertions(+), 7 deletions(-)
diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java
index efa5981b..7aad7c84 100644
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java
@@ -70,6 +70,18 @@ public class DeclareStyleableInfo {
mFormats = formats;
}
+ /**
+ * @param name The XML Name of the attribute
+ * @param formats The formats of the attribute. Cannot be null.
+ * Should have at least one format.
+ * @param javadoc Short javadoc (i.e. the first sentence).
+ */
+ public AttributeInfo(String name, Format[] formats, String javadoc) {
+ mName = name;
+ mFormats = formats;
+ mJavaDoc = javadoc;
+ }
+
public AttributeInfo(AttributeInfo info) {
mName = info.mName;
mFormats = info.mFormats;
diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java
index 55501553..6a9b7db2 100644
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java
@@ -24,6 +24,7 @@ import com.android.sdklib.SdkConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -221,6 +222,18 @@ public class ElementDescriptor {
mChildren = newChildren;
}
+ /** Sets the list of allowed children.
+ *
+ * This is just a convenience method that converts a Collection into an array and
+ * calls {@link #setChildren(ElementDescriptor[])}.
+ *
+ * This means a copy of the collection is made. The collection is not
+ * stored by the recipient and can thus be altered by the caller.
+ */
+ public void setChildren(Collection newChildren) {
+ setChildren(newChildren.toArray(new ElementDescriptor[newChildren.size()]));
+ }
+
/**
* Returns an optional tooltip. Will be null if not present.
*
diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java
index 5726d789..2c0f984d 100644
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java
@@ -43,7 +43,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
public static final String ID_ATTR = "id"; //$NON-NLS-1$
/** The document descriptor. Contains all layouts and views linked together. */
- private DocumentDescriptor mDescriptor =
+ private DocumentDescriptor mRootDescriptor =
new DocumentDescriptor("layout_doc", null); //$NON-NLS-1$
/** The list of all known ViewLayout descriptors. */
@@ -60,7 +60,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
/** @return the document descriptor. Contains all layouts and views linked together. */
public DocumentDescriptor getDescriptor() {
- return mDescriptor;
+ return mRootDescriptor;
}
/** @return The read-only list of all known ViewLayout descriptors. */
@@ -74,7 +74,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
}
public ElementDescriptor[] getRootElementDescriptors() {
- return mDescriptor.getChildren();
+ return mRootDescriptor.getChildren();
}
/**
@@ -98,6 +98,10 @@ public final class LayoutDescriptors implements IDescriptorProvider {
}
}
+ // Create as a synthetic regular view.
+ // Note: ViewStub is already described by attrs.xml
+ insertInclude(newViews);
+
ArrayList newLayouts = new ArrayList();
if (layouts != null) {
for (ViewClassInfo info : layouts) {
@@ -109,17 +113,22 @@ public final class LayoutDescriptors implements IDescriptorProvider {
ArrayList newDescriptors = new ArrayList();
newDescriptors.addAll(newLayouts);
newDescriptors.addAll(newViews);
- ElementDescriptor[] newArray = newDescriptors.toArray(
- new ElementDescriptor[newDescriptors.size()]);
// Link all layouts to everything else here.. recursively
for (ElementDescriptor layoutDesc : newLayouts) {
- layoutDesc.setChildren(newArray);
+ layoutDesc.setChildren(newDescriptors);
}
+ // The tag can only be a root tag, so it is added at the end.
+ // It gets everything else as children but it is not made a child itself.
+ ElementDescriptor mergeTag = createMerge();
+ mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list
+ newDescriptors.add(mergeTag);
+ newLayouts.add(mergeTag);
+
mViewDescriptors = newViews;
mLayoutDescriptors = newLayouts;
- mDescriptor.setChildren(newArray);
+ mRootDescriptor.setChildren(newDescriptors);
mROLayoutDescriptors = Collections.unmodifiableList(mLayoutDescriptors);
mROViewDescriptors = Collections.unmodifiableList(mViewDescriptors);
@@ -217,4 +226,91 @@ public final class LayoutDescriptors implements IDescriptorProvider {
false /* mandatory */);
}
+ /**
+ * Creates a new descriptor and adds it to the list of view descriptors.
+ *
+ * @param newViews A list of view descriptors being populated. Also used to find the
+ * View description and extract its layout attributes.
+ */
+ private void insertInclude(ArrayList newViews) {
+ String xml_name = "include"; //$NON-NLS-1$
+
+ // Create the include custom attributes
+ ArrayList attributes = new ArrayList();
+
+ // Note that the "layout" attribute does NOT have the Android namespace
+ DescriptorsUtils.appendAttribute(attributes,
+ null, //elementXmlName
+ null, //nsUri
+ new AttributeInfo(
+ "layout", //$NON-NLS-1$
+ new AttributeInfo.Format[] { AttributeInfo.Format.REFERENCE }
+ ),
+ true, //required
+ null); //overrides
+
+ DescriptorsUtils.appendAttribute(attributes,
+ null, //elementXmlName
+ SdkConstants.NS_RESOURCES, //nsUri
+ new AttributeInfo(
+ "id", //$NON-NLS-1$
+ new AttributeInfo.Format[] { AttributeInfo.Format.REFERENCE }
+ ),
+ true, //required
+ null); //overrides
+
+ // Find View and inherit all its layout attributes
+ AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews);
+
+ // Create the include descriptor
+ ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
+ xml_name, // ui_name
+ null, // canonical class name, we don't have one
+ "Lets you statically include XML layouts inside other XML layouts.", // tooltip
+ null, // sdk_url
+ attributes.toArray(new AttributeDescriptor[attributes.size()]),
+ viewLayoutAttribs, // layout attributes
+ null, // children
+ false /* mandatory */);
+
+ newViews.add(desc);
+ }
+
+ /**
+ * Finds the View descriptor and retrieves all its layout attributes.
+ */
+ private AttributeDescriptor[] findViewLayoutAttributes(
+ ArrayList newViews) {
+
+ for (ElementDescriptor desc : newViews) {
+ if (desc instanceof ViewElementDescriptor) {
+ ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc;
+ if (AndroidConstants.CLASS_VIEW.equals(viewDesc.getCanonicalClassName())) {
+ return viewDesc.getLayoutAttributes();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates and return a new descriptor.
+ */
+ private ElementDescriptor createMerge() {
+ String xml_name = "merge"; //$NON-NLS-1$
+
+ // Create the include descriptor
+ ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
+ xml_name, // ui_name
+ null, // canonical class name, we don't have one
+ "A root tag useful for XML layouts inflated using a ViewStub.", // tooltip
+ null, // sdk_url
+ null, // attributes
+ null, // layout attributes
+ null, // children
+ false /* mandatory */);
+
+ return desc;
+ }
}
--
2.11.0