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.descriptors; 18 19 import com.android.ide.common.api.IAttributeInfo; 20 import com.android.ide.eclipse.adt.internal.editors.ui.ListValueCellEditor; 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.UiListAttributeNode; 24 25 import org.eclipse.jface.viewers.CellEditor; 26 import org.eclipse.swt.widgets.Composite; 27 28 /** 29 * Describes a text attribute that can contains some predefined values. 30 * It is displayed by a {@link UiListAttributeNode}. 31 */ 32 public class ListAttributeDescriptor extends TextAttributeDescriptor { 33 34 private String[] mValues = null; 35 36 /** 37 * Used by {@link DescriptorsUtils} to create instances of this descriptor. 38 */ 39 public static final ITextAttributeCreator CREATOR = new ITextAttributeCreator() { 40 public TextAttributeDescriptor create(String xmlLocalName, 41 String uiName, String nsUri, String tooltip, 42 IAttributeInfo attrInfo) { 43 return new ListAttributeDescriptor(xmlLocalName, uiName, nsUri, tooltip, attrInfo); 44 } 45 }; 46 47 /** 48 * Creates a new {@link ListAttributeDescriptor}. 49 * <p/> 50 * If <code>attrInfo</code> is not null and has non-null enum values, these will be 51 * used for the list. 52 * Otherwise values are automatically extracted from the FrameworkResourceManager. 53 */ 54 public ListAttributeDescriptor(String xmlLocalName, String uiName, String nsUri, 55 String tooltip, IAttributeInfo attrInfo) { 56 super(xmlLocalName, uiName, nsUri, tooltip, attrInfo); 57 if (attrInfo != null) { 58 mValues = attrInfo.getEnumValues(); 59 } 60 } 61 62 /** 63 * Creates a new {@link ListAttributeDescriptor} which uses the provided values 64 * and does not lookup the content of <code>attrInfo</code>. 65 */ 66 public ListAttributeDescriptor(String xmlLocalName, String uiName, String nsUri, 67 String tooltip, IAttributeInfo attrInfo, String[] values) { 68 super(xmlLocalName, uiName, nsUri, tooltip, attrInfo); 69 mValues = values; 70 } 71 72 public String[] getValues() { 73 return mValues; 74 } 75 76 /** 77 * @return A new {@link UiListAttributeNode} linked to this descriptor. 78 */ 79 @Override 80 public UiAttributeNode createUiNode(UiElementNode uiParent) { 81 return new UiListAttributeNode(this, uiParent); 82 } 83 84 // ------- IPropertyDescriptor Methods 85 86 @Override 87 public CellEditor createPropertyEditor(Composite parent) { 88 return new ListValueCellEditor(parent); 89 } 90 } 91