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