aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/descriptors/ValuesDescriptors.java
blob: 724e0193268977d8be2e564cc40128b887bfc568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ide.eclipse.adt.internal.editors.values.descriptors;

import static com.android.SdkConstants.ATTR_NAME;
import static com.android.SdkConstants.ATTR_TYPE;
import static com.android.SdkConstants.TAG_COLOR;
import static com.android.SdkConstants.TAG_DIMEN;
import static com.android.SdkConstants.TAG_DRAWABLE;
import static com.android.SdkConstants.TAG_INTEGER_ARRAY;
import static com.android.SdkConstants.TAG_ITEM;
import static com.android.SdkConstants.TAG_PLURALS;
import static com.android.SdkConstants.TAG_RESOURCES;
import static com.android.SdkConstants.TAG_STRING;
import static com.android.SdkConstants.TAG_STRING_ARRAY;
import static com.android.SdkConstants.TAG_STYLE;

import com.android.ide.common.api.IAttributeInfo.Format;
import com.android.ide.common.resources.platform.AttributeInfo;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.EnumAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.FlagAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor;
import com.android.resources.ResourceType;

import java.util.EnumSet;


/**
 * Complete description of the structure for resources XML files (under res/values/)
 */
public final class ValuesDescriptors implements IDescriptorProvider {
    private static final ValuesDescriptors sThis = new ValuesDescriptors();

    /** The {@link ElementDescriptor} for the root Resources element. */
    public final ElementDescriptor mResourcesElement;

    public static ValuesDescriptors getInstance() {
        return sThis;
    }

    /*
     * @see com.android.ide.eclipse.editors.descriptors.IDescriptorProvider#getRootElementDescriptors()
     */
    @Override
    public ElementDescriptor[] getRootElementDescriptors() {
        return new ElementDescriptor[] { mResourcesElement };
    }

    @Override
    public ElementDescriptor getDescriptor() {
        return mResourcesElement;
    }

    public ElementDescriptor getElementDescriptor() {
        return mResourcesElement;
    }

    private ValuesDescriptors() {

        // Common attributes used in many placed

        // Elements

        AttributeInfo nameAttrInfo = new AttributeInfo(ATTR_NAME, Format.STRING_SET);

        ElementDescriptor color_element = new ElementDescriptor(
                TAG_COLOR,
                "Color",
                "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.",
                "http://code.google.com/android/reference/available-resources.html#colorvals",  //$NON-NLS-1$
                new AttributeDescriptor[] {
                        new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo),
                        new ColorValueDescriptor(
                                "Value*",
                                "A mandatory color value.")
                        .setTooltip("The mandatory name used in referring to this color.")
                },
                null,  // no child nodes
                false /* not mandatory */);

