KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > mapping > ResourceMappingLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.mapping;
12
13 import org.eclipse.core.resources.mapping.ModelProvider;
14 import org.eclipse.core.resources.mapping.ResourceMapping;
15 import org.eclipse.jface.viewers.LabelProvider;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.model.WorkbenchLabelProvider;
18
19 public class ResourceMappingLabelProvider extends LabelProvider {
20     WorkbenchLabelProvider provider = new WorkbenchLabelProvider();
21     public String JavaDoc getText(Object JavaDoc element) {
22         if (element instanceof ResourceMapping) {
23             ResourceMapping mapping = (ResourceMapping) element;
24             String JavaDoc text = provider.getText(mapping.getModelObject());
25             if (text != null && text.length() > 0)
26                 return text;
27             return super.getText(mapping.getModelObject());
28         }
29         if (element instanceof ModelProvider) {
30             ModelProvider provider = (ModelProvider) element;
31             return provider.getDescriptor().getLabel();
32         }
33         String JavaDoc text = provider.getText(element);
34         if (text != null && text.length() > 0)
35             return text;
36         return super.getText(element);
37     }
38     public Image getImage(Object JavaDoc element) {
39         Image image = provider.getImage(element);
40         if (image != null)
41             return image;
42         if (element instanceof ResourceMapping) {
43             ResourceMapping mapping = (ResourceMapping) element;
44             image = provider.getImage(mapping.getModelObject());
45             if (image != null)
46                 return image;
47         }
48         return super.getImage(element);
49     }
50     public void dispose() {
51         provider.dispose();
52         super.dispose();
53     }
54 }
Popular Tags