KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > WorkingSetLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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
12 package org.eclipse.ui.internal.dialogs;
13
14 import java.util.Hashtable JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.core.runtime.Assert;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.viewers.LabelProvider;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.ui.IWorkingSet;
23
24 public class WorkingSetLabelProvider extends LabelProvider {
25     private Map JavaDoc icons;
26
27     /**
28      * Create a new instance of the receiver.
29      */

30     public WorkingSetLabelProvider() {
31         icons = new Hashtable JavaDoc();
32     }
33
34     public void dispose() {
35         Iterator JavaDoc iterator = icons.values().iterator();
36
37         while (iterator.hasNext()) {
38             Image icon = (Image) iterator.next();
39             icon.dispose();
40         }
41         super.dispose();
42     }
43
44     public Image getImage(Object JavaDoc object) {
45         Assert.isTrue(object instanceof IWorkingSet);
46         IWorkingSet workingSet = (IWorkingSet) object;
47         ImageDescriptor imageDescriptor = workingSet.getImageDescriptor();
48
49         if (imageDescriptor == null) {
50             return null;
51         }
52
53         Image icon = (Image) icons.get(imageDescriptor);
54         if (icon == null) {
55             icon = imageDescriptor.createImage();
56             icons.put(imageDescriptor, icon);
57         }
58         return icon;
59     }
60
61     public String JavaDoc getText(Object JavaDoc object) {
62         Assert.isTrue(object instanceof IWorkingSet);
63         IWorkingSet workingSet = (IWorkingSet) object;
64         return workingSet.getLabel();
65     }
66 }
67
Popular Tags