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 17package com.android.ide.eclipse.adt.internal.editors.descriptors; 18 19import com.android.ide.common.api.IAttributeInfo; 20import com.android.ide.eclipse.adt.internal.editors.ui.ListValueCellEditor; 21import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; 22import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 23import com.android.ide.eclipse.adt.internal.editors.uimodel.UiListAttributeNode; 24 25import org.eclipse.jface.viewers.CellEditor; 26import 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 */ 32public 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 @Override 41 public TextAttributeDescriptor create(String xmlLocalName, 42 String nsUri, IAttributeInfo attrInfo) { 43 return new ListAttributeDescriptor(xmlLocalName, nsUri, 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 nsUri, IAttributeInfo attrInfo) { 55 super(xmlLocalName, nsUri, attrInfo); 56 if (attrInfo != null) { 57 mValues = attrInfo.getEnumValues(); 58 } 59 } 60 61 /** 62 * Creates a new {@link ListAttributeDescriptor} which uses the provided values 63 * and does not lookup the content of <code>attrInfo</code>. 64 */ 65 public ListAttributeDescriptor(String xmlLocalName, String nsUri, IAttributeInfo attrInfo, 66 String[] values) { 67 super(xmlLocalName, nsUri, attrInfo); 68 mValues = values; 69 } 70 71 public String[] getValues() { 72 return mValues; 73 } 74 75 /** 76 * @return A new {@link UiListAttributeNode} linked to this descriptor. 77 */ 78 @Override 79 public UiAttributeNode createUiNode(UiElementNode uiParent) { 80 return new UiListAttributeNode(this, uiParent); 81 } 82 83 // ------- IPropertyDescriptor Methods 84 85 @Override 86 public CellEditor createPropertyEditor(Composite parent) { 87 return new ListValueCellEditor(parent); 88 } 89} 90