How can I enable "Mark Occurrences" in a Java editor that is loaded in a multi page editor?
I am working on a multi page editor that loads opens multiple files (e.g. java, html) in separate tabs of a multi page editor. The files get opened with the default editors associated with the file type and these default editors are embedded in the multi page editor as tabs.
Here is how I am determining which editor to load (for a file type):
void createPage() throws PartInitException
{
// get editor registry
IEditorRegistry editorRegistry = Activator.getDefault().getWorkbench().getEditorRegistry();
// loop through mappings until the extension matches.
IEditorDescriptor editorDescriptor = editorRegistry.getDefaultEditor(((IFileEditorInput)getEditorInput()).getFile().getName());
// if no editor was found that is associated to the file extension
if (editorDescriptor == null)
{
IEditorRegistry registry = Activator.getDefault().getWorkbench().getEditorRegistry();
editorDescriptor = registry.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID);
}
IConfigurationElement configuration = ((EditorDescriptor) editorDescriptor).getConfigurationElement();
String className = configuration.getAttribute("class");
IEditorPart editor;
try
{
editor = (IEditorPart) WorkbenchPlugin.createExtension(configuration, "class");
} catch (CoreException e) {
throw new RuntimeException(e);
}
final int index = addPage(editor, getEditorInput());
setPageText(index, "TAB_NAME");
}
The multi tab editor gets created without any problems and the correct editors are loaded within the tabs.
But the ‘Mark Occurrences’ functionality is not working in the Java Editor when loaded in a tab.
I validated that mark occurrences is turned on. When I select a variable in the java editor in my multi page editor tab it does not highlight the other occurrences of the variable. But if I open the file in my multi tab editor and in a separate java editor at the same time and select a variable in the separate java editor it will high开发者_Python百科light the other occurrences in the separate java editor as well as the java editor that is embedded in my multi page editor. So the functionality seems to be enabled and loaded, it just does not execute the mark occurrences functionality when the selecting happens in the embedded editor.
What needs to be changed so that I can use the mark occurrences functionality from within the java editor that is embedded in my multi tab editor?
My understanding is that Mark Occurences is a central service so I assume I am missing the part that updates this service when something gets selected in my editor. Any idea on what needs to be done so the service gets updated?
Note: This problem only happens if the java editor is embedded in a multi page editor.
This functionality is build into org.eclipse.jdt.internal.ui.javaeditor.JavaEditor of org.eclipse.jdt.ui As you see it's an internal class. However you can ignore that and subclass it.
The org.eclipse.jdt.internal.ui.javaeditor.ToggleMarkOccurrencesAction will work for all open JavaEditors (try opening the same class twice with the standard CompilationUnitEditor and you will see two "mark occurences" markings).
This is because a central property PreferenceConstants.EDITOR_MARK_OCCURRENCES is set in the PreferenceStore of the JavaPlugin.
In order to show the ToggleMarkOccurrencesAction Button you will need to provide a IEditorActionBarContributor (Take a look at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditorActionContributor)
精彩评论