In my eclipse plugin I have the following code:
public class MyHandler extends AbstractHandler {
@Override
public Object execute( ExecutionEvent event ) throws ExecutionException {
ISelection sel = HandlerUtil
.getActiveWorkbenchWindowChecked( event )
.getSelectionService()
.getSelection();
if( sel instanceof TextSelection ) {
IEditorPart activeEditor = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.getActiveEditor();
IEditorInput editorInput = activeEditor.getEditorInput();
if( editorInput instanceof CompareEditorInput ) {
// here are two possible sources of the text selection, the
// left or the right side of the compare editor.
// How can I find out, which side it is from?
}
}
return null;
}
}
Here I'm handling a text selection event coming from an CompareEditorInput
, i.e. the result of comparing two remote revisions of a file with subclipse.
Now I want to handle the text selection properly. For that I have to know if it selects some text inside the left side editor or inside the right side editor.
How can I find that out?
EDIT 2010-04-10:
Th开发者_C百科e concrete instance of CompareEditorInput
is org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput
.
The issue is: org.eclipse.compare.CompareEditorInput
(which have its java sources here) is an abstract class which has not always "left" or "right" pane:
/**
* The most important part of this implementation is the setup
* of the compare/merge UI.
* The UI uses a simple browser metaphor to present compare results.
* The top half of the layout shows the structural compare results
* (e.g. added, deleted, and changed files),
* The bottom half the content compare results
* (e.g. textual differences between two files).
* A selection in the top pane is fed to the bottom pane.
* If a content viewer is registered for the type of the selected object,
* this viewer is installed in the pane.
* In addition if a structure viewer is registered for the selection type,
* the top pane is split horizontally to make room for another pane
* and the structure viewer is installed in it.
* When comparing Java files this second structure viewer would show
* the structural differences within a Java file,
* e.g. added, deleted or changed methods and fields.
*/
The question is: do you know the exact implementation type of this CompareEditorInput
object?
I.e: It is interesting to see how concrete classes deal with selection:
The org.eclipse.compare.internal.ResourceCompareInput
for instance deals with org.eclipse.jface.viewers.IStructuredSelection
, and comes with an utility function to get left and right IResource
based on the selection.
精彩评论