Home | History | Annotate | Download | only in ui
      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.ui;
     18 
     19 import com.android.ide.common.resources.ResourceFile;
     20 import com.android.ide.common.resources.ResourceItem;
     21 import com.android.resources.ResourceType;
     22 
     23 import org.eclipse.jface.viewers.ILabelProvider;
     24 import org.eclipse.jface.viewers.ILabelProviderListener;
     25 import org.eclipse.jface.viewers.ITableLabelProvider;
     26 import org.eclipse.swt.graphics.Image;
     27 import org.eclipse.ui.ISharedImages;
     28 import org.eclipse.ui.PlatformUI;
     29 
     30 /**
     31  * Label provider for the Resource Explorer TreeView.
     32  * Each level of the tree is represented by a different class.
     33  * <ul>
     34  * <li>{@link ResourceType}. This represents the list of existing Resource Type present
     35  * in the resources. This can be matched to the subclasses inside the class <code>R</code>
     36  * </li>
     37  * <ul>
     38  * <li>{@link ResourceItem}. This represents one resource. The actual type can be
     39  * {@link ConfigurableResourceItem} (which can exist in various alternate versions),
     40  * or {@link IdResourceItem}.
     41  * This is similar to the resource Ids defined as <code>R.sometype.id</code>.
     42  * </li>
     43  * <ul>
     44  * <li>{@link ResourceFile}. This represents a particular version of the {@link ResourceItem}.
     45  * It is displayed as a list of resource qualifier.
     46  * </li>
     47  * </ul>
     48  * </ul>
     49  * </ul>
     50  *
     51  * @see ResourceContentProvider
     52  */
     53 public class ResourceLabelProvider implements ILabelProvider, ITableLabelProvider {
     54     private Image mWarningImage;
     55 
     56     public ResourceLabelProvider() {
     57         mWarningImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
     58                 ISharedImages.IMG_OBJS_WARN_TSK).createImage();
     59     }
     60 
     61     /**
     62      * @see #getColumnImage(Object, int)
     63      */
     64     @Override
     65     public Image getImage(Object element) {
     66         // pass
     67         return null;
     68     }
     69 
     70     /**
     71      * @see #getColumnText(Object, int)
     72      */
     73     @Override
     74     public String getText(Object element) {
     75         return getColumnText(element, 0);
     76     }
     77 
     78     @Override
     79     public void addListener(ILabelProviderListener listener) {
     80         // pass
     81     }
     82 
     83     @Override
     84     public void dispose() {
     85         mWarningImage.dispose();
     86     }
     87 
     88     @Override
     89     public boolean isLabelProperty(Object element, String property) {
     90         return false;
     91     }
     92 
     93     @Override
     94     public void removeListener(ILabelProviderListener listener) {
     95         // pass
     96     }
     97 
     98     @Override
     99     public Image getColumnImage(Object element, int columnIndex) {
    100         if (columnIndex == 1) {
    101             if (element instanceof ResourceItem) {
    102                 ResourceItem item = (ResourceItem)element;
    103                 if (item.hasDefault() == false) {
    104                     return mWarningImage;
    105                 }
    106             }
    107         }
    108         return null;
    109     }
    110 
    111     @Override
    112     public String getColumnText(Object element, int columnIndex) {
    113         switch (columnIndex) {
    114             case 0:
    115                 if (element instanceof ResourceType) {
    116                     return ((ResourceType)element).getDisplayName();
    117                 } else if (element instanceof ResourceItem) {
    118                     return ((ResourceItem)element).getName();
    119                 } else if (element instanceof ResourceFile) {
    120                     return ((ResourceFile)element).getFolder().getConfiguration().toDisplayString();
    121                 }
    122                 break;
    123             case 1:
    124                 if (element instanceof ResourceItem) {
    125                     ResourceItem item = (ResourceItem)element;
    126                     if (item.isDeclaredInline()) {
    127                         return "Declared inline";
    128                     } else {
    129                         int count = item.getAlternateCount();
    130                         if (count > 0) {
    131                             if (item.hasDefault()) {
    132                                 count++;
    133                             }
    134                             return String.format("%1$d version(s)", count);
    135                         }
    136                     }
    137                 }
    138                 return null;
    139         }
    140         return null;
    141     }
    142 }
    143