KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > packageview > WorkingSetAwareLabelProvider


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.jdt.internal.ui.packageview;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.swt.graphics.Image;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20
21 import org.eclipse.ui.IWorkingSet;
22
23 public class WorkingSetAwareLabelProvider extends PackageExplorerLabelProvider {
24
25     private Map JavaDoc fImages= new HashMap JavaDoc();
26     
27     public WorkingSetAwareLabelProvider(long textFlags, int imageFlags, PackageExplorerContentProvider cp) {
28         super(textFlags, imageFlags, cp);
29     }
30
31     /**
32      * {@inheritDoc}
33      */

34     public String JavaDoc getText(Object JavaDoc element) {
35         if (element instanceof IWorkingSet) {
36             return decorateText(((IWorkingSet)element).getLabel(), element);
37         }
38         return super.getText(element);
39     }
40     
41     /**
42      * {@inheritDoc}
43      */

44     public Image getImage(Object JavaDoc element) {
45         if (element instanceof IWorkingSet) {
46             ImageDescriptor image= ((IWorkingSet)element).getImage();
47             Image result= (Image)fImages.get(image);
48             if (result == null) {
49                 result= image.createImage();
50                 fImages.put(image, result);
51             }
52             return decorateImage(result, element);
53         }
54         return super.getImage(element);
55     }
56     
57     /**
58      * {@inheritDoc}
59      */

60     public void dispose() {
61         for (Iterator JavaDoc iter= fImages.values().iterator(); iter.hasNext();) {
62             ((Image)iter.next()).dispose();
63         }
64         super.dispose();
65     }
66 }
67
Popular Tags