01: package org.tcat.citd.sim.udig.bookmarks.internal;
02:
03: import java.util.Collection;
04: import java.util.HashMap;
05:
06: import org.eclipse.jface.viewers.LabelProvider;
07: import org.eclipse.swt.graphics.Image;
08: import org.tcat.citd.sim.udig.bookmarks.Bookmark;
09: import org.tcat.citd.sim.udig.bookmarks.BookmarkManager;
10: import org.tcat.citd.sim.udig.bookmarks.BookmarksPlugin;
11:
12: /**
13: * Provide labels with images to the bookmarks view
14: * <p>
15: * </p>
16: *
17: * @author cole.markham
18: * @since 1.0.0
19: */
20: public class BookmarksLabelProvider extends LabelProvider {
21: private HashMap<Class, Image> table;
22:
23: /**
24: * Default constructor
25: */
26: public BookmarksLabelProvider() {
27: try {
28: table = new HashMap<Class, Image>(4);
29: Image image = BookmarksPlugin
30: .getDefault()
31: .getImageDescriptor("icons/obj16/bookmark_obj.gif").createImage(); //$NON-NLS-1$
32: table.put(Bookmark.class, image);
33: image = BookmarksPlugin.getDefault().getImageDescriptor(
34: "icons/obj16/fldr_obj.gif").createImage(); //$NON-NLS-1$
35: table.put(MapReference.class, image);
36: image = BookmarksPlugin.getDefault().getImageDescriptor(
37: "icons/obj16/fldr_obj.gif").createImage(); //$NON-NLS-1$
38: table.put(ProjectWrapper.class, image);
39: image = BookmarksPlugin
40: .getDefault()
41: .getImageDescriptor(
42: "icons/obj16/bookmarkmanager_obj.gif").createImage(); //$NON-NLS-1$
43: table.put(BookmarkManager.class, image);
44: } catch (Exception e) {
45: e.printStackTrace();
46: }
47: }
48:
49: @Override
50: public void dispose() {
51: Collection<Image> images = table.values();
52: table.clear();
53: for (Image img : images) {
54: img.dispose();
55: }
56: }
57:
58: @Override
59: public String getText(Object obj) {
60: String name;
61: if (obj instanceof BookmarkManager) {
62: BookmarkManager bManager = (BookmarkManager) obj;
63: name = bManager.getName();
64: } else if (obj instanceof Bookmark) {
65: Bookmark bookmark = (Bookmark) obj;
66: name = bookmark.getName();
67: } else if (obj instanceof ProjectWrapper) {
68: ProjectWrapper project = (ProjectWrapper) obj;
69: name = project.getName();
70: } else if (obj instanceof MapReference) {
71: MapReference map = (MapReference) obj;
72: name = map.getName();
73: } else {
74: name = obj.toString();
75: }
76: return name;
77: }
78:
79: @Override
80: public Image getImage(Object obj) {
81: Class theClass = obj.getClass();
82: Image image = table.get(theClass);
83: return image;
84: }
85:
86: }
|