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.manifest.descriptors; 18 19 import com.android.SdkConstants; 20 import com.android.ide.common.api.IAttributeInfo; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.manifest.model.UiClassAttributeNode; 23 import com.android.ide.eclipse.adt.internal.editors.manifest.model.UiClassAttributeNode.IPostTypeCreationAction; 24 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; 25 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 26 27 /** 28 * Describes an XML attribute representing a class name. 29 * It is displayed by a {@link UiClassAttributeNode}. 30 */ 31 public class ClassAttributeDescriptor extends TextAttributeDescriptor { 32 33 /** Superclass of the class value. */ 34 private String mSuperClassName; 35 36 private IPostTypeCreationAction mPostCreationAction; 37 38 /** indicates if the class parameter is mandatory */ 39 boolean mMandatory; 40 41 private final boolean mDefaultToProjectOnly; 42 43 /** 44 * Creates a new {@link ClassAttributeDescriptor} 45 * @param superClassName the fully qualified name of the superclass of the class represented 46 * by the attribute. 47 * @param xmlLocalName The XML name of the attribute (case sensitive, with android: prefix). 48 * @param nsUri The URI of the attribute. Can be null if attribute has no namespace. 49 * See {@link SdkConstants#NS_RESOURCES} for a common value. 50 * @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null. 51 * @param mandatory indicates if the class attribute is mandatory. 52 */ 53 public ClassAttributeDescriptor(String superClassName, 54 String xmlLocalName, 55 String nsUri, 56 IAttributeInfo attrInfo, 57 boolean mandatory) { 58 super(xmlLocalName, nsUri, attrInfo); 59 mSuperClassName = superClassName; 60 mDefaultToProjectOnly = true; 61 if (mandatory) { 62 mMandatory = true; 63 setRequired(true); 64 } 65 } 66 67 /** 68 * Creates a new {@link ClassAttributeDescriptor} 69 * @param superClassName the fully qualified name of the superclass of the class represented 70 * by the attribute. 71 * @param postCreationAction the {@link IPostTypeCreationAction} to be executed on the 72 * newly created class. 73 * @param xmlLocalName The XML local name of the attribute (case sensitive). 74 * @param nsUri The URI of the attribute. Can be null if attribute has no namespace. 75 * See {@link SdkConstants#NS_RESOURCES} for a common value. 76 * @param attrInfo The {@link IAttributeInfo} of this attribute. Can't be null. 77 * @param mandatory indicates if the class attribute is mandatory. 78 * @param defaultToProjectOnly True if only classes from the sources of this project should 79 * be shown by default in the class browser. 80 */ 81 public ClassAttributeDescriptor(String superClassName, 82 IPostTypeCreationAction postCreationAction, 83 String xmlLocalName, 84 String nsUri, 85 IAttributeInfo attrInfo, 86 boolean mandatory, 87 boolean defaultToProjectOnly) { 88 super(xmlLocalName, nsUri, attrInfo); 89 mSuperClassName = superClassName; 90 mPostCreationAction = postCreationAction; 91 mDefaultToProjectOnly = defaultToProjectOnly; 92 if (mandatory) { 93 mMandatory = true; 94 setRequired(true); 95 } 96 } 97 98 /** 99 * @return A new {@link UiClassAttributeNode} linked to this descriptor. 100 */ 101 @Override 102 public UiAttributeNode createUiNode(UiElementNode uiParent) { 103 return new UiClassAttributeNode(mSuperClassName, mPostCreationAction, 104 mMandatory, this, uiParent, mDefaultToProjectOnly); 105 } 106 } 107