FileDocCategorySizeDatePackage
ElementDescriptor.javaAPI DocAndroid 1.5 API12533Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.descriptors

ElementDescriptor

public class ElementDescriptor extends Object
{@link ElementDescriptor} describes the properties expected for a given XML element node. {@link ElementDescriptor} have an XML name, UI name, a tooltip, an SDK url, an attributes list and a children list. An UI node can be "mandatory", meaning the UI node is never deleted and it may lack an actual XML node attached. A non-mandatory UI node MUST have an XML node attached and it will cease to exist when the XML node ceases to exist.

Fields Summary
private String
mXmlName
The XML element node name. Case sensitive.
private String
mUiName
The XML element name for the user interface, typically capitalized.
private AttributeDescriptor[]
mAttributes
The list of allowed attributes.
private ElementDescriptor[]
mChildren
The list of allowed children
private String
mTooltip
private String
mSdkUrl
An optional SKD URL. Can be empty.
private boolean
mMandatory
Whether this UI node must always exist (even for empty models).
Constructors Summary
public ElementDescriptor(String xml_name, String ui_name, String tooltip, String sdk_url, AttributeDescriptor[] attributes, ElementDescriptor[] children, boolean mandatory)
Constructs a new {@link ElementDescriptor} based on its XML name, UI name, tooltip, SDK url, attributes list, children list and mandatory.

param
xml_name The XML element node name. Case sensitive.
param
ui_name The XML element name for the user interface, typically capitalized.
param
tooltip An optional tooltip. Can be null or empty.
param
sdk_url An optional SKD URL. Can be null or empty.
param
attributes The list of allowed attributes. Can be null or empty.
param
children The list of allowed children. Can be null or empty.
param
mandatory Whether this node must always exist (even for empty models). A mandatory UI node is never deleted and it may lack an actual XML node attached. A non-mandatory UI node MUST have an XML node attached and it will cease to exist when the XML node ceases to exist.

        mMandatory = mandatory;
        mXmlName = xml_name;
        mUiName = ui_name;
        mTooltip = (tooltip != null && tooltip.length() > 0) ? tooltip : null;
        mSdkUrl = (sdk_url != null && sdk_url.length() > 0) ? sdk_url : null;
        setAttributes(attributes != null ? attributes : new AttributeDescriptor[]{});
        mChildren = children != null ? children : new ElementDescriptor[]{};
    
public ElementDescriptor(String xml_name, ElementDescriptor[] children, boolean mandatory)
Constructs a new {@link ElementDescriptor} based on its XML name and children list. The UI name is build by capitalizing the XML name. The UI nodes will be non-mandatory.

param
xml_name The XML element node name. Case sensitive.
param
children The list of allowed children. Can be null or empty.
param
mandatory Whether this node must always exist (even for empty models). A mandatory UI node is never deleted and it may lack an actual XML node attached. A non-mandatory UI node MUST have an XML node attached and it will cease to exist when the XML node ceases to exist.

        this(xml_name, prettyName(xml_name), null, null, null, children, mandatory);
    
public ElementDescriptor(String xml_name, ElementDescriptor[] children)
Constructs a new {@link ElementDescriptor} based on its XML name and children list. The UI name is build by capitalizing the XML name. The UI nodes will be non-mandatory.

param
xml_name The XML element node name. Case sensitive.
param
children The list of allowed children. Can be null or empty.

        this(xml_name, prettyName(xml_name), null, null, null, children, false);
    
public ElementDescriptor(String xml_name)
Constructs a new {@link ElementDescriptor} based on its XML name. The UI name is build by capitalizing the XML name. The UI nodes will be non-mandatory.

param
xml_name The XML element node name. Case sensitive.

        this(xml_name, prettyName(xml_name), null, null, null, null, false);
    
Methods Summary
public com.android.ide.eclipse.editors.uimodel.UiElementNodecreateUiNode()

return
A new {@link UiElementNode} linked to this descriptor.

        return new UiElementNode(this);
    
public com.android.ide.eclipse.editors.descriptors.ElementDescriptorfindChildrenDescriptor(java.lang.String element_name, boolean recursive)
Returns the first children of this descriptor that describes the given XML element name.

In recursive mode, searches the direct children first before descending in the hierarchy.

return
The ElementDescriptor matching the requested XML node element name or null.

        return findChildrenDescriptorInternal(element_name, recursive, null);
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorfindChildrenDescriptorInternal(java.lang.String element_name, boolean recursive, java.util.Set visited)

        if (recursive && visited == null) {
            visited = new HashSet<ElementDescriptor>();
        }

        for (ElementDescriptor e : getChildren()) {
            if (e.getXmlName().equals(element_name)) {
                return e;
            }
        }

        if (visited != null) {
            visited.add(this);
        }

        if (recursive) {
            for (ElementDescriptor e : getChildren()) {
                if (visited != null) {
                    if (!visited.add(e)) {  // Set.add() returns false if element is already present
                        continue;
                    }
                }
                ElementDescriptor f = e.findChildrenDescriptorInternal(element_name,
                        recursive, visited);
                if (f != null) {
                    return f;
                }
            }
        }

        return null;
    
