2010-03-23 57 views
4

在我的Eclipse插件,我有以下代码:如何识别来自eclipse中CompareEditorInput的文本选择事件的来源?

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; 
    } 
} 

在这里我处理文本选择的事件从CompareEditorInput到来,即与Subclipse的比较文件的两个远程修改的结果。

现在我想正确处理文本选择。为此,我必须知道它是否在左侧编辑器内或右侧编辑器内选择了一些文本。

我该怎么找到?

编辑2010-04-10:

CompareEditorInput具体实例org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput

回答

1

的问题是:org.eclipse.compare.CompareEditorInput(具有其java sources here)是一个抽象类这并不总是“左”或“右”窗格:

/** 
* 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. 
*/ 

的问题是:你知不知道确切的这个CompareEditorInput对象的实现类型?

即:它是有趣的,看看如何类混凝土选择处理:
org.eclipse.compare.internal.ResourceCompareInput例如涉及org.eclipse.jface.viewers.IStructuredSelection,并配备了一个utility function to get left and right IResource based on the selection