1 /* 2 * Copyright (C) 2008 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.FlagValueCellEditor; 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.UiFlagAttributeNode; 24 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiListAttributeNode; 25 26 import org.eclipse.jface.viewers.CellEditor; 27 import org.eclipse.swt.widgets.Composite; 28 29 /** 30 * Describes a text attribute that can only contains some predefined values. 31 * It is displayed by a {@link UiListAttributeNode}. 32 * 33 * Note: in Android resources, a "flag" is a list of fixed values where one or 34 * more values can be selected using an "or", e.g. "align='left|top'". 35 * By contrast, an "enum" is a list of fixed values of which only one can be 36 * selected at a given time, e.g. "gravity='right'". 37 * <p/> 38 * This class handles the "flag" case. 39 * The "enum" case is done using {@link ListAttributeDescriptor}. 40 */ 41 public class FlagAttributeDescriptor extends TextAttributeDescriptor { 42 43 private String[] mNames; 44 45 /** 46 * Creates a new {@link FlagAttributeDescriptor}. 47 * <p/> 48 * If <code>attrInfo</code> is not null and has non-null flag values, these will be 49 * used for the list. 50 * Otherwise values are automatically extracted from the FrameworkResourceManager. 51 */ 52 public FlagAttributeDescriptor(String xmlLocalName, String nsUri, IAttributeInfo attrInfo) { 53 super(xmlLocalName, nsUri, attrInfo); 54 if (attrInfo != null) { 55 mNames = attrInfo.getFlagValues(); 56 } 57 } 58 59 /** 60 * Creates a new {@link FlagAttributeDescriptor} which uses the provided values 61 * and does not lookup the content of <code>attrInfo</code>. 62 */ 63 public FlagAttributeDescriptor(String xmlLocalName, String uiName, String nsUri, 64 String tooltip, IAttributeInfo attrInfo, String[] names) { 65 super(xmlLocalName, nsUri, attrInfo); 66 mNames = names; 67 } 68 69 /** 70 * @return The initial names of the flags. Can be null, in which case the Framework 71 * resource parser should be checked. 72 */ 73 public String[] getNames() { 74 return mNames; 75 } 76 77 /** 78 * @return A new {@link UiListAttributeNode} linked to this descriptor. 79 */ 80 @Override 81 public UiAttributeNode createUiNode(UiElementNode uiParent) { 82 return new UiFlagAttributeNode(this, uiParent); 83 } 84 85 // ------- IPropertyDescriptor Methods 86 87 @Override 88 public CellEditor createPropertyEditor(Composite parent) { 89 return new FlagValueCellEditor(parent); 90 } 91 92 } 93