• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.editors.layout.gscripts.IAttributeInfo;
20 import com.android.ide.eclipse.adt.internal.editors.ui.ResourceValueCellEditor;
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.UiResourceAttributeNode;
24 import com.android.ide.eclipse.adt.internal.resources.ResourceType;
25 import com.android.sdklib.SdkConstants;
26 
27 import org.eclipse.jface.viewers.CellEditor;
28 import org.eclipse.swt.widgets.Composite;
29 
30 /**
31  * Describes an XML attribute displayed containing a value or a reference to a resource.
32  * It is displayed by a {@link UiResourceAttributeNode}.
33  */
34 public final class ReferenceAttributeDescriptor extends TextAttributeDescriptor {
35 
36     /** The {@link ResourceType} that this reference attribute can accept. It can be null,
37      * in which case any reference type can be used. */
38     private ResourceType mResourceType;
39 
40     /**
41      * Creates a reference attributes that can contain any type of resources.
42      * @param xmlLocalName The XML name of the attribute (case sensitive)
43      * @param uiName The UI name of the attribute. Cannot be an empty string and cannot be null.
44      * @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
45      *              See {@link SdkConstants#NS_RESOURCES} for a common value.
46      * @param tooltip A non-empty tooltip string or null
47      * @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
48      */
ReferenceAttributeDescriptor(String xmlLocalName, String uiName, String nsUri, String tooltip, IAttributeInfo attrInfo)49     public ReferenceAttributeDescriptor(String xmlLocalName, String uiName, String nsUri,
50             String tooltip, IAttributeInfo attrInfo) {
51         super(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
52     }
53 
54     /**
55      * Creates a reference attributes that can contain a reference to a specific
56      * {@link ResourceType}.
57      * @param resourceType The specific {@link ResourceType} that this reference attribute supports.
58      * It can be <code>null</code>, in which case, all resource types are supported.
59      * @param xmlLocalName The XML name of the attribute (case sensitive)
60      * @param uiName The UI name of the attribute. Cannot be an empty string and cannot be null.
61      * @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
62      *              See {@link SdkConstants#NS_RESOURCES} for a common value.
63      * @param tooltip A non-empty tooltip string or null
64      * @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
65      */
ReferenceAttributeDescriptor(ResourceType resourceType, String xmlLocalName, String uiName, String nsUri, String tooltip, IAttributeInfo attrInfo)66     public ReferenceAttributeDescriptor(ResourceType resourceType,
67             String xmlLocalName, String uiName, String nsUri,
68             String tooltip, IAttributeInfo attrInfo) {
69         super(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
70         mResourceType = resourceType;
71     }
72 
73 
74     /** Returns the {@link ResourceType} that this reference attribute can accept.
75      * It can be null, in which case any reference type can be used. */
getResourceType()76     public ResourceType getResourceType() {
77         return mResourceType;
78     }
79 
80     /**
81      * @return A new {@link UiResourceAttributeNode} linked to this reference descriptor.
82      */
83     @Override
createUiNode(UiElementNode uiParent)84     public UiAttributeNode createUiNode(UiElementNode uiParent) {
85         return new UiResourceAttributeNode(mResourceType, this, uiParent);
86     }
87 
88     // ------- IPropertyDescriptor Methods
89 
90     @Override
createPropertyEditor(Composite parent)91     public CellEditor createPropertyEditor(Composite parent) {
92         return new ResourceValueCellEditor(parent);
93     }
94 
95 }
96