2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.eclipse.org/org/documents/epl-v10.php
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.
17 package com.android.ide.eclipse.adt.internal.editors.descriptors;
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;
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;
33 * Describes a textual XML attribute.
35 * Such an attribute has a tooltip and would typically be displayed by
36 * {@link UiTextAttributeNode} using a label widget and text field.
38 * This is the "default" kind of attribute. If in doubt, use this.
40 public class TextAttributeDescriptor extends AttributeDescriptor implements IPropertyDescriptor {
41 private String mUiName;
42 private String mTooltip;
45 * Creates a new {@link TextAttributeDescriptor}
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
53 public TextAttributeDescriptor(String xmlLocalName, String uiName,
54 String nsUri, String tooltip) {
55 super(xmlLocalName, nsUri);
57 mTooltip = (tooltip != null && tooltip.length() > 0) ? tooltip : null;
61 * @return The UI name of the attribute. Cannot be an empty string and cannot be null.
63 public final String getUiName() {
68 * The tooltip string is either null or a non-empty string.
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
74 * An empty string is converted to null, to match the behavior of setToolTipText() in
77 * @return A non-empty tooltip string or null
79 public final String getTooltip() {
84 * @return A new {@link UiTextAttributeNode} linked to this descriptor.
87 public UiAttributeNode createUiNode(UiElementNode uiParent) {
88 return new UiTextAttributeNode(this, uiParent);
91 // ------- IPropertyDescriptor Methods
93 public CellEditor createPropertyEditor(Composite parent) {
94 return new TextValueCellEditor(parent);
97 public String getCategory() {
102 ElementDescriptor parent = getParent();
103 if (parent != null) {
104 return parent.getUiName();
110 public String getDescription() {
114 public String getDisplayName() {
118 public String[] getFilterFlags() {
122 public Object getHelpContextIds() {
126 public Object getId() {
130 public ILabelProvider getLabelProvider() {
131 return AttributeDescriptorLabelProvider.getProvider();
134 public boolean isCompatibleWith(IPropertyDescriptor anotherProperty) {
135 return anotherProperty == this;