OSDN Git Service

android-2.1_r1 snapshot
[android-x86/sdk.git] / eclipse / plugins / com.android.ide.eclipse.adt / src / com / android / ide / eclipse / adt / internal / editors / descriptors / FlagAttributeDescriptor.java
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.descriptors;
18
19 import com.android.ide.eclipse.adt.internal.editors.ui.FlagValueCellEditor;
20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
21 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
22 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiFlagAttributeNode;
23 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiListAttributeNode;
24
25 import org.eclipse.jface.viewers.CellEditor;
26 import org.eclipse.swt.widgets.Composite;
27
28 /**
29  * Describes a text attribute that can only contains some predefined values.
30  * It is displayed by a {@link UiListAttributeNode}.
31  * 
32  * Note: in Android resources, a "flag" is a list of fixed values where one or
33  * more values can be selected using an "or", e.g. "align='left|top'".
34  * By contrast, an "enum" is a list of fixed values of which only one can be
35  * selected at a given time, e.g. "gravity='right'".
36  * <p/>
37  * This class handles the "flag" case.
38  * The "enum" case is done using {@link ListAttributeDescriptor}.
39  */
40 public class FlagAttributeDescriptor extends TextAttributeDescriptor {
41
42     private String[] mNames;
43
44     /**
45      * Creates a new {@link FlagAttributeDescriptor} which automatically gets its
46      * values from the FrameworkResourceManager.
47      */
48     public FlagAttributeDescriptor(String xmlLocalName, String uiName, String nsUri,
49             String tooltip) {
50         super(xmlLocalName, uiName, nsUri, tooltip);
51     }
52
53     /**
54     * Creates a new {@link FlagAttributeDescriptor} which uses the provided values.
55     */
56     public FlagAttributeDescriptor(String xmlLocalName, String uiName, String nsUri,
57             String tooltip, String[] names) {
58        super(xmlLocalName, uiName, nsUri, tooltip);
59        mNames = names;
60     }
61
62     /**
63      * @return The initial names of the flags. Can be null, in which case the Framework
64      *         resource parser should be checked.
65      */
66     public String[] getNames() {
67         return mNames;
68     }
69     
70     /**
71      * @return A new {@link UiListAttributeNode} linked to this descriptor.
72      */
73     @Override
74     public UiAttributeNode createUiNode(UiElementNode uiParent) {
75         return new UiFlagAttributeNode(this, uiParent);
76     }
77     
78     // ------- IPropertyDescriptor Methods
79
80     @Override
81     public CellEditor createPropertyEditor(Composite parent) {
82         return new FlagValueCellEditor(parent);
83     }
84
85 }