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