1 /* 2 * Copyright (C) 2007 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.resources.descriptors; 18 19 import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo.Format; 20 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.descriptors.FlagAttributeDescriptor; 23 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; 24 import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor; 25 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; 26 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; 27 import com.android.ide.eclipse.adt.internal.resources.AttributeInfo; 28 import com.android.ide.eclipse.adt.internal.resources.ResourceType; 29 30 31 /** 32 * Complete description of the structure for resources XML files (under res/values/) 33 */ 34 public final class ResourcesDescriptors implements IDescriptorProvider { 35 36 // Public attributes names, attributes descriptors and elements descriptors 37 38 public static final String ROOT_ELEMENT = "resources"; //$NON-NLS-1$ 39 40 public static final String NAME_ATTR = "name"; //$NON-NLS-1$ 41 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ 42 43 private static final ResourcesDescriptors sThis = new ResourcesDescriptors(); 44 45 /** The {@link ElementDescriptor} for the root Resources element. */ 46 public final ElementDescriptor mResourcesElement; 47 getInstance()48 public static ResourcesDescriptors getInstance() { 49 return sThis; 50 } 51 52 /* 53 * @see com.android.ide.eclipse.editors.descriptors.IDescriptorProvider#getRootElementDescriptors() 54 */ getRootElementDescriptors()55 public ElementDescriptor[] getRootElementDescriptors() { 56 return new ElementDescriptor[] { mResourcesElement }; 57 } 58 getDescriptor()59 public ElementDescriptor getDescriptor() { 60 return mResourcesElement; 61 } 62 getElementDescriptor()63 public ElementDescriptor getElementDescriptor() { 64 return mResourcesElement; 65 } 66 ResourcesDescriptors()67 private ResourcesDescriptors() { 68 69 // Common attributes used in many placed 70 71 // Elements 72 73 AttributeInfo nameAttrInfo = new AttributeInfo(NAME_ATTR, new Format[] { Format.STRING } ); 74 75 ElementDescriptor color_element = new ElementDescriptor( 76 "color", //$NON-NLS-1$ 77 "Color", 78 "A @color@ value specifies an RGB value with an alpha channel, which can be used in various places such as specifying a solid color for a Drawable or the color to use for text. It always begins with a # character and then is followed by the alpha-red-green-blue information in one of the following formats: #RGB, #ARGB, #RRGGBB or #AARRGGBB.", 79 "http://code.google.com/android/reference/available-resources.html#colorvals", //$NON-NLS-1$ 80 new AttributeDescriptor[] { 81 new TextAttributeDescriptor(NAME_ATTR, 82 "Name*", 83 null /* nsUri */, 84 "The mandatory name used in referring to this color.", 85 nameAttrInfo), 86 new ColorValueDescriptor( 87 "Value*", 88 "A mandatory color value.") 89 }, 90 null, // no child nodes 91 false /* not mandatory */); 92 93 ElementDescriptor string_element = new ElementDescriptor( 94 "string", //$NON-NLS-1$ 95 "String", 96 "@Strings@, with optional simple formatting, can be stored and retrieved as resources. You can add formatting to your string by using three standard HTML tags: b, i, and u. If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes.", 97 "http://code.google.com/android/reference/available-resources.html#stringresources", //$NON-NLS-1$ 98 new AttributeDescriptor[] { 99 new TextAttributeDescriptor(NAME_ATTR, 100 "Name*", 101 null /* nsUri */, 102 "The mandatory name used in referring to this string.", 103 nameAttrInfo), 104 new TextValueDescriptor( 105 "Value*", 106 "A mandatory string value.") 107 }, 108 null, // no child nodes 109 false /* not mandatory */); 110 111 ElementDescriptor item_element = new ItemElementDescriptor( 112 "item", //$NON-NLS-1$ 113 "Item", 114 null, // TODO find javadoc 115 null, // TODO find link to javadoc 116 new AttributeDescriptor[] { 117 new TextAttributeDescriptor(NAME_ATTR, 118 "Name*", 119 null /* nsUri */, 120 "The mandatory name used in referring to this resource.", 121 nameAttrInfo), 122 new ListAttributeDescriptor(TYPE_ATTR, 123 "Type*", 124 null /* nsUri */, 125 "The mandatory type of this resource.", 126 new AttributeInfo(TYPE_ATTR, 127 new Format[] { Format.STRING, Format.ENUM } 128 ).setEnumValues(ResourceType.getNames()) 129 ), 130 new FlagAttributeDescriptor("format", //$NON-NLS-1$ 131 "Format", 132 null /* nsUri */, 133 "The optional format of this resource.", 134 new AttributeInfo("format", 135 new Format[] { Format.STRING, Format.FLAG } 136 ).setFlagValues( 137 new String[] { 138 "boolean", //$NON-NLS-1$ 139 "color", //$NON-NLS-1$ 140 "dimension", //$NON-NLS-1$ 141 "float", //$NON-NLS-1$ 142 "fraction", //$NON-NLS-1$ 143 "integer", //$NON-NLS-1$ 144 "reference", //$NON-NLS-1$ 145 "string" //$NON-NLS-1$ 146 } ) 147 ), 148 new TextValueDescriptor( 149 "Value", 150 "A standard string, hex color value, or reference to any other resource type.") 151 }, 152 null, // no child nodes 153 false /* not mandatory */); 154 155 ElementDescriptor drawable_element = new ElementDescriptor( 156 "drawable", //$NON-NLS-1$ 157 "Drawable", 158 "A @drawable@ defines a rectangle of color. Android accepts color values written in various web-style formats -- a hexadecimal constant in any of the following forms: #RGB, #ARGB, #RRGGBB, #AARRGGBB. Zero in the alpha channel means transparent. The default value is opaque.", 159 "http://code.google.com/android/reference/available-resources.html#colordrawableresources", //$NON-NLS-1$ 160 new AttributeDescriptor[] { 161 new TextAttributeDescriptor(NAME_ATTR, 162 "Name*", 163 null /* nsUri */, 164 "The mandatory name used in referring to this drawable.", 165 nameAttrInfo), 166 new TextValueDescriptor( 167 "Value*", 168 "A mandatory color value in the form #RGB, #ARGB, #RRGGBB or #AARRGGBB.") 169 }, 170 null, // no child nodes 171 false /* not mandatory */); 172 173 ElementDescriptor dimen_element = new ElementDescriptor( 174 "dimen", //$NON-NLS-1$ 175 "Dimension", 176 "You can create common dimensions to use for various screen elements by defining @dimension@ values in XML. A dimension resource is a number followed by a unit of measurement. Supported units are px (pixels), in (inches), mm (millimeters), pt (points at 72 DPI), dp (density-independent pixels) and sp (scale-independent pixels)", 177 "http://code.google.com/android/reference/available-resources.html#dimension", //$NON-NLS-1$ 178 new AttributeDescriptor[] { 179 new TextAttributeDescriptor(NAME_ATTR, 180 "Name*", 181 null /* nsUri */, 182 "The mandatory name used in referring to this dimension.", 183 nameAttrInfo), 184 new TextValueDescriptor( 185 "Value*", 186 "A mandatory dimension value is a number followed by a unit of measurement. For example: 10px, 2in, 5sp.") 187 }, 188 null, // no child nodes 189 false /* not mandatory */); 190 191 ElementDescriptor style_element = new ElementDescriptor( 192 "style", //$NON-NLS-1$ 193 "Style/Theme", 194 "Both @styles and themes@ are defined in a style block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on).", 195 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 196 new AttributeDescriptor[] { 197 new TextAttributeDescriptor(NAME_ATTR, 198 "Name*", 199 null /* nsUri */, 200 "The mandatory name used in referring to this theme.", 201 nameAttrInfo), 202 new TextAttributeDescriptor("parent", // $NON-NLS-1$ 203 "Parent", 204 null /* nsUri */, 205 "An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values.", 206 new AttributeInfo("parent", //$NON-NLS-1$ 207 new Format[] { Format.STRING })), 208 }, 209 new ElementDescriptor[] { 210 new ElementDescriptor( 211 "item", //$NON-NLS-1$ 212 "Item", 213 "A value to use in this @theme@. It can be a standard string, a hex color value, or a reference to any other resource type.", 214 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 215 new AttributeDescriptor[] { 216 new TextAttributeDescriptor(NAME_ATTR, 217 "Name*", 218 null /* nsUri */, 219 "The mandatory name used in referring to this item.", 220 nameAttrInfo), 221 new TextValueDescriptor( 222 "Value*", 223 "A mandatory standard string, hex color value, or reference to any other resource type.") 224 }, 225 null, // no child nodes 226 false /* not mandatory */) 227 }, 228 false /* not mandatory */); 229 230 ElementDescriptor string_array_element = new ElementDescriptor( 231 "string-array", //$NON-NLS-1$ 232 "String Array", 233 "An array of strings. Strings are added as underlying item elements to the array.", 234 null, // tooltips 235 new AttributeDescriptor[] { 236 new TextAttributeDescriptor(NAME_ATTR, 237 "Name*", 238 null /* nsUri */, 239 "The mandatory name used in referring to this string array.", 240 nameAttrInfo), 241 }, 242 new ElementDescriptor[] { 243 new ElementDescriptor( 244 "item", //$NON-NLS-1$ 245 "Item", 246 "A string value to use in this string array.", 247 null, // tooltip 248 new AttributeDescriptor[] { 249 new TextValueDescriptor( 250 "Value*", 251 "A mandatory string.") 252 }, 253 null, // no child nodes 254 false /* not mandatory */) 255 }, 256 false /* not mandatory */); 257 258 ElementDescriptor integer_array_element = new ElementDescriptor( 259 "integer-array", //$NON-NLS-1$ 260 "Integer Array", 261 "An array of integers. Integers are added as underlying item elements to the array.", 262 null, // tooltips 263 new AttributeDescriptor[] { 264 new TextAttributeDescriptor(NAME_ATTR, 265 "Name*", 266 null /* nsUri */, 267 "The mandatory name used in referring to this integer array.", 268 nameAttrInfo), 269 }, 270 new ElementDescriptor[] { 271 new ElementDescriptor( 272 "item", //$NON-NLS-1$ 273 "Item", 274 "An integer value to use in this integer array.", 275 null, // tooltip 276 new AttributeDescriptor[] { 277 new TextValueDescriptor( 278 "Value*", 279 "A mandatory integer.") 280 }, 281 null, // no child nodes 282 false /* not mandatory */) 283 }, 284 false /* not mandatory */); 285 286 mResourcesElement = new ElementDescriptor( 287 ROOT_ELEMENT, 288 "Resources", 289 null, 290 "http://code.google.com/android/reference/available-resources.html", //$NON-NLS-1$ 291 null, // no attributes 292 new ElementDescriptor[] { 293 string_element, 294 color_element, 295 dimen_element, 296 drawable_element, 297 style_element, 298 item_element, 299 string_array_element, 300 integer_array_element, 301 }, 302 true /* mandatory */); 303 } 304 } 305