annotate src/de/codedo/java/editor/CodedoJavaEditor.java @ 7:fe67b0af9b23

increment version number to 1.0.1
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 07 Sep 2015 14:49:50 +0200
parents 6287f5e469f1
children 778c251baa66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
3 import java.lang.reflect.Field;
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
4
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
5 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
6 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
7 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
8 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
9 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
10 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
11
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 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
13 {
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
14 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
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: 0
diff changeset
16 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
17 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
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: 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 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
21 {
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
22 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
23 {
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
24 JavaUILabelProvider labelProvider = getJavaUILabelProvider();
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
25 setupJavaElementImageProvider(labelProvider);
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
26 }
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
27 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
28 {
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
29 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
30 }
ca07a15b6cc8 created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 }
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 private JavaUILabelProvider getJavaUILabelProvider() throws ReflectiveOperationException
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
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: 0
diff changeset
35 JavaEditorErrorTickUpdater tickUpdater = getJavaEditorErrorTickUpdater();
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
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: 0
diff changeset
37 Field field = tickUpdater.getClass().getDeclaredField("fLabelProvider");
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
38 field.setAccessible(true);
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
39 return (JavaUILabelProvider)field.get(tickUpdater);
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
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: 0
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: 0
diff changeset
42 private JavaEditorErrorTickUpdater getJavaEditorErrorTickUpdater() throws ReflectiveOperationException
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
43 {
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
44 Field field = getClass().getSuperclass().getDeclaredField("fJavaEditorErrorTickUpdater");
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
45 field.setAccessible(true);
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
46 return (JavaEditorErrorTickUpdater)field.get(this);
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
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: 0
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: 0
diff changeset
49 private void setupJavaElementImageProvider(JavaUILabelProvider labelProvider) throws ReflectiveOperationException
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
50 {
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
51 CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider();
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
52
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
53 Field field = labelProvider.getClass().getDeclaredField("fImageLabelProvider");
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
54 field.setAccessible(true);
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
55 field.set(labelProvider, 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
56 }
ca07a15b6cc8 created a plugin that allows to set a custom icon on a java editor
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
57
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
58 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
59 {
6
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
60 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
61
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
62 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
63 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
64 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
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 @Override
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
68 public void dispose()
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
69 {
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
70 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
71
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
72 IJavaElement javaElement = getJavaElement();
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
73 imageProvider.resetTitleImage(javaElement);
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
74
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
75 super.dispose();
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
76 }
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
77
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
78 private IJavaElement getJavaElement()
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
79 {
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
80 IEditorInput input = getEditorInput();
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
81
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
82 // 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
83 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
84 }
6287f5e469f1 Reset the title image when an editor is closed.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 1
diff changeset
85
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
86 }