Mercurial > hg > de.codedo.java.editor
annotate src/de/codedo/java/editor/CodedoJavaEditor.java @ 9:935df68696c0 default tip
Reflection Code in eigene Klasse verschoben.
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Thu, 15 Oct 2020 12:05:06 +0200 |
parents | 778c251baa66 |
children |
rev | line source |
---|---|
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 package de.codedo.java.editor; |
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 |
9
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
3 import static de.codedo.java.editor.ReflectionUtils.getFieldValue; |
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
4 import static de.codedo.java.editor.ReflectionUtils.setFieldValue; |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 |
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:
0
diff
changeset
|
6 import org.eclipse.jdt.core.IJavaElement; |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; |
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:
0
diff
changeset
|
8 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditorErrorTickUpdater; |
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:
0
diff
changeset
|
9 import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider; |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 import org.eclipse.swt.graphics.Image; |
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:
0
diff
changeset
|
11 import org.eclipse.ui.IEditorInput; |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 |
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 public class CodedoJavaEditor extends CompilationUnitEditor |
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 { |
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:
0
diff
changeset
|
15 public CodedoJavaEditor() |
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:
0
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:
0
diff
changeset
|
17 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:
0
diff
changeset
|
18 installJavaElementImageProvider(); |
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:
0
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:
0
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:
0
diff
changeset
|
21 private void installJavaElementImageProvider() |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 { |
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:
0
diff
changeset
|
23 try |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
24 { |
9
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
25 JavaEditorErrorTickUpdater tickUpdater = getFieldValue("fJavaEditorErrorTickUpdater", this); |
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
26 JavaUILabelProvider labelProvider = getFieldValue("fLabelProvider", tickUpdater); |
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
27 |
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
28 CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); |
935df68696c0
Reflection Code in eigene Klasse verschoben.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
8
diff
changeset
|
29 setFieldValue(labelProvider, "fImageLabelProvider", imageProvider); |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
30 } |
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:
0
diff
changeset
|
31 catch (ReflectiveOperationException e) |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
32 { |
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:
0
diff
changeset
|
33 throw new RuntimeException(e); |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
34 } |
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
35 } |
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
36 |
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:
0
diff
changeset
|
37 public void toggleTitleImage() |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
38 { |
6
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
39 IJavaElement javaElement = getJavaElement(); |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
40 |
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:
0
diff
changeset
|
41 CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); |
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:
0
diff
changeset
|
42 Image newTitleImage = imageProvider.toggleTitleImage(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:
0
diff
changeset
|
43 setTitleImage(newTitleImage); |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
44 } |
6
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
45 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
46 @Override |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
47 public void dispose() |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
48 { |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
49 CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
50 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
51 IJavaElement javaElement = getJavaElement(); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
52 imageProvider.resetTitleImage(javaElement); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
53 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
54 super.dispose(); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
55 } |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
56 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
57 private IJavaElement getJavaElement() |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
58 { |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
59 IEditorInput input = getEditorInput(); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
60 |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
61 // this class is registered as Java editor so we should always have a java element here |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
62 return (IJavaElement)input.getAdapter(IJavaElement.class); |
6287f5e469f1
Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
1
diff
changeset
|
63 } |
0
ca07a15b6cc8
created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
64 } |