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.values.uimodel; 18 19 import com.android.ide.eclipse.adt.AdtUtils; 20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 21 import com.android.ide.eclipse.adt.internal.editors.values.descriptors.ItemElementDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.values.descriptors.ValuesDescriptors; 23 24 import org.w3c.dom.Element; 25 import org.w3c.dom.Node; 26 27 /** 28 * {@link UiItemElementNode} is a special version of {@link UiElementNode} that 29 * customizes the element display to include the item type attribute if present. 30 */ 31 public class UiItemElementNode extends UiElementNode { 32 33 /** 34 * Creates a new {@link UiElementNode} described by a given {@link ItemElementDescriptor}. 35 * 36 * @param elementDescriptor The {@link ItemElementDescriptor} for the XML node. Cannot be null. 37 */ 38 public UiItemElementNode(ItemElementDescriptor elementDescriptor) { 39 super(elementDescriptor); 40 } 41 42 @Override 43 public String getShortDescription() { 44 Node xmlNode = getXmlNode(); 45 if (xmlNode != null && xmlNode instanceof Element && xmlNode.hasAttributes()) { 46 47 Element elem = (Element) xmlNode; 48 String type = elem.getAttribute(ValuesDescriptors.TYPE_ATTR); 49 String name = elem.getAttribute(ValuesDescriptors.NAME_ATTR); 50 if (type != null && name != null && type.length() > 0 && name.length() > 0) { 51 type = AdtUtils.capitalize(type); 52 return String.format("%1$s (%2$s %3$s)", name, type, getDescriptor().getUiName()); 53 } 54 } 55 56 return super.getShortDescription(); 57 } 58 } 59