OSDN Git Service

snapshot
[android-x86/sdk.git] / eclipse / plugins / com.android.ide.eclipse.adt / src / com / android / ide / eclipse / adt / internal / editors / descriptors / TextAttributeDescriptor.java
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.descriptors;
18
19 import com.android.ide.eclipse.adt.internal.editors.ui.TextValueCellEditor;
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.UiTextAttributeNode;
23 import com.android.sdklib.SdkConstants;
24
25 import org.eclipse.jface.viewers.CellEditor;
26 import org.eclipse.jface.viewers.ILabelProvider;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.ui.views.properties.IPropertyDescriptor;
30
31
32 /**
33  * Describes a textual XML attribute.
34  * <p/>
35  * Such an attribute has a tooltip and would typically be displayed by
36  * {@link UiTextAttributeNode} using a label widget and text field.
37  * <p/>
38  * This is the "default" kind of attribute. If in doubt, use this.
39  */
40 public class TextAttributeDescriptor extends AttributeDescriptor implements IPropertyDescriptor {
41     private String mUiName;
42     private String mTooltip;
43     
44     /**
45      * Creates a new {@link TextAttributeDescriptor}
46      * 
47      * @param xmlLocalName The XML name of the attribute (case sensitive)
48      * @param uiName The UI name of the attribute. Cannot be an empty string and cannot be null.
49      * @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
50      *              See {@link SdkConstants#NS_RESOURCES} for a common value.
51      * @param tooltip A non-empty tooltip string or null
52      */
53     public TextAttributeDescriptor(String xmlLocalName, String uiName,
54             String nsUri, String tooltip) {
55         super(xmlLocalName, nsUri);
56         mUiName = uiName;
57         mTooltip = (tooltip != null && tooltip.length() > 0) ? tooltip : null;
58     }
59
60     /**
61      * @return The UI name of the attribute. Cannot be an empty string and cannot be null.
62      */
63     public final String getUiName() {
64         return mUiName;
65     }
66
67     /**
68      * The tooltip string is either null or a non-empty string.
69      * <p/>
70      * The tooltip is based on the Javadoc of the attribute and already processed via
71      * {@link DescriptorsUtils#formatTooltip(String)} to be displayed right away as
72      * a UI tooltip.
73      * <p/>
74      * An empty string is converted to null, to match the behavior of setToolTipText() in
75      * {@link Control}.
76      * 
77      * @return A non-empty tooltip string or null
78      */
79     public final String getTooltip() {
80         return mTooltip;
81     }
82     
83     /**
84      * @return A new {@link UiTextAttributeNode} linked to this descriptor.
85      */
86     @Override
87     public UiAttributeNode createUiNode(UiElementNode uiParent) {
88         return new UiTextAttributeNode(this, uiParent);
89     }
90     
91     // ------- IPropertyDescriptor Methods
92
93     public CellEditor createPropertyEditor(Composite parent) {
94         return new TextValueCellEditor(parent);
95     }
96
97     public String getCategory() {
98         if (isDeprecated()) {
99             return "Deprecated";
100         }
101
102         ElementDescriptor parent = getParent();
103         if (parent != null) {
104             return parent.getUiName();
105         }
106
107         return null;
108     }
109
110     public String getDescription() {
111         return mTooltip;
112     }
113
114     public String getDisplayName() {
115         return mUiName;
116     }
117
118     public String[] getFilterFlags() {
119         return null;
120     }
121
122     public Object getHelpContextIds() {
123         return null;
124     }
125
126     public Object getId() {
127         return this;
128     }
129
130     public ILabelProvider getLabelProvider() {
131         return AttributeDescriptorLabelProvider.getProvider();
132     }
133
134     public boolean isCompatibleWith(IPropertyDescriptor anotherProperty) {
135         return anotherProperty == this;
136     }
137 }