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