public AttributeDescriptor[]getAttributes()

        return mAttributes;
    
public com.android.ide.eclipse.editors.descriptors.ElementDescriptor[]getChildren()
Returns the list of allowed children

        return mChildren;
    
public org.eclipse.swt.graphics.ImagegetIcon()
Returns an optional icon for the element.

By default this tries to return an icon based on the XML name of the element. If this fails, it tries to return the default Android logo as defined in the plugin. If all fails, it returns null.

return
An icon for this element or null.

        IconFactory factory = IconFactory.getInstance();
        int color = hasChildren() ? IconFactory.COLOR_BLUE : IconFactory.COLOR_GREEN;
        int shape = hasChildren() ? IconFactory.SHAPE_RECT : IconFactory.SHAPE_CIRCLE;
        Image icon = factory.getIcon(mXmlName, color, shape);
        return icon != null ? icon : AdtPlugin.getAndroidLogo();
    
public org.eclipse.jface.resource.ImageDescriptorgetImageDescriptor()
Returns an optional ImageDescriptor for the element.

By default this tries to return an image based on the XML name of the element. If this fails, it tries to return the default Android logo as defined in the plugin. If all fails, it returns null.

return
An ImageDescriptor for this element or null.

        IconFactory factory = IconFactory.getInstance();
        int color = hasChildren() ? IconFactory.COLOR_BLUE : IconFactory.COLOR_GREEN;
        int shape = hasChildren() ? IconFactory.SHAPE_RECT : IconFactory.SHAPE_CIRCLE;
        ImageDescriptor id = factory.getImageDescriptor(mXmlName, color, shape);
        return id != null ? id : AdtPlugin.getAndroidLogoDesc();
    
public final java.lang.StringgetNamespace()
Returns the namespace of the attribute.

        // For now we hard-code the prefix as being "android"
        if (mXmlName.startsWith("android:")) { //$NON-NLs-1$
            return SdkConstants.NS_RESOURCES;
        }
        
        return ""; //$NON-NLs-1$
    
public java.lang.StringgetSdkUrl()
Returns an optional SKD URL. Will be null if not present.

        return mSdkUrl;
    
public java.lang.StringgetTooltip()
Returns an optional tooltip. Will be null if not present.

The tooltip is based on the Javadoc of the element and already processed via {@link DescriptorsUtils#formatTooltip(String)} to be displayed right away as a UI tooltip.

        return mTooltip;
    
public java.lang.StringgetUiName()
Returns the XML element name for the user interface, typically capitalized.

        return mUiName;
    
public final java.lang.StringgetXmlLocalName()
Returns the XML element node local name (case sensitive)

        int pos = mXmlName.indexOf(':"); 
        if (pos != -1) {
            return mXmlName.substring(pos+1);
        }
        return mXmlName;
    
public java.lang.StringgetXmlName()
Returns the XML element node name. Case sensitive.

        return mXmlName;
    
public booleanhasChildren()

return
True if this descriptor has children available

        return mChildren.length > 0;
    
public booleanisMandatory()
Returns whether this node must always exist (even for empty models)

        return mMandatory;
    
private static java.lang.StringprettyName(java.lang.String xml_name)
Utility helper than pretty-formats an XML Name for the UI. This is used by the simplified constructor that takes only an XML element name.

param
xml_name The XML name to convert.
return
The XML name with dashes replaced by spaces and capitalized.

        char c[] = xml_name.toCharArray();
        if (c.length > 0) {
            c[0] = Character.toUpperCase(c[0]);
        }
        return new String(c).replace("-", " ");  //$NON-NLS-1$  //$NON-NLS-2$
    
public voidsetAttributes(AttributeDescriptor[] attributes)

        mAttributes = attributes;
        for (AttributeDescriptor attribute : attributes) {
            attribute.setParent(this);
        }
    
public voidsetChildren(com.android.ide.eclipse.editors.descriptors.ElementDescriptor[] newChildren)
Sets the list of allowed children.

        mChildren = newChildren;
    
public voidsetChildren(java.util.Collection 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.

        setChildren(newChildren.toArray(new ElementDescriptor[newChildren.size()]));
    
public voidsetSdkUrl(java.lang.String sdkUrl)
Sets the optional SDK URL. Can be null or empty.

        mSdkUrl = sdkUrl;
    
public voidsetTooltip(java.lang.String tooltip)
Sets the optional tooltip. Can be null or empty.

        mTooltip = tooltip;