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.layout; 18 19 import com.android.annotations.VisibleForTesting; 20 import com.android.ide.eclipse.adt.internal.editors.AndroidContentAssist; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 22 import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; 23 24 import org.w3c.dom.Node; 25 26 /** 27 * Content Assist Processor for /res/layout XML files 28 */ 29 @VisibleForTesting 30 public final class LayoutContentAssist extends AndroidContentAssist { 31 32 /** 33 * Constructor for LayoutContentAssist 34 */ 35 public LayoutContentAssist() { 36 super(AndroidTargetData.DESCRIPTOR_LAYOUT); 37 } 38 39 @Override 40 protected Object[] getChoicesForElement(String parent, Node currentNode) { 41 Object[] choices = super.getChoicesForElement(parent, currentNode); 42 if (choices == null) { 43 if (currentNode.getParentNode().getNodeType() == Node.ELEMENT_NODE) { 44 String parentName = currentNode.getParentNode().getNodeName(); 45 if (parentName.indexOf('.') != -1) { 46 // Custom view with unknown children; just use the root descriptor 47 // to get all eligible views instead 48 ElementDescriptor[] children = getRootDescriptor().getChildren(); 49 for (ElementDescriptor e : children) { 50 if (e.getXmlName().startsWith(parent)) { 51 return sort(children); 52 } 53 } 54 } 55 } 56 } 57 58 return choices; 59 } 60 } 61