MenuDescriptorspublic final class MenuDescriptors extends Object implements com.android.ide.eclipse.editors.descriptors.IDescriptorProviderComplete description of the menu structure. |
Fields Summary |
---|
public static final String | MENU_ROOT_ELEMENT | private com.android.ide.eclipse.editors.descriptors.ElementDescriptor | mDescriptorThe root element descriptor. |
Methods Summary |
---|
private com.android.ide.eclipse.editors.descriptors.ElementDescriptor | createElement(java.util.Map styleMap, java.lang.String xmlName, java.lang.String uiName, java.lang.String sdkUrl, com.android.ide.eclipse.editors.descriptors.AttributeDescriptor extraAttribute, com.android.ide.eclipse.editors.descriptors.ElementDescriptor[] childrenElements, boolean mandatory)Returns a new ElementDescriptor constructed from the information given here
and the javadoc & attributes extracted from the style map if any.
ElementDescriptor element = new ElementDescriptor(xmlName, uiName, null, sdkUrl,
null, childrenElements, mandatory);
return updateElement(element, styleMap,
getStyleName(xmlName),
extraAttribute);
| public com.android.ide.eclipse.editors.descriptors.ElementDescriptor | getDescriptor()
return mDescriptor;
| public com.android.ide.eclipse.editors.descriptors.ElementDescriptor[] | getRootElementDescriptors()
return mDescriptor.getChildren();
| private java.lang.String | getStyleName(java.lang.String xmlName)Returns the style name (i.e. the name found in attrs.xml)
for a given XML element name.
The rule is that all elements have for style name:
- their xml name capitalized
- a "Menu" prefix, except for | public synchronized void | updateDescriptors(java.util.Map styleMap)Updates the document descriptor.
It first computes the new children of the descriptor and then updates them
all at once.
// There are 3 elements: menu, item and group.
// The root element MUST be a menu.
// A top menu can contain items or group:
// - top groups can contain top items
// - top items can contain sub-menus
// A sub menu can contains sub items or sub groups:
// - sub groups can contain sub items
// - sub items cannot contain anything
if (mDescriptor == null) {
mDescriptor = createElement(styleMap,
MENU_ROOT_ELEMENT, // xmlName
"Menu", // uiName,
null, // TODO SDK URL
null, // extraAttribute
null, // childrenElements,
true /* mandatory */);
}
// -- sub menu can have sub_items, sub_groups but not sub_menus
ElementDescriptor sub_item = createElement(styleMap,
"item", // xmlName //$NON-NLS-1$
"Item", // uiName,
null, // TODO SDK URL
null, // extraAttribute
null, // childrenElements,
false /* mandatory */);
ElementDescriptor sub_group = createElement(styleMap,
"group", // xmlName //$NON-NLS-1$
"Group", // uiName,
null, // TODO SDK URL
null, // extraAttribute
new ElementDescriptor[] { sub_item }, // childrenElements,
false /* mandatory */);
ElementDescriptor sub_menu = createElement(styleMap,
MENU_ROOT_ELEMENT, // xmlName //$NON-NLS-1$
"Sub-Menu", // uiName,
null, // TODO SDK URL
null, // extraAttribute
new ElementDescriptor[] { sub_item, sub_group }, // childrenElements,
true /* mandatory */);
// -- top menu can have all top groups and top items (which can have sub menus)
ElementDescriptor top_item = createElement(styleMap,
"item", // xmlName //$NON-NLS-1$
"Item", // uiName,
null, // TODO SDK URL
null, // extraAttribute
new ElementDescriptor[] { sub_menu }, // childrenElements,
false /* mandatory */);
ElementDescriptor top_group = createElement(styleMap,
"group", // xmlName //$NON-NLS-1$
"Group", // uiName,
null, // TODO SDK URL
null, // extraAttribute
new ElementDescriptor[] { top_item }, // childrenElements,
false /* mandatory */);
XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor("android", //$NON-NLS-1$
SdkConstants.NS_RESOURCES);
updateElement(mDescriptor, styleMap, "Menu", xmlns); //$NON-NLS-1$
mDescriptor.setChildren(new ElementDescriptor[] { top_item, top_group });
| private com.android.ide.eclipse.editors.descriptors.ElementDescriptor | updateElement(com.android.ide.eclipse.editors.descriptors.ElementDescriptor element, java.util.Map styleMap, java.lang.String styleName, com.android.ide.eclipse.editors.descriptors.AttributeDescriptor extraAttribute)Updates an ElementDescriptor with the javadoc & attributes extracted from the style
map if any.
ArrayList<AttributeDescriptor> descs = new ArrayList<AttributeDescriptor>();
DeclareStyleableInfo style = styleMap != null ? styleMap.get(styleName) : null;
if (style != null) {
DescriptorsUtils.appendAttributes(descs,
null, // elementName
SdkConstants.NS_RESOURCES,
style.getAttributes(),
null, // requiredAttributes
null); // overrides
element.setTooltip(style.getJavaDoc());
}
if (extraAttribute != null) {
descs.add(extraAttribute);
}
element.setAttributes(descs.toArray(new AttributeDescriptor[descs.size()]));
return element;
|
|