1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.layout.descriptors; 18 19 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 20 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 21 import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode; 22 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 23 24 /** 25 * {@link ViewElementDescriptor} describes the properties expected for a given XML element node 26 * representing a class in an XML Layout file. 27 * <p/> 28 * These descriptors describe Android views XML elements. 29 * <p/> 30 * The base class {@link ElementDescriptor} has a notion of "children", that is an XML element 31 * can produce another set of XML elements. Because of the flat nature of Android's layout 32 * XML files all possible views are children of the document and of themselves (that is any 33 * view group can contain any other view). This is an implied contract of this class that is 34 * enforces at construction by {@link LayoutDescriptors}. Note that by construction any code 35 * that deals with the children hierarchy must also deal with potential infinite loops since views 36 * <em>will</em> reference themselves (e.g. a ViewGroup can contain a ViewGroup). 37 * <p/> 38 * Since Views are also Java classes, they derive from each other. Here this is represented 39 * as the "super class", which denotes the fact that a given View java class derives from 40 * another class. These properties are also set at construction by {@link LayoutDescriptors}. 41 * The super class hierarchy is very different from the descriptor's children hierarchy: the 42 * later represents Java inheritance, the former represents an XML nesting capability. 43 * 44 * @see ElementDescriptor 45 */ 46 public final class ViewElementDescriptor extends ElementDescriptor { 47 48 /** The full class name (FQCN) of this view. */ 49 private String mFullClassName; 50 51 /** The list of layout attributes. Can be empty but not null. */ 52 private AttributeDescriptor[] mLayoutAttributes; 53 54 /** The super-class descriptor. Can be null. */ 55 private ViewElementDescriptor mSuperClassDesc; 56 57 /** 58 * Constructs a new {@link ViewElementDescriptor} based on its XML name, UI name, 59 * the canonical name of the class it represents, its tooltip, its SDK url, its attributes list, 60 * its children list and its mandatory flag. 61 * 62 * @param xml_name The XML element node name. Case sensitive. 63 * @param ui_name The XML element name for the user interface, typically capitalized. 64 * @param fullClassName The fully qualified class name the {@link ViewElementDescriptor} is 65 * representing. 66 * @param tooltip An optional tooltip. Can be null or empty. 67 * @param sdk_url An optional SKD URL. Can be null or empty. 68 * @param attributes The list of allowed attributes. Can be null or empty. 69 * @param layoutAttributes The list of layout attributes. Can be null or empty. 70 * @param children The list of allowed children. Can be null or empty. 71 * @param mandatory Whether this node must always exist (even for empty models). A mandatory 72 * UI node is never deleted and it may lack an actual XML node attached. A non-mandatory 73 * UI node MUST have an XML node attached and it will cease to exist when the XML node 74 * ceases to exist. 75 */ ViewElementDescriptor(String xml_name, String ui_name, String fullClassName, String tooltip, String sdk_url, AttributeDescriptor[] attributes, AttributeDescriptor[] layoutAttributes, ElementDescriptor[] children, boolean mandatory)76 public ViewElementDescriptor(String xml_name, String ui_name, 77 String fullClassName, 78 String tooltip, String sdk_url, 79 AttributeDescriptor[] attributes, AttributeDescriptor[] layoutAttributes, 80 ElementDescriptor[] children, boolean mandatory) { 81 super(xml_name, ui_name, tooltip, sdk_url, attributes, children, mandatory); 82 mFullClassName = fullClassName; 83 mLayoutAttributes = layoutAttributes != null ? layoutAttributes : new AttributeDescriptor[0]; 84 } 85 86 /** 87 * Constructs a new {@link ElementDescriptor} based on its XML name, the canonical 88 * name of the class it represents, and its children list. 89 * The UI name is build by capitalizing the XML name. 90 * The UI nodes will be non-mandatory. 91 * 92 * @param xml_name The XML element node name. Case sensitive. 93 * @param fullClassName The fully qualified class name the {@link ViewElementDescriptor} is 94 * representing. 95 * @param children The list of allowed children. Can be null or empty. 96 * @param mandatory Whether this node must always exist (even for empty models). A mandatory 97 * UI node is never deleted and it may lack an actual XML node attached. A non-mandatory 98 * UI node MUST have an XML node attached and it will cease to exist when the XML node 99 * ceases to exist. 100 * 101 * @deprecated Never used. We should clean it up someday. 102 */ ViewElementDescriptor(String xml_name, String fullClassName, ElementDescriptor[] children, boolean mandatory)103 public ViewElementDescriptor(String xml_name, String fullClassName, 104 ElementDescriptor[] children, 105 boolean mandatory) { 106 super(xml_name, children, mandatory); 107 mFullClassName = fullClassName; 108 } 109 110 /** 111 * Constructs a new {@link ElementDescriptor} based on its XML name and children list. 112 * The UI name is build by capitalizing the XML name. 113 * The UI nodes will be non-mandatory. 114 * 115 * @param xml_name The XML element node name. Case sensitive. 116 * @param fullClassName The fully qualified class name the {@link ViewElementDescriptor} is 117 * representing. 118 * @param children The list of allowed children. Can be null or empty. 119 * 120 * @deprecated Never used. We should clean it up someday. 121 */ ViewElementDescriptor(String xml_name, String fullClassName, ElementDescriptor[] children)122 public ViewElementDescriptor(String xml_name, String fullClassName, 123 ElementDescriptor[] children) { 124 super(xml_name, children); 125 mFullClassName = fullClassName; 126 } 127 128 /** 129 * Constructs a new {@link ElementDescriptor} based on its XML name and on the canonical 130 * name of the class it represents. 131 * The UI name is build by capitalizing the XML name. 132 * The UI nodes will be non-mandatory. 133 * 134 * @param xml_name The XML element node name. Case sensitive. 135 * @param fullClassName The fully qualified class name the {@link ViewElementDescriptor} is 136 * representing. 137 */ ViewElementDescriptor(String xml_name, String fullClassName)138 public ViewElementDescriptor(String xml_name, String fullClassName) { 139 super(xml_name); 140 mFullClassName = fullClassName; 141 } 142 143 /** 144 * Returns the fully qualified name of the View class represented by this element descriptor 145 * e.g. "android.view.View". 146 */ getFullClassName()147 public String getFullClassName() { 148 return mFullClassName; 149 } 150 151 /** Returns the list of layout attributes. Can be empty but not null. */ getLayoutAttributes()152 public AttributeDescriptor[] getLayoutAttributes() { 153 return mLayoutAttributes; 154 } 155 156 /** 157 * Returns a new {@link UiViewElementNode} linked to this descriptor. 158 */ 159 @Override createUiNode()160 public UiElementNode createUiNode() { 161 return new UiViewElementNode(this); 162 } 163 164 /** 165 * Returns the {@link ViewElementDescriptor} of the super-class of this View descriptor 166 * that matches the java View hierarchy. Can be null. 167 */ getSuperClassDesc()168 public ViewElementDescriptor getSuperClassDesc() { 169 return mSuperClassDesc; 170 } 171 172 /** 173 * Sets the {@link ViewElementDescriptor} of the super-class of this View descriptor 174 * that matches the java View hierarchy. Can be null. 175 */ setSuperClass(ViewElementDescriptor superClassDesc)176 public void setSuperClass(ViewElementDescriptor superClassDesc) { 177 mSuperClassDesc = superClassDesc; 178 } 179 } 180