aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourceLabelProvider.java
blob: 5bf8615d8cf5c11b880481dec723bda7d29e8245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ide.eclipse.adt.internal.ui;

import com.android.ide.common.resources.ResourceFile;
import com.android.ide.common.resources.ResourceItem;
import com.android.resources.ResourceType;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

/**
 * Label provider for the Resource Explorer TreeView.
 * Each level of the tree is represented by a different class.
 * <ul>
 * <li>{@link ResourceType}. This represents the list of existing Resource Type present
 * in the resources. This can be matched to the subclasses inside the class <code>R</code>
 * </li>
 * <ul>
 * <li>{@link ResourceItem}. This represents one resource. The actual type can be
 * {@link ConfigurableResourceItem} (which can exist in various alternate versions),
 * or {@link IdResourceItem}.
 * This is similar to the resource Ids defined as <code>R.sometype.id</code>.
 * </li>
 * <ul>
 * <li>{@link ResourceFile}. This represents a particular version of the {@link ResourceItem}.
 * It is displayed as a list of resource qualifier.
 * </li>
 * </ul>
 * </ul>
 * </ul>
 *
 * @see ResourceContentProvider
 */
public class ResourceLabelProvider implements ILabelProvider, ITableLabelProvider {
    private Image mWarningImage;

    public ResourceLabelProvider() {
        mWarningImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
                ISharedImages.IMG_OBJS_WARN_TSK).createImage();
    }

    /**
     * @see #getColumnImage(Object, int)
     */
    @Override
    public Image getImage(Object element) {
        // pass
        return null;
    }

    /**
     * @see #getColumnText(Object, int)
     */
    @Override
    public String getText(Object element) {
        return getColumnText(element, 0);
    }

    @Override
    public void addListener(ILabelProviderListener listener) {
        // pass
    }

    @Override
    public void dispose() {
        mWarningImage.dispose();
    }

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void removeListener(ILabelProviderListener listener) {
        // pass
    }

    @Override
    public Image getColumnImage(Object element, int columnIndex) {
        if (columnIndex == 1) {
            if (element instanceof ResourceItem) {
                ResourceItem item = (ResourceItem)element;
                if (item.hasDefault() == false) {
                    return mWarningImage;
                }
            }
        }
        return null;
    }

    @Override
    public String getColumnText(Object element, int columnIndex) {
        switch (columnIndex) {
            case 0:
                if (element instanceof ResourceType) {
                    return ((ResourceType)element).getDisplayName();
                } else if (element instanceof ResourceItem) {
                    return ((ResourceItem)element).getName();
                } else if (element instanceof ResourceFile) {
                    return ((ResourceFile)element).getFolder().getConfiguration().toDisplayString();
                }
                break;
            case 1:
                if (element instanceof ResourceItem) {
                    ResourceItem item = (ResourceItem)element;
                    if (item.isDeclaredInline()) {
                        return "Declared inline";
                    } else {
                        int count = item.getAlternateCount();
                        if (count > 0) {
                            if (item.hasDefault()) {
                                count++;
                            }
                            return String.format("%1$d version(s)", count);
                        }
                    }
                }
                return null;
        }
        return null;
    }
}