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 * 28 * @see ElementDescriptor 29 */ 30 public final class ViewElementDescriptor extends ElementDescriptor { 31 32 private String mCanonicalClassName; 33 34 /** The list of layout attributes. Can be empty but not null. */ 35 private AttributeDescriptor[] mLayoutAttributes; 36 37 38 /** 39 * Constructs a new {@link ViewElementDescriptor} based on its XML name, UI name, 40 * the canonical name of the class it represents, its tooltip, its SDK url, its attributes list, 41 * its children list and its mandatory flag. 42 * 43 * @param xml_name The XML element node name. Case sensitive. 44 * @param ui_name The XML element name for the user interface, typically capitalized. 45 * @param canonicalClassName The canonical class name the {@link ViewElementDescriptor} is 46 * representing. 47 * @param tooltip An optional tooltip. Can be null or empty. 48 * @param sdk_url An optional SKD URL. Can be null or empty. 49 * @param attributes The list of allowed attributes. Can be null or empty. 50 * @param layoutAttributes The list of layout attributes. Can be null or empty. 51 * @param children The list of allowed children. Can be null or empty. 52 * @param mandatory Whether this node must always exist (even for empty models). A mandatory 53 * UI node is never deleted and it may lack an actual XML node attached. A non-mandatory 54 * UI node MUST have an XML node attached and it will cease to exist when the XML node 55 * ceases to exist. 56 */ ViewElementDescriptor(String xml_name, String ui_name, String canonicalClassName, String tooltip, String sdk_url, AttributeDescriptor[] attributes, AttributeDescriptor[] layoutAttributes, ElementDescriptor[] children, boolean mandatory)57 public ViewElementDescriptor(String xml_name, String ui_name, 58 String canonicalClassName, 59 String tooltip, String sdk_url, 60 AttributeDescriptor[] attributes, AttributeDescriptor[] layoutAttributes, 61 ElementDescriptor[] children, boolean mandatory) { 62 super(xml_name, ui_name, tooltip, sdk_url, attributes, children, mandatory); 63 mCanonicalClassName = canonicalClassName; 64 mLayoutAttributes = layoutAttributes != null ? layoutAttributes : new AttributeDescriptor[0]; 65 } 66 67 /** 68 * Constructs a new {@link ElementDescriptor} based on its XML name, the canonical 69 * name of the class it represents, and its children list. 70 * The UI name is build by capitalizing the XML name. 71 * The UI nodes will be non-mandatory. 72 * 73 * @param xml_name The XML element node name. Case sensitive. 74 * @param canonicalClassName The canonical class name the {@link ViewElementDescriptor} is 75 * representing. 76 * @param children The list of allowed children. Can be null or empty. 77 * @param mandatory Whether this node must always exist (even for empty models). A mandatory 78 * UI node is never deleted and it may lack an actual XML node attached. A non-mandatory 79 * UI node MUST have an XML node attached and it will cease to exist when the XML node 80 * ceases to exist. 81 */ ViewElementDescriptor(String xml_name, String canonicalClassName, ElementDescriptor[] children, boolean mandatory)82 public ViewElementDescriptor(String xml_name, String canonicalClassName, 83 ElementDescriptor[] children, 84 boolean mandatory) { 85 super(xml_name, children, mandatory); 86 mCanonicalClassName = canonicalClassName; 87 } 88 89 /** 90 * Constructs a new {@link ElementDescriptor} based on its XML name and children list. 91 * The UI name is build by capitalizing the XML name. 92 * The UI nodes will be non-mandatory. 93 * 94 * @param xml_name The XML element node name. Case sensitive. 95 * @param canonicalClassName The canonical class name the {@link ViewElementDescriptor} is 96 * representing. 97 * @param children The list of allowed children. Can be null or empty. 98 */ ViewElementDescriptor(String xml_name, String canonicalClassName, ElementDescriptor[] children)99 public ViewElementDescriptor(String xml_name, String canonicalClassName, 100 ElementDescriptor[] children) { 101 super(xml_name, children); 102 mCanonicalClassName = canonicalClassName; 103 } 104 105 /** 106 * Constructs a new {@link ElementDescriptor} based on its XML name and on the canonical 107 * name of the class it represents. 108 * The UI name is build by capitalizing the XML name. 109 * The UI nodes will be non-mandatory. 110 * 111 * @param xml_name The XML element node name. Case sensitive. 112 * @param canonicalClassName The canonical class name the {@link ViewElementDescriptor} is 113 * representing. 114 */ ViewElementDescriptor(String xml_name, String canonicalClassName)115 public ViewElementDescriptor(String xml_name, String canonicalClassName) { 116 super(xml_name); 117 mCanonicalClassName = canonicalClassName; 118 } 119 120 /** 121 * Returns the canonical name of the class represented by this element descriptor. 122 */ getCanonicalClassName()123 public String getCanonicalClassName() { 124 return mCanonicalClassName; 125 } 126 127 /** Returns the list of layout attributes. Can be empty but not null. */ getLayoutAttributes()128 public AttributeDescriptor[] getLayoutAttributes() { 129 return mLayoutAttributes; 130 } 131 132 /** 133 * @return A new {@link UiViewElementNode} linked to this descriptor. 134 */ 135 @Override createUiNode()136 public UiElementNode createUiNode() { 137 return new UiViewElementNode(this); 138 } 139 } 140