2015-03-13 53 views
0

我在這裏爲Eclipse創建自己的編輯器,發現問題。 如果我打開一個文件並且它已經打開,Eclipse會打開一個新的編輯器。關閉Eclipse編輯器,如果文件打開兩次

因此,我需要避免這種情況,或者在打開後關閉編輯器。

我的編輯器類是MultiPageEditorPart的子類,它有兩個選項卡:第一個是Java編輯器,第二個是文本編輯器。 Java編輯器打開.java文件,文本編輯器打開我自己的文件。 我看到一些關於如何解決這個問題的文章,但我不在這裏的任何地方實現IEditorInput接口。

任何人都可以幫助我嗎? 非常感謝

Here's我的編輯的定義:

<extension point="org.eclipse.ui.editors"> 
    <editor id="br.com.senior.wb.asas.editor.AsasEditor" 
     class="br.com.senior.wb.asas.editor.AsasEditor" 
     contributorClass="br.com.senior.wb.asas.editor.AsasEditorContributor" 
     extensions="java, afm" 
     icon="icons/editor_asas.png" name="Editor ASAS"> 
    </editor> 
</extension> 
+0

這是不是很清楚自己在做什麼。你打開什麼樣的文件?哪個編輯器打開?你想打開哪個編輯器? – 2015-03-13 11:47:26

+0

嗨。 這是一種文本文件。第二個編輯器只是一個TextEditor。 如果我嘗試打開.java兩次,它工作正常。但如果我打開另一個文件兩次,它不斷創建新的編輯器。 – 2015-03-13 11:51:10

+0

向我們展示如何使用'org.eclipse.ui.editors'擴展點定義編輯器(編輯問題以添加此項)。 – 2015-03-13 11:57:29

回答

0

如果你的意思是你要打開一個編輯器時,無論是Java或AFM文件打開時,其他文件已被打開,那麼你需要使用編輯器定義的matchingStrategy屬性來定義編輯器匹配策略。

喜歡的東西:

<extension point="org.eclipse.ui.editors"> 
    <editor id="br.com.senior.wb.asas.editor.AsasEditor" 
     class="br.com.senior.wb.asas.editor.AsasEditor" 
     contributorClass="br.com.senior.wb.asas.editor.AsasEditorContributor" 
     matchingStrategy="br.com.senior.wb.asas.editor.AsasEditorMatchingStrategy" 
     extensions="java, afm" 
     icon="icons/editor_asas.png" name="Editor ASAS"> 
    </editor> 
</extension> 
public class AsasEditorMatchingStrategy implements IEditorMatchingStrategy 
{ 
    public boolean matches(IEditorReference editorRef, IEditorInput input) 
    { 
    if (!(input instanceof IFileEditorInput)) 
     return false; 

    IFile inputFile = (IFile)input.getAdapter(IFile.class); 
    if (inputFile == null) 
     return false; 

    IFile currInputFile = (IFile)editorRef.getEditorInput().getAdapter(IFile.class); 
    if (currInputFile == null) 
     return false; 

    if (!inputFile.getProject().equals(currInputFile.getProject())) 
     return false; 

    // TODO add more checks that 'inputFile' and 'currInputFile' are a matching pair of files 
    } 
+0

它仍然真的不清楚你在做什麼。我只是在猜測。做一些調試。匹配策略是否被調用? – 2015-03-13 17:33:27

+0

是的。策略在我創建之後立即被調用。 – 2015-03-13 17:35:53

+0

那麼通過它,看看發生了什麼 – 2015-03-13 17:37:51

相關問題