FileDocCategorySizeDatePackage
UiViewElementNode.javaAPI DocAndroid 1.5 API5200Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.layout.uimodel

UiViewElementNode

public class UiViewElementNode extends com.android.ide.eclipse.editors.uimodel.UiElementNode
Specialized version of {@link UiElementNode} for the {@link ViewElementDescriptor}s.

Fields Summary
private com.android.ide.eclipse.editors.descriptors.AttributeDescriptor[]
mCachedAttributeDescriptors
Constructors Summary
public UiViewElementNode(com.android.ide.eclipse.editors.layout.descriptors.ViewElementDescriptor elementDescriptor)

        super(elementDescriptor);
    
Methods Summary
public com.android.ide.eclipse.editors.descriptors.AttributeDescriptor[]getAttributeDescriptors()
Returns an AttributeDescriptor array that depends on the current UiParent.

The array merges both "direct" attributes with the descriptor layout attributes. The array instance is cached and cleared if the UiParent is changed.

        if (mCachedAttributeDescriptors != null) {
            return mCachedAttributeDescriptors;
        }

        UiElementNode ui_parent = getUiParent();
        AttributeDescriptor[] direct_attrs = super.getAttributeDescriptors();
        mCachedAttributeDescriptors = direct_attrs;

        AttributeDescriptor[] layout_attrs = null;
        boolean need_xmlns = false;

        if (ui_parent instanceof UiDocumentNode) {
            // Limitation: right now the layout behaves as if everything was
            // owned by a FrameLayout.
            // TODO replace by something user-configurable.

            List<ElementDescriptor> layoutDescriptors = null;
            IProject project = getEditor().getProject();
            if (project != null) {
                Sdk currentSdk = Sdk.getCurrent();
                IAndroidTarget target = currentSdk.getTarget(project);
                if (target != null) {
                    AndroidTargetData data = currentSdk.getTargetData(target);
                    layoutDescriptors = data.getLayoutDescriptors().getLayoutDescriptors();
                }
            }
            
            if (layoutDescriptors != null) {
                for (ElementDescriptor desc : layoutDescriptors) {
                    if (desc instanceof ViewElementDescriptor &&
                            desc.getXmlName().equals(AndroidConstants.CLASS_NAME_FRAMELAYOUT)) {
                        layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes();
                        need_xmlns = true;
                        break;
                    }
                }
            }
        } else if (ui_parent instanceof UiViewElementNode){
            layout_attrs =
                ((ViewElementDescriptor) ui_parent.getDescriptor()).getLayoutAttributes();
        }

        if (layout_attrs == null || layout_attrs.length == 0) {
            return mCachedAttributeDescriptors;
        }

        mCachedAttributeDescriptors =
            new AttributeDescriptor[direct_attrs.length +
                                    layout_attrs.length +
                                    (need_xmlns ? 1 : 0)];
        System.arraycopy(direct_attrs, 0,
                mCachedAttributeDescriptors, 0,
                direct_attrs.length);
        System.arraycopy(layout_attrs, 0,
                mCachedAttributeDescriptors, direct_attrs.length,
                layout_attrs.length);
        if (need_xmlns) {
            AttributeDescriptor desc = new XmlnsAttributeDescriptor(
                    "android",  //$NON-NLS-1$
                    SdkConstants.NS_RESOURCES);
            mCachedAttributeDescriptors[direct_attrs.length + layout_attrs.length] = desc;
        }

        return mCachedAttributeDescriptors;
    
protected voidsetUiParent(com.android.ide.eclipse.editors.uimodel.UiElementNode parent)
Sets the parent of this UI node.

Also removes the cached AttributeDescriptor array that depends on the current UiParent.

        super.setUiParent(parent);
        mCachedAttributeDescriptors = null;