Mercurial > hg > de.codedo.java.editor
annotate src/de/codedo/java/editor/CodedoJavaElementImageProvider.java @ 8:778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Thu, 15 Oct 2020 09:43:34 +0200 |
parents | 6287f5e469f1 |
children | 935df68696c0 |
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 |
8
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
3 import java.io.IOException; |
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
|
4 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
|
5 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
|
6 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
|
7 |
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.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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 |
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 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
|
16 { |
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 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
|
18 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
|
19 |
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 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
|
21 { |
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 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
|
23 _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
|
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 |
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 @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
|
27 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
|
28 { |
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 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
|
30 { |
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 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
|
32 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
|
33 { |
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 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
|
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 |
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 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
|
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 |
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 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
|
42 { |
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 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
|
44 { |
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 _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
|
46 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
|
47 } |
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 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
|
49 { |
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 _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
|
51 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
|
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 |
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 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
|
56 { |
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 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
|
58 { |
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 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
|
60 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
|
61 |
8
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
62 try (InputStream input = getClass().getClassLoader().getResourceAsStream("icons/icon.png")) |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
63 { |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
64 _customTitleImage = new Image(device, input); |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
65 } |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
66 catch (IOException ex) |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
67 { |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
68 throw new IllegalStateException(ex); |
778c251baa66
Anpassungen fuer aktuelles JDK. Input Stream, aus dem das Icon geladen wird, ordentlich schliessen.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
6
diff
changeset
|
69 } |
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
|
70 } |
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 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
|
72 } |
6
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
73 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
74 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
|
75 { |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
76 _editorsWithCustomTitleImage.remove(element); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
77 } |
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
|
78 } |