        ElementDescriptor string_element = new ElementDescriptor(
                TAG_STRING,
                "String",
                "@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.",
                "http://code.google.com/android/reference/available-resources.html#stringresources",  //$NON-NLS-1$
                new AttributeDescriptor[] {
                        new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo)
                        .setTooltip("The mandatory name used in referring to this string."),
                        new TextValueDescriptor(
                                "Value*",
                                "A mandatory string value.")
                },
                null,  // no child nodes
                false /* not mandatory */);

        ElementDescriptor item_element = new ItemElementDescriptor(
                 TAG_ITEM,
                 "Item",
                 null,  // TODO find javadoc
                 null,  // TODO find link to javadoc
                 new AttributeDescriptor[] {
                         new TextAttributeDescriptor(ATTR_NAME,
                                 null /* nsUri */,
                                 nameAttrInfo)
                         .setTooltip("The mandatory name used in referring to this resource."),
                         new ListAttributeDescriptor(ATTR_TYPE,
                                 null /* nsUri */,
                                 new AttributeInfo(ATTR_TYPE,
                                         EnumSet.of(Format.STRING, Format.ENUM)
                                 ).setEnumValues(ResourceType.getNames())
                         ).setTooltip("The mandatory type of this resource."),
                         new FlagAttributeDescriptor("format",      //$NON-NLS-1$
                                 null /* nsUri */,
                                 new AttributeInfo("format",
                                         EnumSet.of(Format.STRING, Format.FLAG)
                                 ).setFlagValues(
                                     new String[] {
                                         "boolean",     //$NON-NLS-1$
                                         TAG_COLOR,
                                         "dimension",   //$NON-NLS-1$
                                         "float",       //$NON-NLS-1$
                                         "fraction",    //$NON-NLS-1$
                                         "integer",     //$NON-NLS-1$
                                         "reference",   //$NON-NLS-1$
                                         "string"       //$NON-NLS-1$
                                     } )
                         ).setTooltip("The optional format of this resource."),
                         new TextValueDescriptor(
                                 "Value",
                                 "A standard string, hex color value, or reference to any other resource type.")
                 },
                 null,  // no child nodes
                 false /* not mandatory */);

        ElementDescriptor drawable_element = new ElementDescriptor(
                TAG_DRAWABLE,
                "Drawable",
                "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.",
                "http://code.google.com/android/reference/available-resources.html#colordrawableresources",  //$NON-NLS-1$
                new AttributeDescriptor[] {
                        new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo)
                        .setTooltip("The mandatory name used in referring to this drawable."),
                        new TextValueDescriptor(
                                "Value*",
                                "A mandatory color value in the form #RGB, #ARGB, #RRGGBB or #AARRGGBB.")
                },
                null,  // no child nodes
                false /* not mandatory */);

        ElementDescriptor dimen_element = new ElementDescriptor(
                TAG_DIMEN,
                "Dimension",
                "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)",
                "http://code.google.com/android/reference/available-resources.html#dimension",  //$NON-NLS-1$
                new AttributeDescriptor[] {
                        new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo)
                        .setTooltip("The mandatory name used in referring to this dimension."),
                        new TextValueDescriptor(
                                "Value*",
                                "A mandatory dimension value is a number followed by a unit of measurement. For example: 10px, 2in, 5sp.")
                },
                null,  // no child nodes
                false /* not mandatory */);

         ElementDescriptor style_element = new ElementDescriptor(
                TAG_STYLE,
                "Style/Theme",
                "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).",
                "http://code.google.com/android/reference/available-resources.html#stylesandthemes",  //$NON-NLS-1$
                new AttributeDescriptor[] {
                        new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo)
                        .setTooltip("The mandatory name used in referring to this theme."),
                        new TextAttributeDescriptor("parent", //$NON-NLS-1$
                                null /* nsUri */,
                                new AttributeInfo("parent",  //$NON-NLS-1$
                                        Format.STRING_SET))
                        .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."),
                },
                new ElementDescriptor[] {
                    new ElementDescriptor(
                        TAG_ITEM,
                        "Item",
                        "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.",
                        "http://code.google.com/android/reference/available-resources.html#stylesandthemes",  //$NON-NLS-1$
                        new AttributeDescriptor[] {
                            new TextAttributeDescriptor(ATTR_NAME,
                                null /* nsUri */,
                                nameAttrInfo)
                            .setTooltip("The mandatory name used in referring to this item."),
                            new TextValueDescriptor(
                                "Value*",
                                "A mandatory standard string, hex color value, or reference to any other resource type.")
                        },
                        null,  // no child nodes
                        false /* not mandatory */)
                },
                false /* not mandatory */);

         ElementDescriptor string_array_element = new ElementDescriptor(
                 TAG_STRING_ARRAY,
                 "String Array",
                 "An array of strings. Strings are added as underlying item elements to the array.",
                 null, // tooltips
                 new AttributeDescriptor[] {
                         new TextAttributeDescriptor(ATTR_NAME,
                                 null /* nsUri */,
                                 nameAttrInfo)
                         .setTooltip("The mandatory name used in referring to this string array."),
                 },
                 new ElementDescriptor[] {
                     new ElementDescriptor(
                         TAG_ITEM,
                         "Item",
                         "A string value to use in this string array.",
                         null, // tooltip
                         new AttributeDescriptor[] {
                             new TextValueDescriptor(
                                 "Value*",
                                 "A mandatory string.")
                         },
                         null,  // no child nodes
                         false /* not mandatory */)
                 },
                 false /* not mandatory */);

         ElementDescriptor plurals_element = new ElementDescriptor(
                 TAG_PLURALS,
                 "Quantity Strings (Plurals)",
                 "A quantity string",
                 null, // tooltips
                 new AttributeDescriptor[] {
                         new TextAttributeDescriptor(ATTR_NAME,
                                 null /* nsUri */,
                                 nameAttrInfo)
                         .setTooltip("A name for the pair of strings. This name will be used as the resource ID."),
                 },
                 new ElementDescriptor[] {
                     new ElementDescriptor(
                         TAG_ITEM,
                         "Item",
                         "A plural or singular string",
                         null, // tooltip
                         new AttributeDescriptor[] {
                             new EnumAttributeDescriptor(
                                 "quantity", "Quantity", null,
                                 "A keyword value indicating when this string should be used",
                                 new AttributeInfo("quantity", Format.ENUM_SET)
                                 .setEnumValues(new String[] {
                                         "zero", //$NON-NLS-1$
                                         "one",  //$NON-NLS-1$
                                         "two",  //$NON-NLS-1$
                                         "few",  //$NON-NLS-1$
                                         "many", //$NON-NLS-1$
                                         "other" //$NON-NLS-1$
                                 }))
                         },
                         null,  // no child nodes
                         false /* not mandatory */)
                 },
                 false /* not mandatory */);

         ElementDescriptor integer_array_element = new ElementDescriptor(
                 TAG_INTEGER_ARRAY,
                 "Integer Array",
                 "An array of integers. Integers are added as underlying item elements to the array.",
                 null, // tooltips
                 new AttributeDescriptor[] {
                         new TextAttributeDescriptor(ATTR_NAME,
                                 null /* nsUri */,
                                 nameAttrInfo)
                         .setTooltip("The mandatory name used in referring to this integer array.")
                 },
                 new ElementDescriptor[] {
                     new ElementDescriptor(
                         TAG_ITEM,
                         "Item",
                         "An integer value to use in this integer array.",
                         null, // tooltip
                         new AttributeDescriptor[] {
                             new TextValueDescriptor(
                                 "Value*",
                                 "A mandatory integer.")
                         },
                         null,  // no child nodes
                         false /* not mandatory */)
                 },
                 false /* not mandatory */);

         mResourcesElement = new ElementDescriptor(
                        TAG_RESOURCES,
                        "Resources",
                        null,
                        "http://code.google.com/android/reference/available-resources.html",  //$NON-NLS-1$
                        null,  // no attributes
                        new ElementDescriptor[] {
                                string_element,
                                color_element,
                                dimen_element,
                                drawable_element,
                                style_element,
                                item_element,
                                string_array_element,
                                integer_array_element,
                                plurals_element,
                        },
                        true /* mandatory */);
    }
}