How to determine the source of a text selection event coming from CompareEditorInput in eclipse?

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 am handling a text selection event emanating from CompareEditorInput , that is, the result of comparing two deleted file versions with a sub-loan.

Now I want to edit the text correctly. To do this, I need to know if he selects any text inside the editor of the left side or inside the editor of the right side.

How can I find out?

EDIT 2010-04-10:

A specific example of CompareEditorInput is org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput .

+4
source share
1 answer

The problem is this: org.eclipse.compare.CompareEditorInput (which contains the java sources here ) is an abstract class that is not always the "left" or "right" panel:

 /** * 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 * (eg added, deleted, and changed files), * The bottom half the content compare results * (eg 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, * eg added, deleted or changed methods and fields. */ 

Question: Do you know the exact implementation type of this CompareEditorInput object?

Ie: It is interesting to see how specific classes make choices:
org.eclipse.compare.internal.ResourceCompareInput , for example, deals with org.eclipse.jface.viewers.IStructuredSelection , and comes with a function to get the left and right IResource based on the selection .

+1
source

Source: https://habr.com/ru/post/1304939/


All Articles