1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.adt.internal.editors.descriptors;
import com.android.ide.common.api.IAttributeInfo;
import com.android.ide.common.api.IAttributeInfo.Format;
import com.android.ide.common.resources.platform.AttributeInfo;
import com.android.ide.eclipse.adt.internal.editors.ui.ResourceValueCellEditor;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiResourceAttributeNode;
import com.android.resources.ResourceType;
import com.android.sdklib.SdkConstants;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
/**
* Describes an XML attribute displayed containing a value or a reference to a resource.
* It is displayed by a {@link UiResourceAttributeNode}.
*/
public final class ReferenceAttributeDescriptor extends TextAttributeDescriptor {
/**
* The {@link ResourceType} that this reference attribute can accept. It can be null,
* in which case any reference type can be used.
*/
private ResourceType mResourceType;
/**
* Used by {@link DescriptorsUtils} to create instances of this descriptor.
*/
public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() {
@Override
public TextAttributeDescriptor create(String xmlLocalName,
String nsUri, IAttributeInfo attrInfo) {
return new ReferenceAttributeDescriptor(
ResourceType.DRAWABLE,
xmlLocalName, nsUri,
new AttributeInfo(xmlLocalName, Format.REFERENCE_SET));
}
};
/**
* Creates a reference attributes that can contain any type of resources.
* @param xmlLocalName The XML name of the attribute (case sensitive)
* @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
* See {@link SdkConstants#NS_RESOURCES} for a common value.
* @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
*/
public ReferenceAttributeDescriptor(String xmlLocalName, String nsUri,
IAttributeInfo attrInfo) {
super(xmlLocalName, nsUri, attrInfo);
}
/**
* Creates a reference attributes that can contain a reference to a specific
* {@link ResourceType}.
* @param resourceType The specific {@link ResourceType} that this reference attribute supports.
* It can be <code>null</code>, in which case, all resource types are supported.
* @param xmlLocalName The XML name of the attribute (case sensitive)
* @param nsUri The URI of the attribute. Can be null if attribute has no namespace.
* See {@link SdkConstants#NS_RESOURCES} for a common value.
* @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
*/
public ReferenceAttributeDescriptor(ResourceType resourceType,
String xmlLocalName, String nsUri, IAttributeInfo attrInfo) {
super(xmlLocalName, nsUri, attrInfo);
mResourceType = resourceType;
}
/** Returns the {@link ResourceType} that this reference attribute can accept.
* It can be null, in which case any reference type can be used. */
public ResourceType getResourceType() {
return mResourceType;
}
/**
* @return A new {@link UiResourceAttributeNode} linked to this reference descriptor.
*/
@Override
public UiAttributeNode createUiNode(UiElementNode uiParent) {
return new UiResourceAttributeNode(mResourceType, this, uiParent);
}
// ------- IPropertyDescriptor Methods
@Override
public CellEditor createPropertyEditor(Composite parent) {
return new ResourceValueCellEditor(parent);
}
}
|