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.ui.tree; 18 19 import com.android.ide.eclipse.adt.AdtPlugin; 20 import com.android.ide.eclipse.adt.internal.editors.IconFactory; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 23 24 import org.eclipse.jface.viewers.ILabelProvider; 25 import org.eclipse.jface.viewers.ILabelProviderListener; 26 import org.eclipse.swt.graphics.Image; 27 28 /** 29 * UiModelTreeLabelProvider is a trivial implementation of {@link ILabelProvider} 30 * where elements are expected to derive from {@link UiElementNode} or 31 * from {@link ElementDescriptor}. 32 * 33 * It is used by both the master tree viewer and by the list in the Add... selection dialog. 34 */ 35 public class UiModelTreeLabelProvider implements ILabelProvider { 36 37 public UiModelTreeLabelProvider() { 38 } 39 40 /** 41 * Returns the element's logo with a fallback on the android logo. 42 */ 43 @Override 44 public Image getImage(Object element) { 45 ElementDescriptor desc = null; 46 UiElementNode node = null; 47 48 if (element instanceof ElementDescriptor) { 49 desc = (ElementDescriptor) element; 50 } else if (element instanceof UiElementNode) { 51 node = (UiElementNode) element; 52 desc = node.getDescriptor(); 53 } 54 55 if (desc != null) { 56 Image img = desc.getCustomizedIcon(); 57 if (img != null) { 58 if (node != null && node.hasError()) { 59 return IconFactory.getInstance().addErrorIcon(img); 60 } else { 61 return img; 62 } 63 } 64 } 65 66 return AdtPlugin.getAndroidLogo(); 67 } 68 69 /** 70 * Uses UiElementNode.shortDescription for the label for this tree item. 71 */ 72 @Override 73 public String getText(Object element) { 74 if (element instanceof ElementDescriptor) { 75 ElementDescriptor desc = (ElementDescriptor) element; 76 return desc.getUiName(); 77 } else if (element instanceof UiElementNode) { 78 UiElementNode node = (UiElementNode) element; 79 return node.getShortDescription(); 80 } 81 return element.toString(); 82 } 83 84 @Override 85 public void addListener(ILabelProviderListener listener) { 86 // pass 87 } 88 89 @Override 90 public void dispose() { 91 // pass 92 } 93 94 @Override 95 public boolean isLabelProperty(Object element, String property) { 96 // pass 97 return false; 98 } 99 100 @Override 101 public void removeListener(ILabelProviderListener listener) { 102 // pass 103 } 104 } 105 106 107