Mercurial > hg > de.codedo.java.editor
annotate src/de/codedo/java/editor/CodedoJavaElementImageProvider.java @ 6:6287f5e469f1
Reset the title image when an editor is closed.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 07 Sep 2015 14:42:44 +0200 |
parents | f7d908568cfc |
children | 778c251baa66 |
rev | line source |
---|---|
1
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 package de.codedo.java.editor; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 import java.io.InputStream; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 import java.util.HashSet; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 import java.util.Set; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 import org.eclipse.jdt.core.IJavaElement; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 import org.eclipse.swt.graphics.Device; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 import org.eclipse.swt.graphics.Image; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 import org.eclipse.ui.ISharedImages; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 import org.eclipse.ui.PlatformUI; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 public class CodedoJavaElementImageProvider extends JavaElementImageProvider |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 private Set<IJavaElement> _editorsWithCustomTitleImage; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 private Image _customTitleImage; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 public CodedoJavaElementImageProvider() |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 super(); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 _editorsWithCustomTitleImage = new HashSet<>(); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
23 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
24 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
25 @Override |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
26 public Image getImageLabel(Object element, int flags) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
27 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
28 if (element instanceof IJavaElement) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
29 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
30 IJavaElement javaElement = (IJavaElement)element; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
31 if (_editorsWithCustomTitleImage.contains(javaElement)) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
32 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
33 return getCustomTitleImage(); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
34 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
35 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
36 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
37 return super.getImageLabel(element, flags); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
38 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
39 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
40 public Image toggleTitleImage(IJavaElement element) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
41 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
42 if (_editorsWithCustomTitleImage.contains(element)) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
43 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
44 _editorsWithCustomTitleImage.remove(element); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
45 return super.getImageLabel(element, 0); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
46 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
47 else |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
48 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
49 _editorsWithCustomTitleImage.add(element); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
50 return getCustomTitleImage(); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
51 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
52 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
53 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
54 protected Image getCustomTitleImage() |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
55 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
56 if (_customTitleImage == null) |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
57 { |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
58 Image image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
59 Device device = image.getDevice(); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
60 |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
61 InputStream input = getClass().getClassLoader().getResourceAsStream("icons/icon.png"); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
62 _customTitleImage = new Image(device, input); |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
63 } |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
64 return _customTitleImage; |
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
65 } |
6
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
66 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
67 public void resetTitleImage(IJavaElement element) |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
68 { |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
69 _editorsWithCustomTitleImage.remove(element); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
70 } |
1
f7d908568cfc
Install a custom JavaElementImageProvider subclass so that the custom title image stays in place even if the editor icon is decorated e.g. by error markers.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
71 } |