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.values.descriptors; 18 19 import com.android.ide.common.api.IAttributeInfo.Format; 20 import com.android.ide.common.resources.platform.AttributeInfo; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 23 import com.android.ide.eclipse.adt.internal.editors.descriptors.FlagAttributeDescriptor; 24 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; 25 import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor; 26 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; 27 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; 28 import com.android.resources.ResourceType; 29 30 import java.util.EnumSet; 31 32 33 /** 34 * Complete description of the structure for resources XML files (under res/values/) 35 */ 36 public final class ValuesDescriptors implements IDescriptorProvider { 37 38 // Public attributes names, attributes descriptors and elements descriptors 39 40 public static final String ROOT_ELEMENT = "resources"; //$NON-NLS-1$ 41 public static final String STRING_ELEMENT = "string"; //$NON-NLS-1$ 42 public static final String STYLE_ELEMENT = "style"; //$NON-NLS-1$ 43 public static final String COLOR_ELEMENT = "color"; //$NON-NLS-1$ 44 public static final String DIMEN_ELEMENT = "dimen"; //$NON-NLS-1$ 45 public static final String DRAWABLE_ELEMENT = "drawable"; //$NON-NLS-1$ 46 public static final String INTEGER_ARRAY_ELEMENT = "integer-array"; //$NON-NLS-1$ 47 public static final String STRING_ARRAY_ELEMENT = "string-array"; //$NON-NLS-1$ 48 49 public static final String ITEM_TAG = "item"; //$NON-NLS-1$ 50 public static final String NAME_ATTR = "name"; //$NON-NLS-1$ 51 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ 52 public static final String PARENT_ATTR = "parent"; //$NON-NLS-1$ 53 54 private static final ValuesDescriptors sThis = new ValuesDescriptors(); 55 56 /** The {@link ElementDescriptor} for the root Resources element. */ 57 public final ElementDescriptor mResourcesElement; 58 59 public static ValuesDescriptors getInstance() { 60 return sThis; 61 } 62 63 /* 64 * @see com.android.ide.eclipse.editors.descriptors.IDescriptorProvider#getRootElementDescriptors() 65 */ 66 @Override 67 public ElementDescriptor[] getRootElementDescriptors() { 68 return new ElementDescriptor[] { mResourcesElement }; 69 } 70 71 @Override 72 public ElementDescriptor getDescriptor() { 73 return mResourcesElement; 74 } 75 76 public ElementDescriptor getElementDescriptor() { 77 return mResourcesElement; 78 } 79 80 private ValuesDescriptors() { 81 82 // Common attributes used in many placed 83 84 // Elements 85 86 AttributeInfo nameAttrInfo = new AttributeInfo(NAME_ATTR, Format.STRING_SET); 87 88 ElementDescriptor color_element = new ElementDescriptor( 89 COLOR_ELEMENT, 90 "Color", 91 "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.", 92 "http://code.google.com/android/reference/available-resources.html#colorvals", //$NON-NLS-1$ 93 new AttributeDescriptor[] { 94 new TextAttributeDescriptor(NAME_ATTR, 95 null /* nsUri */, 96 nameAttrInfo), 97 new ColorValueDescriptor( 98 "Value*", 99 "A mandatory color value.") 100 .setTooltip("The mandatory name used in referring to this color.") 101 }, 102 null, // no child nodes 103 false /* not mandatory */); 104 105 ElementDescriptor string_element = new ElementDescriptor( 106 STRING_ELEMENT, 107 "String", 108 "@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.", 109 "http://code.google.com/android/reference/available-resources.html#stringresources", //$NON-NLS-1$ 110 new AttributeDescriptor[] { 111 new TextAttributeDescriptor(NAME_ATTR, 112 null /* nsUri */, 113 nameAttrInfo) 114 .setTooltip("The mandatory name used in referring to this string."), 115 new TextValueDescriptor( 116 "Value*", 117 "A mandatory string value.") 118 }, 119 null, // no child nodes 120 false /* not mandatory */); 121 122 ElementDescriptor item_element = new ItemElementDescriptor( 123 ITEM_TAG, 124 "Item", 125 null, // TODO find javadoc 126 null, // TODO find link to javadoc 127 new AttributeDescriptor[] { 128 new TextAttributeDescriptor(NAME_ATTR, 129 null /* nsUri */, 130 nameAttrInfo) 131 .setTooltip("The mandatory name used in referring to this resource."), 132 new ListAttributeDescriptor(TYPE_ATTR, 133 null /* nsUri */, 134 new AttributeInfo(TYPE_ATTR, 135 EnumSet.of(Format.STRING, Format.ENUM) 136 ).setEnumValues(ResourceType.getNames()) 137 ).setTooltip("The mandatory type of this resource."), 138 new FlagAttributeDescriptor("format", //$NON-NLS-1$ 139 null /* nsUri */, 140 new AttributeInfo("format", 141 EnumSet.of(Format.STRING, Format.FLAG) 142 ).setFlagValues( 143 new String[] { 144 "boolean", //$NON-NLS-1$ 145 COLOR_ELEMENT, 146 "dimension", //$NON-NLS-1$ 147 "float", //$NON-NLS-1$ 148 "fraction", //$NON-NLS-1$ 149 "integer", //$NON-NLS-1$ 150 "reference", //$NON-NLS-1$ 151 "string" //$NON-NLS-1$ 152 } ) 153 ).setTooltip("The optional format of this resource."), 154 new TextValueDescriptor( 155 "Value", 156 "A standard string, hex color value, or reference to any other resource type.") 157 }, 158 null, // no child nodes 159 false /* not mandatory */); 160 161 ElementDescriptor drawable_element = new ElementDescriptor( 162 DRAWABLE_ELEMENT, 163 "Drawable", 164 "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.", 165 "http://code.google.com/android/reference/available-resources.html#colordrawableresources", //$NON-NLS-1$ 166 new AttributeDescriptor[] { 167 new TextAttributeDescriptor(NAME_ATTR, 168 null /* nsUri */, 169 nameAttrInfo) 170 .setTooltip("The mandatory name used in referring to this drawable."), 171 new TextValueDescriptor( 172 "Value*", 173 "A mandatory color value in the form #RGB, #ARGB, #RRGGBB or #AARRGGBB.") 174 }, 175 null, // no child nodes 176 false /* not mandatory */); 177 178 ElementDescriptor dimen_element = new ElementDescriptor( 179 DIMEN_ELEMENT, 180 "Dimension", 181 "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)", 182 "http://code.google.com/android/reference/available-resources.html#dimension", //$NON-NLS-1$ 183 new AttributeDescriptor[] { 184 new TextAttributeDescriptor(NAME_ATTR, 185 null /* nsUri */, 186 nameAttrInfo) 187 .setTooltip("The mandatory name used in referring to this dimension."), 188 new TextValueDescriptor( 189 "Value*", 190 "A mandatory dimension value is a number followed by a unit of measurement. For example: 10px, 2in, 5sp.") 191 }, 192 null, // no child nodes 193 false /* not mandatory */); 194 195 ElementDescriptor style_element = new ElementDescriptor( 196 STYLE_ELEMENT, 197 "Style/Theme", 198 "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).", 199 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 200 new AttributeDescriptor[] { 201 new TextAttributeDescriptor(NAME_ATTR, 202 null /* nsUri */, 203 nameAttrInfo) 204 .setTooltip("The mandatory name used in referring to this theme."), 205 new TextAttributeDescriptor("parent", //$NON-NLS-1$ 206 null /* nsUri */, 207 new AttributeInfo("parent", //$NON-NLS-1$ 208 Format.STRING_SET)) 209 .setTooltip("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."), 210 }, 211 new ElementDescriptor[] { 212 new ElementDescriptor( 213 ITEM_TAG, 214 "Item", 215 "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.", 216 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 217 new AttributeDescriptor[] { 218 new TextAttributeDescriptor(NAME_ATTR, 219 null /* nsUri */, 220 nameAttrInfo) 221 .setTooltip("The mandatory name used in referring to this item."), 222 new TextValueDescriptor( 223 "Value*", 224 "A mandatory standard string, hex color value, or reference to any other resource type.") 225 }, 226 null, // no child nodes 227 false /* not mandatory */) 228 }, 229 false /* not mandatory */); 230 231 ElementDescriptor string_array_element = new ElementDescriptor( 232 STRING_ARRAY_ELEMENT, 233 "String Array", 234 "An array of strings. Strings are added as underlying item elements to the array.", 235 null, // tooltips 236 new AttributeDescriptor[] { 237 new TextAttributeDescriptor(NAME_ATTR, 238 null /* nsUri */, 239 nameAttrInfo) 240 .setTooltip("The mandatory name used in referring to this string array."), 241 }, 242 new ElementDescriptor[] { 243 new ElementDescriptor( 244 ITEM_TAG, 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_ELEMENT, 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 null /* nsUri */, 266 nameAttrInfo) 267 .setTooltip("The mandatory name used in referring to this integer array.") 268 }, 269 new ElementDescriptor[] { 270 new ElementDescriptor( 271 ITEM_TAG, 272 "Item", 273 "An integer value to use in this integer array.", 274 null, // tooltip 275 new AttributeDescriptor[] { 276 new TextValueDescriptor( 277 "Value*", 278 "A mandatory integer.") 279 }, 280 null, // no child nodes 281 false /* not mandatory */) 282 }, 283 false /* not mandatory */); 284 285 mResourcesElement = new ElementDescriptor( 286 ROOT_ELEMENT, 287 "Resources", 288 null, 289 "http://code.google.com/android/reference/available-resources.html", //$NON-NLS-1$ 290 null, // no attributes 291 new ElementDescriptor[] { 292 string_element, 293 color_element, 294 dimen_element, 295 drawable_element, 296 style_element, 297 item_element, 298 string_array_element, 299 integer_array_element, 300 }, 301 true /* mandatory */); 302 } 303 } 304