import org.eclipse.swt.graphics.Image;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
private static final String BREAK = "$break"; //$NON-NLS-1$
/**
- * The {@link ITextAttributeCreator} interface is used by the appendAttribute() method
- * to provide a way for caller to override the kind of {@link TextAttributeDescriptor}
- * created for a give XML attribute name.
- */
- public interface ITextAttributeCreator {
- /**
- * Creates a new {@link TextAttributeDescriptor} instance for the given XML name,
- * UI name and tooltip.
- *
- * @param xmlName The XML attribute name.
- * @param uiName The UI attribute name.
- * @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 tooltip An optional tooltip.
- * @return A new {@link TextAttributeDescriptor} (or derived) instance.
- */
- public TextAttributeDescriptor create(String xmlName, String uiName, String nsUri,
- String tooltip);
- }
-
- /**
* Add all {@link AttributeInfo} to the the array of {@link AttributeDescriptor}.
*
* @param attributes The list of {@link AttributeDescriptor} to append to
* @param requiredAttributes An optional set of attributes to mark as "required" (i.e. append
* a "*" to their UI name as a hint for the user.) If not null, must contains
* entries in the form "elem-name/attr-name". Elem-name can be "*".
- * @param overrides A map [attribute name => TextAttributeDescriptor creator]. A creator
- * can either by a Class<? extends TextAttributeDescriptor> or an instance of
- * {@link ITextAttributeCreator} that instantiates the right TextAttributeDescriptor.
+ * @param overrides A map [attribute name => ITextAttributeCreator creator].
*/
public static void appendAttributes(ArrayList<AttributeDescriptor> attributes,
String elementXmlName,
String nsUri, AttributeInfo[] infos,
Set<String> requiredAttributes,
- Map<String, Object> overrides) {
+ Map<String, ITextAttributeCreator> overrides) {
for (AttributeInfo info : infos) {
boolean required = false;
if (requiredAttributes != null) {
* See {@link SdkConstants#NS_RESOURCES} for a common value.
* @param required True if the attribute is to be marked as "required" (i.e. append
* a "*" to its UI name as a hint for the user.)
- * @param overrides A map [attribute name => TextAttributeDescriptor creator]. A creator
- * can either by a Class<? extends TextAttributeDescriptor> or an instance of
- * {@link ITextAttributeCreator} that instantiates the right TextAttributeDescriptor.
+ * @param overrides A map [attribute name => ITextAttributeCreator creator].
*/
public static void appendAttribute(ArrayList<AttributeDescriptor> attributes,
String elementXmlName,
String nsUri,
AttributeInfo info, boolean required,
- Map<String, Object> overrides) {
+ Map<String, ITextAttributeCreator> overrides) {
AttributeDescriptor attr = null;
String xmlLocalName = info.getName();
sb.append("]"); //$NON-NLS-1$
if (required) {
- sb.append(".@@* "); //$NON-NLS-1$ @@ inserts a break.
- sb.append("Required.");
+ // Note: this string is split in 2 to make it translatable.
+ sb.append(".@@"); //$NON-NLS-1$ @@ inserts a break and is not translatable
+ sb.append("* Required.");
}
// The extra space at the end makes the tooltip more readable on Windows.
// Create a specialized attribute if we can
if (overrides != null) {
- for (Entry<String, Object> entry: overrides.entrySet()) {
+ for (Entry<String, ITextAttributeCreator> entry: overrides.entrySet()) {
+ // The override key can have the following formats:
+ // */xmlLocalName
+ // element/xmlLocalName
+ // element1,element2,...,elementN/xmlLocalName
String key = entry.getKey();
String elements[] = key.split("/"); //$NON-NLS-1$
String overrideAttrLocalName = null;
continue;
}
- Object override = entry.getValue();
- if (override instanceof Class<?>) {
- try {
- // The override is instance of the class to create, which must
- // have a constructor compatible with TextAttributeDescriptor.
- @SuppressWarnings("unchecked") //$NON-NLS-1$
- Class<? extends TextAttributeDescriptor> clazz =
- (Class<? extends TextAttributeDescriptor>) override;
- Constructor<? extends TextAttributeDescriptor> cons;
- cons = clazz.getConstructor(new Class<?>[] {
- String.class, String.class, String.class, String.class } );
- attr = cons.newInstance(
- new Object[] { xmlLocalName, uiName, nsUri, tooltip });
- } catch (SecurityException e) {
- // ignore
- } catch (NoSuchMethodException e) {
- // ignore
- } catch (IllegalArgumentException e) {
- // ignore
- } catch (InstantiationException e) {
- // ignore
- } catch (IllegalAccessException e) {
- // ignore
- } catch (InvocationTargetException e) {
- // ignore
- }
- } else if (override instanceof ITextAttributeCreator) {
- attr = ((ITextAttributeCreator) override).create(
- xmlLocalName, uiName, nsUri, tooltip);
+ ITextAttributeCreator override = entry.getValue();
+ if (override != null) {
+ attr = override.create(xmlLocalName, uiName, nsUri, tooltip, info);
}
}
} // if overrides
--- /dev/null
+/*
+ * Copyright (C) 2010 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.eclipse.adt.editors.layout.gscripts.IAttributeInfo;
+import com.android.sdklib.SdkConstants;
+
+
+/**
+ * The {@link ITextAttributeCreator} interface is used by the appendAttribute(...) in
+ * {@link DescriptorsUtils} to allows callers to override the kind of
+ * {@link TextAttributeDescriptor} created for a given XML attribute name.
+ * <p/>
+ * The <code>create()</code> method must take arguments that are similar to the
+ * single constructor for {@link TextAttributeDescriptor}.
+ */
+public interface ITextAttributeCreator {
+
+ /**
+ * Creates a new {@link TextAttributeDescriptor} instance for the given XML name,
+ * UI name and tooltip.
+ *
+ * @param xmlLocalName The XML name of the attribute (case sensitive)
+ * @param uiName The UI attribute name.
+ * @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 tooltip An optional tooltip.
+ * @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
+ *
+ * @return A new {@link TextAttributeDescriptor} (or derived) instance.
+ */
+ public TextAttributeDescriptor create(
+ String xmlLocalName,
+ String uiName,
+ String nsUri,
+ String tooltip,
+ IAttributeInfo attrInfo);
+}
private String[] mValues = null;
/**
+ * Used by {@link DescriptorsUtils} to create instances of this descriptor.
+ */
+ public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() {
+ public TextAttributeDescriptor create(String xmlLocalName,
+ String uiName, String nsUri, String tooltip,
+ IAttributeInfo attrInfo) {
+ return new ListAttributeDescriptor(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
+ }
+ };
+
+ /**
* Creates a new {@link ListAttributeDescriptor}.
* <p/>
* If <code>attrInfo</code> is not null and has non-null enum values, these will be
package com.android.ide.eclipse.adt.internal.editors.descriptors;
import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo;
+import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo.Format;
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.ide.eclipse.adt.internal.resources.AttributeInfo;
import com.android.ide.eclipse.adt.internal.resources.ResourceType;
import com.android.sdklib.SdkConstants;
*/
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. */
+ /**
+ * 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() {
+ public TextAttributeDescriptor create(String xmlLocalName,
+ String uiName, String nsUri, String tooltip,
+ IAttributeInfo attrInfo) {
+ return new ReferenceAttributeDescriptor(
+ ResourceType.DRAWABLE,
+ xmlLocalName, uiName, nsUri, tooltip,
+ new AttributeInfo(xmlLocalName, new Format[] { Format.REFERENCE }));
+ }
+ };
+
+ /**
* Creates a reference attributes that can contain any type of resources.
* @param xmlLocalName The XML name of the attribute (case sensitive)
* @param uiName The UI name of the attribute. Cannot be an empty string and cannot be null.
* @param tooltip A non-empty tooltip string or null
* @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null.
*/
- public TextAttributeDescriptor(String xmlLocalName, String uiName,
- String nsUri, String tooltip, IAttributeInfo attrInfo) {
+ public TextAttributeDescriptor(
+ String xmlLocalName,
+ String uiName,
+ String nsUri,
+ String tooltip,
+ IAttributeInfo attrInfo) {
super(xmlLocalName, nsUri, attrInfo);
mUiName = uiName;
mTooltip = (tooltip != null && tooltip.length() > 0) ? tooltip : null;
import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.ITextAttributeCreator;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ReferenceAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.resources.AttributeInfo;
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo;
-import com.android.ide.eclipse.adt.internal.resources.ResourceType;
import com.android.sdklib.SdkConstants;
import org.eclipse.core.runtime.IStatus;
// The key for each override is "element1,element2,.../attr-xml-local-name" or
// "*/attr-xml-local-name" to match the attribute in any element.
- Map<String, Object> overrides = new HashMap<String, Object>();
+ Map<String, ITextAttributeCreator> overrides = new HashMap<String, ITextAttributeCreator>();
- overrides.put("*/icon", new DescriptorsUtils.ITextAttributeCreator() { //$NON-NLS-1$
- public TextAttributeDescriptor create(String xmlName, String uiName, String nsUri,
- String tooltip) {
- return new ReferenceAttributeDescriptor(
- ResourceType.DRAWABLE,
- xmlName, uiName, nsUri,
- tooltip,
- new AttributeInfo(xmlName, new Format[] { Format.REFERENCE }) );
- }
- });
+ overrides.put("*/icon", ReferenceAttributeDescriptor.CREATOR); //$NON-NLS-1$
- overrides.put("*/theme", ThemeAttributeDescriptor.class); //$NON-NLS-1$
- overrides.put("*/permission", ListAttributeDescriptor.class); //$NON-NLS-1$
- overrides.put("*/targetPackage", ManifestPkgAttrDescriptor.class); //$NON-NLS-1$
+ overrides.put("*/theme", ThemeAttributeDescriptor.CREATOR); //$NON-NLS-1$
+ overrides.put("*/permission", ListAttributeDescriptor.CREATOR); //$NON-NLS-1$
+ overrides.put("*/targetPackage", ManifestPkgAttrDescriptor.CREATOR); //$NON-NLS-1$
- overrides.put("uses-library/name", ListAttributeDescriptor.class); //$NON-NLS-1$
+ overrides.put("uses-library/name", ListAttributeDescriptor.CREATOR); //$NON-NLS-1$
+ overrides.put("action,category,uses-permission/" + ANDROID_NAME_ATTR, //$NON-NLS-1$
+ ListAttributeDescriptor.CREATOR);
- overrides.put("action,category,uses-permission/" + ANDROID_NAME_ATTR, //$NON-NLS-1$
- ListAttributeDescriptor.class);
- overrides.put("application/" + ANDROID_NAME_ATTR, ApplicationAttributeDescriptor.class); //$NON-NLS-1$
+ overrides.put("application/" + ANDROID_NAME_ATTR, //$NON-NLS-1$
+ ApplicationAttributeDescriptor.CREATOR);
overrideClassName(overrides, "activity", SdkConstants.CLASS_ACTIVITY); //$NON-NLS-1$
overrideClassName(overrides, "receiver", SdkConstants.CLASS_BROADCASTRECEIVER); //$NON-NLS-1$
- overrideClassName(overrides, "service", SdkConstants.CLASS_SERVICE); //$NON-NLS-1$
+ overrideClassName(overrides, "service", SdkConstants.CLASS_SERVICE); //$NON-NLS-1$
overrideClassName(overrides, "provider", SdkConstants.CLASS_CONTENTPROVIDER); //$NON-NLS-1$
overrideClassName(overrides, "instrumentation", SdkConstants.CLASS_INSTRUMENTATION); //$NON-NLS-1$
* Sets up an attribute override for ANDROID_NAME_ATTR using a ClassAttributeDescriptor
* with the specified class name.
*/
- private static void overrideClassName(Map<String, Object> overrides,
- String elementName, final String className) {
+ private static void overrideClassName(
+ Map<String, ITextAttributeCreator> overrides,
+ String elementName,
+ final String className) {
overrides.put(elementName + "/" + ANDROID_NAME_ATTR,
- new DescriptorsUtils.ITextAttributeCreator() {
+ new ITextAttributeCreator() {
public TextAttributeDescriptor create(String xmlName, String uiName, String nsUri,
- String tooltip) {
+ String tooltip, IAttributeInfo attrInfo) {
uiName += "*"; //$NON-NLS-1$
- IAttributeInfo attrInfo = new AttributeInfo(xmlName,
- new Format[] { Format.STRING } );
+ if (attrInfo == null) {
+ attrInfo = new AttributeInfo(xmlName, new Format[] { Format.STRING } );
+ }
if (SdkConstants.CLASS_ACTIVITY.equals(className)) {
return new ClassAttributeDescriptor(
*/
private void inflateElement(
Map<String, DeclareStyleableInfo> styleMap,
- Map<String, Object> overrides,
+ Map<String, ITextAttributeCreator> overrides,
Set<String> requiredAttributes,
HashMap<String, ElementDescriptor> existingElementDescs,
ElementDescriptor elemDesc,
assert styleName != null;
assert styleMap != null;
+ if (styleMap == null) {
+ return;
+ }
+
// define attributes
- DeclareStyleableInfo style = styleMap != null ? styleMap.get(styleName) : null;
+ DeclareStyleableInfo style = styleMap.get(styleName);
if (style != null) {
ArrayList<AttributeDescriptor> attrDescs = new ArrayList<AttributeDescriptor>();
DescriptorsUtils.appendAttributes(attrDescs,
package com.android.ide.eclipse.adt.internal.editors.manifest.descriptors;
import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.ITextAttributeCreator;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.manifest.model.UiClassAttributeNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
* Describes an 'Application' class XML attribute. It is displayed by a
* {@link UiClassAttributeNode}, that restricts creation and selection to classes
* inheriting from android.app.Application.
- * @deprecated Does not seem used anymore. Cleanup later.
+ * <p/>
+ * Used by the override for application/name in {@link AndroidManifestDescriptors}.
*/
public class ApplicationAttributeDescriptor extends TextAttributeDescriptor {
+ /**
+ * Used by {@link DescriptorsUtils} to create instances of this descriptor.
+ */
+ public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() {
+ public TextAttributeDescriptor create(String xmlLocalName,
+ String uiName, String nsUri, String tooltip,
+ IAttributeInfo attrInfo) {
+ return new ApplicationAttributeDescriptor(
+ xmlLocalName, uiName, nsUri, tooltip, attrInfo);
+ }
+ };
+
public ApplicationAttributeDescriptor(String xmlLocalName, String uiName,
String nsUri, String tooltip, IAttributeInfo attrInfo) {
super(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
package com.android.ide.eclipse.adt.internal.editors.manifest.descriptors;
import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.ITextAttributeCreator;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.manifest.model.UiManifestPkgAttrNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
/**
* Describes a package XML attribute. It is displayed by a {@link UiManifestPkgAttrNode}.
- * @deprecated Does not seem used anymore. Cleanup later.
+ * <p/>
+ * Used by the override for .../targetPackage in {@link AndroidManifestDescriptors}.
*/
public class ManifestPkgAttrDescriptor extends TextAttributeDescriptor {
+ /**
+ * Used by {@link DescriptorsUtils} to create instances of this descriptor.
+ */
+ public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() {
+ public TextAttributeDescriptor create(String xmlLocalName,
+ String uiName, String nsUri, String tooltip,
+ IAttributeInfo attrInfo) {
+ return new ManifestPkgAttrDescriptor(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
+ }
+ };
+
public ManifestPkgAttrDescriptor(String xmlLocalName, String uiName, String nsUri,
String tooltip, IAttributeInfo attrInfo) {
super(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
package com.android.ide.eclipse.adt.internal.editors.manifest.descriptors;
import com.android.ide.eclipse.adt.editors.layout.gscripts.IAttributeInfo;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils;
+import com.android.ide.eclipse.adt.internal.editors.descriptors.ITextAttributeCreator;
import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
/**
* Describes a Theme/Style XML attribute displayed by a {@link UiResourceAttributeNode}
- * @deprecated Does not seem used anymore. Cleanup later.
+ * <p/>
+ * Used by the override for .../theme in {@link AndroidManifestDescriptors}.
*/
public final class ThemeAttributeDescriptor extends TextAttributeDescriptor {
+ /**
+ * Used by {@link DescriptorsUtils} to create instances of this descriptor.
+ */
+ public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() {
+ public TextAttributeDescriptor create(String xmlLocalName,
+ String uiName, String nsUri, String tooltip,
+ IAttributeInfo attrInfo) {
+ return new ThemeAttributeDescriptor(xmlLocalName, uiName, nsUri, tooltip, attrInfo);
+ }
+ };
+
public ThemeAttributeDescriptor(String xmlLocalName, String uiName, String nsUri,
String tooltip, IAttributeInfo attrInfo) {
super(xmlLocalName, uiName, nsUri, tooltip, attrInfo);