• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.AdtPlugin;
20 import com.android.ide.eclipse.adt.internal.editors.IconFactory;
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.sdklib.SdkConstants;
24 
25 import org.eclipse.swt.graphics.Image;
26 
27 /**
28  * {@link AttributeDescriptor} describes an XML attribute with its XML attribute name.
29  * <p/>
30  * An attribute descriptor also knows which UI node should be instantiated to represent
31  * this particular attribute (e.g. text field, icon chooser, class selector, etc.)
32  * Some attributes may be hidden and have no user interface at all.
33  * <p/>
34  * This is an abstract class. Derived classes must implement data description and return
35  * the correct UiAttributeNode-derived class.
36  */
37 public abstract class AttributeDescriptor {
38     private String mXmlLocalName;
39     private ElementDescriptor mParent;
40     private final String mNsUri;
41     private boolean mDeprecated;
42 
43     /**
44      * Creates a new {@link AttributeDescriptor}
45      *
46      * @param xmlLocalName The XML name of the attribute (case sensitive)
47      * @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
48      *              See {@link SdkConstants#NS_RESOURCES} for a common value.
49      */
AttributeDescriptor(String xmlLocalName, String nsUri)50     public AttributeDescriptor(String xmlLocalName, String nsUri) {
51         mXmlLocalName = xmlLocalName;
52         mNsUri = nsUri;
53     }
54 
55     /**
56      * Returns the XML local name of the attribute (case sensitive)
57      */
getXmlLocalName()58     public final String getXmlLocalName() {
59         return mXmlLocalName;
60     }
61 
getNamespaceUri()62     public final String getNamespaceUri() {
63         return mNsUri;
64     }
65 
setParent(ElementDescriptor parent)66     final void setParent(ElementDescriptor parent) {
67         mParent = parent;
68     }
69 
getParent()70     public final ElementDescriptor getParent() {
71         return mParent;
72     }
73 
setDeprecated(boolean isDeprecated)74     public void setDeprecated(boolean isDeprecated) {
75         mDeprecated = isDeprecated;
76     }
77 
isDeprecated()78     public boolean isDeprecated() {
79         return mDeprecated;
80     }
81 
82     /**
83      * Returns an optional icon for the attribute.
84      * <p/>
85      * By default this tries to return an icon based on the XML name of the attribute.
86      * If this fails, it tries to return the default Android logo as defined in the
87      * plugin. If all fails, it returns null.
88      *
89      * @return An icon for this element or null.
90      */
getIcon()91     public Image getIcon() {
92         IconFactory factory = IconFactory.getInstance();
93         Image icon;
94         icon = factory.getIcon(getXmlLocalName(), IconFactory.COLOR_RED, IconFactory.SHAPE_CIRCLE);
95         return icon != null ? icon : AdtPlugin.getAndroidLogo();
96     }
97 
98     /**
99      * @param uiParent The {@link UiElementNode} parent of this UI attribute.
100      * @return A new {@link UiAttributeNode} linked to this descriptor or null if this
101      *         attribute has no user interface.
102      */
createUiNode(UiElementNode uiParent)103     public abstract UiAttributeNode createUiNode(UiElementNode uiParent);
104 }
105