ElementDescriptorpublic 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 | mXmlNameThe XML element node name. Case sensitive. | private String | mUiNameThe XML element name for the user interface, typically capitalized. | private AttributeDescriptor[] | mAttributesThe list of allowed attributes. | private ElementDescriptor[] | mChildrenThe list of allowed children | private String | mTooltip | private String | mSdkUrlAn optional SKD URL. Can be empty. | private boolean | mMandatoryWhether 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.
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.
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.
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.
this(xml_name, prettyName(xml_name), null, null, null, null, false);
|
Methods Summary |
---|
public com.android.ide.eclipse.editors.uimodel.UiElementNode | createUiNode()
return new UiElementNode(this);
| public com.android.ide.eclipse.editors.descriptors.ElementDescriptor | findChildrenDescriptor(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 findChildrenDescriptorInternal(element_name, recursive, null);
| private com.android.ide.eclipse.editors.descriptors.ElementDescriptor | findChildrenDescriptorInternal(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.Image | getIcon()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.
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.ImageDescriptor | getImageDescriptor()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.
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.String | getNamespace()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.String | getSdkUrl()Returns an optional SKD URL. Will be null if not present.
return mSdkUrl;
| public java.lang.String | getTooltip()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.String | getUiName()Returns the XML element name for the user interface, typically capitalized.
return mUiName;
| public final java.lang.String | getXmlLocalName()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.String | getXmlName()Returns the XML element node name. Case sensitive.
return mXmlName;
| public boolean | hasChildren()
return mChildren.length > 0;
| public boolean | isMandatory()Returns whether this node must always exist (even for empty models)
return mMandatory;
| private static java.lang.String | prettyName(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.
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 void | setAttributes(AttributeDescriptor[] attributes)
mAttributes = attributes;
for (AttributeDescriptor attribute : attributes) {
attribute.setParent(this);
}
| public void | setChildren(com.android.ide.eclipse.editors.descriptors.ElementDescriptor[] newChildren)Sets the list of allowed children.
mChildren = newChildren;
| public void | setChildren(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 void | setSdkUrl(java.lang.String sdkUrl)Sets the optional SDK URL. Can be null or empty.
mSdkUrl = sdkUrl;
| public void | setTooltip(java.lang.String tooltip)Sets the optional tooltip. Can be null or empty.
mTooltip = tooltip;
|
|